Remove python code validation specific to legacy_v2
As legacy v2 code is removed and v2.1(v2 compatible mode) validate API request body through json schema, python code validation for some request param is not needed now. - UUID checks for sch_hint: 'group' - Done by JSON schema - create network param checking - moved to nova-manage(for API, JSON schema does validation) Adding more UT and also removing legacy_v2 files from py34 blacklist tests file. Partially implements blueprint remove-legacy-v2-api-code Change-Id: I2e247051c982e894b81c1ef83aa12dc9d56d94da
This commit is contained in:
parent
6e2e1dc912
commit
36ce472ace
@ -540,6 +540,16 @@ class NetworkCommands(object):
|
||||
dns1=None, dns2=None, project_id=None, priority=None,
|
||||
uuid=None, fixed_cidr=None):
|
||||
"""Creates fixed IPs for host by range."""
|
||||
|
||||
# NOTE(gmann): These checks are moved here as API layer does all these
|
||||
# validation through JSON schema.
|
||||
if not label:
|
||||
raise exception.NetworkNotCreated(req="label")
|
||||
if len(label) > 255:
|
||||
raise exception.LabelTooLong()
|
||||
if not (cidr or cidr_v6):
|
||||
raise exception.NetworkNotCreated(req="cidr or cidr_v6")
|
||||
|
||||
kwargs = {k: v for k, v in six.iteritems(locals())
|
||||
if v and k != "self"}
|
||||
if multi_host is not None:
|
||||
|
@ -1050,12 +1050,6 @@ class API(base.Base):
|
||||
if not group_hint:
|
||||
return
|
||||
|
||||
# TODO(gibi): We need to remove the following validation code when
|
||||
# removing legacy v2 code.
|
||||
if not uuidutils.is_uuid_like(group_hint):
|
||||
msg = _('Server group scheduler hint must be a UUID.')
|
||||
raise exception.InvalidInput(reason=msg)
|
||||
|
||||
return objects.InstanceGroup.get_by_uuid(context, group_hint)
|
||||
|
||||
def _create_instance(self, context, instance_type,
|
||||
|
@ -594,8 +594,7 @@ def check_http_not_implemented(logical_line, physical_line, filename):
|
||||
" common raise_feature_not_supported().")
|
||||
if pep8.noqa(physical_line):
|
||||
return
|
||||
if ("nova/api/openstack/compute/legacy_v2" in filename or
|
||||
"nova/api/openstack/compute" not in filename):
|
||||
if ("nova/api/openstack/compute" not in filename):
|
||||
return
|
||||
if re.match(http_not_implemented_re, logical_line):
|
||||
yield(0, msg)
|
||||
|
@ -1105,24 +1105,6 @@ class NetworkManager(manager.Manager):
|
||||
kwargs[name] = locals()[name]
|
||||
self._convert_int_args(kwargs)
|
||||
|
||||
# check for certain required inputs
|
||||
# NOTE: We can remove this check after v2.0 API code is removed because
|
||||
# jsonschema has checked already before this.
|
||||
label = kwargs["label"]
|
||||
if not label:
|
||||
raise exception.NetworkNotCreated(req="label")
|
||||
|
||||
# Size of "label" column in nova.networks is 255, hence the restriction
|
||||
# NOTE: We can remove this check after v2.0 API code is removed because
|
||||
# jsonschema has checked already before this.
|
||||
if len(label) > 255:
|
||||
raise exception.LabelTooLong()
|
||||
|
||||
# NOTE: We can remove this check after v2.0 API code is removed because
|
||||
# jsonschema has checked already before this.
|
||||
if not (kwargs["cidr"] or kwargs["cidr_v6"]):
|
||||
raise exception.NetworkNotCreated(req="cidr or cidr_v6")
|
||||
|
||||
kwargs["bridge"] = kwargs["bridge"] or CONF.flat_network_bridge
|
||||
kwargs["bridge_interface"] = (kwargs["bridge_interface"] or
|
||||
CONF.flat_interface)
|
||||
|
@ -257,7 +257,19 @@ class NetworkCreateExceptionsTestV21(test.TestCase):
|
||||
body=self.new_network)
|
||||
|
||||
def test_network_create_no_cidr(self):
|
||||
self.new_network['network']['cidr'] = ''
|
||||
del self.new_network['network']['cidr']
|
||||
self.assertRaises(self.validation_error,
|
||||
self.controller.create, self.req,
|
||||
body=self.new_network)
|
||||
|
||||
def test_network_create_no_label(self):
|
||||
del self.new_network['network']['label']
|
||||
self.assertRaises(self.validation_error,
|
||||
self.controller.create, self.req,
|
||||
body=self.new_network)
|
||||
|
||||
def test_network_create_label_too_long(self):
|
||||
self.new_network['network']['label'] = "x" * 256
|
||||
self.assertRaises(self.validation_error,
|
||||
self.controller.create, self.req,
|
||||
body=self.new_network)
|
||||
|
@ -7776,18 +7776,6 @@ class ComputeAPITestCase(BaseTestCase):
|
||||
group = objects.InstanceGroup.get_by_uuid(self.context, group.uuid)
|
||||
self.assertIn(refs[0]['uuid'], group.members)
|
||||
|
||||
def test_instance_create_with_group_name_fails(self):
|
||||
self.stubs.Set(fake_image._FakeImageService, 'show', self.fake_show)
|
||||
|
||||
inst_type = flavors.get_default_flavor()
|
||||
self.assertRaises(
|
||||
exception.InvalidInput,
|
||||
self.compute_api.create,
|
||||
self.context,
|
||||
inst_type,
|
||||
self.fake_image['id'],
|
||||
scheduler_hints={'group': 'non-uuid'})
|
||||
|
||||
def test_instance_create_with_group_uuid_fails_group_not_exist(self):
|
||||
self.stub_out('nova.tests.unit.image.fake._FakeImageService.show',
|
||||
self.fake_show)
|
||||
|
@ -531,10 +531,6 @@ class HackingTestCase(test.NoDBTestCase):
|
||||
self._assert_has_errors(code, checks.check_http_not_implemented,
|
||||
expected_errors=errors, filename=filename)
|
||||
|
||||
filename = "nova/api/openstack/compute/legacy_v2/test.py"
|
||||
self._assert_has_no_errors(code, checks.check_http_not_implemented,
|
||||
filename=filename)
|
||||
|
||||
def test_check_contextlib_use(self):
|
||||
code = """
|
||||
with test.nested(
|
||||
|
@ -210,6 +210,63 @@ class NetworkCommandsTestCase(test.NoDBTestCase):
|
||||
dns2='8.8.4.4',
|
||||
uuid='aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa')
|
||||
|
||||
def test_create_without_lable(self):
|
||||
self.assertRaises(exception.NetworkNotCreated,
|
||||
self.commands.create,
|
||||
cidr='10.2.0.0/24',
|
||||
num_networks=1,
|
||||
network_size=256,
|
||||
multi_host='F',
|
||||
vlan=200,
|
||||
vlan_start=201,
|
||||
vpn_start=2000,
|
||||
cidr_v6='fd00:2::/120',
|
||||
gateway='10.2.0.1',
|
||||
gateway_v6='fd00:2::22',
|
||||
bridge='br200',
|
||||
bridge_interface='eth0',
|
||||
dns1='8.8.8.8',
|
||||
dns2='8.8.4.4',
|
||||
uuid='aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa')
|
||||
|
||||
def test_create_with_lable_too_long(self):
|
||||
self.assertRaises(exception.LabelTooLong,
|
||||
self.commands.create,
|
||||
label='x' * 256,
|
||||
cidr='10.2.0.0/24',
|
||||
num_networks=1,
|
||||
network_size=256,
|
||||
multi_host='F',
|
||||
vlan=200,
|
||||
vlan_start=201,
|
||||
vpn_start=2000,
|
||||
cidr_v6='fd00:2::/120',
|
||||
gateway='10.2.0.1',
|
||||
gateway_v6='fd00:2::22',
|
||||
bridge='br200',
|
||||
bridge_interface='eth0',
|
||||
dns1='8.8.8.8',
|
||||
dns2='8.8.4.4',
|
||||
uuid='aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa')
|
||||
|
||||
def test_create_without_cidr(self):
|
||||
self.assertRaises(exception.NetworkNotCreated,
|
||||
self.commands.create,
|
||||
label='Test',
|
||||
num_networks=1,
|
||||
network_size=256,
|
||||
multi_host='F',
|
||||
vlan=200,
|
||||
vlan_start=201,
|
||||
vpn_start=2000,
|
||||
gateway='10.2.0.1',
|
||||
gateway_v6='fd00:2::22',
|
||||
bridge='br200',
|
||||
bridge_interface='eth0',
|
||||
dns1='8.8.8.8',
|
||||
dns2='8.8.4.4',
|
||||
uuid='aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa')
|
||||
|
||||
def test_list(self):
|
||||
|
||||
def fake_network_get_all(context):
|
||||
|
@ -1,10 +1,3 @@
|
||||
nova.tests.unit.api.openstack.compute.legacy_v2.test_extensions.ActionExtensionTest
|
||||
nova.tests.unit.api.openstack.compute.legacy_v2.test_extensions.ControllerExtensionTest
|
||||
nova.tests.unit.api.openstack.compute.legacy_v2.test_extensions.ExtensionControllerIdFormatTest
|
||||
nova.tests.unit.api.openstack.compute.legacy_v2.test_extensions.ExtensionManagerTest
|
||||
nova.tests.unit.api.openstack.compute.legacy_v2.test_extensions.ResourceExtensionTest
|
||||
nova.tests.unit.api.openstack.compute.legacy_v2.test_servers.ServersControllerCreateTest
|
||||
nova.tests.unit.api.openstack.compute.legacy_v2.test_servers.ServersControllerTest
|
||||
nova.tests.unit.api.openstack.compute.test_api.APITest
|
||||
nova.tests.unit.api.openstack.compute.test_api.APITestV21
|
||||
nova.tests.unit.api.openstack.compute.test_console_output.ConsoleOutputExtensionTestV2
|
||||
|
Loading…
Reference in New Issue
Block a user