diff options
| author | Andrew Laski <andrew.laski@rackspace.com> | 2013-02-21 17:30:06 -0500 |
|---|---|---|
| committer | Andrew Laski <andrew.laski@rackspace.com> | 2013-02-25 19:33:02 -0500 |
| commit | ab2920726c0e2633c033a31a324f30a97fdce6bd (patch) | |
| tree | 2c93e8a84654049f3420b19a537a0bd392f68001 /nova/tests | |
| parent | 73a58f9cc85bf8d7fc745d4260577d764e8bc81c (diff) | |
Rework instance actions to work with cells
In a cells setup an instance action is recorded at the global cell level
while events try to get recorded in a child cell compute node or
scheduler. The event recording fails because it can't find an action to
link to. This patch adds the recording of actions at the child cell
level, and changes the API extension to query the db in a child cell for
the record of actions and events.
This does not address the fact that an action is recorded at the global
cell level.
Bug 1132935
Change-Id: I5831f146397e7afa2d93d26c5d6f9abb9bc6670d
Diffstat (limited to 'nova/tests')
| -rw-r--r-- | nova/tests/api/openstack/compute/contrib/test_instance_actions.py | 5 | ||||
| -rw-r--r-- | nova/tests/cells/test_cells_manager.py | 44 | ||||
| -rw-r--r-- | nova/tests/cells/test_cells_messaging.py | 47 | ||||
| -rw-r--r-- | nova/tests/cells/test_cells_rpcapi.py | 55 | ||||
| -rw-r--r-- | nova/tests/integrated/test_api_samples.py | 4 |
5 files changed, 155 insertions, 0 deletions
diff --git a/nova/tests/api/openstack/compute/contrib/test_instance_actions.py b/nova/tests/api/openstack/compute/contrib/test_instance_actions.py index 8650275a7..573385a52 100644 --- a/nova/tests/api/openstack/compute/contrib/test_instance_actions.py +++ b/nova/tests/api/openstack/compute/contrib/test_instance_actions.py @@ -20,6 +20,7 @@ from lxml import etree from webob import exc from nova.api.openstack.compute.contrib import instance_actions +from nova.compute import api as compute_api from nova import db from nova.db.sqlalchemy import models from nova import exception @@ -92,9 +93,13 @@ class InstanceActionsTest(test.TestCase): self.fake_actions = copy.deepcopy(fake_instance_actions.FAKE_ACTIONS) self.fake_events = copy.deepcopy(fake_instance_actions.FAKE_EVENTS) + def fake_get(self, context, instance_uuid): + return {'uuid': instance_uuid} + def fake_instance_get_by_uuid(context, instance_id): return {'name': 'fake', 'project_id': context.project_id} + self.stubs.Set(compute_api.API, 'get', fake_get) self.stubs.Set(db, 'instance_get_by_uuid', fake_instance_get_by_uuid) def test_list_actions(self): diff --git a/nova/tests/cells/test_cells_manager.py b/nova/tests/cells/test_cells_manager.py index d53fdbb7f..7dfb0fa02 100644 --- a/nova/tests/cells/test_cells_manager.py +++ b/nova/tests/cells/test_cells_manager.py @@ -27,6 +27,7 @@ from nova.openstack.common import rpc from nova.openstack.common import timeutils from nova import test from nova.tests.cells import fakes +from nova.tests import fake_instance_actions CONF = cfg.CONF CONF.import_opt('compute_topic', 'nova.compute.rpcapi') @@ -429,3 +430,46 @@ class CellsManagerClassTestCase(test.TestCase): response = self.cells_manager.compute_node_get(self.ctxt, compute_id=cell_and_id) self.assertEqual(expected_response, response) + + def test_actions_get(self): + fake_uuid = fake_instance_actions.FAKE_UUID + fake_req_id = fake_instance_actions.FAKE_REQUEST_ID1 + fake_act = fake_instance_actions.FAKE_ACTIONS[fake_uuid][fake_req_id] + fake_response = messaging.Response('fake-cell', [fake_act], False) + expected_response = [fake_act] + self.mox.StubOutWithMock(self.msg_runner, 'actions_get') + self.msg_runner.actions_get(self.ctxt, 'fake-cell', + 'fake-uuid').AndReturn(fake_response) + self.mox.ReplayAll() + response = self.cells_manager.actions_get(self.ctxt, 'fake-cell', + 'fake-uuid') + self.assertEqual(expected_response, response) + + def test_action_get_by_request_id(self): + fake_uuid = fake_instance_actions.FAKE_UUID + fake_req_id = fake_instance_actions.FAKE_REQUEST_ID1 + fake_act = fake_instance_actions.FAKE_ACTIONS[fake_uuid][fake_req_id] + fake_response = messaging.Response('fake-cell', fake_act, False) + expected_response = fake_act + self.mox.StubOutWithMock(self.msg_runner, 'action_get_by_request_id') + self.msg_runner.action_get_by_request_id(self.ctxt, 'fake-cell', + 'fake-uuid', 'req-fake').AndReturn(fake_response) + self.mox.ReplayAll() + response = self.cells_manager.action_get_by_request_id(self.ctxt, + 'fake-cell', + 'fake-uuid', + 'req-fake') + self.assertEqual(expected_response, response) + + def test_action_events_get(self): + fake_action_id = fake_instance_actions.FAKE_ACTION_ID1 + fake_events = fake_instance_actions.FAKE_EVENTS[fake_action_id] + fake_response = messaging.Response('fake-cell', fake_events, False) + expected_response = fake_events + self.mox.StubOutWithMock(self.msg_runner, 'action_events_get') + self.msg_runner.action_events_get(self.ctxt, 'fake-cell', + 'fake-action').AndReturn(fake_response) + self.mox.ReplayAll() + response = self.cells_manager.action_events_get(self.ctxt, 'fake-cell', + 'fake-action') + self.assertEqual(expected_response, response) diff --git a/nova/tests/cells/test_cells_messaging.py b/nova/tests/cells/test_cells_messaging.py index 30adfdcd7..effe27660 100644 --- a/nova/tests/cells/test_cells_messaging.py +++ b/nova/tests/cells/test_cells_messaging.py @@ -25,6 +25,7 @@ from nova.openstack.common import rpc from nova.openstack.common import timeutils from nova import test from nova.tests.cells import fakes +from nova.tests import fake_instance_actions CONF = cfg.CONF CONF.import_opt('name', 'nova.cells.opts', group='cells') @@ -825,6 +826,52 @@ class CellsTargetedMethodsTestCase(test.TestCase): result = response.value_or_raise() self.assertEqual('fake_result', result) + def test_actions_get(self): + fake_uuid = fake_instance_actions.FAKE_UUID + fake_req_id = fake_instance_actions.FAKE_REQUEST_ID1 + fake_act = fake_instance_actions.FAKE_ACTIONS[fake_uuid][fake_req_id] + + self.mox.StubOutWithMock(self.tgt_db_inst, 'actions_get') + self.tgt_db_inst.actions_get(self.ctxt, + 'fake-uuid').AndReturn([fake_act]) + self.mox.ReplayAll() + + response = self.src_msg_runner.actions_get(self.ctxt, + self.tgt_cell_name, + 'fake-uuid') + result = response.value_or_raise() + self.assertEqual([fake_act], result) + + def test_action_get_by_request_id(self): + fake_uuid = fake_instance_actions.FAKE_UUID + fake_req_id = fake_instance_actions.FAKE_REQUEST_ID1 + fake_act = fake_instance_actions.FAKE_ACTIONS[fake_uuid][fake_req_id] + + self.mox.StubOutWithMock(self.tgt_db_inst, 'action_get_by_request_id') + self.tgt_db_inst.action_get_by_request_id(self.ctxt, + 'fake-uuid', 'req-fake').AndReturn(fake_act) + self.mox.ReplayAll() + + response = self.src_msg_runner.action_get_by_request_id(self.ctxt, + self.tgt_cell_name, 'fake-uuid', 'req-fake') + result = response.value_or_raise() + self.assertEqual(fake_act, result) + + def test_action_events_get(self): + fake_action_id = fake_instance_actions.FAKE_ACTION_ID1 + fake_events = fake_instance_actions.FAKE_EVENTS[fake_action_id] + + self.mox.StubOutWithMock(self.tgt_db_inst, 'action_events_get') + self.tgt_db_inst.action_events_get(self.ctxt, + 'fake-action').AndReturn(fake_events) + self.mox.ReplayAll() + + response = self.src_msg_runner.action_events_get(self.ctxt, + self.tgt_cell_name, + 'fake-action') + result = response.value_or_raise() + self.assertEqual(fake_events, result) + class CellsBroadcastMethodsTestCase(test.TestCase): """Test case for _BroadcastMessageMethods class. Most of these diff --git a/nova/tests/cells/test_cells_rpcapi.py b/nova/tests/cells/test_cells_rpcapi.py index f00b1b290..c915a5bae 100644 --- a/nova/tests/cells/test_cells_rpcapi.py +++ b/nova/tests/cells/test_cells_rpcapi.py @@ -19,6 +19,7 @@ Tests For Cells RPCAPI from oslo.config import cfg from nova.cells import rpcapi as cells_rpcapi +from nova import exception from nova.openstack.common import rpc from nova import test @@ -305,3 +306,57 @@ class CellsAPITestCase(test.TestCase): self._check_result(call_info, 'compute_node_get', expected_args, version='1.4') self.assertEqual(result, 'fake_response') + + def test_actions_get(self): + fake_instance = {'uuid': 'fake-uuid', 'cell_name': 'region!child'} + call_info = self._stub_rpc_method('call', 'fake_response') + result = self.cells_rpcapi.actions_get(self.fake_context, + fake_instance) + expected_args = {'cell_name': 'region!child', + 'instance_uuid': fake_instance['uuid']} + self._check_result(call_info, 'actions_get', expected_args, + version='1.5') + self.assertEqual(result, 'fake_response') + + def test_actions_get_no_cell(self): + fake_instance = {'uuid': 'fake-uuid', 'cell_name': None} + self.assertRaises(exception.InstanceUnknownCell, + self.cells_rpcapi.actions_get, self.fake_context, + fake_instance) + + def test_action_get_by_request_id(self): + fake_instance = {'uuid': 'fake-uuid', 'cell_name': 'region!child'} + call_info = self._stub_rpc_method('call', 'fake_response') + result = self.cells_rpcapi.action_get_by_request_id(self.fake_context, + fake_instance, + 'req-fake') + expected_args = {'cell_name': 'region!child', + 'instance_uuid': fake_instance['uuid'], + 'request_id': 'req-fake'} + self._check_result(call_info, 'action_get_by_request_id', + expected_args, version='1.5') + self.assertEqual(result, 'fake_response') + + def test_action_get_by_request_id_no_cell(self): + fake_instance = {'uuid': 'fake-uuid', 'cell_name': None} + self.assertRaises(exception.InstanceUnknownCell, + self.cells_rpcapi.action_get_by_request_id, + self.fake_context, fake_instance, 'req-fake') + + def test_action_events_get(self): + fake_instance = {'uuid': 'fake-uuid', 'cell_name': 'region!child'} + call_info = self._stub_rpc_method('call', 'fake_response') + result = self.cells_rpcapi.action_events_get(self.fake_context, + fake_instance, + 'fake-action') + expected_args = {'cell_name': 'region!child', + 'action_id': 'fake-action'} + self._check_result(call_info, 'action_events_get', expected_args, + version='1.5') + self.assertEqual(result, 'fake_response') + + def test_action_events_get_no_cell(self): + fake_instance = {'uuid': 'fake-uuid', 'cell_name': None} + self.assertRaises(exception.InstanceUnknownCell, + self.cells_rpcapi.action_events_get, + self.fake_context, fake_instance, 'fake-action') diff --git a/nova/tests/integrated/test_api_samples.py b/nova/tests/integrated/test_api_samples.py index aaf22ff9d..d48ef5091 100644 --- a/nova/tests/integrated/test_api_samples.py +++ b/nova/tests/integrated/test_api_samples.py @@ -3165,12 +3165,16 @@ class InstanceActionsSampleJsonTest(ApiSampleTestBase): def fake_instance_get_by_uuid(context, instance_id): return self.instance + def fake_get(self, context, instance_uuid): + return {'uuid': instance_uuid} + self.stubs.Set(db, 'action_get_by_request_id', fake_instance_action_get_by_request_id) self.stubs.Set(db, 'actions_get', fake_instance_actions_get) self.stubs.Set(db, 'action_events_get', fake_instance_action_events_get) self.stubs.Set(db, 'instance_get_by_uuid', fake_instance_get_by_uuid) + self.stubs.Set(compute_api.API, 'get', fake_get) def test_instance_action_get(self): fake_uuid = fake_instance_actions.FAKE_UUID |
