Add return-request-id-to-caller function(5/5)
Add return-request-id-to-caller function to resources and resource managers in the following files. The methods in the resource class and resource manager return a wrapper class that has 'request_ids' property. The caller can get request ids of the callee via the property. * novaclient/v2/volume_snapshots.py * novaclient/v2/volumes.py * novaclient/v2/volume_types.py Co-authored-by: Ankit Agrawal <ankit11.agrawal@nttdata.com> Change-Id: I4de8c5cf685a5970acc92f8a58a1db26a8d9ffc7 Implements: blueprint return-request-id-to-caller
This commit is contained in:
parent
9f10d7d0b0
commit
209f172242
@ -2184,7 +2184,7 @@ class FakeHTTPClient(base_client.HTTPClient):
|
||||
# I suppose they are outdated and should be updated after Cinder released
|
||||
|
||||
def get_volumes_detail(self, **kw):
|
||||
return (200, {}, {"volumes": [
|
||||
return (200, FAKE_RESPONSE_HEADERS, {"volumes": [
|
||||
{
|
||||
"display_name": "Work",
|
||||
"display_description": "volume for work",
|
||||
@ -2211,7 +2211,7 @@ class FakeHTTPClient(base_client.HTTPClient):
|
||||
"metadata": {}}]})
|
||||
|
||||
def get_volumes(self, **kw):
|
||||
return (200, {}, {"volumes": [
|
||||
return (200, FAKE_RESPONSE_HEADERS, {"volumes": [
|
||||
{
|
||||
"display_name": "Work",
|
||||
"display_description": "volume for work",
|
||||
@ -2238,7 +2238,7 @@ class FakeHTTPClient(base_client.HTTPClient):
|
||||
"metadata": {}}]})
|
||||
|
||||
def get_volumes_15e59938_07d5_11e1_90e3_e3dffe0c5983(self, **kw):
|
||||
return (200, {}, {
|
||||
return (200, FAKE_RESPONSE_HEADERS, {
|
||||
"volume": self.get_volumes_detail()[2]['volumes'][0]})
|
||||
|
||||
def get_volumes_15e59938_07d5_11e1_90e3_ee32ba30feaa(self, **kw):
|
||||
@ -2246,7 +2246,7 @@ class FakeHTTPClient(base_client.HTTPClient):
|
||||
"volume": self.get_volumes_detail()[2]['volumes'][1]})
|
||||
|
||||
def post_volumes(self, **kw):
|
||||
return (200, {}, {"volume":
|
||||
return (200, FAKE_RESPONSE_HEADERS, {"volume":
|
||||
{"status": "creating",
|
||||
"display_name": "vol-007",
|
||||
"attachments": [(0)],
|
||||
@ -2260,22 +2260,23 @@ class FakeHTTPClient(base_client.HTTPClient):
|
||||
"size": 1}})
|
||||
|
||||
def delete_volumes_15e59938_07d5_11e1_90e3_e3dffe0c5983(self, **kw):
|
||||
return (200, {}, {})
|
||||
return (200, FAKE_RESPONSE_HEADERS, {})
|
||||
|
||||
def delete_volumes_15e59938_07d5_11e1_90e3_ee32ba30feaa(self, **kw):
|
||||
return (200, {}, {})
|
||||
|
||||
def post_servers_1234_os_volume_attachments(self, **kw):
|
||||
return (200, {}, {
|
||||
return (200, FAKE_RESPONSE_HEADERS, {
|
||||
"volumeAttachment":
|
||||
{"device": "/dev/vdb",
|
||||
"volumeId": 2}})
|
||||
|
||||
def put_servers_1234_os_volume_attachments_Work(self, **kw):
|
||||
return (200, {}, {"volumeAttachment": {"volumeId": 2}})
|
||||
return (200, FAKE_RESPONSE_HEADERS,
|
||||
{"volumeAttachment": {"volumeId": 2}})
|
||||
|
||||
def get_servers_1234_os_volume_attachments(self, **kw):
|
||||
return (200, {}, {
|
||||
return (200, FAKE_RESPONSE_HEADERS, {
|
||||
"volumeAttachments": [
|
||||
{"display_name": "Work",
|
||||
"display_description": "volume for work",
|
||||
@ -2288,7 +2289,7 @@ class FakeHTTPClient(base_client.HTTPClient):
|
||||
"metadata": {}}]})
|
||||
|
||||
def get_servers_1234_os_volume_attachments_Work(self, **kw):
|
||||
return (200, {}, {
|
||||
return (200, FAKE_RESPONSE_HEADERS, {
|
||||
"volumeAttachment":
|
||||
{"display_name": "Work",
|
||||
"display_description": "volume for work",
|
||||
@ -2301,7 +2302,7 @@ class FakeHTTPClient(base_client.HTTPClient):
|
||||
"metadata": {}}})
|
||||
|
||||
def delete_servers_1234_os_volume_attachments_Work(self, **kw):
|
||||
return (200, {}, {})
|
||||
return (200, FAKE_RESPONSE_HEADERS, {})
|
||||
|
||||
def get_servers_1234_os_instance_actions(self, **kw):
|
||||
return (200, FAKE_RESPONSE_HEADERS, {
|
||||
|
@ -30,6 +30,7 @@ class VolumesTest(utils.TestCase):
|
||||
@mock.patch.object(warnings, 'warn')
|
||||
def test_list_volumes(self, mock_warn):
|
||||
vl = cs.volumes.list()
|
||||
self.assert_request_id(vl, fakes.FAKE_REQUEST_ID_LIST)
|
||||
cs.assert_called('GET', '/volumes/detail')
|
||||
for v in vl:
|
||||
self.assertIsInstance(v, volumes.Volume)
|
||||
@ -38,6 +39,7 @@ class VolumesTest(utils.TestCase):
|
||||
@mock.patch.object(warnings, 'warn')
|
||||
def test_list_volumes_undetailed(self, mock_warn):
|
||||
vl = cs.volumes.list(detailed=False)
|
||||
self.assert_request_id(vl, fakes.FAKE_REQUEST_ID_LIST)
|
||||
cs.assert_called('GET', '/volumes')
|
||||
for v in vl:
|
||||
self.assertIsInstance(v, volumes.Volume)
|
||||
@ -47,6 +49,7 @@ class VolumesTest(utils.TestCase):
|
||||
def test_get_volume_details(self, mock_warn):
|
||||
vol_id = '15e59938-07d5-11e1-90e3-e3dffe0c5983'
|
||||
v = cs.volumes.get(vol_id)
|
||||
self.assert_request_id(v, fakes.FAKE_REQUEST_ID_LIST)
|
||||
cs.assert_called('GET', '/volumes/%s' % vol_id)
|
||||
self.assertIsInstance(v, volumes.Volume)
|
||||
self.assertEqual(v.id, vol_id)
|
||||
@ -59,6 +62,7 @@ class VolumesTest(utils.TestCase):
|
||||
display_name="My volume",
|
||||
display_description="My volume desc",
|
||||
)
|
||||
self.assert_request_id(v, fakes.FAKE_REQUEST_ID_LIST)
|
||||
cs.assert_called('POST', '/volumes')
|
||||
self.assertIsInstance(v, volumes.Volume)
|
||||
self.assertEqual(1, mock_warn.call_count)
|
||||
@ -67,11 +71,14 @@ class VolumesTest(utils.TestCase):
|
||||
def test_delete_volume(self, mock_warn):
|
||||
vol_id = '15e59938-07d5-11e1-90e3-e3dffe0c5983'
|
||||
v = cs.volumes.get(vol_id)
|
||||
v.delete()
|
||||
ret = v.delete()
|
||||
self.assert_request_id(ret, fakes.FAKE_REQUEST_ID_LIST)
|
||||
cs.assert_called('DELETE', '/volumes/%s' % vol_id)
|
||||
cs.volumes.delete(vol_id)
|
||||
ret = cs.volumes.delete(vol_id)
|
||||
self.assert_request_id(ret, fakes.FAKE_REQUEST_ID_LIST)
|
||||
cs.assert_called('DELETE', '/volumes/%s' % vol_id)
|
||||
cs.volumes.delete(v)
|
||||
ret = cs.volumes.delete(v)
|
||||
self.assert_request_id(ret, fakes.FAKE_REQUEST_ID_LIST)
|
||||
cs.assert_called('DELETE', '/volumes/%s' % vol_id)
|
||||
self.assertEqual(4, mock_warn.call_count)
|
||||
|
||||
@ -81,6 +88,7 @@ class VolumesTest(utils.TestCase):
|
||||
volume_id='15e59938-07d5-11e1-90e3-e3dffe0c5983',
|
||||
device='/dev/vdb'
|
||||
)
|
||||
self.assert_request_id(v, fakes.FAKE_REQUEST_ID_LIST)
|
||||
cs.assert_called('POST', '/servers/1234/os-volume_attachments')
|
||||
self.assertIsInstance(v, volumes.Volume)
|
||||
|
||||
@ -91,20 +99,24 @@ class VolumesTest(utils.TestCase):
|
||||
attachment_id='Work',
|
||||
new_volume_id=vol_id
|
||||
)
|
||||
self.assert_request_id(v, fakes.FAKE_REQUEST_ID_LIST)
|
||||
cs.assert_called('PUT', '/servers/1234/os-volume_attachments/Work')
|
||||
self.assertIsInstance(v, volumes.Volume)
|
||||
|
||||
def test_get_server_volume(self):
|
||||
v = cs.volumes.get_server_volume(1234, 'Work')
|
||||
self.assert_request_id(v, fakes.FAKE_REQUEST_ID_LIST)
|
||||
cs.assert_called('GET', '/servers/1234/os-volume_attachments/Work')
|
||||
self.assertIsInstance(v, volumes.Volume)
|
||||
|
||||
def test_list_server_volumes(self):
|
||||
vl = cs.volumes.get_server_volumes(1234)
|
||||
self.assert_request_id(vl, fakes.FAKE_REQUEST_ID_LIST)
|
||||
cs.assert_called('GET', '/servers/1234/os-volume_attachments')
|
||||
for v in vl:
|
||||
self.assertIsInstance(v, volumes.Volume)
|
||||
|
||||
def test_delete_server_volume(self):
|
||||
cs.volumes.delete_server_volume(1234, 'Work')
|
||||
ret = cs.volumes.delete_server_volume(1234, 'Work')
|
||||
self.assert_request_id(ret, fakes.FAKE_REQUEST_ID_LIST)
|
||||
cs.assert_called('DELETE', '/servers/1234/os-volume_attachments/Work')
|
||||
|
@ -34,8 +34,10 @@ class Snapshot(base.Resource):
|
||||
def delete(self):
|
||||
"""
|
||||
DEPRECATED: Delete this snapshot.
|
||||
|
||||
:returns: An instance of novaclient.base.TupleWithMeta
|
||||
"""
|
||||
self.manager.delete(self)
|
||||
return self.manager.delete(self)
|
||||
|
||||
|
||||
class SnapshotManager(base.ManagerWithFind):
|
||||
@ -107,6 +109,7 @@ class SnapshotManager(base.ManagerWithFind):
|
||||
DEPRECATED: Delete a snapshot.
|
||||
|
||||
:param snapshot: The :class:`Snapshot` to delete.
|
||||
:returns: An instance of novaclient.base.TupleWithMeta
|
||||
"""
|
||||
warnings.warn('The novaclient.v2.volume_snapshots module is '
|
||||
'deprecated and will be removed after Nova 13.0.0 is '
|
||||
@ -114,4 +117,4 @@ class SnapshotManager(base.ManagerWithFind):
|
||||
'python-openstacksdk instead.', DeprecationWarning)
|
||||
with self.alternate_service_type(
|
||||
'volumev2', allowed_types=('volume', 'volumev2')):
|
||||
self._delete("/snapshots/%s" % base.getid(snapshot))
|
||||
return self._delete("/snapshots/%s" % base.getid(snapshot))
|
||||
|
@ -72,6 +72,7 @@ class VolumeTypeManager(base.ManagerWithFind):
|
||||
DEPRECATED: Delete a specific volume_type.
|
||||
|
||||
:param volume_type: The ID of the :class:`VolumeType` to get.
|
||||
:returns: An instance of novaclient.base.TupleWithMeta
|
||||
"""
|
||||
warnings.warn('The novaclient.v2.volume_types module is deprecated '
|
||||
'and will be removed after Nova 13.0.0 is released. Use '
|
||||
@ -79,7 +80,7 @@ class VolumeTypeManager(base.ManagerWithFind):
|
||||
DeprecationWarning)
|
||||
with self.alternate_service_type(
|
||||
'volumev2', allowed_types=('volume', 'volumev2')):
|
||||
self._delete("/types/%s" % base.getid(volume_type))
|
||||
return self._delete("/types/%s" % base.getid(volume_type))
|
||||
|
||||
def create(self, name):
|
||||
"""
|
||||
|
@ -38,8 +38,10 @@ class Volume(base.Resource):
|
||||
def delete(self):
|
||||
"""
|
||||
DEPRECATED: Delete this volume.
|
||||
|
||||
:returns: An instance of novaclient.base.TupleWithMeta
|
||||
"""
|
||||
self.manager.delete(self)
|
||||
return self.manager.delete(self)
|
||||
|
||||
|
||||
class VolumeManager(base.ManagerWithFind):
|
||||
@ -126,6 +128,7 @@ class VolumeManager(base.ManagerWithFind):
|
||||
DEPRECATED: Delete a volume.
|
||||
|
||||
:param volume: The :class:`Volume` to delete.
|
||||
:returns: An instance of novaclient.base.TupleWithMeta
|
||||
"""
|
||||
warnings.warn('The novaclient.v2.volumes.VolumeManager.delete() '
|
||||
'method is deprecated and will be removed after Nova '
|
||||
@ -133,7 +136,7 @@ class VolumeManager(base.ManagerWithFind):
|
||||
'python-openstacksdk instead.', DeprecationWarning)
|
||||
with self.alternate_service_type(
|
||||
'volumev2', allowed_types=('volume', 'volumev2')):
|
||||
self._delete("/volumes/%s" % base.getid(volume))
|
||||
return self._delete("/volumes/%s" % base.getid(volume))
|
||||
|
||||
def create_server_volume(self, server_id, volume_id, device=None):
|
||||
"""
|
||||
@ -193,6 +196,7 @@ class VolumeManager(base.ManagerWithFind):
|
||||
|
||||
:param server_id: The ID of the server
|
||||
:param attachment_id: The ID of the attachment
|
||||
:returns: An instance of novaclient.base.TupleWithMeta
|
||||
"""
|
||||
self._delete("/servers/%s/os-volume_attachments/%s" %
|
||||
(server_id, attachment_id,))
|
||||
return self._delete("/servers/%s/os-volume_attachments/%s" %
|
||||
(server_id, attachment_id,))
|
||||
|
Loading…
Reference in New Issue
Block a user