Follow-up: Add delete_on_termination to volume-attach API

Some comment mainly from gmann and takashin in [1] PS15.
Add some tests in test_volumes.py, and fix some docs error.

[1]https://review.opendev.org/#/c/673133/15/nova/tests/unit/api/openstack/compute/test_volumes.py@1902

Depends-On: https://review.opendev.org/#/c/673133/
Part of blueprint support-delete-on-termination-in-server-attach-volume

Change-Id: I8dfa61f03ce927a1e86d42f8fb03bf4cb3e48160
This commit is contained in:
zhangbailin 2019-09-06 18:44:08 +08:00 committed by Eric Fried
parent 9fa3600fca
commit dcac6825c5
5 changed files with 64 additions and 6 deletions

View File

@ -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

View File

@ -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

View File

@ -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:

View File

@ -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):

View File

@ -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: