Add filters support to constant queries test
This allows the tests to ensure constant query behavior is observed when passing in filters. This patch updates the port query to test with a few different column matches. This also fixes the test to not observe queries emitted by the quota engine that happen as a result of a list operation right after a create operation. TrivialFix Change-Id: Ie1eab034ad99a233888cb048319bc31107be6fa3
This commit is contained in:
parent
f448cccabb
commit
e91561e97e
|
@ -6468,19 +6468,31 @@ class DbOperationBoundMixin(object):
|
|||
context_ = self._get_context()
|
||||
return {'set_context': True, 'tenant_id': context_.tenant}
|
||||
|
||||
def _list_and_count_queries(self, resource):
|
||||
def _list_and_count_queries(self, resource, query_params=None):
|
||||
kwargs = {'neutron_context': self._get_context()}
|
||||
if query_params:
|
||||
kwargs['query_params'] = query_params
|
||||
# list once before tracking to flush out any quota recalculations.
|
||||
# otherwise the first list after a create will be different than
|
||||
# a subsequent list with no create.
|
||||
self._list(resource, **kwargs)
|
||||
self._db_execute_count = 0
|
||||
self.assertNotEqual([],
|
||||
self._list(resource,
|
||||
neutron_context=self._get_context()))
|
||||
self.assertNotEqual([], self._list(resource, **kwargs))
|
||||
query_count = self._db_execute_count
|
||||
# sanity check to make sure queries are being observed
|
||||
self.assertNotEqual(0, query_count)
|
||||
return query_count
|
||||
|
||||
def _assert_object_list_queries_constant(self, obj_creator, plural):
|
||||
def _assert_object_list_queries_constant(self, obj_creator, plural,
|
||||
filters=None):
|
||||
obj_creator()
|
||||
before_count = self._list_and_count_queries(plural)
|
||||
# one more thing shouldn't change the db query count
|
||||
obj_creator()
|
||||
self.assertEqual(before_count, self._list_and_count_queries(plural))
|
||||
obj = list(obj_creator().values())[0]
|
||||
after_count = self._list_and_count_queries(plural)
|
||||
self.assertEqual(before_count, after_count)
|
||||
# using filters shouldn't change the count either
|
||||
if filters:
|
||||
query_params = "&".join(["%s=%s" % (f, obj[f]) for f in filters])
|
||||
after_count = self._list_and_count_queries(plural, query_params)
|
||||
self.assertEqual(before_count, after_count)
|
||||
|
|
|
@ -3689,10 +3689,12 @@ class TestL3DbOperationBounds(test_db_base_plugin_v2.DbOperationBoundMixin,
|
|||
|
||||
def router_maker():
|
||||
ext_info = {'network_id': s['subnet']['network_id']}
|
||||
self._create_router(self.fmt,
|
||||
res = self._create_router(
|
||||
self.fmt,
|
||||
arg_list=('external_gateway_info',),
|
||||
external_gateway_info=ext_info,
|
||||
**self.kwargs)
|
||||
return self.deserialize(self.fmt, res)
|
||||
|
||||
self._assert_object_list_queries_constant(router_maker, 'routers')
|
||||
|
||||
|
@ -3704,7 +3706,7 @@ class TestL3DbOperationBounds(test_db_base_plugin_v2.DbOperationBoundMixin,
|
|||
def float_maker():
|
||||
port = self._make_port(
|
||||
self.fmt, internal_net_id, **self.kwargs)
|
||||
self._make_floatingip(
|
||||
return self._make_floatingip(
|
||||
self.fmt, flip['floatingip']['floating_network_id'],
|
||||
port_id=port['port']['id'],
|
||||
**self.kwargs)
|
||||
|
|
|
@ -1472,7 +1472,7 @@ class BaseDbObjectTestCase(_BaseObjectTestCase,
|
|||
iter_db_obj = iter(self.db_objs)
|
||||
|
||||
def _create():
|
||||
self._create_object_with_synthetic_fields(next(iter_db_obj))
|
||||
return self._create_object_with_synthetic_fields(next(iter_db_obj))
|
||||
|
||||
self._assert_object_list_queries_constant(_create, self._test_class)
|
||||
|
||||
|
|
|
@ -679,6 +679,15 @@ class TestMl2DbOperationBounds(test_plugin.DbOperationBoundMixin,
|
|||
|
||||
def test_port_list_queries_constant(self):
|
||||
self._assert_object_list_queries_constant(self.make_port, 'ports')
|
||||
self._assert_object_list_queries_constant(self.make_port, 'ports',
|
||||
filters=['device_id'])
|
||||
self._assert_object_list_queries_constant(self.make_port, 'ports',
|
||||
filters=['device_id',
|
||||
'device_owner'])
|
||||
self._assert_object_list_queries_constant(self.make_port, 'ports',
|
||||
filters=['tenant_id',
|
||||
'name',
|
||||
'device_id'])
|
||||
|
||||
|
||||
class TestMl2DbOperationBoundsTenant(TestMl2DbOperationBounds):
|
||||
|
|
Loading…
Reference in New Issue