diff options
| author | Dan Smith <danms@us.ibm.com> | 2013-01-29 20:36:52 -0500 |
|---|---|---|
| committer | Dan Smith <danms@us.ibm.com> | 2013-02-04 15:21:51 -0500 |
| commit | 6371c091450d093595e6103b6a37b38bbbb2f921 (patch) | |
| tree | 0b26b6387dae74f16d50dc5870685ad3fb6a397d | |
| parent | 734b48b85fa76c8932d18b2258aa51169678b81a (diff) | |
| download | nova-6371c091450d093595e6103b6a37b38bbbb2f921.tar.gz nova-6371c091450d093595e6103b6a37b38bbbb2f921.tar.xz nova-6371c091450d093595e6103b6a37b38bbbb2f921.zip | |
Teach resource tracker about stashed instance types
This removes instance_type-related database queries from the
resource_tracker.
Related to blueprint no-db-compute
Change-Id: Ia5dd407181fa733cc81d3ce03edc1c06c2aae762
| -rw-r--r-- | nova/compute/resource_tracker.py | 37 | ||||
| -rw-r--r-- | nova/tests/compute/test_resource_tracker.py | 24 |
2 files changed, 38 insertions, 23 deletions
diff --git a/nova/compute/resource_tracker.py b/nova/compute/resource_tracker.py index f5d3a8008..825422e86 100644 --- a/nova/compute/resource_tracker.py +++ b/nova/compute/resource_tracker.py @@ -144,7 +144,8 @@ class ResourceTracker(object): # Mark the resources in-use for the resize landing on this # compute host: - self._update_usage_from_migration(self.compute_node, migration_ref) + self._update_usage_from_migration(instance_ref, self.compute_node, + migration_ref) elevated = context.elevated() self._update(elevated, self.compute_node) @@ -158,12 +159,7 @@ class ResourceTracker(object): be done while the COMPUTE_RESOURCES_SEMAPHORE is held so the resource claim will not be lost if the audit process starts. """ - # TODO(russellb): no-db-compute: Send the old instance type - # info that is needed via rpc so db access isn't required - # here. - old_instance_type_id = instance['instance_type_id'] - old_instance_type = instance_types.get_instance_type( - old_instance_type_id) + old_instance_type = instance_types.extract_instance_type(instance) return self.conductor_api.migration_create(context, instance, {'dest_compute': self.host, @@ -379,7 +375,7 @@ class ResourceTracker(object): resources['running_vms'] = self.stats.num_instances resources['vcpus_used'] = self.stats.num_vcpus_used - def _update_usage_from_migration(self, resources, migration): + def _update_usage_from_migration(self, instance, resources, migration): """Update usage for a single migration. The record may represent an incoming or outbound migration. """ @@ -392,7 +388,7 @@ class ResourceTracker(object): migration['source_node'] == self.nodename) same_node = (incoming and outbound) - instance = self.tracked_instances.get(uuid, None) + record = self.tracked_instances.get(uuid, None) itype = None if same_node: @@ -400,27 +396,25 @@ class ResourceTracker(object): # instance is *not* in: if (instance['instance_type_id'] == migration['old_instance_type_id']): - - itype = migration['new_instance_type_id'] + itype = instance_types.extract_instance_type(instance) else: # instance record already has new flavor, hold space for a # possible revert to the old instance type: - itype = migration['old_instance_type_id'] + itype = instance_types.extract_instance_type(instance, 'old_') - elif incoming and not instance: + elif incoming and not record: # instance has not yet migrated here: - itype = migration['new_instance_type_id'] + itype = instance_types.extract_instance_type(instance, 'new_') - elif outbound and not instance: + elif outbound and not record: # instance migrated, but record usage for a possible revert: - itype = migration['old_instance_type_id'] + itype = instance_types.extract_instance_type(instance, 'old_') if itype: - instance_type = instance_types.get_instance_type(itype) - self.stats.update_stats_for_migration(instance_type) - self._update_usage(resources, instance_type) + self.stats.update_stats_for_migration(itype) + self._update_usage(resources, itype) resources['stats'] = self.stats - self.tracked_migrations[uuid] = (migration, instance_type) + self.tracked_migrations[uuid] = (migration, itype) def _update_usage_from_migrations(self, resources, migrations): @@ -453,7 +447,8 @@ class ResourceTracker(object): for migration in filtered.values(): try: - self._update_usage_from_migration(resources, migration) + self._update_usage_from_migration(instance, resources, + migration) except exception.InstanceTypeNotFound: LOG.warn(_("InstanceType could not be found, skipping " "migration."), instance_uuid=uuid) diff --git a/nova/tests/compute/test_resource_tracker.py b/nova/tests/compute/test_resource_tracker.py index eaa0df5bf..f1d0d1f0c 100644 --- a/nova/tests/compute/test_resource_tracker.py +++ b/nova/tests/compute/test_resource_tracker.py @@ -19,6 +19,7 @@ import uuid +from nova.compute import instance_types from nova.compute import resource_tracker from nova.compute import task_states from nova.compute import vm_states @@ -152,8 +153,22 @@ class BaseTestCase(test.TestCase): } return service + def _fake_instance_system_metadata(self, instance_type, prefix=''): + sys_meta = [] + for key in instance_types.system_metadata_instance_type_props.keys(): + sys_meta.append({'key': '%sinstance_type_%s' % (prefix, key), + 'value': instance_type[key]}) + return sys_meta + def _fake_instance(self, *args, **kwargs): + # Default to an instance ready to resize to or from the same + # instance_type + itype = self._fake_instance_type_create() + sys_meta = (self._fake_instance_system_metadata(itype) + + self._fake_instance_system_metadata(itype, 'new_') + + self._fake_instance_system_metadata(itype, 'old_')) + instance_uuid = str(uuid.uuid1()) instance = { 'uuid': instance_uuid, @@ -169,6 +184,7 @@ class BaseTestCase(test.TestCase): 'node': None, 'instance_type_id': 1, 'launched_on': None, + 'system_metadata': sys_meta, } instance.update(kwargs) @@ -183,6 +199,9 @@ class BaseTestCase(test.TestCase): 'vcpus': FAKE_VIRT_VCPUS, 'root_gb': FAKE_VIRT_LOCAL_GB / 2, 'ephemeral_gb': FAKE_VIRT_LOCAL_GB / 2, + 'swap': 0, + 'rxtx_factor': 1.0, + 'vcpu_weight': 1, 'flavorid': 'fakeflavor' } instance_type.update(**kwargs) @@ -714,11 +733,12 @@ class ResizeClaimTestCase(BaseTrackerTestCase): # make an instance of src_type: instance = self._fake_instance(memory_mb=1, root_gb=1, ephemeral_gb=0, vcpus=1, instance_type_id=2) - + instance['system_metadata'] = self._fake_instance_system_metadata( + dest_type) self.tracker.instance_claim(self.context, instance, self.limits) # resize to dest_type: - claim = self.tracker.resize_claim(self.context, self.instance, + claim = self.tracker.resize_claim(self.context, instance, dest_type, self.limits) self._assert(3, 'memory_mb_used') |
