diff options
-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 ec9ea3fea..c5803c24c 100644 --- a/nova/tests/test_compute.py +++ b/nova/tests/test_compute.py @@ -299,26 +299,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}) @@ -338,7 +324,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}) @@ -356,7 +342,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}) @@ -1263,7 +1249,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, @@ -1396,8 +1381,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') @@ -1415,7 +1400,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']) @@ -1447,9 +1432,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']) @@ -2372,7 +2357,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 @@ -2393,7 +2378,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 @@ -3068,7 +3053,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']) @@ -3105,22 +3089,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""" |