From fed1ea1d7528e7a3d2da181112da62cf04cb5092 Mon Sep 17 00:00:00 2001 From: Dan Smith Date: Fri, 8 Mar 2013 13:46:59 -0500 Subject: 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 --- nova/db/sqlalchemy/api.py | 16 +--------------- nova/db/sqlalchemy/models.py | 7 ------- 2 files changed, 1 insertion(+), 22 deletions(-) (limited to 'nova/db') 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.""" -- cgit