summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2013-01-08 19:44:53 +0000
committerGerrit Code Review <review@openstack.org>2013-01-08 19:44:53 +0000
commit8a812a75ce0e72fd79d6c73d94943bfe30eb3977 (patch)
tree36f90560ee5c5184962045e6649f07098b89743e
parent885271e06e7860cca05d06d9f49ac0a2646684a8 (diff)
parent4e02fa1964f5de3a6ba345d858623f35b24beafd (diff)
downloadnova-8a812a75ce0e72fd79d6c73d94943bfe30eb3977.tar.gz
nova-8a812a75ce0e72fd79d6c73d94943bfe30eb3977.tar.xz
nova-8a812a75ce0e72fd79d6c73d94943bfe30eb3977.zip
Merge "Add exception handler for previous deleted flavor."
-rw-r--r--nova/api/openstack/compute/servers.py3
-rw-r--r--nova/compute/resource_tracker.py7
-rw-r--r--nova/tests/compute/test_compute.py34
3 files changed, 43 insertions, 1 deletions
diff --git a/nova/api/openstack/compute/servers.py b/nova/api/openstack/compute/servers.py
index f992dc445..ff616a2e8 100644
--- a/nova/api/openstack/compute/servers.py
+++ b/nova/api/openstack/compute/servers.py
@@ -1028,6 +1028,9 @@ class Controller(wsgi.Controller):
except exception.MigrationNotFound:
msg = _("Instance has not been resized.")
raise exc.HTTPBadRequest(explanation=msg)
+ except exception.InstanceTypeNotFound:
+ msg = _("Flavor used by the instance could not be found.")
+ raise exc.HTTPBadRequest(explanation=msg)
except exception.InstanceInvalidState as state_error:
common.raise_http_conflict_for_instance_invalid_state(state_error,
'revertResize')
diff --git a/nova/compute/resource_tracker.py b/nova/compute/resource_tracker.py
index c784fd83d..ba1915f42 100644
--- a/nova/compute/resource_tracker.py
+++ b/nova/compute/resource_tracker.py
@@ -453,7 +453,12 @@ class ResourceTracker(object):
filtered[uuid] = migration
for migration in filtered.values():
- self._update_usage_from_migration(resources, migration)
+ try:
+ self._update_usage_from_migration(resources, migration)
+ except exception.InstanceTypeNotFound:
+ LOG.warn(_("InstanceType could not be found, skipping "
+ "migration."), instance_uuid=uuid)
+ continue
def _update_usage_from_instance(self, resources, instance):
"""Update usage for a single instance."""
diff --git a/nova/tests/compute/test_compute.py b/nova/tests/compute/test_compute.py
index 4c26e42b5..dabb8bb89 100644
--- a/nova/tests/compute/test_compute.py
+++ b/nova/tests/compute/test_compute.py
@@ -4254,6 +4254,40 @@ class ComputeAPITestCase(BaseTestCase):
instance_types.destroy(name)
self.compute.terminate_instance(self.context, instance=instance)
+ def test_resize_revert_deleted_flavor_fails(self):
+ orig_name = 'test_resize_revert_orig_flavor'
+ orig_flavorid = 11
+ memory_mb = 128
+ root_gb = 0
+ vcpus = 1
+ instance_types.create(orig_name, memory_mb, vcpus, root_gb, 0,
+ orig_flavorid, 0, 1.0, True)
+
+ instance = self._create_fake_instance(type_name=orig_name)
+ instance = db.instance_get_by_uuid(self.context, instance['uuid'])
+ instance = jsonutils.to_primitive(instance)
+ self.compute.run_instance(self.context, instance=instance)
+
+ old_instance_type_id = instance['instance_type_id']
+ new_flavor = instance_types.get_instance_type_by_name('m1.tiny')
+ new_flavorid = new_flavor['flavorid']
+ new_instance_type_id = new_flavor['id']
+ self.compute_api.resize(self.context, instance, new_flavorid)
+
+ db.migration_create(self.context.elevated(),
+ {'instance_uuid': instance['uuid'],
+ 'old_instance_type_id': old_instance_type_id,
+ 'new_instance_type_id': new_instance_type_id,
+ 'status': 'finished'})
+ instance = db.instance_update(self.context, instance['uuid'],
+ {'task_state': None,
+ 'vm_state': vm_states.RESIZED})
+ instance_types.destroy(orig_name)
+ self.assertRaises(exception.InstanceTypeNotFound,
+ self.compute_api.revert_resize,
+ self.context, instance)
+ self.compute.terminate_instance(self.context, instance=instance)
+
def test_migrate(self):
instance = self._create_fake_instance()
instance = db.instance_get_by_uuid(self.context, instance['uuid'])