summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Smith <danms@us.ibm.com>2013-03-08 13:46:59 -0500
committerDan Smith <danms@us.ibm.com>2013-03-11 11:51:29 -0400
commitfed1ea1d7528e7a3d2da181112da62cf04cb5092 (patch)
tree1c520e200cf0ffcbe7b3a634d25227136cd8bc29
parentf543f347c84e7f5de2c584ca55363e4dee5b0a3d (diff)
downloadnova-fed1ea1d7528e7a3d2da181112da62cf04cb5092.tar.gz
nova-fed1ea1d7528e7a3d2da181112da62cf04cb5092.tar.xz
nova-fed1ea1d7528e7a3d2da181112da62cf04cb5092.zip
Remove instance['instance_type'] relationship from db api
This removes the entire relationship between an instance and the flavor it was created from. As such, it removes two tests entirely which examined the old behavior. This is one change in a series aimed at removing the use of instance-linked instance_type objects, in favor of the decoupled type data in system_metadata. See bug 1140119 for more details. Change-Id: I8b525a900bf2dc6b193e54aae35fc32248e4cff4
-rw-r--r--nova/cells/messaging.py4
-rw-r--r--nova/db/sqlalchemy/api.py16
-rw-r--r--nova/db/sqlalchemy/models.py7
-rw-r--r--nova/tests/cells/test_cells_messaging.py1
-rw-r--r--nova/tests/test_db_api.py20
-rw-r--r--nova/tests/test_instance_types.py18
6 files changed, 3 insertions, 63 deletions
diff --git a/nova/cells/messaging.py b/nova/cells/messaging.py
index f83f141dc..82f0a6a48 100644
--- a/nova/cells/messaging.py
+++ b/nova/cells/messaging.py
@@ -749,8 +749,8 @@ class _BroadcastMessageMethods(_BaseMessageMethods):
# 'metadata' is only updated in the API cell, so don't overwrite
# it based on what child cells say. Make sure to update
# 'cell_name' based on the routing path.
- items_to_remove = ['id', 'security_groups', 'instance_type',
- 'volumes', 'cell_name', 'name', 'metadata']
+ items_to_remove = ['id', 'security_groups', 'volumes', 'cell_name',
+ 'name', 'metadata']
for key in items_to_remove:
instance.pop(key, None)
instance['cell_name'] = _reverse_path(message.routing_path)
diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py
index 96c77bce3..8b8f51968 100644
--- a/nova/db/sqlalchemy/api.py
+++ b/nova/db/sqlalchemy/api.py
@@ -1438,9 +1438,6 @@ def instance_create(context, values):
instance_ref.security_groups = _get_sec_group_models(session,
security_groups)
instance_ref.save(session=session)
- # NOTE(comstud): This forces instance_type to be loaded so it
- # exists in the ref when we return. Fixes lazy loading issues.
- instance_ref.instance_type
# create the instance uuid to ec2_id mapping entry for instance
db.ec2_instance_create(context, instance_ref['uuid'])
@@ -1530,7 +1527,6 @@ def _build_instance_get(context, session=None):
options(joinedload_all('security_groups.rules')).\
options(joinedload('info_cache')).\
options(joinedload('metadata')).\
- options(joinedload('instance_type')).\
options(joinedload('system_metadata'))
@@ -1538,7 +1534,7 @@ def _build_instance_get(context, session=None):
def instance_get_all(context, columns_to_join=None):
if columns_to_join is None:
columns_to_join = ['info_cache', 'security_groups', 'metadata',
- 'instance_type', 'system_metadata']
+ 'system_metadata']
query = model_query(context, models.Instance)
for column in columns_to_join:
query = query.options(joinedload(column))
@@ -1568,7 +1564,6 @@ def instance_get_all_by_filters(context, filters, sort_key, sort_dir,
options(joinedload('security_groups')).\
options(joinedload('system_metadata')).\
options(joinedload('metadata')).\
- options(joinedload('instance_type')).\
order_by(sort_fn[sort_dir](getattr(models.Instance, sort_key)))
# Make a copy of the filters dictionary to use going forward, as we'll
@@ -1667,7 +1662,6 @@ def instance_get_active_by_window_joined(context, begin, end=None,
query = query.options(joinedload('info_cache')).\
options(joinedload('security_groups')).\
options(joinedload('metadata')).\
- options(joinedload('instance_type')).\
options(joinedload('system_metadata')).\
filter(or_(models.Instance.terminated_at == None,
models.Instance.terminated_at > begin))
@@ -1687,7 +1681,6 @@ def _instance_get_all_query(context, project_only=False):
options(joinedload('info_cache')).\
options(joinedload('security_groups')).\
options(joinedload('metadata')).\
- options(joinedload('instance_type')).\
options(joinedload('system_metadata'))
@@ -1856,13 +1849,6 @@ def _instance_update(context, instance_uuid, values, copy_old_instance=False):
instance_ref.update(values)
instance_ref.save(session=session)
- if 'instance_type_id' in values:
- # NOTE(comstud): It appears that sqlalchemy doesn't refresh
- # the instance_type model after you update the ID. You end
- # up with an instance_type model that only has 'id' updated,
- # but the rest of the model has the data from the old
- # instance_type.
- session.refresh(instance_ref['instance_type'])
return (old_instance_ref, instance_ref)
diff --git a/nova/db/sqlalchemy/models.py b/nova/db/sqlalchemy/models.py
index a675357df..3f45c614b 100644
--- a/nova/db/sqlalchemy/models.py
+++ b/nova/db/sqlalchemy/models.py
@@ -273,13 +273,6 @@ class InstanceTypes(BASE, NovaBase):
disabled = Column(Boolean, default=False)
is_public = Column(Boolean, default=True)
- instances = relationship(Instance,
- backref=backref('instance_type', uselist=False),
- foreign_keys=id,
- primaryjoin='and_('
- 'Instance.instance_type_id == '
- 'InstanceTypes.id)')
-
class Volume(BASE, NovaBase):
"""Represents a block storage device that can be attached to a VM."""
diff --git a/nova/tests/cells/test_cells_messaging.py b/nova/tests/cells/test_cells_messaging.py
index effe27660..3c7dd1941 100644
--- a/nova/tests/cells/test_cells_messaging.py
+++ b/nova/tests/cells/test_cells_messaging.py
@@ -938,7 +938,6 @@ class CellsBroadcastMethodsTestCase(test.TestCase):
fake_instance = {'id': 2,
'uuid': 'fake_uuid',
'security_groups': 'fake',
- 'instance_type': 'fake',
'volumes': 'fake',
'cell_name': 'fake',
'name': 'fake',
diff --git a/nova/tests/test_db_api.py b/nova/tests/test_db_api.py
index 769ddaea2..0aaa06538 100644
--- a/nova/tests/test_db_api.py
+++ b/nova/tests/test_db_api.py
@@ -369,26 +369,6 @@ class DbApiTestCase(test.TestCase):
system_meta = db.instance_system_metadata_get(ctxt, instance['uuid'])
self.assertEqual('baz', system_meta['original_image_ref'])
- def test_instance_update_of_instance_type_id(self):
- ctxt = context.get_admin_context()
-
- inst_type1 = db.instance_type_get_by_name(ctxt, 'm1.tiny')
- inst_type2 = db.instance_type_get_by_name(ctxt, 'm1.small')
-
- values = {'instance_type_id': inst_type1['id']}
- instance = db.instance_create(ctxt, values)
-
- self.assertEqual(instance['instance_type']['id'], inst_type1['id'])
- self.assertEqual(instance['instance_type']['name'],
- inst_type1['name'])
-
- values = {'instance_type_id': inst_type2['id']}
- instance = db.instance_update(ctxt, instance['uuid'], values)
-
- self.assertEqual(instance['instance_type']['id'], inst_type2['id'])
- self.assertEqual(instance['instance_type']['name'],
- inst_type2['name'])
-
def test_instance_update_unique_name(self):
otherprojectcontext = context.RequestContext(self.user_id,
"%s2" % self.project_id)
diff --git a/nova/tests/test_instance_types.py b/nova/tests/test_instance_types.py
index 6ae28a1c9..01cdd1327 100644
--- a/nova/tests/test_instance_types.py
+++ b/nova/tests/test_instance_types.py
@@ -351,24 +351,6 @@ class InstanceTypeTestCase(test.TestCase):
"test1", read_deleted="no")
self.assertEqual("instance_type1_redo", instance_type["name"])
- def test_will_list_deleted_type_for_active_instance(self):
- # Ensure deleted instance types with active instances can be read.
- ctxt = context.get_admin_context()
- inst_type = instance_types.create("test", 256, 1, 120, 100, "test1")
-
- instance_params = {"instance_type_id": inst_type["id"]}
- instance = db.instance_create(ctxt, instance_params)
-
- # NOTE(jk0): Delete the instance type and reload the instance from the
- # DB. The instance_type object will still be available to the active
- # instance, otherwise being None.
- instance_types.destroy(inst_type["name"])
- instance = db.instance_get_by_uuid(ctxt, instance["uuid"])
-
- self.assertRaises(exception.InstanceTypeNotFound,
- instance_types.get_instance_type, inst_type["name"])
- self.assertTrue(instance["instance_type"])
-
class InstanceTypeToolsTest(test.TestCase):
def _dict_to_metadata(self, data):