summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2013-03-08 22:38:50 +0000
committerGerrit Code Review <review@openstack.org>2013-03-08 22:38:50 +0000
commitdb5721d3e9a4feadaba9d427d25e7101ce9844be (patch)
tree7be5b558725f11ab4798d40b14ae38e23cd64d33
parent3152a9dfeb62d07bf65470dc542f987ebed387a4 (diff)
parent86e4587fb36aec74102d58c50d614fc6c006ebd3 (diff)
downloadnova-db5721d3e9a4feadaba9d427d25e7101ce9844be.tar.gz
nova-db5721d3e9a4feadaba9d427d25e7101ce9844be.tar.xz
nova-db5721d3e9a4feadaba9d427d25e7101ce9844be.zip
Merge "Remove uses of instance['instance_type'] from nova/compute"
-rw-r--r--nova/compute/api.py11
-rw-r--r--nova/tests/api/openstack/fakes.py5
-rw-r--r--nova/tests/compute/test_compute.py53
-rw-r--r--nova/tests/test_utils.py10
-rw-r--r--nova/utils.py7
5 files changed, 29 insertions, 57 deletions
diff --git a/nova/compute/api.py b/nova/compute/api.py
index 76d4d06ba..fba538c5e 100644
--- a/nova/compute/api.py
+++ b/nova/compute/api.py
@@ -1238,7 +1238,7 @@ class API(base.Base):
def restore(self, context, instance):
"""Restore a previously deleted (but not reclaimed) instance."""
# Reserve quotas
- instance_type = instance['instance_type']
+ instance_type = instance_types.extract_instance_type(instance)
num_instances, quota_reservations = self._check_num_instances_quota(
context, instance_type, 1, 1)
@@ -1654,7 +1654,8 @@ class API(base.Base):
#disk format of vhd is non-shrinkable
if orig_image.get('disk_format') == 'vhd':
- min_disk = instance['instance_type']['root_gb']
+ instance_type = instance_types.extract_instance_type(instance)
+ min_disk = instance_type['root_gb']
else:
#set new image values to the original image values
min_disk = orig_image.get('min_disk')
@@ -1745,7 +1746,7 @@ class API(base.Base):
metadata = kwargs.get('metadata', {})
self._check_metadata_properties_quota(context, metadata)
- instance_type = instance['instance_type']
+ instance_type = instance_types.extract_instance_type(instance)
if instance_type['memory_mb'] < int(image.get('min_ram') or 0):
raise exception.InstanceTypeMemoryTooSmall()
if instance_type['root_gb'] < int(image.get('min_disk') or 0):
@@ -1956,7 +1957,7 @@ class API(base.Base):
the original flavor_id. If flavor_id is not None, the instance should
be migrated to a new host and resized to the new flavor_id.
"""
- current_instance_type = instance['instance_type']
+ current_instance_type = instance_types.extract_instance_type(instance)
# If flavor_id is not provided, only migrate the instance.
if not flavor_id:
@@ -1982,7 +1983,7 @@ class API(base.Base):
# NOTE(sirp): We don't want to force a customer to change their flavor
# when Ops is migrating off of a failed host.
- if new_instance_type['disabled'] and not same_instance_type:
+ if not same_instance_type and new_instance_type['disabled']:
raise exception.FlavorNotFound(flavor_id=flavor_id)
# NOTE(markwash): look up the image early to avoid auth problems later
diff --git a/nova/tests/api/openstack/fakes.py b/nova/tests/api/openstack/fakes.py
index 1bc7b313e..97321212c 100644
--- a/nova/tests/api/openstack/fakes.py
+++ b/nova/tests/api/openstack/fakes.py
@@ -45,6 +45,7 @@ from nova.openstack.common import timeutils
from nova import quota
from nova.tests import fake_network
from nova.tests.glance import stubs as glance_stubs
+from nova import utils
from nova import wsgi
@@ -434,6 +435,7 @@ def stub_instance(id, user_id=None, project_id=None, host=None,
metadata = []
inst_type = instance_types.get_instance_type_by_flavor_id(int(flavor_id))
+ sys_meta = instance_types.save_instance_type_info({}, inst_type)
if host is not None:
host = str(host)
@@ -497,7 +499,8 @@ def stub_instance(id, user_id=None, project_id=None, host=None,
"shutdown_terminate": True,
"disable_terminate": False,
"security_groups": security_groups,
- "root_device_name": root_device_name}
+ "root_device_name": root_device_name,
+ "system_metadata": utils.dict_to_metadata(sys_meta)}
instance.update(info_cache)
diff --git a/nova/tests/compute/test_compute.py b/nova/tests/compute/test_compute.py
index 9ec527d12..c295ed75a 100644
--- a/nova/tests/compute/test_compute.py
+++ b/nova/tests/compute/test_compute.py
@@ -4846,7 +4846,7 @@ class ComputeAPITestCase(BaseTestCase):
{'extra_param': 'value1'})
self.assertEqual(image['name'], 'snap1')
- instance_type = instance['instance_type']
+ instance_type = instance_types.extract_instance_type(instance)
self.assertEqual(image['min_ram'], self.fake_image['min_ram'])
self.assertEqual(image['min_disk'], instance_type['root_gb'])
properties = image['properties']
@@ -5242,7 +5242,7 @@ class ComputeAPITestCase(BaseTestCase):
instance = self._create_fake_instance(dict(host='host2'))
instance = db.instance_get_by_uuid(self.context, instance['uuid'])
instance = jsonutils.to_primitive(instance)
- orig_instance_type = instance['instance_type']
+ orig_instance_type = instance_types.extract_instance_type(instance)
self.compute.run_instance(self.context, instance=instance)
# We need to set the host to something 'known'. Unfortunately,
# the compute manager is using a cached copy of CONF.host,
@@ -7077,33 +7077,6 @@ class DisabledInstanceTypesTestCase(BaseTestCase):
self.assertRaises(exception.InstanceTypeNotFound,
self.compute_api.create, self.context, self.inst_type, None)
- def test_can_rebuild_instance_from_visible_instance_type(self):
- instance = self._create_fake_instance()
- image_href = 'fake-image-id'
- admin_password = 'blah'
-
- instance['instance_type']['disabled'] = True
-
- # Assert no errors were raised
- self.compute_api.rebuild(self.context, instance, image_href,
- admin_password)
-
- def test_can_rebuild_instance_from_disabled_instance_type(self):
- """
- A rebuild or a restore should only change the 'image',
- not the 'instance_type'. Therefore, should be allowed even
- when the slice is on disabled type already.
- """
- instance = self._create_fake_instance()
- image_href = 'fake-image-id'
- admin_password = 'blah'
-
- instance['instance_type']['disabled'] = True
-
- # Assert no errors were raised
- self.compute_api.rebuild(self.context, instance, image_href,
- admin_password)
-
def test_can_resize_to_visible_instance_type(self):
instance = self._create_fake_instance()
orig_get_instance_type_by_flavor_id =\
@@ -7147,28 +7120,6 @@ class DisabledInstanceTypesTestCase(BaseTestCase):
self.assertRaises(exception.FlavorNotFound,
self.compute_api.resize, self.context, instance, '4')
- def test_can_migrate_to_visible_instance_type(self):
- instance = self._create_fake_instance()
- instance['instance_type']['disabled'] = False
-
- # FIXME(sirp): for legacy this raises FlavorNotFound instead of
- # InstanceTypeNotFound; we should eventually make it raise
- # InstanceTypeNotFound for consistency.
- self.compute_api.resize(self.context, instance, None)
-
- def test_can_migrate_to_disabled_instance_type(self):
- """
- We don't want to require a customers instance-type to change when ops
- is migrating a failed server.
- """
- instance = self._create_fake_instance()
- instance['instance_type']['disabled'] = True
-
- # FIXME(sirp): for legacy this raises FlavorNotFound instead of
- # InstanceTypeNotFound; we should eventually make it raise
- # InstanceTypeNotFound for consistency.
- self.compute_api.resize(self.context, instance, None)
-
class ComputeReschedulingTestCase(BaseTestCase):
"""Tests re-scheduling logic for new build requests."""
diff --git a/nova/tests/test_utils.py b/nova/tests/test_utils.py
index d22fb12ea..c601bb0af 100644
--- a/nova/tests/test_utils.py
+++ b/nova/tests/test_utils.py
@@ -916,6 +916,16 @@ class MetadataToDictTestCase(test.TestCase):
def test_metadata_to_dict_empty(self):
self.assertEqual(utils.metadata_to_dict([]), {})
+ def test_dict_to_metadata(self):
+ expected = [{'key': 'foo1', 'value': 'bar1'},
+ {'key': 'foo2', 'value': 'bar2'}]
+ self.assertEqual(utils.dict_to_metadata(dict(foo1='bar1',
+ foo2='bar2')),
+ expected)
+
+ def test_dict_to_metadata_empty(self):
+ self.assertEqual(utils.dict_to_metadata({}), [])
+
class WrappedCodeTestCase(test.TestCase):
"""Test the get_wrapped_function utility method."""
diff --git a/nova/utils.py b/nova/utils.py
index eb6c44106..fe6c75df3 100644
--- a/nova/utils.py
+++ b/nova/utils.py
@@ -1362,6 +1362,13 @@ def metadata_to_dict(metadata):
return result
+def dict_to_metadata(metadata):
+ result = []
+ for key, value in metadata.iteritems():
+ result.append(dict(key=key, value=value))
+ return result
+
+
def get_wrapped_function(function):
"""Get the method at the bottom of a stack of decorators."""
if not hasattr(function, 'func_closure') or not function.func_closure: