def test_shelve(self): # Ensure instance can be shelved. fake_instance = self._create_fake_instance_obj( {'display_name': 'vm01'}) instance = fake_instance self.assertIsNone(instance['task_state']) def fake_init(self2): # In original _FakeImageService.__init__(), some fake images are # created. To verify the snapshot name of this test only, here # sets a fake method. self2.images = {} def fake_create(self2, ctxt, metadata, data=None): self.assertEqual(metadata['name'], 'vm01-shelved') metadata['id'] = '8b24ed3f-ee57-43bc-bc2e-fb2e9482bc42' return metadata fake_image.stub_out_image_service(self.stubs) self.stubs.Set(fake_image._FakeImageService, '__init__', fake_init) self.stubs.Set(fake_image._FakeImageService, 'create', fake_create) self.compute_api.shelve(self.context, instance) self.assertEqual(instance.task_state, task_states.SHELVING) db.instance_destroy(self.context, instance['uuid'])
def test_shelve(self): # Ensure instance can be shelved. fake_instance = self._create_fake_instance_obj({"display_name": "vm01"}) instance = fake_instance self.assertIsNone(instance["task_state"]) def fake_init(self2): # In original _FakeImageService.__init__(), some fake images are # created. To verify the snapshot name of this test only, here # sets a fake method. self2.images = {} def fake_create(self2, ctxt, metadata, data=None): self.assertEqual(metadata["name"], "vm01-shelved") metadata["id"] = "8b24ed3f-ee57-43bc-bc2e-fb2e9482bc42" return metadata fake_image.stub_out_image_service(self.stubs) self.stubs.Set(fake_image._FakeImageService, "__init__", fake_init) self.stubs.Set(fake_image._FakeImageService, "create", fake_create) self.compute_api.shelve(self.context, instance) self.assertEqual(instance.task_state, task_states.SHELVING) db.instance_destroy(self.context, instance["uuid"])
def test_remove_console(self): instance = self._create_instance() console_id = self.console.add_console(self.context, instance['id']) self.console.remove_console(self.context, console_id) self.assertRaises(exception.NotFound, db.console_get, self.context, console_id) db.instance_destroy(self.context, instance['uuid'])
def test_add_console(self): instance = self._create_instance() self.console.add_console(self.context, instance['id']) instance = db.instance_get(self.context, instance['id']) pool = db.console_pool_get_by_host_type(self.context, instance['host'], self.console.host, self.console.driver.console_type) console_instances = [con['instance_uuid'] for con in pool['consoles']] self.assertIn(instance['uuid'], console_instances) db.instance_destroy(self.context, instance['uuid'])
def test_unshelve(self): # Ensure instance can be unshelved. instance = self._create_fake_instance_obj() self.assertIsNone(instance['task_state']) self.compute_api.shelve(self.context, instance) instance.task_state = None instance.vm_state = vm_states.SHELVED instance.save() self.compute_api.unshelve(self.context, instance) self.assertEqual(instance.task_state, task_states.UNSHELVING) db.instance_destroy(self.context, instance['uuid'])
def test_unshelve(self): # Ensure instance can be unshelved. instance = self._create_fake_instance_obj() self.assertIsNone(instance["task_state"]) self.compute_api.shelve(self.context, instance) instance.task_state = None instance.vm_state = vm_states.SHELVED instance.save() self.compute_api.unshelve(self.context, instance) self.assertEqual(instance.task_state, task_states.UNSHELVING) db.instance_destroy(self.context, instance["uuid"])
def test_show_works_correctly(self): """show() works correctly as expected.""" ctxt = context_maker.get_admin_context() s_ref = self._create_compute_service() i_ref1 = _create_instance(project_id='p-01', host=s_ref['host']) i_ref2 = _create_instance(project_id='p-02', vcpus=3, host=s_ref['host']) result = self.controller.show(self.req, s_ref['host']) proj = ['(total)', '(used_now)', '(used_max)', 'p-01', 'p-02'] column = ['host', 'project', 'cpu', 'memory_mb', 'disk_gb'] self.assertEqual(len(result['host']), 5) for resource in result['host']: self.assertIn(resource['resource']['project'], proj) self.assertEqual(len(resource['resource']), 5) self.assertEqual(set(column), set(resource['resource'].keys())) db.service_destroy(ctxt, s_ref['id']) db.instance_destroy(ctxt, i_ref1['uuid']) db.instance_destroy(ctxt, i_ref2['uuid'])
def test_add_console_does_not_duplicate(self): instance = self._create_instance() cons1 = self.console.add_console(self.context, instance['id']) cons2 = self.console.add_console(self.context, instance['id']) self.assertEqual(cons1, cons2) db.instance_destroy(self.context, instance['uuid'])