本文整理汇总了Python中nova.db.instance_destroy函数的典型用法代码示例。如果您正苦于以下问题:Python instance_destroy函数的具体用法?Python instance_destroy怎么用?Python instance_destroy使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了instance_destroy函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_live_migration_common_check_service_different_hypervisor
def test_live_migration_common_check_service_different_hypervisor(self):
"""Original host and dest host has different hypervisor type."""
dest = "dummydest"
instance_id = self._create_instance()
i_ref = db.instance_get(self.context, instance_id)
# compute service for destination
s_ref = self._create_compute_service(host=i_ref["host"])
# compute service for original host
s_ref2 = self._create_compute_service(host=dest, hypervisor_type="xen")
# mocks
driver = self.scheduler.driver
self.mox.StubOutWithMock(driver, "mounted_on_same_shared_storage")
driver.mounted_on_same_shared_storage(mox.IgnoreArg(), i_ref, dest)
self.mox.ReplayAll()
self.assertRaises(
exception.InvalidHypervisorType,
self.scheduler.driver._live_migration_common_check,
self.context,
i_ref,
dest,
)
db.instance_destroy(self.context, instance_id)
db.service_destroy(self.context, s_ref["id"])
db.service_destroy(self.context, s_ref2["id"])
示例2: test_unfilter_instance_undefines_nwfilters
def test_unfilter_instance_undefines_nwfilters(self):
admin_ctxt = context.get_admin_context()
fakefilter = NWFilterFakes()
self.fw._conn.nwfilterDefineXML = fakefilter.filterDefineXMLMock
self.fw._conn.nwfilterLookupByName = fakefilter.nwfilterLookupByName
instance_ref = self._create_instance()
inst_id = instance_ref['id']
inst_uuid = instance_ref['uuid']
self.security_group = self.setup_and_return_security_group()
db.instance_add_security_group(self.context, inst_uuid,
self.security_group['id'])
instance = db.instance_get(self.context, inst_id)
network_info = _fake_network_info(self.stubs, 1)
self.fw.setup_basic_filtering(instance, network_info)
original_filter_count = len(fakefilter.filters)
self.fw.unfilter_instance(instance, network_info)
self.assertEqual(original_filter_count - len(fakefilter.filters), 1)
db.instance_destroy(admin_ctxt, instance_ref['uuid'])
示例3: test_shelve
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)
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'])
示例4: test_add_console_does_not_duplicate
def test_add_console_does_not_duplicate(self, mock_get):
mock_get.return_value = self.pool_info
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'])
示例5: test_delete_fast_if_host_not_set
def test_delete_fast_if_host_not_set(self):
inst = self._create_instance_obj()
inst.host = ''
updates = {'progress': 0, 'task_state': task_states.DELETING}
self.mox.StubOutWithMock(inst, 'save')
self.mox.StubOutWithMock(db,
'block_device_mapping_get_all_by_instance')
self.mox.StubOutWithMock(db, 'constraint')
self.mox.StubOutWithMock(db, 'instance_destroy')
self.mox.StubOutWithMock(self.compute_api, '_create_reservations')
db.block_device_mapping_get_all_by_instance(self.context,
inst.uuid).AndReturn([])
inst.save()
self.compute_api._create_reservations(self.context,
inst, inst.instance_type_id,
inst.project_id, inst.user_id
).AndReturn(None)
db.constraint(host=mox.IgnoreArg()).AndReturn('constraint')
db.instance_destroy(self.context, inst.uuid, 'constraint')
self.mox.ReplayAll()
self.compute_api.delete(self.context, inst)
for k, v in updates.items():
self.assertEqual(inst[k], v)
示例6: test_too_many_cores
def test_too_many_cores(self):
"""Ensures we don't go over max cores"""
compute1 = self.start_service('compute', host='host1')
compute2 = self.start_service('compute', host='host2')
instance_ids1 = []
instance_ids2 = []
for index in xrange(FLAGS.max_cores):
instance_id = self._create_instance()
compute1.run_instance(self.context, instance_id)
instance_ids1.append(instance_id)
instance_id = self._create_instance()
compute2.run_instance(self.context, instance_id)
instance_ids2.append(instance_id)
instance_id = self._create_instance()
self.assertRaises(driver.NoValidHost,
self.scheduler.driver.schedule_run_instance,
self.context,
instance_id)
db.instance_destroy(self.context, instance_id)
for instance_id in instance_ids1:
compute1.terminate_instance(self.context, instance_id)
for instance_id in instance_ids2:
compute2.terminate_instance(self.context, instance_id)
compute1.kill()
compute2.kill()
示例7: test_destroy_with_not_equal_constraint_met
def test_destroy_with_not_equal_constraint_met(self):
ctx = context.get_admin_context()
instance = db.instance_create(ctx, {'task_state': 'deleting'})
constraint = db.constraint(task_state=db.not_equal('error', 'resize'))
db.instance_destroy(ctx, instance['uuid'], constraint)
self.assertRaises(exception.InstanceNotFound, db.instance_get_by_uuid,
ctx, instance['uuid'])
示例8: test_update_of_instance_wont_update_private_fields
def test_update_of_instance_wont_update_private_fields(self):
inst = db.instance_create(self.context, {})
self.cloud.update_instance(self.context, inst['id'],
mac_address='DE:AD:BE:EF')
inst = db.instance_get(self.context, inst['id'])
self.assertEqual(None, inst['mac_address'])
db.instance_destroy(self.context, inst['id'])
示例9: test_describe_instances
def test_describe_instances(self):
"""Makes sure describe_instances works and filters results."""
inst1 = db.instance_create(self.context, {'reservation_id': 'a',
'host': 'host1'})
inst2 = db.instance_create(self.context, {'reservation_id': 'a',
'host': 'host2'})
comp1 = db.service_create(self.context, {'host': 'host1',
'availability_zone': 'zone1',
'topic': "compute"})
comp2 = db.service_create(self.context, {'host': 'host2',
'availability_zone': 'zone2',
'topic': "compute"})
result = self.cloud.describe_instances(self.context)
result = result['reservationSet'][0]
self.assertEqual(len(result['instancesSet']), 2)
instance_id = cloud.id_to_ec2_id(inst2['id'])
result = self.cloud.describe_instances(self.context,
instance_id=[instance_id])
result = result['reservationSet'][0]
self.assertEqual(len(result['instancesSet']), 1)
self.assertEqual(result['instancesSet'][0]['instanceId'],
instance_id)
self.assertEqual(result['instancesSet'][0]
['placement']['availabilityZone'], 'zone2')
db.instance_destroy(self.context, inst1['id'])
db.instance_destroy(self.context, inst2['id'])
db.service_destroy(self.context, comp1['id'])
db.service_destroy(self.context, comp2['id'])
示例10: tearDown
def tearDown(self):
try:
shutil.rmtree(FLAGS.volumes_dir)
except OSError:
pass
db.instance_destroy(self.context, self.instance_uuid)
super(VolumeTestCase, self).tearDown()
示例11: test_remove_console
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"])
示例12: test_live_migration_common_check_service_orig_not_exists
def test_live_migration_common_check_service_orig_not_exists(self):
"""Destination host does not exist."""
dest = 'dummydest'
# mocks for live_migration_common_check()
instance_id = self._create_instance()
i_ref = db.instance_get(self.context, instance_id)
t1 = utils.utcnow() - datetime.timedelta(10)
s_ref = self._create_compute_service(created_at=t1, updated_at=t1,
host=dest)
# mocks for mounted_on_same_shared_storage()
fpath = '/test/20110127120000'
self.mox.StubOutWithMock(driver, 'rpc', use_mock_anything=True)
topic = FLAGS.compute_topic
driver.rpc.call(mox.IgnoreArg(),
db.queue_get_for(self.context, topic, dest),
{"method": 'create_shared_storage_test_file'}).AndReturn(fpath)
driver.rpc.call(mox.IgnoreArg(),
db.queue_get_for(mox.IgnoreArg(), topic, i_ref['host']),
{"method": 'check_shared_storage_test_file',
"args": {'filename': fpath}})
driver.rpc.call(mox.IgnoreArg(),
db.queue_get_for(mox.IgnoreArg(), topic, dest),
{"method": 'cleanup_shared_storage_test_file',
"args": {'filename': fpath}})
self.mox.ReplayAll()
self.assertRaises(exception.SourceHostUnavailable,
self.scheduler.driver._live_migration_common_check,
self.context, i_ref, dest)
db.instance_destroy(self.context, instance_id)
db.service_destroy(self.context, s_ref['id'])
示例13: test_live_migration_common_check_service_different_version
def test_live_migration_common_check_service_different_version(self):
"""Original host and dest host has different hypervisor version."""
dest = 'dummydest'
instance_id = self._create_instance()
i_ref = db.instance_get(self.context, instance_id)
# compute service for destination
s_ref = self._create_compute_service(host=i_ref['host'])
# compute service for original host
s_ref2 = self._create_compute_service(host=dest,
hypervisor_version=12002)
# mocks
driver = self.scheduler.driver
self.mox.StubOutWithMock(driver, 'mounted_on_same_shared_storage')
driver.mounted_on_same_shared_storage(mox.IgnoreArg(), i_ref, dest)
self.mox.ReplayAll()
self.assertRaises(exception.DestinationHypervisorTooOld,
self.scheduler.driver._live_migration_common_check,
self.context, i_ref, dest)
db.instance_destroy(self.context, instance_id)
db.service_destroy(self.context, s_ref['id'])
db.service_destroy(self.context, s_ref2['id'])
示例14: test_shelve
def test_shelve(self):
# Ensure instance can be shelved.
fake_instance = self._create_fake_instance({'display_name': 'vm01'})
instance = jsonutils.to_primitive(fake_instance)
instance_uuid = instance['uuid']
self.compute.run_instance(self.context, instance, {}, {}, [], None,
None, True, None, False)
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):
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)
inst_obj = instance_obj.Instance.get_by_uuid(self.context,
instance_uuid)
self.compute_api.shelve(self.context, inst_obj)
inst_obj.refresh()
self.assertEqual(inst_obj.task_state, task_states.SHELVING)
db.instance_destroy(self.context, instance['uuid'])
示例15: test_shelve
def test_shelve(self):
# Ensure instance can be shelved.
fake_instance = self._create_fake_instance({"display_name": "vm01"})
instance = jsonutils.to_primitive(fake_instance)
instance_uuid = instance["uuid"]
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)
inst_obj = objects.Instance.get_by_uuid(self.context, instance_uuid)
self.compute_api.shelve(self.context, inst_obj)
inst_obj.refresh()
self.assertEqual(inst_obj.task_state, task_states.SHELVING)
db.instance_destroy(self.context, instance["uuid"])