Merge "Fix joins in instance_get_all_by_host"

This commit is contained in:
Jenkins
2017-04-12 11:49:24 +00:00
committed by Gerrit Code Review
2 changed files with 25 additions and 2 deletions

View File

@@ -2526,9 +2526,10 @@ def _instance_get_all_query(context, project_only=False, joins=None):
@pick_context_manager_reader_allow_async
def instance_get_all_by_host(context, host, columns_to_join=None):
query = _instance_get_all_query(context, joins=columns_to_join)
return _instances_fill_metadata(context,
_instance_get_all_query(context).filter_by(host=host).all(),
manual_joins=columns_to_join)
query.filter_by(host=host).all(),
manual_joins=columns_to_join)
def _instance_get_all_uuids_by_host(context, host):

View File

@@ -1182,6 +1182,28 @@ class SqlAlchemyDbApiTestCase(DbTestCase):
result = test(ctxt)
self.assertEqual(2, len(result))
# make sure info_cache and security_groups were auto-joined
instance = result[0]
self.assertIn('info_cache', instance)
self.assertIn('security_groups', instance)
def test_instance_get_all_by_host_no_joins(self):
"""Tests that we don't join on the info_cache and security_groups
tables if columns_to_join is an empty list.
"""
self.create_instance_with_args()
@sqlalchemy_api.pick_context_manager_reader
def test(ctxt):
return sqlalchemy_api.instance_get_all_by_host(
ctxt, 'host1', columns_to_join=[])
result = test(context.get_admin_context())
self.assertEqual(1, len(result))
# make sure info_cache and security_groups were not auto-joined
instance = result[0]
self.assertNotIn('info_cache', instance)
self.assertNotIn('security_groups', instance)
def test_instance_get_all_uuids_by_host(self):
ctxt = context.get_admin_context()