@@ -0,0 +1,2779 @@
+# Copyright 2016 HPE, Inc.%0A#%0A# Licensed under the Apache License, Version 2.0 (the %22License%22); you may%0A# not use this file except in compliance with the License. You may obtain%0A# a copy of the License at%0A#%0A#      http://www.apache.org/licenses/LICENSE-2.0%0A#%0A# Unless required by applicable law or agreed to in writing, software%0A# distributed under the License is distributed on an %22AS IS%22 BASIS, WITHOUT%0A# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the%0A# License for the specific language governing permissions and limitations%0A# under the License.%0A%0Afrom oslo_config import cfg%0A%0Aimport nova.scheduler.utils%0Aimport nova.servicegroup%0Afrom nova import test%0Afrom nova.tests import fixtures as nova_fixtures%0Afrom nova.tests.functional.api import client%0Aimport nova.tests.unit.image.fake%0Afrom nova.tests.unit import policy_fixture%0A%0ACONF = cfg.CONF%0A%0A%0Aclass TestServerValidation(test.TestCase):%0A    REQUIRES_LOCKING = True%0A    microversion = None%0A%0A    def setUp(self):%0A        super(TestServerValidation, self).setUp()%0A        self.useFixture(policy_fixture.RealPolicyFixture())%0A        api_fixture = self.useFixture(nova_fixtures.OSAPIFixture(%0A            api_version='v2.1'))%0A%0A        # the image fake backend needed for image discovery%0A        nova.tests.unit.image.fake.stub_out_image_service(self)%0A        self.addCleanup(nova.tests.unit.image.fake.FakeImageService_reset)%0A%0A        self.api = api_fixture.api%0A        self.image_id = self.api.get_images()%5B0%5D%5B'id'%5D%0A        self.flavor_id = self.api.get_flavors()%5B0%5D%5B'id'%5D%0A%0A    def test_name_validation(self):%0A        %22%22%22Regression test for bug #1541691.%0A%0A        The current jsonschema validation spits a giant wall of regex%0A        at you (about 500k characters). This is not useful to%0A        determine why your request actually failed.%0A%0A        Ensure that once we fix this it doesn't regress.%0A        %22%22%22%0A        server = dict(name='server1 ',%0A                      imageRef=self.image_id,%0A                      flavorRef=self.flavor_id)%0A        try:%0A            self.api.post_server(%7B'server': server%7D)%0A        except client.OpenStackApiException as osae:%0A            # We expect this to be a 400 error with validation problems.%0A            self.assertEqual(400, osae.response.status_code)%0A            # NOTE(sdague): using expectFailure means we can land this%0A            # test while the bug still exists, then fix it after.%0A            self.expectFailure(%0A                %22This is expected to fail until bug 1541691 is fixed%22,%0A                self.assertLess,%0A                len(osae.response.content),%0A                1000,%0A                %22The length of the error response is %3E 1k. Something is %22%0A                %22wrong.%22)%0A            return%0A        self.fail(%22We should have thrown a 400 error%22)%0A

add regression test for bug #1541691