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
This commit is contained in:
parent
0414bab3d3
commit
9f10d7d0b0
@ -15,6 +15,9 @@
|
||||
from novaclient.tests.unit.v2 import fakes
|
||||
from novaclient.v2 import client
|
||||
|
||||
FAKE_REQUEST_ID_LIST = fakes.FAKE_REQUEST_ID_LIST
|
||||
FAKE_RESPONSE_HEADERS = fakes.FAKE_RESPONSE_HEADERS
|
||||
|
||||
|
||||
class FakeClient(fakes.FakeClient):
|
||||
def __init__(self, *args, **kwargs):
|
||||
@ -27,29 +30,29 @@ class FakeClient(fakes.FakeClient):
|
||||
|
||||
class FakeHTTPClient(fakes.FakeHTTPClient):
|
||||
def get_os_tenant_networks(self):
|
||||
return (200, {}, {
|
||||
return (200, FAKE_RESPONSE_HEADERS, {
|
||||
'networks': [{"label": "1", "cidr": "10.0.0.0/24",
|
||||
'project_id': '4ffc664c198e435e9853f2538fbcd7a7',
|
||||
'id': '1'}]})
|
||||
|
||||
def get_os_tenant_networks_1(self, **kw):
|
||||
return (200, {}, {
|
||||
return (200, FAKE_RESPONSE_HEADERS, {
|
||||
'network': {"label": "1", "cidr": "10.0.0.0/24",
|
||||
'project_id': '4ffc664c198e435e9853f2538fbcd7a7',
|
||||
'id': '1'}})
|
||||
|
||||
def post_os_tenant_networks(self, **kw):
|
||||
return (201, {}, {
|
||||
return (201, FAKE_RESPONSE_HEADERS, {
|
||||
'network': {"label": "1", "cidr": "10.0.0.0/24",
|
||||
'project_id': '4ffc664c198e435e9853f2538fbcd7a7',
|
||||
'id': '1'}})
|
||||
|
||||
def delete_os_tenant_networks_1(self, **kw):
|
||||
return (204, {}, None)
|
||||
return (204, FAKE_RESPONSE_HEADERS, None)
|
||||
|
||||
def get_os_baremetal_nodes(self, **kw):
|
||||
return (
|
||||
200, {}, {
|
||||
200, FAKE_RESPONSE_HEADERS, {
|
||||
'nodes': [
|
||||
{
|
||||
"id": 1,
|
||||
@ -72,7 +75,7 @@ class FakeHTTPClient(fakes.FakeHTTPClient):
|
||||
|
||||
def get_os_baremetal_nodes_1(self, **kw):
|
||||
return (
|
||||
200, {}, {
|
||||
200, FAKE_RESPONSE_HEADERS, {
|
||||
'node': {
|
||||
"id": 1,
|
||||
"instance_uuid": None,
|
||||
@ -93,7 +96,7 @@ class FakeHTTPClient(fakes.FakeHTTPClient):
|
||||
|
||||
def post_os_baremetal_nodes(self, **kw):
|
||||
return (
|
||||
200, {}, {
|
||||
200, FAKE_RESPONSE_HEADERS, {
|
||||
'node': {
|
||||
"id": 1,
|
||||
"instance_uuid": None,
|
||||
@ -112,14 +115,14 @@ class FakeHTTPClient(fakes.FakeHTTPClient):
|
||||
)
|
||||
|
||||
def delete_os_baremetal_nodes_1(self, **kw):
|
||||
return (202, {}, {})
|
||||
return (202, FAKE_RESPONSE_HEADERS, {})
|
||||
|
||||
def post_os_baremetal_nodes_1_action(self, **kw):
|
||||
body = kw['body']
|
||||
action = list(body)[0]
|
||||
if action == "add_interface":
|
||||
return (
|
||||
200, {}, {
|
||||
200, FAKE_RESPONSE_HEADERS, {
|
||||
'interface': {
|
||||
"id": 2,
|
||||
"address": "bb:cc:dd:ee:ff:aa",
|
||||
@ -129,18 +132,19 @@ class FakeHTTPClient(fakes.FakeHTTPClient):
|
||||
}
|
||||
)
|
||||
elif action == "remove_interface":
|
||||
return (202, {}, {})
|
||||
return (202, FAKE_RESPONSE_HEADERS, {})
|
||||
else:
|
||||
return (500, {}, {})
|
||||
|
||||
def post_os_assisted_volume_snapshots(self, **kw):
|
||||
return (202, {}, {'snapshot': {'id': 'blah', 'volumeId': '1'}})
|
||||
return (202, FAKE_RESPONSE_HEADERS,
|
||||
{'snapshot': {'id': 'blah', 'volumeId': '1'}})
|
||||
|
||||
def delete_os_assisted_volume_snapshots_x(self, **kw):
|
||||
return (202, {}, {})
|
||||
return (202, FAKE_RESPONSE_HEADERS, {})
|
||||
|
||||
def post_os_server_external_events(self, **kw):
|
||||
return (200, {}, {
|
||||
return (200, FAKE_RESPONSE_HEADERS, {
|
||||
'events': [
|
||||
{'name': 'test-event',
|
||||
'status': 'completed',
|
||||
|
@ -32,11 +32,13 @@ cs = fakes.FakeClient(extensions=extensions)
|
||||
class AssistedVolumeSnapshotsTestCase(utils.TestCase):
|
||||
|
||||
def test_create_snap(self):
|
||||
cs.assisted_volume_snapshots.create('1', {})
|
||||
vs = cs.assisted_volume_snapshots.create('1', {})
|
||||
self.assert_request_id(vs, fakes.FAKE_REQUEST_ID_LIST)
|
||||
cs.assert_called('POST', '/os-assisted-volume-snapshots')
|
||||
|
||||
def test_delete_snap(self):
|
||||
cs.assisted_volume_snapshots.delete('x', {})
|
||||
vs = cs.assisted_volume_snapshots.delete('x', {})
|
||||
self.assert_request_id(vs, fakes.FAKE_REQUEST_ID_LIST)
|
||||
cs.assert_called(
|
||||
'DELETE',
|
||||
'/os-assisted-volume-snapshots/x?delete_info={}')
|
||||
|
@ -30,35 +30,42 @@ class BaremetalExtensionTest(utils.TestCase):
|
||||
|
||||
def test_list_nodes(self):
|
||||
nl = cs.baremetal.list()
|
||||
self.assert_request_id(nl, fakes.FAKE_REQUEST_ID_LIST)
|
||||
cs.assert_called('GET', '/os-baremetal-nodes')
|
||||
for n in nl:
|
||||
self.assertIsInstance(n, baremetal.BareMetalNode)
|
||||
|
||||
def test_get_node(self):
|
||||
n = cs.baremetal.get(1)
|
||||
self.assert_request_id(n, fakes.FAKE_REQUEST_ID_LIST)
|
||||
cs.assert_called('GET', '/os-baremetal-nodes/1')
|
||||
self.assertIsInstance(n, baremetal.BareMetalNode)
|
||||
|
||||
def test_create_node(self):
|
||||
n = cs.baremetal.create("service_host", 1, 1024, 2048,
|
||||
"aa:bb:cc:dd:ee:ff")
|
||||
self.assert_request_id(n, fakes.FAKE_REQUEST_ID_LIST)
|
||||
cs.assert_called('POST', '/os-baremetal-nodes')
|
||||
self.assertIsInstance(n, baremetal.BareMetalNode)
|
||||
|
||||
def test_delete_node(self):
|
||||
n = cs.baremetal.get(1)
|
||||
cs.baremetal.delete(n)
|
||||
ret = cs.baremetal.delete(n)
|
||||
self.assert_request_id(ret, fakes.FAKE_REQUEST_ID_LIST)
|
||||
cs.assert_called('DELETE', '/os-baremetal-nodes/1')
|
||||
|
||||
def test_node_add_interface(self):
|
||||
i = cs.baremetal.add_interface(1, "bb:cc:dd:ee:ff:aa", 1, 2)
|
||||
self.assert_request_id(i, fakes.FAKE_REQUEST_ID_LIST)
|
||||
cs.assert_called('POST', '/os-baremetal-nodes/1/action')
|
||||
self.assertIsInstance(i, baremetal.BareMetalNodeInterface)
|
||||
|
||||
def test_node_remove_interface(self):
|
||||
cs.baremetal.remove_interface(1, "bb:cc:dd:ee:ff:aa")
|
||||
ret = cs.baremetal.remove_interface(1, "bb:cc:dd:ee:ff:aa")
|
||||
self.assert_request_id(ret, fakes.FAKE_REQUEST_ID_LIST)
|
||||
cs.assert_called('POST', '/os-baremetal-nodes/1/action')
|
||||
|
||||
def test_node_list_interfaces(self):
|
||||
cs.baremetal.list_interfaces(1)
|
||||
il = cs.baremetal.list_interfaces(1)
|
||||
self.assert_request_id(il, fakes.FAKE_REQUEST_ID_LIST)
|
||||
cs.assert_called('GET', '/os-baremetal-nodes/1')
|
||||
|
@ -29,14 +29,17 @@ cs = fakes.FakeClient(extensions=extensions)
|
||||
class CellsExtensionTests(utils.TestCase):
|
||||
def test_get_cells(self):
|
||||
cell_name = 'child_cell'
|
||||
cs.cells.get(cell_name)
|
||||
cell = cs.cells.get(cell_name)
|
||||
self.assert_request_id(cell, fakes.FAKE_REQUEST_ID_LIST)
|
||||
cs.assert_called('GET', '/os-cells/%s' % cell_name)
|
||||
|
||||
def test_get_capacities_for_a_given_cell(self):
|
||||
cell_name = 'child_cell'
|
||||
cs.cells.capacities(cell_name)
|
||||
ca = cs.cells.capacities(cell_name)
|
||||
self.assert_request_id(ca, fakes.FAKE_REQUEST_ID_LIST)
|
||||
cs.assert_called('GET', '/os-cells/%s/capacities' % cell_name)
|
||||
|
||||
def test_get_capacities_for_all_cells(self):
|
||||
cs.cells.capacities()
|
||||
ca = cs.cells.capacities()
|
||||
self.assert_request_id(ca, fakes.FAKE_REQUEST_ID_LIST)
|
||||
cs.assert_called('GET', '/os-cells/capacities')
|
||||
|
@ -29,7 +29,8 @@ cs = fakes.FakeClient(extensions=extensions)
|
||||
class InstanceActionExtensionTests(utils.TestCase):
|
||||
def test_list_instance_actions(self):
|
||||
server_uuid = '1234'
|
||||
cs.instance_action.list(server_uuid)
|
||||
ial = cs.instance_action.list(server_uuid)
|
||||
self.assert_request_id(ial, fakes.FAKE_REQUEST_ID_LIST)
|
||||
cs.assert_called(
|
||||
'GET', '/servers/%s/os-instance-actions' %
|
||||
server_uuid)
|
||||
@ -37,7 +38,8 @@ class InstanceActionExtensionTests(utils.TestCase):
|
||||
def test_get_instance_action(self):
|
||||
server_uuid = '1234'
|
||||
request_id = 'req-abcde12345'
|
||||
cs.instance_action.get(server_uuid, request_id)
|
||||
ia = cs.instance_action.get(server_uuid, request_id)
|
||||
self.assert_request_id(ia, fakes.FAKE_REQUEST_ID_LIST)
|
||||
cs.assert_called(
|
||||
'GET', '/servers/%s/os-instance-actions/%s'
|
||||
% (server_uuid, request_id))
|
||||
|
@ -27,6 +27,7 @@ cs = fakes.FakeClient(extensions=extensions)
|
||||
class ListExtensionsTests(utils.TestCase):
|
||||
def test_list_extensions(self):
|
||||
all_exts = cs.list_extensions.show_all()
|
||||
self.assert_request_id(all_exts, fakes.FAKE_REQUEST_ID_LIST)
|
||||
cs.assert_called('GET', '/extensions')
|
||||
self.assertTrue(len(all_exts) > 0)
|
||||
for r in all_exts:
|
||||
|
@ -26,12 +26,14 @@ class MigrationsTest(utils.TestCase):
|
||||
|
||||
def test_list_migrations(self):
|
||||
ml = cs.migrations.list()
|
||||
self.assert_request_id(ml, fakes.FAKE_REQUEST_ID_LIST)
|
||||
cs.assert_called('GET', '/os-migrations')
|
||||
for m in ml:
|
||||
self.assertIsInstance(m, migrations.Migration)
|
||||
|
||||
def test_list_migrations_with_filters(self):
|
||||
ml = cs.migrations.list('host1', 'finished', 'child1')
|
||||
self.assert_request_id(ml, fakes.FAKE_REQUEST_ID_LIST)
|
||||
|
||||
cs.assert_called('GET',
|
||||
'/os-migrations?cell_name=child1&host=host1'
|
||||
|
@ -40,5 +40,6 @@ class ServerExternalEventsTestCase(utils.TestCase):
|
||||
'status': 'completed',
|
||||
'tag': 'tag'}]
|
||||
result = cs.server_external_events.create(events)
|
||||
self.assert_request_id(result, fakes.FAKE_REQUEST_ID_LIST)
|
||||
self.assertEqual(events, result)
|
||||
cs.assert_called('POST', '/os-server-external-events')
|
||||
|
@ -29,18 +29,22 @@ cs = fakes.FakeClient(extensions=extensions)
|
||||
class TenantNetworkExtensionTests(utils.TestCase):
|
||||
def test_list_tenant_networks(self):
|
||||
nets = cs.tenant_networks.list()
|
||||
self.assert_request_id(nets, fakes.FAKE_REQUEST_ID_LIST)
|
||||
cs.assert_called('GET', '/os-tenant-networks')
|
||||
self.assertTrue(len(nets) > 0)
|
||||
|
||||
def test_get_tenant_network(self):
|
||||
cs.tenant_networks.get(1)
|
||||
net = cs.tenant_networks.get(1)
|
||||
self.assert_request_id(net, fakes.FAKE_REQUEST_ID_LIST)
|
||||
cs.assert_called('GET', '/os-tenant-networks/1')
|
||||
|
||||
def test_create_tenant_networks(self):
|
||||
cs.tenant_networks.create(label="net",
|
||||
cidr="10.0.0.0/24")
|
||||
net = cs.tenant_networks.create(label="net",
|
||||
cidr="10.0.0.0/24")
|
||||
self.assert_request_id(net, fakes.FAKE_REQUEST_ID_LIST)
|
||||
cs.assert_called('POST', '/os-tenant-networks')
|
||||
|
||||
def test_delete_tenant_networks(self):
|
||||
cs.tenant_networks.delete(1)
|
||||
ret = cs.tenant_networks.delete(1)
|
||||
self.assert_request_id(ret, fakes.FAKE_REQUEST_ID_LIST)
|
||||
cs.assert_called('DELETE', '/os-tenant-networks/1')
|
||||
|
@ -296,7 +296,7 @@ class FakeHTTPClient(base_client.HTTPClient):
|
||||
"updated": "2011-11-03T00:00:00+00:00"
|
||||
},
|
||||
]
|
||||
return (200, {}, {
|
||||
return (200, FAKE_RESPONSE_HEADERS, {
|
||||
"extensions": exts,
|
||||
})
|
||||
|
||||
@ -2304,7 +2304,7 @@ class FakeHTTPClient(base_client.HTTPClient):
|
||||
return (200, {}, {})
|
||||
|
||||
def get_servers_1234_os_instance_actions(self, **kw):
|
||||
return (200, {}, {
|
||||
return (200, FAKE_RESPONSE_HEADERS, {
|
||||
"instanceActions":
|
||||
[{"instance_uuid": "1234",
|
||||
"user_id": "b968c25e04ab405f9fe4e6ca54cce9a5",
|
||||
@ -2315,7 +2315,7 @@ class FakeHTTPClient(base_client.HTTPClient):
|
||||
"project_id": "04019601fe3648c0abd4f4abfb9e6106"}]})
|
||||
|
||||
def get_servers_1234_os_instance_actions_req_abcde12345(self, **kw):
|
||||
return (200, {}, {
|
||||
return (200, FAKE_RESPONSE_HEADERS, {
|
||||
"instanceAction":
|
||||
{"instance_uuid": "1234",
|
||||
"user_id": "b968c25e04ab405f9fe4e6ca54cce9a5",
|
||||
@ -2352,7 +2352,7 @@ class FakeHTTPClient(base_client.HTTPClient):
|
||||
'rpc_port': 5673,
|
||||
'loaded': True
|
||||
}}
|
||||
return (200, {}, cell)
|
||||
return (200, FAKE_RESPONSE_HEADERS, cell)
|
||||
|
||||
def get_os_cells_capacities(self, **kw):
|
||||
cell_capacities_response = {"cell": {"capacities": {"ram_free": {
|
||||
@ -2360,7 +2360,7 @@ class FakeHTTPClient(base_client.HTTPClient):
|
||||
"16384": 0}, "total_mb": 7680}, "disk_free": {
|
||||
"units_by_mb": {"81920": 11, "20480": 46, "40960": 23, "163840": 5,
|
||||
"0": 0}, "total_mb": 1052672}}}}
|
||||
return (200, {}, cell_capacities_response)
|
||||
return (200, FAKE_RESPONSE_HEADERS, cell_capacities_response)
|
||||
|
||||
def get_os_cells_child_cell_capacities(self, **kw):
|
||||
return self.get_os_cells_capacities()
|
||||
@ -2381,7 +2381,7 @@ class FakeHTTPClient(base_client.HTTPClient):
|
||||
"status": "Done",
|
||||
"updated_at": "2012-10-29T13:42:02.000000"
|
||||
}]}
|
||||
return (200, {}, migrations)
|
||||
return (200, FAKE_RESPONSE_HEADERS, migrations)
|
||||
|
||||
def post_os_server_external_events(self, **kw):
|
||||
return (200, {}, {'events': [
|
||||
|
@ -28,8 +28,10 @@ class Snapshot(base.Resource):
|
||||
def delete(self):
|
||||
"""
|
||||
Delete this snapshot.
|
||||
|
||||
:returns: An instance of novaclient.base.TupleWithMeta
|
||||
"""
|
||||
self.manager.delete(self)
|
||||
return self.manager.delete(self)
|
||||
|
||||
|
||||
class AssistedSnapshotManager(base.Manager):
|
||||
@ -41,8 +43,15 @@ class AssistedSnapshotManager(base.Manager):
|
||||
return self._create('/os-assisted-volume-snapshots', body, 'snapshot')
|
||||
|
||||
def delete(self, snapshot, delete_info):
|
||||
self._delete("/os-assisted-volume-snapshots/%s?delete_info=%s" % (
|
||||
base.getid(snapshot), json.dumps(delete_info)))
|
||||
"""
|
||||
Delete a specified assisted volume snapshot.
|
||||
|
||||
:param snapshot: an assisted volume snapshot to delete
|
||||
:param delete_info: Information for snapshot deletion
|
||||
:returns: An instance of novaclient.base.TupleWithMeta
|
||||
"""
|
||||
return self._delete("/os-assisted-volume-snapshots/%s?delete_info=%s" %
|
||||
(base.getid(snapshot), json.dumps(delete_info)))
|
||||
|
||||
manager_class = AssistedSnapshotManager
|
||||
name = 'assisted_volume_snapshots'
|
||||
|
@ -88,8 +88,9 @@ class BareMetalNodeManager(base.ManagerWithFind):
|
||||
Delete a baremetal node.
|
||||
|
||||
:param node: The :class:`BareMetalNode` to delete.
|
||||
:returns: An instance of novaclient.base.TupleWithMeta
|
||||
"""
|
||||
self._delete('/os-baremetal-nodes/%s' % base.getid(node))
|
||||
return self._delete('/os-baremetal-nodes/%s' % base.getid(node))
|
||||
|
||||
def get(self, node_id):
|
||||
"""
|
||||
@ -122,8 +123,8 @@ class BareMetalNodeManager(base.ManagerWithFind):
|
||||
'datapath_id': datapath_id,
|
||||
'port_no': port_no}}
|
||||
url = '/os-baremetal-nodes/%s/action' % node_id
|
||||
_resp, body = self.api.client.post(url, body=body)
|
||||
return BareMetalNodeInterface(self, body['interface'])
|
||||
resp, body = self.api.client.post(url, body=body)
|
||||
return BareMetalNodeInterface(self, body['interface'], resp=resp)
|
||||
|
||||
def remove_interface(self, node_id, address):
|
||||
"""
|
||||
@ -131,21 +132,24 @@ class BareMetalNodeManager(base.ManagerWithFind):
|
||||
|
||||
:param node_id: The ID of the node to modify.
|
||||
:param address: The MAC address to remove.
|
||||
:rtype: bool
|
||||
:returns: An instance of novaclient.base.TupleWithMeta
|
||||
"""
|
||||
req_body = {'remove_interface': {'address': address}}
|
||||
url = '/os-baremetal-nodes/%s/action' % node_id
|
||||
self.api.client.post(url, body=req_body)
|
||||
resp, body = self.api.client.post(url, body=req_body)
|
||||
|
||||
return self.convert_into_with_meta(body, resp)
|
||||
|
||||
def list_interfaces(self, node_id):
|
||||
"""
|
||||
List the interfaces on a baremetal node.
|
||||
|
||||
:param node_id: The ID of the node to list.
|
||||
:rtype: list
|
||||
:rtype: novaclient.base.ListWithMeta
|
||||
"""
|
||||
interfaces = []
|
||||
interfaces = base.ListWithMeta([], None)
|
||||
node = self._get("/os-baremetal-nodes/%s" % node_id, 'node')
|
||||
interfaces.append_request_ids(node.request_ids)
|
||||
for interface in node.interfaces:
|
||||
interface_object = BareMetalNodeInterface(self, interface)
|
||||
interfaces.append(interface_object)
|
||||
|
@ -20,7 +20,12 @@ from novaclient import utils
|
||||
|
||||
class TenantNetwork(base.Resource):
|
||||
def delete(self):
|
||||
self.manager.delete(network=self)
|
||||
"""
|
||||
Delete this project network.
|
||||
|
||||
:returns: An instance of novaclient.base.TupleWithMeta
|
||||
"""
|
||||
return self.manager.delete(network=self)
|
||||
|
||||
|
||||
class TenantNetworkManager(base.ManagerWithFind):
|
||||
@ -34,7 +39,13 @@ class TenantNetworkManager(base.ManagerWithFind):
|
||||
'network')
|
||||
|
||||
def delete(self, network):
|
||||
self._delete('/os-tenant-networks/%s' % base.getid(network))
|
||||
"""
|
||||
Delete a specified project network.
|
||||
|
||||
:param network: a project network to delete
|
||||
:returns: An instance of novaclient.base.TupleWithMeta
|
||||
"""
|
||||
return self._delete('/os-tenant-networks/%s' % base.getid(network))
|
||||
|
||||
def create(self, label, cidr):
|
||||
body = {'network': {'label': label, 'cidr': cidr}}
|
||||
|
Loading…
Reference in New Issue
Block a user