Make instance_get_all_*() funtions support the smart extra.$foo columns
This is a follow-on to a previous patch set that made the extra columns valid for being specified in columns_to_join, as they require slightly different handling. Related to blueprint flavor-from-sysmeta-to-blob Change-Id: Ieffec0e846565b7521fe620694d9f84c67066e11
This commit is contained in:
@@ -1916,7 +1916,10 @@ def instance_get_all_by_filters_sort(context, filters, limit=None, marker=None,
|
||||
|
||||
query_prefix = session.query(models.Instance)
|
||||
for column in columns_to_join_new:
|
||||
query_prefix = query_prefix.options(joinedload(column))
|
||||
if 'extra.' in column:
|
||||
query_prefix = query_prefix.options(undefer(column))
|
||||
else:
|
||||
query_prefix = query_prefix.options(joinedload(column))
|
||||
|
||||
# Note: order_by is done in the sqlalchemy.utils.py paginate_query(),
|
||||
# no need to do it here as well
|
||||
@@ -2244,7 +2247,10 @@ def instance_get_active_by_window_joined(context, begin, end=None,
|
||||
_manual_join_columns(columns_to_join))
|
||||
|
||||
for column in columns_to_join_new:
|
||||
query = query.options(joinedload(column))
|
||||
if 'extra.' in column:
|
||||
query = query.options(undefer(column))
|
||||
else:
|
||||
query = query.options(joinedload(column))
|
||||
|
||||
query = query.filter(or_(models.Instance.terminated_at == null(),
|
||||
models.Instance.terminated_at > begin))
|
||||
|
||||
@@ -1907,6 +1907,29 @@ class InstanceTestCase(test.TestCase, ModelsObjectComparatorMixin):
|
||||
self.create_instance_with_args(context=context2, hostname='h2')
|
||||
self.flags(osapi_compute_unique_server_name_scope=None)
|
||||
|
||||
@mock.patch('nova.db.sqlalchemy.api.undefer')
|
||||
@mock.patch('nova.db.sqlalchemy.api.joinedload')
|
||||
def test_instance_get_all_by_filters_extra_columns(self,
|
||||
mock_joinedload,
|
||||
mock_undefer):
|
||||
db.instance_get_all_by_filters_sort(
|
||||
self.ctxt, {},
|
||||
columns_to_join=['info_cache', 'extra.pci_requests'])
|
||||
mock_joinedload.assert_called_once_with('info_cache')
|
||||
mock_undefer.assert_called_once_with('extra.pci_requests')
|
||||
|
||||
@mock.patch('nova.db.sqlalchemy.api.undefer')
|
||||
@mock.patch('nova.db.sqlalchemy.api.joinedload')
|
||||
def test_instance_get_active_by_window_extra_columns(self,
|
||||
mock_joinedload,
|
||||
mock_undefer):
|
||||
now = datetime.datetime(2013, 10, 10, 17, 16, 37, 156701)
|
||||
db.instance_get_active_by_window_joined(
|
||||
self.ctxt, now,
|
||||
columns_to_join=['info_cache', 'extra.pci_requests'])
|
||||
mock_joinedload.assert_called_once_with('info_cache')
|
||||
mock_undefer.assert_called_once_with('extra.pci_requests')
|
||||
|
||||
def test_instance_get_all_by_filters_with_meta(self):
|
||||
inst = self.create_instance_with_args()
|
||||
for inst in db.instance_get_all_by_filters(self.ctxt, {}):
|
||||
|
||||
Reference in New Issue
Block a user