summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVishvananda Ishaya <vishvananda@gmail.com>2013-03-12 10:49:21 -0700
committerVishvananda Ishaya <vishvananda@gmail.com>2013-03-12 14:52:20 -0700
commitedf57ca3f4e822e45300f50471fbb90f14f1ab94 (patch)
tree151edc50814e837ea6e6705bccea8479d5ff42d7
parent562b0787421b145c4a91ccbbcacfc74c340cead8 (diff)
downloadnova-edf57ca3f4e822e45300f50471fbb90f14f1ab94.tar.gz
nova-edf57ca3f4e822e45300f50471fbb90f14f1ab94.tar.xz
nova-edf57ca3f4e822e45300f50471fbb90f14f1ab94.zip
Don't load system_metadata when it isn't joined.
If we always load system_metadata, it will throw a sqlalchemy error if it isn't joined in the column. Rather than putting it in extra keys we need to explicitly join it if it is missing. Adds a test to make sure that system_metadata is returned properly from the migration call even though the extra keys parameter was removed. Fixes bug 1146000 Change-Id: I05365906ed528a06fe5704449dab72c857fefa65
-rw-r--r--nova/db/sqlalchemy/api.py2
-rw-r--r--nova/db/sqlalchemy/models.py2
-rw-r--r--nova/tests/test_db_api.py14
3 files changed, 15 insertions, 3 deletions
diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py
index 0bd9cfce7..e6ef1a71d 100644
--- a/nova/db/sqlalchemy/api.py
+++ b/nova/db/sqlalchemy/api.py
@@ -3342,7 +3342,7 @@ def migration_get_in_progress_by_host_and_node(context, host, node,
and_(models.Migration.dest_compute == host,
models.Migration.dest_node == node))).\
filter(~models.Migration.status.in_(['confirmed', 'reverted'])).\
- options(joinedload('instance')).\
+ options(joinedload_all('instance.system_metadata')).\
all()
diff --git a/nova/db/sqlalchemy/models.py b/nova/db/sqlalchemy/models.py
index a675357df..c287cc0c5 100644
--- a/nova/db/sqlalchemy/models.py
+++ b/nova/db/sqlalchemy/models.py
@@ -154,7 +154,7 @@ class Instance(BASE, NovaBase):
return base_name
def _extra_keys(self):
- return ['name', 'system_metadata']
+ return ['name']
user_id = Column(String(255))
project_id = Column(String(255))
diff --git a/nova/tests/test_db_api.py b/nova/tests/test_db_api.py
index 0a2d81fb1..793149ac9 100644
--- a/nova/tests/test_db_api.py
+++ b/nova/tests/test_db_api.py
@@ -1553,10 +1553,14 @@ class MigrationTestCase(test.TestCase):
self._create(source_compute='host3', dest_compute='host4')
def _create(self, status='migrating', source_compute='host1',
- source_node='a', dest_compute='host2', dest_node='b'):
+ source_node='a', dest_compute='host2', dest_node='b',
+ system_metadata=None):
values = {'host': source_compute}
instance = db.instance_create(self.ctxt, values)
+ if system_metadata:
+ db.instance_system_metadata_update(self.ctxt, instance['uuid'],
+ system_metadata, False)
values = {'status': status, 'source_compute': source_compute,
'source_node': source_node, 'dest_compute': dest_compute,
@@ -1568,6 +1572,14 @@ class MigrationTestCase(test.TestCase):
self.assertNotEqual('confirmed', migration['status'])
self.assertNotEqual('reverted', migration['status'])
+ def test_migration_get_in_progress_joins(self):
+ self._create(source_compute='foo', system_metadata={'foo': 'bar'})
+ migrations = db.migration_get_in_progress_by_host_and_node(self.ctxt,
+ 'foo', 'a')
+ system_metadata = migrations[0]['instance']['system_metadata'][0]
+ self.assertEqual(system_metadata['key'], 'foo')
+ self.assertEqual(system_metadata['value'], 'bar')
+
def test_in_progress_host1_nodea(self):
migrations = db.migration_get_in_progress_by_host_and_node(self.ctxt,
'host1', 'a')