From 51ee17a94dccd297101725593b223f01c4f9b906 Mon Sep 17 00:00:00 2001 From: Lee Yarwood Date: Thu, 12 Aug 2021 11:27:17 +0100 Subject: [PATCH] compute: Add support for microversion 2.89 This microversion drops the duplicate ``id`` field while adding ``attachment_id`` and ``bdm_uuid`` to the output of the os-volume_attachments API reflected within osc by the ``openstack server volume list $server``command. Depends-On: https://review.opendev.org/c/openstack/nova/+/804275 Change-Id: I8a7002d8d65d7795e106b768df868198ab8b8143 --- openstackclient/compute/v2/server_volume.py | 18 +++++-- .../tests/unit/compute/v2/fakes.py | 3 ++ .../unit/compute/v2/test_server_volume.py | 49 +++++++++++++++++++ ...to_volume_attachment-cea605585db29e14.yaml | 11 +++++ 4 files changed, 77 insertions(+), 4 deletions(-) create mode 100644 releasenotes/notes/add_attachment_id_to_volume_attachment-cea605585db29e14.yaml diff --git a/openstackclient/compute/v2/server_volume.py b/openstackclient/compute/v2/server_volume.py index b53c92fe5e..d53cec931d 100644 --- a/openstackclient/compute/v2/server_volume.py +++ b/openstackclient/compute/v2/server_volume.py @@ -44,18 +44,24 @@ class ListServerVolume(command.Lister): volumes = compute_client.volumes.get_server_volumes(server.id) - columns = ( - 'id', + columns = () + column_headers = () + + if compute_client.api_version < api_versions.APIVersion('2.89'): + columns += ('id',) + column_headers += ('ID',) + + columns += ( 'device', 'serverId', 'volumeId', ) - column_headers = ( - 'ID', + column_headers += ( 'Device', 'Server ID', 'Volume ID', ) + if compute_client.api_version >= api_versions.APIVersion('2.70'): columns += ('tag',) column_headers += ('Tag',) @@ -64,6 +70,10 @@ class ListServerVolume(command.Lister): columns += ('delete_on_termination',) column_headers += ('Delete On Termination?',) + if compute_client.api_version >= api_versions.APIVersion('2.89'): + columns += ('attachment_id', 'bdm_uuid') + column_headers += ('Attachment ID', 'BlockDeviceMapping UUID') + return ( column_headers, ( diff --git a/openstackclient/tests/unit/compute/v2/fakes.py b/openstackclient/tests/unit/compute/v2/fakes.py index 05a14e16a7..3142a24489 100644 --- a/openstackclient/tests/unit/compute/v2/fakes.py +++ b/openstackclient/tests/unit/compute/v2/fakes.py @@ -1715,6 +1715,9 @@ class FakeVolumeAttachment(object): "tag": "foo", # introduced in API microversion 2.79 "delete_on_termination": True, + # introduced in API microversion 2.89 + "attachment_id": uuid.uuid4().hex, + "bdm_uuid": uuid.uuid4().hex } # Overwrite default attributes. diff --git a/openstackclient/tests/unit/compute/v2/test_server_volume.py b/openstackclient/tests/unit/compute/v2/test_server_volume.py index 4d4916b7ec..02d378f82a 100644 --- a/openstackclient/tests/unit/compute/v2/test_server_volume.py +++ b/openstackclient/tests/unit/compute/v2/test_server_volume.py @@ -167,6 +167,55 @@ class TestServerVolumeList(TestServerVolume): self.servers_volumes_mock.get_server_volumes.assert_called_once_with( self.server.id) + def test_server_volume_list_with_attachment_ids(self): + self.app.client_manager.compute.api_version = \ + api_versions.APIVersion('2.89') + + arglist = [ + self.server.id, + ] + verifylist = [ + ('server', self.server.id), + ] + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + columns, data = self.cmd.take_action(parsed_args) + + self.assertEqual( + ( + 'Device', 'Server ID', 'Volume ID', 'Tag', + 'Delete On Termination?', 'Attachment ID', + 'BlockDeviceMapping UUID', + ), + columns, + ) + self.assertEqual( + ( + ( + self.volume_attachments[0].device, + self.volume_attachments[0].serverId, + self.volume_attachments[0].volumeId, + self.volume_attachments[0].tag, + self.volume_attachments[0].delete_on_termination, + self.volume_attachments[0].attachment_id, + self.volume_attachments[0].bdm_uuid + + ), + ( + self.volume_attachments[1].device, + self.volume_attachments[1].serverId, + self.volume_attachments[1].volumeId, + self.volume_attachments[1].tag, + self.volume_attachments[1].delete_on_termination, + self.volume_attachments[1].attachment_id, + self.volume_attachments[1].bdm_uuid + ), + ), + tuple(data), + ) + self.servers_volumes_mock.get_server_volumes.assert_called_once_with( + self.server.id) + class TestServerVolumeUpdate(TestServerVolume): diff --git a/releasenotes/notes/add_attachment_id_to_volume_attachment-cea605585db29e14.yaml b/releasenotes/notes/add_attachment_id_to_volume_attachment-cea605585db29e14.yaml new file mode 100644 index 0000000000..9a43989683 --- /dev/null +++ b/releasenotes/notes/add_attachment_id_to_volume_attachment-cea605585db29e14.yaml @@ -0,0 +1,11 @@ +--- +features: + - | + Added support for `microversion 2.89`_. This microversion removes the + ``id`` field while adding the ``attachment_id`` and ``bdm_uuid`` fields to + the responses of ``GET /servers/{server_id}/os-volume_attachments`` and + ``GET /servers/{server_id}/os-volume_attachments/{volume_id}`` with these + changes reflected in novaclient under the ``openstack server volume list`` + command. + + .. _microversion 2.89: https://docs.openstack.org/nova/latest/reference/api-microversion-history.html#microversion-2-89