Merge "Alter stack_count_all_by_tenant to stack_count_all"
This commit is contained in:
commit
43d870cc4b
@ -130,8 +130,9 @@ def stack_get_all_by_owner_id(context, owner_id):
|
|||||||
return IMPL.stack_get_all_by_owner_id(context, owner_id)
|
return IMPL.stack_get_all_by_owner_id(context, owner_id)
|
||||||
|
|
||||||
|
|
||||||
def stack_count_all_by_tenant(context, filters=None):
|
def stack_count_all(context, filters=None, tenant_safe=True):
|
||||||
return IMPL.stack_count_all_by_tenant(context, filters=filters)
|
return IMPL.stack_count_all(context, filters=filters,
|
||||||
|
tenant_safe=tenant_safe)
|
||||||
|
|
||||||
|
|
||||||
def stack_create(context, values):
|
def stack_create(context, values):
|
||||||
|
@ -354,8 +354,8 @@ def _filter_and_page_query(context, query, limit=None, sort_keys=None,
|
|||||||
whitelisted_sort_keys, marker, sort_dir)
|
whitelisted_sort_keys, marker, sort_dir)
|
||||||
|
|
||||||
|
|
||||||
def stack_count_all_by_tenant(context, filters=None):
|
def stack_count_all(context, filters=None, tenant_safe=True):
|
||||||
query = _query_stack_get_all(context)
|
query = _query_stack_get_all(context, tenant_safe=tenant_safe)
|
||||||
query = db_filters.exact_filter(query, models.Stack, filters)
|
query = db_filters.exact_filter(query, models.Stack, filters)
|
||||||
return query.count()
|
return query.count()
|
||||||
|
|
||||||
|
@ -342,7 +342,7 @@ class EngineService(service.Service):
|
|||||||
:param filters: a dict of ATTR:VALUE to match against stacks
|
:param filters: a dict of ATTR:VALUE to match against stacks
|
||||||
:returns: a integer representing the number of matched stacks
|
:returns: a integer representing the number of matched stacks
|
||||||
"""
|
"""
|
||||||
return db_api.stack_count_all_by_tenant(cnxt, filters=filters)
|
return db_api.stack_count_all(cnxt, filters=filters)
|
||||||
|
|
||||||
def _validate_deferred_auth_context(self, cnxt, stack):
|
def _validate_deferred_auth_context(self, cnxt, stack):
|
||||||
if cfg.CONF.deferred_auth_method != 'password':
|
if cfg.CONF.deferred_auth_method != 'password':
|
||||||
@ -361,7 +361,7 @@ class EngineService(service.Service):
|
|||||||
raise exception.StackExists(stack_name=stack_name)
|
raise exception.StackExists(stack_name=stack_name)
|
||||||
|
|
||||||
tenant_limit = cfg.CONF.max_stacks_per_tenant
|
tenant_limit = cfg.CONF.max_stacks_per_tenant
|
||||||
if db_api.stack_count_all_by_tenant(cnxt) >= tenant_limit:
|
if db_api.stack_count_all(cnxt) >= tenant_limit:
|
||||||
message = _("You have reached the maximum stacks per tenant, %d."
|
message = _("You have reached the maximum stacks per tenant, %d."
|
||||||
" Please delete some stacks.") % tenant_limit
|
" Please delete some stacks.") % tenant_limit
|
||||||
raise exception.RequestLimitExceeded(message=message)
|
raise exception.RequestLimitExceeded(message=message)
|
||||||
|
@ -2551,7 +2551,7 @@ class StackServiceTest(HeatTestCase):
|
|||||||
self.assertRaises(exception.StackExists, self.eng._validate_new_stack,
|
self.assertRaises(exception.StackExists, self.eng._validate_new_stack,
|
||||||
self.ctx, 'test_existing_stack', 'parsed_template')
|
self.ctx, 'test_existing_stack', 'parsed_template')
|
||||||
|
|
||||||
@mock.patch.object(service.db_api, 'stack_count_all_by_tenant')
|
@mock.patch.object(service.db_api, 'stack_count_all')
|
||||||
def test_validate_new_stack_checks_stack_limit(self, mock_db_count):
|
def test_validate_new_stack_checks_stack_limit(self, mock_db_count):
|
||||||
cfg.CONF.set_override('max_stacks_per_tenant', 99)
|
cfg.CONF.set_override('max_stacks_per_tenant', 99)
|
||||||
mock_db_count.return_value = 99
|
mock_db_count.return_value = 99
|
||||||
|
@ -457,27 +457,27 @@ class SqlAlchemyTest(HeatTestCase):
|
|||||||
db_api.stack_get_all(self.ctx, sort_keys=sort_keys)
|
db_api.stack_get_all(self.ctx, sort_keys=sort_keys)
|
||||||
self.assertEqual(['id'], sort_keys)
|
self.assertEqual(['id'], sort_keys)
|
||||||
|
|
||||||
def test_stack_count_all_by_tenant(self):
|
def test_stack_count_all(self):
|
||||||
stacks = [self._setup_test_stack('stack', x)[1] for x in UUIDs]
|
stacks = [self._setup_test_stack('stack', x)[1] for x in UUIDs]
|
||||||
|
|
||||||
st_db = db_api.stack_count_all_by_tenant(self.ctx)
|
st_db = db_api.stack_count_all(self.ctx)
|
||||||
self.assertEqual(3, st_db)
|
self.assertEqual(3, st_db)
|
||||||
|
|
||||||
stacks[0].delete()
|
stacks[0].delete()
|
||||||
st_db = db_api.stack_count_all_by_tenant(self.ctx)
|
st_db = db_api.stack_count_all(self.ctx)
|
||||||
self.assertEqual(2, st_db)
|
self.assertEqual(2, st_db)
|
||||||
|
|
||||||
stacks[1].delete()
|
stacks[1].delete()
|
||||||
st_db = db_api.stack_count_all_by_tenant(self.ctx)
|
st_db = db_api.stack_count_all(self.ctx)
|
||||||
self.assertEqual(1, st_db)
|
self.assertEqual(1, st_db)
|
||||||
|
|
||||||
def test_stack_count_all_by_tenant_with_filters(self):
|
def test_stack_count_all_with_filters(self):
|
||||||
self._setup_test_stack('foo', UUID1)
|
self._setup_test_stack('foo', UUID1)
|
||||||
self._setup_test_stack('bar', UUID2)
|
self._setup_test_stack('bar', UUID2)
|
||||||
self._setup_test_stack('bar', UUID3)
|
self._setup_test_stack('bar', UUID3)
|
||||||
filters = {'name': 'bar'}
|
filters = {'name': 'bar'}
|
||||||
|
|
||||||
st_db = db_api.stack_count_all_by_tenant(self.ctx, filters=filters)
|
st_db = db_api.stack_count_all(self.ctx, filters=filters)
|
||||||
self.assertEqual(2, st_db)
|
self.assertEqual(2, st_db)
|
||||||
|
|
||||||
def test_event_get_all_by_stack(self):
|
def test_event_get_all_by_stack(self):
|
||||||
@ -1091,15 +1091,36 @@ class DBAPIStackTest(HeatTestCase):
|
|||||||
stacks = db_api.stack_get_all(self.ctx, tenant_safe=False)
|
stacks = db_api.stack_get_all(self.ctx, tenant_safe=False)
|
||||||
self.assertEqual(5, len(stacks))
|
self.assertEqual(5, len(stacks))
|
||||||
|
|
||||||
def test_stack_count_all_by_tenant(self):
|
def test_stack_count_all_with_regular_tenant(self):
|
||||||
values = [
|
values = [
|
||||||
{'tenant': self.ctx.tenant_id},
|
{'tenant': UUID1},
|
||||||
{'tenant': self.ctx.tenant_id},
|
{'tenant': UUID1},
|
||||||
|
{'tenant': UUID2},
|
||||||
|
{'tenant': UUID2},
|
||||||
|
{'tenant': UUID2},
|
||||||
]
|
]
|
||||||
[create_stack(self.ctx, self.template, self.user_creds,
|
[create_stack(self.ctx, self.template, self.user_creds,
|
||||||
**val) for val in values]
|
**val) for val in values]
|
||||||
|
|
||||||
self.assertEqual(2, db_api.stack_count_all_by_tenant(self.ctx))
|
self.ctx.tenant_id = UUID1
|
||||||
|
self.assertEqual(2, db_api.stack_count_all(self.ctx))
|
||||||
|
|
||||||
|
self.ctx.tenant_id = UUID2
|
||||||
|
self.assertEqual(3, db_api.stack_count_all(self.ctx))
|
||||||
|
|
||||||
|
def test_stack_count_all_with_tenant_safe_false(self):
|
||||||
|
values = [
|
||||||
|
{'tenant': UUID1},
|
||||||
|
{'tenant': UUID1},
|
||||||
|
{'tenant': UUID2},
|
||||||
|
{'tenant': UUID2},
|
||||||
|
{'tenant': UUID2},
|
||||||
|
]
|
||||||
|
[create_stack(self.ctx, self.template, self.user_creds,
|
||||||
|
**val) for val in values]
|
||||||
|
|
||||||
|
self.assertEqual(5,
|
||||||
|
db_api.stack_count_all(self.ctx, tenant_safe=False))
|
||||||
|
|
||||||
def test_purge_deleted(self):
|
def test_purge_deleted(self):
|
||||||
now = datetime.now()
|
now = datetime.now()
|
||||||
|
Loading…
Reference in New Issue
Block a user