From e3c089bf1dd689419a14d5a5841cbdcffdd4787e Mon Sep 17 00:00:00 2001 From: Matt Riedemann Date: Mon, 28 Jan 2019 17:31:05 -0500 Subject: [PATCH] Make VolumeAttachmentsSampleV249 test other methods The 2.49 microversion for the os-volume_attachments API only changes the POST action to attach a volume with a tag. But we should make sure 2.49 is backward compatible on the GET, PUT and DELETE methods for the same API. This makes VolumeAttachmentsSampleV249 extend VolumeAttachmentsSample and also removes duplicate code by adding the _get_vol_attachment_subs method. In addition, VolumeAttachmentsSampleV249OldCinderFlow is removed since it didn't really work properly (it was missing a few stubs) and was redundant with the test_tagged_attach_volume unit test found in nova.tests.unit.test_compute_api. Change-Id: I757576d3474997c49c67745fb245122fc2c6decc --- .../v2.49/attach-volume-to-server-resp.json | 6 +- .../v2.49/list-volume-attachments-resp.json | 16 +++++ .../os-volumes/v2.49/update-volume-req.json | 5 ++ .../v2.49/volume-attachment-detail-resp.json | 8 +++ .../list-volume-attachments-resp.json.tpl | 16 +++++ .../v2.49/update-volume-req.json.tpl | 5 ++ .../volume-attachment-detail-resp.json.tpl | 8 +++ .../api_sample_tests/test_volumes.py | 60 +++---------------- 8 files changed, 70 insertions(+), 54 deletions(-) create mode 100644 doc/api_samples/os-volumes/v2.49/list-volume-attachments-resp.json create mode 100644 doc/api_samples/os-volumes/v2.49/update-volume-req.json create mode 100644 doc/api_samples/os-volumes/v2.49/volume-attachment-detail-resp.json create mode 100644 nova/tests/functional/api_sample_tests/api_samples/os-volumes/v2.49/list-volume-attachments-resp.json.tpl create mode 100644 nova/tests/functional/api_sample_tests/api_samples/os-volumes/v2.49/update-volume-req.json.tpl create mode 100644 nova/tests/functional/api_sample_tests/api_samples/os-volumes/v2.49/volume-attachment-detail-resp.json.tpl diff --git a/doc/api_samples/os-volumes/v2.49/attach-volume-to-server-resp.json b/doc/api_samples/os-volumes/v2.49/attach-volume-to-server-resp.json index 5f610bcaebea..df5b887e2186 100644 --- a/doc/api_samples/os-volumes/v2.49/attach-volume-to-server-resp.json +++ b/doc/api_samples/os-volumes/v2.49/attach-volume-to-server-resp.json @@ -1,8 +1,8 @@ { "volumeAttachment": { - "device": "/dev/sdb", + "device": "/dev/vdd", "id": "a26887c6-c47b-4654-abb5-dfadf7d3f803", - "serverId": "84ffbfa0-daf4-4e23-bf4b-dc532c459d4e", + "serverId": "189dc814-35bc-428b-bba4-8d5ac0d1e087", "volumeId": "a26887c6-c47b-4654-abb5-dfadf7d3f803" } -} +} \ No newline at end of file diff --git a/doc/api_samples/os-volumes/v2.49/list-volume-attachments-resp.json b/doc/api_samples/os-volumes/v2.49/list-volume-attachments-resp.json new file mode 100644 index 000000000000..01623c372335 --- /dev/null +++ b/doc/api_samples/os-volumes/v2.49/list-volume-attachments-resp.json @@ -0,0 +1,16 @@ +{ + "volumeAttachments": [ + { + "device": "/dev/sdd", + "id": "a26887c6-c47b-4654-abb5-dfadf7d3f803", + "serverId": "4bcb3ae6-68aa-4e89-aac3-97b3dac2f714", + "volumeId": "a26887c6-c47b-4654-abb5-dfadf7d3f803" + }, + { + "device": "/dev/sdc", + "id": "a26887c6-c47b-4654-abb5-dfadf7d3f804", + "serverId": "4bcb3ae6-68aa-4e89-aac3-97b3dac2f714", + "volumeId": "a26887c6-c47b-4654-abb5-dfadf7d3f804" + } + ] +} \ No newline at end of file diff --git a/doc/api_samples/os-volumes/v2.49/update-volume-req.json b/doc/api_samples/os-volumes/v2.49/update-volume-req.json new file mode 100644 index 000000000000..bba735eec834 --- /dev/null +++ b/doc/api_samples/os-volumes/v2.49/update-volume-req.json @@ -0,0 +1,5 @@ +{ + "volumeAttachment": { + "volumeId": "a26887c6-c47b-4654-abb5-dfadf7d3f805" + } +} \ No newline at end of file diff --git a/doc/api_samples/os-volumes/v2.49/volume-attachment-detail-resp.json b/doc/api_samples/os-volumes/v2.49/volume-attachment-detail-resp.json new file mode 100644 index 000000000000..9e483ea66030 --- /dev/null +++ b/doc/api_samples/os-volumes/v2.49/volume-attachment-detail-resp.json @@ -0,0 +1,8 @@ +{ + "volumeAttachment": { + "device": "/dev/sdd", + "id": "a26887c6-c47b-4654-abb5-dfadf7d3f803", + "serverId": "3dc0a2a6-e1bb-4643-8b6f-c146684d676d", + "volumeId": "a26887c6-c47b-4654-abb5-dfadf7d3f803" + } +} \ No newline at end of file diff --git a/nova/tests/functional/api_sample_tests/api_samples/os-volumes/v2.49/list-volume-attachments-resp.json.tpl b/nova/tests/functional/api_sample_tests/api_samples/os-volumes/v2.49/list-volume-attachments-resp.json.tpl new file mode 100644 index 000000000000..6c1da07ef6f9 --- /dev/null +++ b/nova/tests/functional/api_sample_tests/api_samples/os-volumes/v2.49/list-volume-attachments-resp.json.tpl @@ -0,0 +1,16 @@ +{ + "volumeAttachments": [ + { + "device": "/dev/sdd", + "id": "a26887c6-c47b-4654-abb5-dfadf7d3f803", + "serverId": "%(uuid)s", + "volumeId": "a26887c6-c47b-4654-abb5-dfadf7d3f803" + }, + { + "device": "/dev/sdc", + "id": "a26887c6-c47b-4654-abb5-dfadf7d3f804", + "serverId": "%(uuid)s", + "volumeId": "a26887c6-c47b-4654-abb5-dfadf7d3f804" + } + ] +} diff --git a/nova/tests/functional/api_sample_tests/api_samples/os-volumes/v2.49/update-volume-req.json.tpl b/nova/tests/functional/api_sample_tests/api_samples/os-volumes/v2.49/update-volume-req.json.tpl new file mode 100644 index 000000000000..41411472ab09 --- /dev/null +++ b/nova/tests/functional/api_sample_tests/api_samples/os-volumes/v2.49/update-volume-req.json.tpl @@ -0,0 +1,5 @@ +{ + "volumeAttachment": { + "volumeId": "%(volume_id)s" + } +} diff --git a/nova/tests/functional/api_sample_tests/api_samples/os-volumes/v2.49/volume-attachment-detail-resp.json.tpl b/nova/tests/functional/api_sample_tests/api_samples/os-volumes/v2.49/volume-attachment-detail-resp.json.tpl new file mode 100644 index 000000000000..86099eeb8718 --- /dev/null +++ b/nova/tests/functional/api_sample_tests/api_samples/os-volumes/v2.49/volume-attachment-detail-resp.json.tpl @@ -0,0 +1,8 @@ +{ + "volumeAttachment": { + "device": "/dev/sdd", + "id": "a26887c6-c47b-4654-abb5-dfadf7d3f803", + "serverId": "%(uuid)s", + "volumeId": "a26887c6-c47b-4654-abb5-dfadf7d3f803" + } +} diff --git a/nova/tests/functional/api_sample_tests/test_volumes.py b/nova/tests/functional/api_sample_tests/test_volumes.py index 63893c26f6ff..1d70f4899767 100644 --- a/nova/tests/functional/api_sample_tests/test_volumes.py +++ b/nova/tests/functional/api_sample_tests/test_volumes.py @@ -245,6 +245,10 @@ class VolumeAttachmentsSample(test_servers.ServersSampleBase): self.stub_out('nova.compute.api.API.get', fake_compute_api_get) + def _get_vol_attachment_subs(self, subs): + """Allows subclasses to override/supplement request/response subs""" + return subs + def test_attach_volume_to_server(self): self.stub_out('nova.objects.Service.get_minimum_version', lambda *a, **k: COMPUTE_VERSION_OLD_ATTACH_FLOW) @@ -268,6 +272,7 @@ class VolumeAttachmentsSample(test_servers.ServersSampleBase): 'device': device_name } server_id = self._post_server() + subs = self._get_vol_attachment_subs(subs) response = self._do_post('servers/%s/os-volume_attachments' % server_id, 'attach-volume-to-server-req', subs) @@ -300,6 +305,7 @@ class VolumeAttachmentsSample(test_servers.ServersSampleBase): 'device': device_name } server_id = self._post_server() + subs = self._get_vol_attachment_subs(subs) response = self._do_post('servers/%s/os-volume_attachments' % server_id, 'attach-volume-to-server-req', subs) @@ -362,7 +368,7 @@ class VolumeAttachmentsSample(test_servers.ServersSampleBase): self.assertEqual('', response.text) -class VolumeAttachmentsSampleV249(test_servers.ServersSampleBase): +class VolumeAttachmentsSampleV249(VolumeAttachmentsSample): sample_dir = "os-volumes" microversion = '2.49' scenarios = [('v2_49', {'api_major_version': 'v2.1'})] @@ -371,53 +377,5 @@ class VolumeAttachmentsSampleV249(test_servers.ServersSampleBase): super(VolumeAttachmentsSampleV249, self).setUp() self.useFixture(fixtures.CinderFixtureNewAttachFlow(self)) - def test_attach_volume_to_server(self): - device_name = '/dev/sdb' - bdm = objects.BlockDeviceMapping() - bdm['device_name'] = device_name - volume = fakes.stub_volume_get(None, context.get_admin_context(), - 'a26887c6-c47b-4654-abb5-dfadf7d3f803') - subs = { - 'volume_id': volume['id'], - 'device': device_name, - 'tag': 'foo', - } - server_id = self._post_server() - response = self._do_post('servers/%s/os-volume_attachments' - % server_id, - 'attach-volume-to-server-req', subs) - - self._verify_response('attach-volume-to-server-resp', subs, - response, 200) - - -class VolumeAttachmentsSampleV249OldCinderFlow(test_servers.ServersSampleBase): - - sample_dir = "os-volumes" - microversion = '2.49' - scenarios = [('v2_49', {'api_major_version': 'v2.1'})] - - def setUp(self): - super(VolumeAttachmentsSampleV249OldCinderFlow, self).setUp() - self.useFixture(fixtures.CinderFixture(self)) - - def test_attach_volume_to_server(self): - device_name = '/dev/sdb' - bdm = objects.BlockDeviceMapping() - bdm['device_name'] = device_name - volume = fakes.stub_volume_get(None, context.get_admin_context(), - 'a26887c6-c47b-4654-abb5-dfadf7d3f803') - self.stub_out('nova.objects.Service.get_minimum_version', - lambda *a, **k: COMPUTE_VERSION_OLD_ATTACH_FLOW) - subs = { - 'volume_id': volume['id'], - 'device': device_name, - 'tag': 'foo', - } - server_id = self._post_server() - response = self._do_post('servers/%s/os-volume_attachments' - % server_id, - 'attach-volume-to-server-req', subs) - - self._verify_response('attach-volume-to-server-resp', subs, - response, 200) + def _get_vol_attachment_subs(self, subs): + return dict(subs, tag='foo')