def test_instance_info(self): inst_info = vm.InstanceInfo(self.apt, 'inst_name', '1234') # Test the static properties self.assertEqual(inst_info.id, '1234') self.assertEqual(inst_info.cpu_time_ns, 0) # Check that we raise an exception if the instance is gone. self.apt.read.side_effect = pvm_exc.HttpNotFound( mock.MagicMock(status=404)) self.assertRaises(exception.InstanceNotFound, inst_info.__getattribute__, 'state') # Reset the test inst_info inst_info = vm.InstanceInfo(self.apt, 'inst_name', '1234') class FakeResp2(object): def __init__(self, body): self.body = '"%s"' % body self.apt.read.side_effect = None self.apt.read.return_value = FakeResp2('running') self.assertEqual(inst_info.state, power_state.RUNNING) # Check the __eq__ method inst_info1 = vm.InstanceInfo(self.apt, 'inst_name', '1234') inst_info2 = vm.InstanceInfo(self.apt, 'inst_name', '1234') self.assertEqual(inst_info1, inst_info2) inst_info2 = vm.InstanceInfo(self.apt, 'name', '4321') self.assertNotEqual(inst_info1, inst_info2)
def test_instance_info(self): # Test at least one state translation self.assertEqual(vm._translate_vm_state('running'), power_state.RUNNING) inst_info = vm.InstanceInfo(self.apt, 'inst_name', '1234') # Test the static properties self.assertEqual(inst_info.id, '1234') self.assertEqual(inst_info.cpu_time_ns, 0) # Check that we raise an exception if the instance is gone. exc = pvm_exc.Error('Not found', response=FakeAdapterResponse(404)) self.apt.read.side_effect = exc self.assertRaises(exception.InstanceNotFound, inst_info.__getattribute__, 'state') # Reset the test inst_info inst_info = vm.InstanceInfo(self.apt, 'inst_name', '1234') class FakeResp2(object): def __init__(self, body): self.body = '"%s"' % body resp = FakeResp2('running') def return_resp(*args, **kwds): return resp self.apt.read.side_effect = return_resp self.assertEqual(inst_info.state, power_state.RUNNING) # Check the __eq__ method inst_info1 = vm.InstanceInfo(self.apt, 'inst_name', '1234') inst_info2 = vm.InstanceInfo(self.apt, 'inst_name', '1234') self.assertEqual(inst_info1, inst_info2) inst_info2 = vm.InstanceInfo(self.apt, 'name', '4321') self.assertNotEqual(inst_info1, inst_info2)