Skip to content

Commit

Permalink
Merge "Fix joins in instance_get_all_by_host"
Browse files Browse the repository at this point in the history
  • Loading branch information
Jenkins authored and openstack-gerrit committed Apr 12, 2017
2 parents 2b5b478 + d52bcc6 commit 32c20db
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
5 changes: 3 additions & 2 deletions nova/db/sqlalchemy/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
22 changes: 22 additions & 0 deletions nova/tests/unit/db/test_db_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1182,6 +1182,28 @@ def test(context):
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()
Expand Down

0 comments on commit 32c20db

Please sign in to comment.