From 6a09c00cf199c36d77aa4b12e25c3f63f6aa8119 Mon Sep 17 00:00:00 2001 From: Ken'ichi Ohmichi Date: Sun, 8 May 2016 11:03:03 +0900 Subject: [PATCH] Switch api unit tests to use v2.1 API TestNeutronSecurityGroupsOutputTest and BootFromVolumeTest were tests only for legacy v2 API code, and v2.1 API were not tested on the same test cases. This patch makes the tests work for v2.1 API code for the test coverage. In addition, this patch changes a request body of BootFromVolumeTest because v2.1 API validation detected the bugs of the body like the following: * Invalid input for field/attribute volume_id. Value: 1. u'1' is not a 'uuid'" * Additional properties are not allowed (u'virtual' was unexpected) Change-Id: I9c2a53679ed6a097b062ba542dddd85a42c9964f --- .../compute/test_neutron_security_groups.py | 6 +++++- .../unit/api/openstack/compute/test_volumes.py | 14 +++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/nova/tests/unit/api/openstack/compute/test_neutron_security_groups.py b/nova/tests/unit/api/openstack/compute/test_neutron_security_groups.py index ae50656013..d69cde7536 100644 --- a/nova/tests/unit/api/openstack/compute/test_neutron_security_groups.py +++ b/nova/tests/unit/api/openstack/compute/test_neutron_security_groups.py @@ -508,7 +508,11 @@ class TestNeutronSecurityGroupsOutputTest(TestNeutronSecurityGroupsTestCase): req.body = encodeutils.safe_encode(self._encode_body(body)) req.content_type = self.content_type req.headers['Accept'] = self.content_type - res = req.get_response(fakes.wsgi_app(init_only=('servers',))) + + # NOTE: This 'os-security-groups' is for enabling security_groups + # attribute on response body. + res = req.get_response(fakes.wsgi_app_v21( + init_only=('servers', 'os-security-groups'))) return res def _encode_body(self, body): diff --git a/nova/tests/unit/api/openstack/compute/test_volumes.py b/nova/tests/unit/api/openstack/compute/test_volumes.py index acec2592cf..064a54f59f 100644 --- a/nova/tests/unit/api/openstack/compute/test_volumes.py +++ b/nova/tests/unit/api/openstack/compute/test_volumes.py @@ -170,9 +170,8 @@ class BootFromVolumeTest(test.TestCase): name='test_server', imageRef=IMAGE_UUID, flavorRef=2, min_count=1, max_count=1, block_device_mapping=[dict( - volume_id='1', + volume_id='ca9fe3f5-cede-43cb-8050-1672acabe348', device_name='/dev/vda', - virtual='root', delete_on_termination=False, )] )) @@ -180,15 +179,16 @@ class BootFromVolumeTest(test.TestCase): req.method = 'POST' req.body = jsonutils.dump_as_bytes(body) req.headers['content-type'] = 'application/json' - res = req.get_response(fakes.wsgi_app( - init_only=('os-volumes_boot', 'servers'))) + res = req.get_response(fakes.wsgi_app_v21( + init_only=('os-volumes', 'servers'))) self.assertEqual(202, res.status_int) server = jsonutils.loads(res.body)['server'] self.assertEqual(FAKE_UUID, server['id']) self.assertEqual(CONF.password_length, len(server['adminPass'])) self.assertEqual(1, len(self._block_device_mapping_seen)) self.assertTrue(self._legacy_bdm_seen) - self.assertEqual('1', self._block_device_mapping_seen[0]['volume_id']) + self.assertEqual('ca9fe3f5-cede-43cb-8050-1672acabe348', + self._block_device_mapping_seen[0]['volume_id']) self.assertEqual('/dev/vda', self._block_device_mapping_seen[0]['device_name']) @@ -208,8 +208,8 @@ class BootFromVolumeTest(test.TestCase): req.method = 'POST' req.body = jsonutils.dump_as_bytes(body) req.headers['content-type'] = 'application/json' - res = req.get_response(fakes.wsgi_app( - init_only=('os-volumes_boot', 'servers'))) + res = req.get_response(fakes.wsgi_app_v21( + init_only=('os-volumes', 'servers'))) self.assertEqual(202, res.status_int) server = jsonutils.loads(res.body)['server'] self.assertEqual(FAKE_UUID, server['id'])