Merge "tests: Move test_resource_tracker to Instance objects"
This commit is contained in:
commit
77cadd2c48
@ -22,7 +22,6 @@ import mock
|
||||
from oslo_config import cfg
|
||||
from oslo_serialization import jsonutils
|
||||
|
||||
from nova.compute import flavors
|
||||
from nova.compute import resource_tracker
|
||||
from nova.compute import resources
|
||||
from nova.compute import task_states
|
||||
@ -214,14 +213,10 @@ class BaseTestCase(test.TestCase):
|
||||
manager=CONF.conductor.manager)
|
||||
|
||||
self._instances = {}
|
||||
self._numa_topologies = {}
|
||||
self._instance_types = {}
|
||||
|
||||
self.stubs.Set(self.conductor.db,
|
||||
'instance_get_all_by_host_and_node',
|
||||
self._fake_instance_get_all_by_host_and_node)
|
||||
self.stubs.Set(db, 'instance_extra_get_by_instance_uuid',
|
||||
self._fake_instance_extra_get_by_instance_uuid)
|
||||
self.stubs.Set(objects.InstanceList, 'get_by_host_and_node',
|
||||
self._fake_instance_get_by_host_and_node)
|
||||
self.stubs.Set(self.conductor.db,
|
||||
'flavor_get', self._fake_flavor_get)
|
||||
|
||||
@ -285,103 +280,6 @@ class BaseTestCase(test.TestCase):
|
||||
}
|
||||
return service
|
||||
|
||||
def _fake_instance_system_metadata(self, instance_type, prefix=''):
|
||||
sys_meta = []
|
||||
for key in flavors.system_metadata_flavor_props.keys():
|
||||
sys_meta.append({'key': '%sinstance_type_%s' % (prefix, key),
|
||||
'value': instance_type[key]})
|
||||
return sys_meta
|
||||
|
||||
def _fake_instance(self, stash=True, flavor=None, **kwargs):
|
||||
# NOTE(danms): Remove this when all the compute_node stuff is
|
||||
# converted to objects
|
||||
|
||||
# Default to an instance ready to resize to or from the same
|
||||
# instance_type
|
||||
flavor = flavor or self._fake_flavor_create()
|
||||
sys_meta = self._fake_instance_system_metadata(flavor)
|
||||
|
||||
if stash:
|
||||
# stash instance types in system metadata.
|
||||
sys_meta = (sys_meta +
|
||||
self._fake_instance_system_metadata(flavor, 'new_') +
|
||||
self._fake_instance_system_metadata(flavor, 'old_'))
|
||||
|
||||
instance_uuid = str(uuid.uuid1())
|
||||
instance = {
|
||||
'uuid': instance_uuid,
|
||||
'vm_state': vm_states.RESIZED,
|
||||
'task_state': None,
|
||||
'ephemeral_key_uuid': None,
|
||||
'os_type': 'Linux',
|
||||
'project_id': '123456',
|
||||
'host': None,
|
||||
'node': None,
|
||||
'instance_type_id': flavor['id'],
|
||||
'memory_mb': flavor['memory_mb'],
|
||||
'vcpus': flavor['vcpus'],
|
||||
'root_gb': flavor['root_gb'],
|
||||
'ephemeral_gb': flavor['ephemeral_gb'],
|
||||
'launched_on': None,
|
||||
'system_metadata': sys_meta,
|
||||
'availability_zone': None,
|
||||
'vm_mode': None,
|
||||
'reservation_id': None,
|
||||
'display_name': None,
|
||||
'default_swap_device': None,
|
||||
'power_state': None,
|
||||
'scheduled_at': None,
|
||||
'access_ip_v6': None,
|
||||
'access_ip_v4': None,
|
||||
'key_name': None,
|
||||
'updated_at': None,
|
||||
'cell_name': None,
|
||||
'locked': None,
|
||||
'locked_by': None,
|
||||
'launch_index': None,
|
||||
'architecture': None,
|
||||
'auto_disk_config': None,
|
||||
'terminated_at': None,
|
||||
'ramdisk_id': None,
|
||||
'user_data': None,
|
||||
'cleaned': None,
|
||||
'deleted_at': None,
|
||||
'id': 333,
|
||||
'disable_terminate': None,
|
||||
'hostname': None,
|
||||
'display_description': None,
|
||||
'key_data': None,
|
||||
'deleted': None,
|
||||
'default_ephemeral_device': None,
|
||||
'progress': None,
|
||||
'launched_at': None,
|
||||
'config_drive': None,
|
||||
'kernel_id': None,
|
||||
'user_id': None,
|
||||
'shutdown_terminate': None,
|
||||
'created_at': None,
|
||||
'image_ref': None,
|
||||
'root_device_name': None,
|
||||
}
|
||||
extra = {
|
||||
'id': 1, 'created_at': None, 'updated_at': None,
|
||||
'deleted_at': None, 'deleted': None,
|
||||
'instance_uuid': instance['uuid'],
|
||||
'numa_topology': None,
|
||||
'pci_requests': None,
|
||||
}
|
||||
|
||||
numa_topology = kwargs.pop('numa_topology', None)
|
||||
if numa_topology:
|
||||
extra['numa_topology'] = numa_topology._to_json()
|
||||
|
||||
instance.update(kwargs)
|
||||
instance['extra'] = extra
|
||||
|
||||
self._instances[instance_uuid] = instance
|
||||
self._numa_topologies[instance_uuid] = extra
|
||||
return instance
|
||||
|
||||
def _fake_instance_obj(self, stash=True, flavor=None, **kwargs):
|
||||
|
||||
# Default to an instance ready to resize to or from the same
|
||||
@ -485,13 +383,10 @@ class BaseTestCase(test.TestCase):
|
||||
self._instance_types[id_] = instance_type
|
||||
return instance_type
|
||||
|
||||
def _fake_instance_get_all_by_host_and_node(self, context, host, nodename,
|
||||
columns_to_join=None):
|
||||
return [i for i in self._instances.values() if i['host'] == host]
|
||||
|
||||
def _fake_instance_extra_get_by_instance_uuid(self, context,
|
||||
instance_uuid, columns=None):
|
||||
return self._numa_topologies.get(instance_uuid)
|
||||
def _fake_instance_get_by_host_and_node(self, context, host, nodename,
|
||||
expected_attrs=None):
|
||||
return objects.InstanceList(
|
||||
objects=[i for i in self._instances.values() if i['host'] == host])
|
||||
|
||||
def _fake_flavor_get(self, ctxt, id_):
|
||||
return self._instance_types[id_]
|
||||
@ -563,7 +458,7 @@ class UnsupportedDriverTestCase(BaseTestCase):
|
||||
self.assertEqual(0, claim.memory_mb)
|
||||
|
||||
def test_disabled_updated_usage(self):
|
||||
instance = self._fake_instance(host='fakehost', memory_mb=5,
|
||||
instance = self._fake_instance_obj(host='fakehost', memory_mb=5,
|
||||
root_gb=10)
|
||||
self.tracker.update_usage(self.context, instance)
|
||||
|
||||
@ -1175,7 +1070,7 @@ class InstanceClaimTestCase(BaseTrackerTestCase):
|
||||
def test_skip_deleted_instances(self):
|
||||
# ensure that the audit process skips instances that have vm_state
|
||||
# DELETED, but the DB record is not yet deleted.
|
||||
self._fake_instance(vm_state=vm_states.DELETED, host=self.host)
|
||||
self._fake_instance_obj(vm_state=vm_states.DELETED, host=self.host)
|
||||
self.tracker.update_available_resource(self.context)
|
||||
|
||||
self.assertEqual(0, self.tracker.compute_node['memory_mb_used'])
|
||||
@ -1309,11 +1204,11 @@ class ResizeClaimTestCase(BaseTrackerTestCase):
|
||||
self._assert(0, 'vcpus_used')
|
||||
|
||||
def test_resize_filter(self):
|
||||
instance = self._fake_instance(vm_state=vm_states.ACTIVE,
|
||||
instance = self._fake_instance_obj(vm_state=vm_states.ACTIVE,
|
||||
task_state=task_states.SUSPENDING)
|
||||
self.assertFalse(self.tracker._instance_in_resize_state(instance))
|
||||
|
||||
instance = self._fake_instance(vm_state=vm_states.RESIZED,
|
||||
instance = self._fake_instance_obj(vm_state=vm_states.RESIZED,
|
||||
task_state=task_states.SUSPENDING)
|
||||
self.assertTrue(self.tracker._instance_in_resize_state(instance))
|
||||
|
||||
@ -1321,8 +1216,8 @@ class ResizeClaimTestCase(BaseTrackerTestCase):
|
||||
task_states.RESIZE_MIGRATED, task_states.RESIZE_FINISH]
|
||||
for vm_state in [vm_states.ACTIVE, vm_states.STOPPED]:
|
||||
for task_state in states:
|
||||
instance = self._fake_instance(vm_state=vm_state,
|
||||
task_state=task_state)
|
||||
instance = self._fake_instance_obj(vm_state=vm_state,
|
||||
task_state=task_state)
|
||||
result = self.tracker._instance_in_resize_state(instance)
|
||||
self.assertTrue(result)
|
||||
|
||||
@ -1346,7 +1241,7 @@ class OrphanTestCase(BaseTrackerTestCase):
|
||||
|
||||
def test_find(self):
|
||||
# create one legit instance and verify the 2 orphans remain
|
||||
self._fake_instance()
|
||||
self._fake_instance_obj()
|
||||
orphans = self.tracker._find_orphaned_instances()
|
||||
|
||||
self.assertEqual(2, len(orphans))
|
||||
@ -1483,7 +1378,7 @@ class StatsDictTestCase(BaseTrackerTestCase):
|
||||
self.assertEqual(FAKE_VIRT_STATS, stats)
|
||||
|
||||
# adding an instance should keep virt driver stats
|
||||
self._fake_instance(vm_state=vm_states.ACTIVE, host=self.host)
|
||||
self._fake_instance_obj(vm_state=vm_states.ACTIVE, host=self.host)
|
||||
self.tracker.update_available_resource(self.context)
|
||||
|
||||
stats = self._get_stats()
|
||||
@ -1517,7 +1412,7 @@ class StatsJsonTestCase(BaseTrackerTestCase):
|
||||
|
||||
# adding an instance should keep virt driver stats
|
||||
# and add rt stats
|
||||
self._fake_instance(vm_state=vm_states.ACTIVE, host=self.host)
|
||||
self._fake_instance_obj(vm_state=vm_states.ACTIVE, host=self.host)
|
||||
self.tracker.update_available_resource(self.context)
|
||||
|
||||
stats = self._get_stats()
|
||||
|
Loading…
Reference in New Issue
Block a user