diff options
author | Jenkins <jenkins@review.openstack.org> | 2012-03-07 17:39:56 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2012-03-07 17:39:56 +0000 |
commit | ddfa36d9e5f3543a459c38ef73d5762c7a05268a (patch) | |
tree | 4051a77ee816f9cfb0fee790cd297f0747cf13ed | |
parent | ff58a84547fc3fb6cb9615d750db685d23190d40 (diff) | |
parent | 76e67bbf80a5819329c9cf2f427ef5596d7c17a9 (diff) | |
download | nova-ddfa36d9e5f3543a459c38ef73d5762c7a05268a.tar.gz nova-ddfa36d9e5f3543a459c38ef73d5762c7a05268a.tar.xz nova-ddfa36d9e5f3543a459c38ef73d5762c7a05268a.zip |
Merge "Make test_compute console tests more robust"
-rw-r--r-- | nova/tests/test_compute.py | 96 |
1 files changed, 59 insertions, 37 deletions
diff --git a/nova/tests/test_compute.py b/nova/tests/test_compute.py index d4ffff569..bcfe90e0e 100644 --- a/nova/tests/test_compute.py +++ b/nova/tests/test_compute.py @@ -298,26 +298,12 @@ class ComputeTestCase(BaseTestCase): finally: db.instance_destroy(self.context, instance['id']) - def _assert_state(self, state_dict): - """assert the instance is in the state defined by state_dict""" - instances = db.instance_get_all(context.get_admin_context()) - self.assertEqual(len(instances), 1) - - if 'vm_state' in state_dict: - self.assertEqual(state_dict['vm_state'], instances[0]['vm_state']) - if 'task_state' in state_dict: - self.assertEqual(state_dict['task_state'], - instances[0]['task_state']) - if 'power_state' in state_dict: - self.assertEqual(state_dict['power_state'], - instances[0]['power_state']) - def test_fail_to_schedule_persists(self): """check the persistence of the ERROR(scheduling) state""" self._create_instance(params={'vm_state': vm_states.ERROR, 'task_state': task_states.SCHEDULING}) #check state is failed even after the periodic poll - error_list = self.compute.periodic_tasks(context.get_admin_context()) + self.compute.periodic_tasks(context.get_admin_context()) self._assert_state({'vm_state': vm_states.ERROR, 'task_state': task_states.SCHEDULING}) @@ -337,7 +323,7 @@ class ComputeTestCase(BaseTestCase): #check state is failed even after the periodic poll self._assert_state({'vm_state': vm_states.ERROR, 'task_state': task_states.BLOCK_DEVICE_MAPPING}) - error_list = self.compute.periodic_tasks(context.get_admin_context()) + self.compute.periodic_tasks(context.get_admin_context()) self._assert_state({'vm_state': vm_states.ERROR, 'task_state': task_states.BLOCK_DEVICE_MAPPING}) @@ -355,7 +341,7 @@ class ComputeTestCase(BaseTestCase): #check state is failed even after the periodic poll self._assert_state({'vm_state': vm_states.ERROR, 'task_state': task_states.SPAWNING}) - error_list = self.compute.periodic_tasks(context.get_admin_context()) + self.compute.periodic_tasks(context.get_admin_context()) self._assert_state({'vm_state': vm_states.ERROR, 'task_state': task_states.SPAWNING}) @@ -1262,7 +1248,6 @@ class ComputeTestCase(BaseTestCase): # creating instance testdata inst_ref = self._create_fake_instance({'host': 'dummy'}) c = context.get_admin_context() - topic = db.queue_get_for(c, FLAGS.compute_topic, inst_ref['host']) # start test self.assertRaises(exception.FixedIpNotFoundForInstance, @@ -1395,8 +1380,8 @@ class ComputeTestCase(BaseTestCase): fix_addr = db.fixed_ip_create(c, {'address': '1.1.1.1', 'instance_id': instance_id}) fix_ref = db.fixed_ip_get_by_address(c, fix_addr) - flo_ref = db.floating_ip_create(c, {'address': flo_addr, - 'fixed_ip_id': fix_ref['id']}) + db.floating_ip_create(c, {'address': flo_addr, + 'fixed_ip_id': fix_ref['id']}) # creating mocks self.mox.StubOutWithMock(self.compute.driver, 'unfilter_instance') @@ -1414,7 +1399,7 @@ class ComputeTestCase(BaseTestCase): # start test self.mox.ReplayAll() - ret = self.compute.post_live_migration(c, i_ref, dest) + self.compute.post_live_migration(c, i_ref, dest) # make sure every data is rewritten to destinatioin hostname. i_ref = db.instance_get(c, i_ref['id']) @@ -1446,9 +1431,9 @@ class ComputeTestCase(BaseTestCase): # Force the compute manager to do its periodic poll ctxt = context.get_admin_context() - self.compute._sync_power_states(context.get_admin_context()) + self.compute._sync_power_states(ctxt) - instances = db.instance_get_all(context.get_admin_context()) + instances = db.instance_get_all(ctxt) LOG.info(_("After force-killing instances: %s"), instances) self.assertEqual(len(instances), 1) self.assertEqual(power_state.NOSTATE, instances[0]['power_state']) @@ -2371,7 +2356,7 @@ class ComputeAPITestCase(BaseTestCase): self.compute_api.resize(context, instance, '4') # create a fake migration record (manager does this) - migration_ref = db.migration_create(context, + db.migration_create(context, {'instance_uuid': instance['uuid'], 'status': 'finished'}) # set the state that the instance gets when resize finishes @@ -2392,7 +2377,7 @@ class ComputeAPITestCase(BaseTestCase): self.compute_api.resize(context, instance, '4') # create a fake migration record (manager does this) - migration_ref = db.migration_create(context, + db.migration_create(context, {'instance_uuid': instance['uuid'], 'status': 'finished'}) # set the state that the instance gets when resize finishes @@ -3067,7 +3052,6 @@ class ComputeAPITestCase(BaseTestCase): """Test the instance_name template""" self.flags(instance_name_template='instance-%d') i_ref = self._create_fake_instance() - instance_id = i_ref['id'] self.assertEqual(i_ref['name'], 'instance-%d' % i_ref['id']) db.instance_destroy(self.context, i_ref['id']) @@ -3104,22 +3088,60 @@ class ComputeAPITestCase(BaseTestCase): def test_vnc_console(self): """Make sure we can a vnc console for an instance.""" - def vnc_rpc_call_wrapper(*args, **kwargs): - return {'token': 'asdf', 'host': '0.0.0.0', - 'port': 8080, 'access_url': None, - 'internal_access_path': None} - self.stubs.Set(rpc, 'call', vnc_rpc_call_wrapper) + fake_instance = {'uuid': 'fake_uuid', + 'host': 'fake_compute_host'} + fake_console_type = "novnc" + fake_connect_info = {'token': 'fake_token', + 'console_type': fake_console_type, + 'host': 'fake_console_host', + 'port': 'fake_console_port', + 'internal_access_path': 'fake_access_path', + 'access_url': 'fake_console_url'} + + self.mox.StubOutWithMock(rpc, 'call') + + rpc_msg1 = {'method': 'get_vnc_console', + 'args': {'instance_uuid': fake_instance['uuid'], + 'console_type': fake_console_type}} + # 2nd rpc.call receives almost everything from fake_connect_info + # except 'access_url' + rpc_msg2_args = dict([(k, v) + for k, v in fake_connect_info.items() + if k != 'access_url']) + rpc_msg2 = {'method': 'authorize_console', + 'args': rpc_msg2_args} + + rpc.call(self.context, 'compute.%s' % fake_instance['host'], + rpc_msg1).AndReturn(fake_connect_info) + rpc.call(self.context, FLAGS.consoleauth_topic, + rpc_msg2).AndReturn(None) + + self.mox.ReplayAll() - instance = self._create_fake_instance() console = self.compute_api.get_vnc_console(self.context, - instance, - 'novnc') - self.compute_api.delete(self.context, instance) + fake_instance, fake_console_type) + self.assertEqual(console, {'url': 'fake_console_url'}) def test_console_output(self): - instance = self._create_fake_instance() - console = self.compute_api.get_console_output(self.context, instance) + fake_instance = {'uuid': 'fake_uuid', + 'host': 'fake_compute_host'} + fake_tail_length = 699 + fake_console_output = 'fake console output' + + self.mox.StubOutWithMock(rpc, 'call') + + rpc_msg = {'method': 'get_console_output', + 'args': {'instance_uuid': fake_instance['uuid'], + 'tail_length': fake_tail_length}} + rpc.call(self.context, 'compute.%s' % fake_instance['host'], + rpc_msg).AndReturn(fake_console_output) + + self.mox.ReplayAll() + + output = self.compute_api.get_console_output(self.context, + fake_instance, tail_length=fake_tail_length) + self.assertEqual(output, fake_console_output) def test_attach_volume(self): """Ensure instance can be soft rebooted""" |