Browse Source

Add return-request-id-to-caller function(4/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/contrib/assisted_volume_snapshots.py
* novaclient/v2/contrib/baremetal.py
* novaclient/v2/contrib/cells.py
* novaclient/v2/contrib/instance_action.py
* novaclient/v2/contrib/list_extensions.py
* novaclient/v2/contrib/migrations.py
* novaclient/v2/contrib/server_external_events.py
* novaclient/v2/contrib/tenant_networks.py

Co-authored-by: Ankit Agrawal <ankit11.agrawal@nttdata.com>
Change-Id: I58ec61eb585d145cb7d638bcb690b3ebee0461e9
Implements: blueprint return-request-id-to-caller
tags/3.3.0
Takashi NATSUME 3 years ago
parent
commit
9f10d7d0b0

+ 17
- 13
novaclient/tests/unit/v2/contrib/fakes.py View File

@@ -15,6 +15,9 @@
15 15
 from novaclient.tests.unit.v2 import fakes
16 16
 from novaclient.v2 import client
17 17
 
18
+FAKE_REQUEST_ID_LIST = fakes.FAKE_REQUEST_ID_LIST
19
+FAKE_RESPONSE_HEADERS = fakes.FAKE_RESPONSE_HEADERS
20
+
18 21
 
19 22
 class FakeClient(fakes.FakeClient):
20 23
     def __init__(self, *args, **kwargs):
@@ -27,29 +30,29 @@ class FakeClient(fakes.FakeClient):
27 30
 
28 31
 class FakeHTTPClient(fakes.FakeHTTPClient):
29 32
     def get_os_tenant_networks(self):
30
-        return (200, {}, {
33
+        return (200, FAKE_RESPONSE_HEADERS, {
31 34
             'networks': [{"label": "1", "cidr": "10.0.0.0/24",
32 35
                           'project_id': '4ffc664c198e435e9853f2538fbcd7a7',
33 36
                           'id': '1'}]})
34 37
 
35 38
     def get_os_tenant_networks_1(self, **kw):
36
-        return (200, {}, {
39
+        return (200, FAKE_RESPONSE_HEADERS, {
37 40
             'network': {"label": "1", "cidr": "10.0.0.0/24",
38 41
                         'project_id': '4ffc664c198e435e9853f2538fbcd7a7',
39 42
                         'id': '1'}})
40 43
 
41 44
     def post_os_tenant_networks(self, **kw):
42
-        return (201, {}, {
45
+        return (201, FAKE_RESPONSE_HEADERS, {
43 46
             'network': {"label": "1", "cidr": "10.0.0.0/24",
44 47
                         'project_id': '4ffc664c198e435e9853f2538fbcd7a7',
45 48
                         'id': '1'}})
46 49
 
47 50
     def delete_os_tenant_networks_1(self, **kw):
48
-        return (204, {}, None)
51
+        return (204, FAKE_RESPONSE_HEADERS, None)
49 52
 
50 53
     def get_os_baremetal_nodes(self, **kw):
51 54
         return (
52
-            200, {}, {
55
+            200, FAKE_RESPONSE_HEADERS, {
53 56
                 'nodes': [
54 57
                     {
55 58
                         "id": 1,
@@ -72,7 +75,7 @@ class FakeHTTPClient(fakes.FakeHTTPClient):
72 75
 
73 76
     def get_os_baremetal_nodes_1(self, **kw):
74 77
         return (
75
-            200, {}, {
78
+            200, FAKE_RESPONSE_HEADERS, {
76 79
                 'node': {
77 80
                     "id": 1,
78 81
                     "instance_uuid": None,
@@ -93,7 +96,7 @@ class FakeHTTPClient(fakes.FakeHTTPClient):
93 96
 
94 97
     def post_os_baremetal_nodes(self, **kw):
95 98
         return (
96
-            200, {}, {
99
+            200, FAKE_RESPONSE_HEADERS, {
97 100
                 'node': {
98 101
                     "id": 1,
99 102
                     "instance_uuid": None,
@@ -112,14 +115,14 @@ class FakeHTTPClient(fakes.FakeHTTPClient):
112 115
         )
113 116
 
114 117
     def delete_os_baremetal_nodes_1(self, **kw):
115
-        return (202, {}, {})
118
+        return (202, FAKE_RESPONSE_HEADERS, {})
116 119
 
117 120
     def post_os_baremetal_nodes_1_action(self, **kw):
118 121
         body = kw['body']
119 122
         action = list(body)[0]
120 123
         if action == "add_interface":
121 124
             return (
122
-                200, {}, {
125
+                200, FAKE_RESPONSE_HEADERS, {
123 126
                     'interface': {
124 127
                         "id": 2,
125 128
                         "address": "bb:cc:dd:ee:ff:aa",
@@ -129,18 +132,19 @@ class FakeHTTPClient(fakes.FakeHTTPClient):
129 132
                 }
130 133
             )
131 134
         elif action == "remove_interface":
132
-            return (202, {}, {})
135
+            return (202, FAKE_RESPONSE_HEADERS, {})
133 136
         else:
134 137
             return (500, {}, {})
135 138
 
136 139
     def post_os_assisted_volume_snapshots(self, **kw):
137
-        return (202, {}, {'snapshot': {'id': 'blah', 'volumeId': '1'}})
140
+        return (202, FAKE_RESPONSE_HEADERS,
141
+                {'snapshot': {'id': 'blah', 'volumeId': '1'}})
138 142
 
139 143
     def delete_os_assisted_volume_snapshots_x(self, **kw):
140
-        return (202, {}, {})
144
+        return (202, FAKE_RESPONSE_HEADERS, {})
141 145
 
142 146
     def post_os_server_external_events(self, **kw):
143
-        return (200, {}, {
147
+        return (200, FAKE_RESPONSE_HEADERS, {
144 148
             'events': [
145 149
                 {'name': 'test-event',
146 150
                  'status': 'completed',

+ 4
- 2
novaclient/tests/unit/v2/contrib/test_assisted_volume_snapshots.py View File

@@ -32,11 +32,13 @@ cs = fakes.FakeClient(extensions=extensions)
32 32
 class AssistedVolumeSnapshotsTestCase(utils.TestCase):
33 33
 
34 34
     def test_create_snap(self):
35
-        cs.assisted_volume_snapshots.create('1', {})
35
+        vs = cs.assisted_volume_snapshots.create('1', {})
36
+        self.assert_request_id(vs, fakes.FAKE_REQUEST_ID_LIST)
36 37
         cs.assert_called('POST', '/os-assisted-volume-snapshots')
37 38
 
38 39
     def test_delete_snap(self):
39
-        cs.assisted_volume_snapshots.delete('x', {})
40
+        vs = cs.assisted_volume_snapshots.delete('x', {})
41
+        self.assert_request_id(vs, fakes.FAKE_REQUEST_ID_LIST)
40 42
         cs.assert_called(
41 43
             'DELETE',
42 44
             '/os-assisted-volume-snapshots/x?delete_info={}')

+ 10
- 3
novaclient/tests/unit/v2/contrib/test_baremetal.py View File

@@ -30,35 +30,42 @@ class BaremetalExtensionTest(utils.TestCase):
30 30
 
31 31
     def test_list_nodes(self):
32 32
         nl = cs.baremetal.list()
33
+        self.assert_request_id(nl, fakes.FAKE_REQUEST_ID_LIST)
33 34
         cs.assert_called('GET', '/os-baremetal-nodes')
34 35
         for n in nl:
35 36
             self.assertIsInstance(n, baremetal.BareMetalNode)
36 37
 
37 38
     def test_get_node(self):
38 39
         n = cs.baremetal.get(1)
40
+        self.assert_request_id(n, fakes.FAKE_REQUEST_ID_LIST)
39 41
         cs.assert_called('GET', '/os-baremetal-nodes/1')
40 42
         self.assertIsInstance(n, baremetal.BareMetalNode)
41 43
 
42 44
     def test_create_node(self):
43 45
         n = cs.baremetal.create("service_host", 1, 1024, 2048,
44 46
                                 "aa:bb:cc:dd:ee:ff")
47
+        self.assert_request_id(n, fakes.FAKE_REQUEST_ID_LIST)
45 48
         cs.assert_called('POST', '/os-baremetal-nodes')
46 49
         self.assertIsInstance(n, baremetal.BareMetalNode)
47 50
 
48 51
     def test_delete_node(self):
49 52
         n = cs.baremetal.get(1)
50
-        cs.baremetal.delete(n)
53
+        ret = cs.baremetal.delete(n)
54
+        self.assert_request_id(ret, fakes.FAKE_REQUEST_ID_LIST)
51 55
         cs.assert_called('DELETE', '/os-baremetal-nodes/1')
52 56
 
53 57
     def test_node_add_interface(self):
54 58
         i = cs.baremetal.add_interface(1, "bb:cc:dd:ee:ff:aa", 1, 2)
59
+        self.assert_request_id(i, fakes.FAKE_REQUEST_ID_LIST)
55 60
         cs.assert_called('POST', '/os-baremetal-nodes/1/action')
56 61
         self.assertIsInstance(i, baremetal.BareMetalNodeInterface)
57 62
 
58 63
     def test_node_remove_interface(self):
59
-        cs.baremetal.remove_interface(1, "bb:cc:dd:ee:ff:aa")
64
+        ret = cs.baremetal.remove_interface(1, "bb:cc:dd:ee:ff:aa")
65
+        self.assert_request_id(ret, fakes.FAKE_REQUEST_ID_LIST)
60 66
         cs.assert_called('POST', '/os-baremetal-nodes/1/action')
61 67
 
62 68
     def test_node_list_interfaces(self):
63
-        cs.baremetal.list_interfaces(1)
69
+        il = cs.baremetal.list_interfaces(1)
70
+        self.assert_request_id(il, fakes.FAKE_REQUEST_ID_LIST)
64 71
         cs.assert_called('GET', '/os-baremetal-nodes/1')

+ 6
- 3
novaclient/tests/unit/v2/contrib/test_cells.py View File

@@ -29,14 +29,17 @@ cs = fakes.FakeClient(extensions=extensions)
29 29
 class CellsExtensionTests(utils.TestCase):
30 30
     def test_get_cells(self):
31 31
         cell_name = 'child_cell'
32
-        cs.cells.get(cell_name)
32
+        cell = cs.cells.get(cell_name)
33
+        self.assert_request_id(cell, fakes.FAKE_REQUEST_ID_LIST)
33 34
         cs.assert_called('GET', '/os-cells/%s' % cell_name)
34 35
 
35 36
     def test_get_capacities_for_a_given_cell(self):
36 37
         cell_name = 'child_cell'
37
-        cs.cells.capacities(cell_name)
38
+        ca = cs.cells.capacities(cell_name)
39
+        self.assert_request_id(ca, fakes.FAKE_REQUEST_ID_LIST)
38 40
         cs.assert_called('GET', '/os-cells/%s/capacities' % cell_name)
39 41
 
40 42
     def test_get_capacities_for_all_cells(self):
41
-        cs.cells.capacities()
43
+        ca = cs.cells.capacities()
44
+        self.assert_request_id(ca, fakes.FAKE_REQUEST_ID_LIST)
42 45
         cs.assert_called('GET', '/os-cells/capacities')

+ 4
- 2
novaclient/tests/unit/v2/contrib/test_instance_actions.py View File

@@ -29,7 +29,8 @@ cs = fakes.FakeClient(extensions=extensions)
29 29
 class InstanceActionExtensionTests(utils.TestCase):
30 30
     def test_list_instance_actions(self):
31 31
         server_uuid = '1234'
32
-        cs.instance_action.list(server_uuid)
32
+        ial = cs.instance_action.list(server_uuid)
33
+        self.assert_request_id(ial, fakes.FAKE_REQUEST_ID_LIST)
33 34
         cs.assert_called(
34 35
             'GET', '/servers/%s/os-instance-actions' %
35 36
             server_uuid)
@@ -37,7 +38,8 @@ class InstanceActionExtensionTests(utils.TestCase):
37 38
     def test_get_instance_action(self):
38 39
         server_uuid = '1234'
39 40
         request_id = 'req-abcde12345'
40
-        cs.instance_action.get(server_uuid, request_id)
41
+        ia = cs.instance_action.get(server_uuid, request_id)
42
+        self.assert_request_id(ia, fakes.FAKE_REQUEST_ID_LIST)
41 43
         cs.assert_called(
42 44
             'GET', '/servers/%s/os-instance-actions/%s'
43 45
             % (server_uuid, request_id))

+ 1
- 0
novaclient/tests/unit/v2/contrib/test_list_extensions.py View File

@@ -27,6 +27,7 @@ cs = fakes.FakeClient(extensions=extensions)
27 27
 class ListExtensionsTests(utils.TestCase):
28 28
     def test_list_extensions(self):
29 29
         all_exts = cs.list_extensions.show_all()
30
+        self.assert_request_id(all_exts, fakes.FAKE_REQUEST_ID_LIST)
30 31
         cs.assert_called('GET', '/extensions')
31 32
         self.assertTrue(len(all_exts) > 0)
32 33
         for r in all_exts:

+ 2
- 0
novaclient/tests/unit/v2/contrib/test_migrations.py View File

@@ -26,12 +26,14 @@ class MigrationsTest(utils.TestCase):
26 26
 
27 27
     def test_list_migrations(self):
28 28
         ml = cs.migrations.list()
29
+        self.assert_request_id(ml, fakes.FAKE_REQUEST_ID_LIST)
29 30
         cs.assert_called('GET', '/os-migrations')
30 31
         for m in ml:
31 32
             self.assertIsInstance(m, migrations.Migration)
32 33
 
33 34
     def test_list_migrations_with_filters(self):
34 35
         ml = cs.migrations.list('host1', 'finished', 'child1')
36
+        self.assert_request_id(ml, fakes.FAKE_REQUEST_ID_LIST)
35 37
 
36 38
         cs.assert_called('GET',
37 39
                          '/os-migrations?cell_name=child1&host=host1'

+ 1
- 0
novaclient/tests/unit/v2/contrib/test_server_external_events.py View File

@@ -40,5 +40,6 @@ class ServerExternalEventsTestCase(utils.TestCase):
40 40
                    'status': 'completed',
41 41
                    'tag': 'tag'}]
42 42
         result = cs.server_external_events.create(events)
43
+        self.assert_request_id(result, fakes.FAKE_REQUEST_ID_LIST)
43 44
         self.assertEqual(events, result)
44 45
         cs.assert_called('POST', '/os-server-external-events')

+ 8
- 4
novaclient/tests/unit/v2/contrib/test_tenant_networks.py View File

@@ -29,18 +29,22 @@ cs = fakes.FakeClient(extensions=extensions)
29 29
 class TenantNetworkExtensionTests(utils.TestCase):
30 30
     def test_list_tenant_networks(self):
31 31
         nets = cs.tenant_networks.list()
32
+        self.assert_request_id(nets, fakes.FAKE_REQUEST_ID_LIST)
32 33
         cs.assert_called('GET', '/os-tenant-networks')
33 34
         self.assertTrue(len(nets) > 0)
34 35
 
35 36
     def test_get_tenant_network(self):
36
-        cs.tenant_networks.get(1)
37
+        net = cs.tenant_networks.get(1)
38
+        self.assert_request_id(net, fakes.FAKE_REQUEST_ID_LIST)
37 39
         cs.assert_called('GET', '/os-tenant-networks/1')
38 40
 
39 41
     def test_create_tenant_networks(self):
40
-        cs.tenant_networks.create(label="net",
41
-                                  cidr="10.0.0.0/24")
42
+        net = cs.tenant_networks.create(label="net",
43
+                                        cidr="10.0.0.0/24")
44
+        self.assert_request_id(net, fakes.FAKE_REQUEST_ID_LIST)
42 45
         cs.assert_called('POST', '/os-tenant-networks')
43 46
 
44 47
     def test_delete_tenant_networks(self):
45
-        cs.tenant_networks.delete(1)
48
+        ret = cs.tenant_networks.delete(1)
49
+        self.assert_request_id(ret, fakes.FAKE_REQUEST_ID_LIST)
46 50
         cs.assert_called('DELETE', '/os-tenant-networks/1')

+ 6
- 6
novaclient/tests/unit/v2/fakes.py View File

@@ -296,7 +296,7 @@ class FakeHTTPClient(base_client.HTTPClient):
296 296
                 "updated": "2011-11-03T00:00:00+00:00"
297 297
             },
298 298
         ]
299
-        return (200, {}, {
299
+        return (200, FAKE_RESPONSE_HEADERS, {
300 300
             "extensions": exts,
301 301
         })
302 302
 
@@ -2304,7 +2304,7 @@ class FakeHTTPClient(base_client.HTTPClient):
2304 2304
         return (200, {}, {})
2305 2305
 
2306 2306
     def get_servers_1234_os_instance_actions(self, **kw):
2307
-        return (200, {}, {
2307
+        return (200, FAKE_RESPONSE_HEADERS, {
2308 2308
             "instanceActions":
2309 2309
                 [{"instance_uuid": "1234",
2310 2310
                   "user_id": "b968c25e04ab405f9fe4e6ca54cce9a5",
@@ -2315,7 +2315,7 @@ class FakeHTTPClient(base_client.HTTPClient):
2315 2315
                   "project_id": "04019601fe3648c0abd4f4abfb9e6106"}]})
2316 2316
 
2317 2317
     def get_servers_1234_os_instance_actions_req_abcde12345(self, **kw):
2318
-        return (200, {}, {
2318
+        return (200, FAKE_RESPONSE_HEADERS, {
2319 2319
             "instanceAction":
2320 2320
                 {"instance_uuid": "1234",
2321 2321
                  "user_id": "b968c25e04ab405f9fe4e6ca54cce9a5",
@@ -2352,7 +2352,7 @@ class FakeHTTPClient(base_client.HTTPClient):
2352 2352
             'rpc_port': 5673,
2353 2353
             'loaded': True
2354 2354
         }}
2355
-        return (200, {}, cell)
2355
+        return (200, FAKE_RESPONSE_HEADERS, cell)
2356 2356
 
2357 2357
     def get_os_cells_capacities(self, **kw):
2358 2358
         cell_capacities_response = {"cell": {"capacities": {"ram_free": {
@@ -2360,7 +2360,7 @@ class FakeHTTPClient(base_client.HTTPClient):
2360 2360
                             "16384": 0}, "total_mb": 7680}, "disk_free": {
2361 2361
             "units_by_mb": {"81920": 11, "20480": 46, "40960": 23, "163840": 5,
2362 2362
                             "0": 0}, "total_mb": 1052672}}}}
2363
-        return (200, {}, cell_capacities_response)
2363
+        return (200, FAKE_RESPONSE_HEADERS, cell_capacities_response)
2364 2364
 
2365 2365
     def get_os_cells_child_cell_capacities(self, **kw):
2366 2366
         return self.get_os_cells_capacities()
@@ -2381,7 +2381,7 @@ class FakeHTTPClient(base_client.HTTPClient):
2381 2381
                 "status": "Done",
2382 2382
                 "updated_at": "2012-10-29T13:42:02.000000"
2383 2383
             }]}
2384
-        return (200, {}, migrations)
2384
+        return (200, FAKE_RESPONSE_HEADERS, migrations)
2385 2385
 
2386 2386
     def post_os_server_external_events(self, **kw):
2387 2387
         return (200, {}, {'events': [

+ 12
- 3
novaclient/v2/contrib/assisted_volume_snapshots.py View File

@@ -28,8 +28,10 @@ class Snapshot(base.Resource):
28 28
     def delete(self):
29 29
         """
30 30
         Delete this snapshot.
31
+
32
+        :returns: An instance of novaclient.base.TupleWithMeta
31 33
         """
32
-        self.manager.delete(self)
34
+        return self.manager.delete(self)
33 35
 
34 36
 
35 37
 class AssistedSnapshotManager(base.Manager):
@@ -41,8 +43,15 @@ class AssistedSnapshotManager(base.Manager):
41 43
         return self._create('/os-assisted-volume-snapshots', body, 'snapshot')
42 44
 
43 45
     def delete(self, snapshot, delete_info):
44
-        self._delete("/os-assisted-volume-snapshots/%s?delete_info=%s" % (
45
-            base.getid(snapshot), json.dumps(delete_info)))
46
+        """
47
+        Delete a specified assisted volume snapshot.
48
+
49
+        :param snapshot: an assisted volume snapshot to delete
50
+        :param delete_info: Information for snapshot deletion
51
+        :returns: An instance of novaclient.base.TupleWithMeta
52
+        """
53
+        return self._delete("/os-assisted-volume-snapshots/%s?delete_info=%s" %
54
+                            (base.getid(snapshot), json.dumps(delete_info)))
46 55
 
47 56
 manager_class = AssistedSnapshotManager
48 57
 name = 'assisted_volume_snapshots'

+ 11
- 7
novaclient/v2/contrib/baremetal.py View File

@@ -88,8 +88,9 @@ class BareMetalNodeManager(base.ManagerWithFind):
88 88
         Delete a baremetal node.
89 89
 
90 90
         :param node: The :class:`BareMetalNode` to delete.
91
+        :returns: An instance of novaclient.base.TupleWithMeta
91 92
         """
92
-        self._delete('/os-baremetal-nodes/%s' % base.getid(node))
93
+        return self._delete('/os-baremetal-nodes/%s' % base.getid(node))
93 94
 
94 95
     def get(self, node_id):
95 96
         """
@@ -122,8 +123,8 @@ class BareMetalNodeManager(base.ManagerWithFind):
122 123
                                   'datapath_id': datapath_id,
123 124
                                   'port_no': port_no}}
124 125
         url = '/os-baremetal-nodes/%s/action' % node_id
125
-        _resp, body = self.api.client.post(url, body=body)
126
-        return BareMetalNodeInterface(self, body['interface'])
126
+        resp, body = self.api.client.post(url, body=body)
127
+        return BareMetalNodeInterface(self, body['interface'], resp=resp)
127 128
 
128 129
     def remove_interface(self, node_id, address):
129 130
         """
@@ -131,21 +132,24 @@ class BareMetalNodeManager(base.ManagerWithFind):
131 132
 
132 133
         :param node_id: The ID of the node to modify.
133 134
         :param address: The MAC address to remove.
134
-        :rtype: bool
135
+        :returns: An instance of novaclient.base.TupleWithMeta
135 136
         """
136 137
         req_body = {'remove_interface': {'address': address}}
137 138
         url = '/os-baremetal-nodes/%s/action' % node_id
138
-        self.api.client.post(url, body=req_body)
139
+        resp, body = self.api.client.post(url, body=req_body)
140
+
141
+        return self.convert_into_with_meta(body, resp)
139 142
 
140 143
     def list_interfaces(self, node_id):
141 144
         """
142 145
         List the interfaces on a baremetal node.
143 146
 
144 147
         :param node_id: The ID of the node to list.
145
-        :rtype: list
148
+        :rtype: novaclient.base.ListWithMeta
146 149
         """
147
-        interfaces = []
150
+        interfaces = base.ListWithMeta([], None)
148 151
         node = self._get("/os-baremetal-nodes/%s" % node_id, 'node')
152
+        interfaces.append_request_ids(node.request_ids)
149 153
         for interface in node.interfaces:
150 154
             interface_object = BareMetalNodeInterface(self, interface)
151 155
             interfaces.append(interface_object)

+ 13
- 2
novaclient/v2/contrib/tenant_networks.py View File

@@ -20,7 +20,12 @@ from novaclient import utils
20 20
 
21 21
 class TenantNetwork(base.Resource):
22 22
     def delete(self):
23
-        self.manager.delete(network=self)
23
+        """
24
+        Delete this project network.
25
+
26
+        :returns: An instance of novaclient.base.TupleWithMeta
27
+        """
28
+        return self.manager.delete(network=self)
24 29
 
25 30
 
26 31
 class TenantNetworkManager(base.ManagerWithFind):
@@ -34,7 +39,13 @@ class TenantNetworkManager(base.ManagerWithFind):
34 39
                          'network')
35 40
 
36 41
     def delete(self, network):
37
-        self._delete('/os-tenant-networks/%s' % base.getid(network))
42
+        """
43
+        Delete a specified project network.
44
+
45
+        :param network: a project network to delete
46
+        :returns: An instance of novaclient.base.TupleWithMeta
47
+        """
48
+        return self._delete('/os-tenant-networks/%s' % base.getid(network))
38 49
 
39 50
     def create(self, label, cidr):
40 51
         body = {'network': {'label': label, 'cidr': cidr}}

Loading…
Cancel
Save