diff --git a/api-ref/source/os-volume-attachments.inc b/api-ref/source/os-volume-attachments.inc index 68db210c2bd4..de73f95ea174 100644 --- a/api-ref/source/os-volume-attachments.inc +++ b/api-ref/source/os-volume-attachments.inc @@ -46,9 +46,9 @@ Response .. literalinclude:: ../../doc/api_samples/os-volumes/list-volume-attachments-resp.json :language: javascript -**Example List tagged volume attachments for an instance (v2.70): JSON response** +**Example List tagged volume attachments for an instance (v2.79): JSON response** -.. literalinclude:: ../../doc/api_samples/os-volumes/v2.70/list-volume-attachments-resp.json +.. literalinclude:: ../../doc/api_samples/os-volumes/v2.79/list-volume-attachments-resp.json :language: javascript Attach a volume to an instance @@ -162,9 +162,9 @@ Response .. literalinclude:: ../../doc/api_samples/os-volumes/volume-attachment-detail-resp.json :language: javascript -**Example Show a detail of a tagged volume attachment (v2.70): JSON response** +**Example Show a detail of a tagged volume attachment (v2.79): JSON response** -.. literalinclude:: ../../doc/api_samples/os-volumes/v2.70/volume-attachment-detail-resp.json +.. literalinclude:: ../../doc/api_samples/os-volumes/v2.79/volume-attachment-detail-resp.json :language: javascript Update a volume attachment diff --git a/nova/api/openstack/api_version_request.py b/nova/api/openstack/api_version_request.py index 09038f416ab3..6c99006779cb 100644 --- a/nova/api/openstack/api_version_request.py +++ b/nova/api/openstack/api_version_request.py @@ -209,6 +209,7 @@ REST_API_VERSION_HISTORY = """REST API Version History: request body to ``POST /servers/{server_id}/os-volume_attachments`` and exposes this via the response from + ``POST /servers/{server_id}/os-volume_attachments``, ``GET /servers/{server_id}/os-volume_attachments`` and ``GET /servers/{server_id}/os-volume_attachments/{volume_id}``. * 2.80 - Adds support for optional query parameters ``user_id`` and diff --git a/nova/api/openstack/compute/rest_api_version_history.rst b/nova/api/openstack/compute/rest_api_version_history.rst index cbdae2707a03..ecb82de0a091 100644 --- a/nova/api/openstack/compute/rest_api_version_history.rst +++ b/nova/api/openstack/compute/rest_api_version_history.rst @@ -1047,7 +1047,8 @@ API microversion 2.79 adds support for specifying the ``delete_on_termination`` field in the request body when attaching a volume to a server, to support configuring whether to delete the data volume when the server is destroyed. Also, ``delete_on_termination`` is added to the GET responses when showing -attached volumes. +attached volumes, and the ``delete_on_termination`` field is contained +in the POST API response body when attaching a volume. The affected APIs are as follows: diff --git a/nova/tests/unit/api/openstack/compute/test_volumes.py b/nova/tests/unit/api/openstack/compute/test_volumes.py index 76eaeebf7804..7c7d5353ba3e 100644 --- a/nova/tests/unit/api/openstack/compute/test_volumes.py +++ b/nova/tests/unit/api/openstack/compute/test_volumes.py @@ -1092,6 +1092,61 @@ class VolumeAttachTestsV279(VolumeAttachTestsV2_75): self.assertIn("Invalid input for field/attribute " "delete_on_termination.", six.text_type(ex)) + @mock.patch('nova.compute.api.API.attach_volume', return_value=None) + def test_attach_volume_v279(self, mock_attach_volume): + body = {'volumeAttachment': {'volumeId': FAKE_UUID_A, + 'delete_on_termination': True}} + req = self._get_req(body) + result = self.attachments.create(req, FAKE_UUID, body=body) + self.assertTrue(result['volumeAttachment']['delete_on_termination']) + mock_attach_volume.assert_called_once_with( + req.environ['nova.context'], test.MatchType(objects.Instance), + FAKE_UUID_A, None, tag=None, supports_multiattach=True, + delete_on_termination=True) + + def test_show_pre_v279(self): + """Before microversion 2.79, show a detail of a volume attachment + does not contain the 'delete_on_termination' field in the response + body. + """ + req = self._get_req(body={}, microversion='2.78') + req.method = 'GET' + result = self.attachments.show(req, FAKE_UUID, FAKE_UUID_A) + + self.assertNotIn('delete_on_termination', result['volumeAttachment']) + + @mock.patch('nova.objects.BlockDeviceMappingList.get_by_instance_uuid') + def test_list_pre_v279(self, mock_get_bdms): + """Before microversion 2.79, list of a volume attachment + does not contain the 'delete_on_termination' field in the response + body. + """ + req = fakes.HTTPRequest.blank( + '/v2/servers/id/os-volume_attachments', + version="2.78") + req.body = jsonutils.dump_as_bytes({}) + req.method = 'GET' + req.headers['content-type'] = 'application/json' + + vol_bdm = objects.BlockDeviceMapping( + self.context, + id=1, + instance_uuid=FAKE_UUID, + volume_id=FAKE_UUID_A, + source_type='volume', + destination_type='volume', + delete_on_termination=True, + connection_info=None, + tag='fake-tag', + device_name='/dev/fake0', + attachment_id=uuids.attachment_id) + bdms = objects.BlockDeviceMappingList(objects=[vol_bdm]) + + mock_get_bdms.return_value = bdms + result = self.attachments.index(req, FAKE_UUID) + + self.assertNotIn('delete_on_termination', result['volumeAttachments']) + class SwapVolumeMultiattachTestCase(test.NoDBTestCase): diff --git a/releasenotes/notes/bp-support-delete-on-termination-in-server-attach-volume-5d08b4e97fdd24f9.yaml b/releasenotes/notes/bp-support-delete-on-termination-in-server-attach-volume-5d08b4e97fdd24f9.yaml index 2ef1e11b0e5e..9dd1effc16d2 100644 --- a/releasenotes/notes/bp-support-delete-on-termination-in-server-attach-volume-5d08b4e97fdd24f9.yaml +++ b/releasenotes/notes/bp-support-delete-on-termination-in-server-attach-volume-5d08b4e97fdd24f9.yaml @@ -5,7 +5,8 @@ features: field in the request body when attaching a volume to a server, to support configuring whether to delete the data volume when the server is destroyed. Also, ``delete_on_termination`` is added to the GET responses when showing - attached volumes. + attached volumes, and the ``delete_on_termination`` field is contained + in the POST API response body when attaching a volume. The affected APIs are as follows: