Refactor more compute tests to use Instance objects
Change-Id: If501760085a2110fedb8bd5e2fd863af25bc6f8e
This commit is contained in:
parent
7fe4c7fa6c
commit
30e68bd3d0
|
@ -452,7 +452,7 @@ class ComputeVolumeTestCase(BaseTestCase):
|
|||
|
||||
def test_detach_volume_api_raises(self):
|
||||
fake_bdm = objects.BlockDeviceMapping(**self.fake_volume)
|
||||
instance = self._create_fake_instance()
|
||||
instance = self._create_fake_instance_obj()
|
||||
|
||||
with contextlib.nested(
|
||||
mock.patch.object(self.compute, '_detach_volume'),
|
||||
|
@ -1488,7 +1488,7 @@ class ComputeTestCase(BaseTestCase):
|
|||
# both total_mem_mb and the oversubscribed limit:
|
||||
params = {"memory_mb": instance_mb, "root_gb": 128,
|
||||
"ephemeral_gb": 128}
|
||||
instance = self._create_fake_instance(params)
|
||||
instance = self._create_fake_instance_obj(params)
|
||||
|
||||
filter_properties = {'limits': {'memory_mb': oversub_limit_mb}}
|
||||
|
||||
|
@ -1587,7 +1587,7 @@ class ComputeTestCase(BaseTestCase):
|
|||
# build an instance, specifying an amount of disk that exceeds
|
||||
# total_disk_gb, but is less than the oversubscribed limit:
|
||||
params = {"root_gb": instance_gb, "memory_mb": 10}
|
||||
instance = self._create_fake_instance(params)
|
||||
instance = self._create_fake_instance_obj(params)
|
||||
|
||||
limits = {'disk_gb': oversub_limit_gb}
|
||||
filter_properties = {'limits': limits}
|
||||
|
@ -1677,7 +1677,7 @@ class ComputeTestCase(BaseTestCase):
|
|||
raise exception.InvalidBDM()
|
||||
self.stubs.Set(nova.compute.manager.ComputeManager,
|
||||
'_prep_block_device', fake)
|
||||
instance = self._create_fake_instance()
|
||||
instance = self._create_fake_instance_obj()
|
||||
self.assertRaises(exception.InvalidBDM, self.compute.run_instance,
|
||||
self.context, instance=instance, request_spec={},
|
||||
filter_properties={}, requested_networks=[],
|
||||
|
@ -1700,7 +1700,7 @@ class ComputeTestCase(BaseTestCase):
|
|||
appropriate exception is raised and the instances to ERROR state, keep
|
||||
the task state.
|
||||
"""
|
||||
instance = self._create_fake_instance()
|
||||
instance = self._create_fake_instance_obj()
|
||||
self.assertRaises(exception.OverQuota, self.compute.run_instance,
|
||||
self.context, instance=instance, request_spec={},
|
||||
filter_properties={}, requested_networks=[],
|
||||
|
@ -1760,7 +1760,7 @@ class ComputeTestCase(BaseTestCase):
|
|||
def test_run_instance_bails_on_missing_instance(self):
|
||||
# Make sure that run_instance() will quickly ignore a deleted instance
|
||||
called = {}
|
||||
instance = self._create_fake_instance()
|
||||
instance = self._create_fake_instance_obj()
|
||||
|
||||
def fake_instance_update(self, *a, **args):
|
||||
called['instance_update'] = True
|
||||
|
@ -1774,7 +1774,7 @@ class ComputeTestCase(BaseTestCase):
|
|||
def test_run_instance_bails_on_deleting_instance(self):
|
||||
# Make sure that run_instance() will quickly ignore a deleting instance
|
||||
called = {}
|
||||
instance = self._create_fake_instance()
|
||||
instance = self._create_fake_instance_obj()
|
||||
|
||||
def fake_instance_update(self, *a, **args):
|
||||
called['instance_update'] = True
|
||||
|
@ -1789,7 +1789,7 @@ class ComputeTestCase(BaseTestCase):
|
|||
def test_run_instance_bails_on_missing_instance_2(self):
|
||||
# Make sure that run_instance() will quickly ignore a deleted instance
|
||||
called = {}
|
||||
instance = self._create_fake_instance()
|
||||
instance = self._create_fake_instance_obj()
|
||||
|
||||
def fake_default_block_device_names(self, *a, **args):
|
||||
called['default_block_device_names'] = True
|
||||
|
|
|
@ -213,6 +213,8 @@ class ShelveComputeManagerTestCase(test_compute.BaseTestCase):
|
|||
|
||||
self.deleted_image_id = None
|
||||
|
||||
db_instance['extra'] = None
|
||||
|
||||
def fake_delete(self2, ctxt, image_id):
|
||||
self.deleted_image_id = image_id
|
||||
|
||||
|
@ -272,16 +274,14 @@ class ShelveComputeManagerTestCase(test_compute.BaseTestCase):
|
|||
self.assertEqual(instance.host, self.compute.host)
|
||||
|
||||
def test_unshelve_volume_backed(self):
|
||||
db_instance = self._create_fake_instance()
|
||||
instance = self._create_fake_instance_obj()
|
||||
db_instance = obj_base.obj_to_primitive(instance)
|
||||
node = test_compute.NODENAME
|
||||
limits = {}
|
||||
filter_properties = {'limits': limits}
|
||||
cur_time = timeutils.utcnow()
|
||||
cur_time_tz = cur_time.replace(tzinfo=iso8601.iso8601.Utc())
|
||||
timeutils.set_time_override(cur_time)
|
||||
instance = objects.Instance.get_by_uuid(
|
||||
self.context, db_instance['uuid'],
|
||||
expected_attrs=['metadata', 'system_metadata'])
|
||||
instance.task_state = task_states.UNSHELVING
|
||||
instance.save()
|
||||
|
||||
|
@ -299,7 +299,8 @@ class ShelveComputeManagerTestCase(test_compute.BaseTestCase):
|
|||
db.instance_update_and_get_original(self.context, instance['uuid'],
|
||||
{'task_state': task_states.SPAWNING},
|
||||
update_cells=False,
|
||||
columns_to_join=['metadata', 'system_metadata']
|
||||
columns_to_join=['metadata', 'system_metadata',
|
||||
'info_cache', 'security_groups']
|
||||
).AndReturn((db_instance, db_instance))
|
||||
self.compute._prep_block_device(self.context, instance,
|
||||
mox.IgnoreArg(), do_check_attach=False).AndReturn('fake_bdm')
|
||||
|
@ -326,7 +327,8 @@ class ShelveComputeManagerTestCase(test_compute.BaseTestCase):
|
|||
'expected_task_state': task_states.SPAWNING,
|
||||
'launched_at': cur_time_tz},
|
||||
update_cells=False,
|
||||
columns_to_join=['metadata', 'system_metadata']
|
||||
columns_to_join=['metadata', 'system_metadata',
|
||||
'info_cache', 'security_groups']
|
||||
).AndReturn((db_instance, db_instance))
|
||||
self.compute._notify_about_instance_usage(self.context, instance,
|
||||
'unshelve.end')
|
||||
|
|
|
@ -1430,15 +1430,10 @@ class _BaseTaskTestCase(object):
|
|||
self.assertEqual(instance.vm_state, vm_states.ERROR)
|
||||
|
||||
def test_unshelve_offloaded_instance_image_id_is_none(self):
|
||||
db_instance = jsonutils.to_primitive(self._create_fake_instance())
|
||||
instance = objects.Instance.get_by_uuid(
|
||||
self.context,
|
||||
db_instance['uuid'],
|
||||
expected_attrs=['system_metadata'])
|
||||
instance = self._create_fake_instance_obj()
|
||||
instance.vm_state = vm_states.SHELVED_OFFLOADED
|
||||
instance.task_state = task_states.UNSHELVING
|
||||
system_metadata = instance.system_metadata
|
||||
system_metadata['shelved_image_id'] = None
|
||||
instance.system_metadata['shelved_image_id'] = None
|
||||
instance.save()
|
||||
|
||||
self.assertRaises(
|
||||
|
|
Loading…
Reference in New Issue