Declare and use keyword args for Stack.get_all

Having such a long positional args list which is then passed through
with *args is error prone and hard to maintain.

Change-Id: I525b00c113099f2f8e4648317cfcbd3cc05398c4
This commit is contained in:
Steve Baker 2016-05-26 10:36:01 +12:00
parent 56b95a00d8
commit c2208f1fc6
4 changed files with 214 additions and 208 deletions

View File

@ -558,19 +558,19 @@ class EngineService(service.Service):
stacks = stack_object.Stack.get_all( stacks = stack_object.Stack.get_all(
cnxt, cnxt,
limit, limit=limit,
sort_keys, sort_keys=sort_keys,
marker, marker=marker,
sort_dir, sort_dir=sort_dir,
filters, filters=filters,
tenant_safe, tenant_safe=tenant_safe,
show_deleted, show_deleted=show_deleted,
show_nested, show_nested=show_nested,
show_hidden, show_hidden=show_hidden,
tags, tags=tags,
tags_any, tags_any=tags_any,
not_tags, not_tags=not_tags,
not_tags_any) or [] not_tags_any=not_tags_any)
return [api.format_stack_db_object(stack) for stack in stacks] return [api.format_stack_db_object(stack) for stack in stacks]
@context.request_context @context.request_context
@ -2184,7 +2184,7 @@ class EngineService(service.Service):
stacks = stack_object.Stack.get_all(cnxt, stacks = stack_object.Stack.get_all(cnxt,
filters=filters, filters=filters,
tenant_safe=False, tenant_safe=False,
show_nested=True) or [] show_nested=True)
for s in stacks: for s in stacks:
stack_id = s.id stack_id = s.id
lock = stack_lock.StackLock(cnxt, stack_id, self.engine_id) lock = stack_lock.StackLock(cnxt, stack_id, self.engine_id)

View File

@ -482,19 +482,19 @@ class Stack(collections.Mapping):
tags_any=None, not_tags=None, not_tags_any=None): tags_any=None, not_tags=None, not_tags_any=None):
stacks = stack_object.Stack.get_all( stacks = stack_object.Stack.get_all(
context, context,
limit, limit=limit,
sort_keys, sort_keys=sort_keys,
marker, marker=marker,
sort_dir, sort_dir=sort_dir,
filters, filters=filters,
tenant_safe, tenant_safe=tenant_safe,
show_deleted, show_deleted=show_deleted,
show_nested, show_nested=show_nested,
show_hidden, show_hidden=show_hidden,
tags, tags=tags,
tags_any, tags_any=tags_any,
not_tags, not_tags=not_tags,
not_tags_any) or [] not_tags_any=not_tags_any)
for stack in stacks: for stack in stacks:
try: try:
yield cls._from_db(context, stack, resolve_data=resolve_data) yield cls._from_db(context, stack, resolve_data=resolve_data)

View File

@ -109,8 +109,26 @@ class Stack(
return stack return stack
@classmethod @classmethod
def get_all(cls, context, *args, **kwargs): def get_all(cls, context, limit=None, sort_keys=None, marker=None,
db_stacks = db_api.stack_get_all(context, *args, **kwargs) sort_dir=None, filters=None, tenant_safe=True,
show_deleted=False, show_nested=False, show_hidden=False,
tags=None, tags_any=None, not_tags=None,
not_tags_any=None):
db_stacks = db_api.stack_get_all(
context,
limit=limit,
sort_keys=sort_keys,
marker=marker,
sort_dir=sort_dir,
filters=filters,
tenant_safe=tenant_safe,
show_deleted=show_deleted,
show_nested=show_nested,
show_hidden=show_hidden,
tags=tags,
tags_any=tags_any,
not_tags=not_tags,
not_tags_any=not_tags_any)
for db_stack in db_stacks: for db_stack in db_stacks:
try: try:
yield cls._from_db_object(context, cls(context), db_stack) yield cls._from_db_object(context, cls(context), db_stack)

View File

@ -487,232 +487,220 @@ class StackServiceTest(common.HeatTestCase):
self.eng.list_stacks(self.ctx, limit=limit, marker=marker, self.eng.list_stacks(self.ctx, limit=limit, marker=marker,
sort_keys=sort_keys, sort_dir=sort_dir) sort_keys=sort_keys, sort_dir=sort_dir)
mock_stack_get_all.assert_called_once_with(self.ctx, mock_stack_get_all.assert_called_once_with(self.ctx,
limit, limit=limit,
sort_keys, sort_keys=sort_keys,
marker, marker=marker,
sort_dir, sort_dir=sort_dir,
mock.ANY, filters=mock.ANY,
mock.ANY, tenant_safe=mock.ANY,
mock.ANY, show_deleted=mock.ANY,
mock.ANY, show_nested=mock.ANY,
mock.ANY, show_hidden=mock.ANY,
mock.ANY, tags=mock.ANY,
mock.ANY, tags_any=mock.ANY,
mock.ANY, not_tags=mock.ANY,
mock.ANY, not_tags_any=mock.ANY)
)
@mock.patch.object(stack_object.Stack, 'get_all') @mock.patch.object(stack_object.Stack, 'get_all')
def test_stack_list_passes_filtering_info(self, mock_stack_get_all): def test_stack_list_passes_filtering_info(self, mock_stack_get_all):
filters = {'foo': 'bar'} filters = {'foo': 'bar'}
self.eng.list_stacks(self.ctx, filters=filters) self.eng.list_stacks(self.ctx, filters=filters)
mock_stack_get_all.assert_called_once_with(mock.ANY, mock_stack_get_all.assert_called_once_with(self.ctx,
mock.ANY, limit=mock.ANY,
mock.ANY, sort_keys=mock.ANY,
mock.ANY, marker=mock.ANY,
mock.ANY, sort_dir=mock.ANY,
filters, filters=filters,
mock.ANY, tenant_safe=mock.ANY,
mock.ANY, show_deleted=mock.ANY,
mock.ANY, show_nested=mock.ANY,
mock.ANY, show_hidden=mock.ANY,
mock.ANY, tags=mock.ANY,
mock.ANY, tags_any=mock.ANY,
mock.ANY, not_tags=mock.ANY,
mock.ANY, not_tags_any=mock.ANY)
)
@mock.patch.object(stack_object.Stack, 'get_all') @mock.patch.object(stack_object.Stack, 'get_all')
def test_stack_list_passes_filter_translated(self, mock_stack_get_all): def test_stack_list_passes_filter_translated(self, mock_stack_get_all):
filters = {'stack_name': 'bar'} filters = {'stack_name': 'bar'}
self.eng.list_stacks(self.ctx, filters=filters) self.eng.list_stacks(self.ctx, filters=filters)
translated = {'name': 'bar'} translated = {'name': 'bar'}
mock_stack_get_all.assert_called_once_with(mock.ANY, mock_stack_get_all.assert_called_once_with(self.ctx,
mock.ANY, limit=mock.ANY,
mock.ANY, sort_keys=mock.ANY,
mock.ANY, marker=mock.ANY,
mock.ANY, sort_dir=mock.ANY,
translated, filters=translated,
mock.ANY, tenant_safe=mock.ANY,
mock.ANY, show_deleted=mock.ANY,
mock.ANY, show_nested=mock.ANY,
mock.ANY, show_hidden=mock.ANY,
mock.ANY, tags=mock.ANY,
mock.ANY, tags_any=mock.ANY,
mock.ANY, not_tags=mock.ANY,
mock.ANY, not_tags_any=mock.ANY)
)
@mock.patch.object(stack_object.Stack, 'get_all') @mock.patch.object(stack_object.Stack, 'get_all')
def test_stack_list_tenant_safe_defaults_to_true(self, mock_stack_get_all): def test_stack_list_tenant_safe_defaults_to_true(self, mock_stack_get_all):
self.eng.list_stacks(self.ctx) self.eng.list_stacks(self.ctx)
mock_stack_get_all.assert_called_once_with(mock.ANY, mock_stack_get_all.assert_called_once_with(self.ctx,
mock.ANY, limit=mock.ANY,
mock.ANY, sort_keys=mock.ANY,
mock.ANY, marker=mock.ANY,
mock.ANY, sort_dir=mock.ANY,
mock.ANY, filters=mock.ANY,
True, tenant_safe=True,
mock.ANY, show_deleted=mock.ANY,
mock.ANY, show_nested=mock.ANY,
mock.ANY, show_hidden=mock.ANY,
mock.ANY, tags=mock.ANY,
mock.ANY, tags_any=mock.ANY,
mock.ANY, not_tags=mock.ANY,
mock.ANY, not_tags_any=mock.ANY)
)
@mock.patch.object(stack_object.Stack, 'get_all') @mock.patch.object(stack_object.Stack, 'get_all')
def test_stack_list_passes_tenant_safe_info(self, mock_stack_get_all): def test_stack_list_passes_tenant_safe_info(self, mock_stack_get_all):
self.eng.list_stacks(self.ctx, tenant_safe=False) self.eng.list_stacks(self.ctx, tenant_safe=False)
mock_stack_get_all.assert_called_once_with(mock.ANY, mock_stack_get_all.assert_called_once_with(self.ctx,
mock.ANY, limit=mock.ANY,
mock.ANY, sort_keys=mock.ANY,
mock.ANY, marker=mock.ANY,
mock.ANY, sort_dir=mock.ANY,
mock.ANY, filters=mock.ANY,
False, tenant_safe=False,
mock.ANY, show_deleted=mock.ANY,
mock.ANY, show_nested=mock.ANY,
mock.ANY, show_hidden=mock.ANY,
mock.ANY, tags=mock.ANY,
mock.ANY, tags_any=mock.ANY,
mock.ANY, not_tags=mock.ANY,
mock.ANY, not_tags_any=mock.ANY)
)
@mock.patch.object(stack_object.Stack, 'get_all') @mock.patch.object(stack_object.Stack, 'get_all')
def test_stack_list_show_nested(self, mock_stack_get_all): def test_stack_list_show_nested(self, mock_stack_get_all):
self.eng.list_stacks(self.ctx, show_nested=True) self.eng.list_stacks(self.ctx, show_nested=True)
mock_stack_get_all.assert_called_once_with(mock.ANY, mock_stack_get_all.assert_called_once_with(self.ctx,
mock.ANY, limit=mock.ANY,
mock.ANY, sort_keys=mock.ANY,
mock.ANY, marker=mock.ANY,
mock.ANY, sort_dir=mock.ANY,
mock.ANY, filters=mock.ANY,
mock.ANY, tenant_safe=mock.ANY,
mock.ANY, show_deleted=mock.ANY,
True, show_nested=True,
mock.ANY, show_hidden=mock.ANY,
mock.ANY, tags=mock.ANY,
mock.ANY, tags_any=mock.ANY,
mock.ANY, not_tags=mock.ANY,
mock.ANY, not_tags_any=mock.ANY)
)
@mock.patch.object(stack_object.Stack, 'get_all') @mock.patch.object(stack_object.Stack, 'get_all')
def test_stack_list_show_deleted(self, mock_stack_get_all): def test_stack_list_show_deleted(self, mock_stack_get_all):
self.eng.list_stacks(self.ctx, show_deleted=True) self.eng.list_stacks(self.ctx, show_deleted=True)
mock_stack_get_all.assert_called_once_with(mock.ANY, mock_stack_get_all.assert_called_once_with(self.ctx,
mock.ANY, limit=mock.ANY,
mock.ANY, sort_keys=mock.ANY,
mock.ANY, marker=mock.ANY,
mock.ANY, sort_dir=mock.ANY,
mock.ANY, filters=mock.ANY,
mock.ANY, tenant_safe=mock.ANY,
True, show_deleted=True,
mock.ANY, show_nested=mock.ANY,
mock.ANY, show_hidden=mock.ANY,
mock.ANY, tags=mock.ANY,
mock.ANY, tags_any=mock.ANY,
mock.ANY, not_tags=mock.ANY,
mock.ANY, not_tags_any=mock.ANY)
)
@mock.patch.object(stack_object.Stack, 'get_all') @mock.patch.object(stack_object.Stack, 'get_all')
def test_stack_list_show_hidden(self, mock_stack_get_all): def test_stack_list_show_hidden(self, mock_stack_get_all):
self.eng.list_stacks(self.ctx, show_hidden=True) self.eng.list_stacks(self.ctx, show_hidden=True)
mock_stack_get_all.assert_called_once_with(mock.ANY, mock_stack_get_all.assert_called_once_with(self.ctx,
mock.ANY, limit=mock.ANY,
mock.ANY, sort_keys=mock.ANY,
mock.ANY, marker=mock.ANY,
mock.ANY, sort_dir=mock.ANY,
mock.ANY, filters=mock.ANY,
mock.ANY, tenant_safe=mock.ANY,
mock.ANY, show_deleted=mock.ANY,
mock.ANY, show_nested=mock.ANY,
True, show_hidden=True,
mock.ANY, tags=mock.ANY,
mock.ANY, tags_any=mock.ANY,
mock.ANY, not_tags=mock.ANY,
mock.ANY, not_tags_any=mock.ANY)
)
@mock.patch.object(stack_object.Stack, 'get_all') @mock.patch.object(stack_object.Stack, 'get_all')
def test_stack_list_tags(self, mock_stack_get_all): def test_stack_list_tags(self, mock_stack_get_all):
self.eng.list_stacks(self.ctx, tags=['foo', 'bar']) self.eng.list_stacks(self.ctx, tags=['foo', 'bar'])
mock_stack_get_all.assert_called_once_with(mock.ANY, mock_stack_get_all.assert_called_once_with(self.ctx,
mock.ANY, limit=mock.ANY,
mock.ANY, sort_keys=mock.ANY,
mock.ANY, marker=mock.ANY,
mock.ANY, sort_dir=mock.ANY,
mock.ANY, filters=mock.ANY,
mock.ANY, tenant_safe=mock.ANY,
mock.ANY, show_deleted=mock.ANY,
mock.ANY, show_nested=mock.ANY,
mock.ANY, show_hidden=mock.ANY,
['foo', 'bar'], tags=['foo', 'bar'],
mock.ANY, tags_any=mock.ANY,
mock.ANY, not_tags=mock.ANY,
mock.ANY, not_tags_any=mock.ANY)
)
@mock.patch.object(stack_object.Stack, 'get_all') @mock.patch.object(stack_object.Stack, 'get_all')
def test_stack_list_tags_any(self, mock_stack_get_all): def test_stack_list_tags_any(self, mock_stack_get_all):
self.eng.list_stacks(self.ctx, tags_any=['foo', 'bar']) self.eng.list_stacks(self.ctx, tags_any=['foo', 'bar'])
mock_stack_get_all.assert_called_once_with(mock.ANY, mock_stack_get_all.assert_called_once_with(self.ctx,
mock.ANY, limit=mock.ANY,
mock.ANY, sort_keys=mock.ANY,
mock.ANY, marker=mock.ANY,
mock.ANY, sort_dir=mock.ANY,
mock.ANY, filters=mock.ANY,
mock.ANY, tenant_safe=mock.ANY,
mock.ANY, show_deleted=mock.ANY,
mock.ANY, show_nested=mock.ANY,
mock.ANY, show_hidden=mock.ANY,
mock.ANY, tags=mock.ANY,
['foo', 'bar'], tags_any=['foo', 'bar'],
mock.ANY, not_tags=mock.ANY,
mock.ANY, not_tags_any=mock.ANY)
)
@mock.patch.object(stack_object.Stack, 'get_all') @mock.patch.object(stack_object.Stack, 'get_all')
def test_stack_list_not_tags(self, mock_stack_get_all): def test_stack_list_not_tags(self, mock_stack_get_all):
self.eng.list_stacks(self.ctx, not_tags=['foo', 'bar']) self.eng.list_stacks(self.ctx, not_tags=['foo', 'bar'])
mock_stack_get_all.assert_called_once_with(mock.ANY, mock_stack_get_all.assert_called_once_with(self.ctx,
mock.ANY, limit=mock.ANY,
mock.ANY, sort_keys=mock.ANY,
mock.ANY, marker=mock.ANY,
mock.ANY, sort_dir=mock.ANY,
mock.ANY, filters=mock.ANY,
mock.ANY, tenant_safe=mock.ANY,
mock.ANY, show_deleted=mock.ANY,
mock.ANY, show_nested=mock.ANY,
mock.ANY, show_hidden=mock.ANY,
mock.ANY, tags=mock.ANY,
mock.ANY, tags_any=mock.ANY,
['foo', 'bar'], not_tags=['foo', 'bar'],
mock.ANY, not_tags_any=mock.ANY)
)
@mock.patch.object(stack_object.Stack, 'get_all') @mock.patch.object(stack_object.Stack, 'get_all')
def test_stack_list_not_tags_any(self, mock_stack_get_all): def test_stack_list_not_tags_any(self, mock_stack_get_all):
self.eng.list_stacks(self.ctx, not_tags_any=['foo', 'bar']) self.eng.list_stacks(self.ctx, not_tags_any=['foo', 'bar'])
mock_stack_get_all.assert_called_once_with(mock.ANY, mock_stack_get_all.assert_called_once_with(self.ctx,
mock.ANY, limit=mock.ANY,
mock.ANY, sort_keys=mock.ANY,
mock.ANY, marker=mock.ANY,
mock.ANY, sort_dir=mock.ANY,
mock.ANY, filters=mock.ANY,
mock.ANY, tenant_safe=mock.ANY,
mock.ANY, show_deleted=mock.ANY,
mock.ANY, show_nested=mock.ANY,
mock.ANY, show_hidden=mock.ANY,
mock.ANY, tags=mock.ANY,
mock.ANY, tags_any=mock.ANY,
mock.ANY, not_tags=mock.ANY,
['foo', 'bar'], not_tags_any=['foo', 'bar'])
)
@mock.patch.object(stack_object.Stack, 'count_all') @mock.patch.object(stack_object.Stack, 'count_all')
def test_count_stacks_passes_filter_info(self, mock_stack_count_all): def test_count_stacks_passes_filter_info(self, mock_stack_count_all):