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:
parent
56b95a00d8
commit
c2208f1fc6
@ -558,19 +558,19 @@ class EngineService(service.Service):
|
||||
|
||||
stacks = stack_object.Stack.get_all(
|
||||
cnxt,
|
||||
limit,
|
||||
sort_keys,
|
||||
marker,
|
||||
sort_dir,
|
||||
filters,
|
||||
tenant_safe,
|
||||
show_deleted,
|
||||
show_nested,
|
||||
show_hidden,
|
||||
tags,
|
||||
tags_any,
|
||||
not_tags,
|
||||
not_tags_any) or []
|
||||
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)
|
||||
return [api.format_stack_db_object(stack) for stack in stacks]
|
||||
|
||||
@context.request_context
|
||||
@ -2184,7 +2184,7 @@ class EngineService(service.Service):
|
||||
stacks = stack_object.Stack.get_all(cnxt,
|
||||
filters=filters,
|
||||
tenant_safe=False,
|
||||
show_nested=True) or []
|
||||
show_nested=True)
|
||||
for s in stacks:
|
||||
stack_id = s.id
|
||||
lock = stack_lock.StackLock(cnxt, stack_id, self.engine_id)
|
||||
|
@ -482,19 +482,19 @@ class Stack(collections.Mapping):
|
||||
tags_any=None, not_tags=None, not_tags_any=None):
|
||||
stacks = stack_object.Stack.get_all(
|
||||
context,
|
||||
limit,
|
||||
sort_keys,
|
||||
marker,
|
||||
sort_dir,
|
||||
filters,
|
||||
tenant_safe,
|
||||
show_deleted,
|
||||
show_nested,
|
||||
show_hidden,
|
||||
tags,
|
||||
tags_any,
|
||||
not_tags,
|
||||
not_tags_any) or []
|
||||
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 stack in stacks:
|
||||
try:
|
||||
yield cls._from_db(context, stack, resolve_data=resolve_data)
|
||||
|
@ -109,8 +109,26 @@ class Stack(
|
||||
return stack
|
||||
|
||||
@classmethod
|
||||
def get_all(cls, context, *args, **kwargs):
|
||||
db_stacks = db_api.stack_get_all(context, *args, **kwargs)
|
||||
def get_all(cls, context, limit=None, sort_keys=None, marker=None,
|
||||
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:
|
||||
try:
|
||||
yield cls._from_db_object(context, cls(context), db_stack)
|
||||
|
@ -487,232 +487,220 @@ class StackServiceTest(common.HeatTestCase):
|
||||
self.eng.list_stacks(self.ctx, limit=limit, marker=marker,
|
||||
sort_keys=sort_keys, sort_dir=sort_dir)
|
||||
mock_stack_get_all.assert_called_once_with(self.ctx,
|
||||
limit,
|
||||
sort_keys,
|
||||
marker,
|
||||
sort_dir,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
)
|
||||
limit=limit,
|
||||
sort_keys=sort_keys,
|
||||
marker=marker,
|
||||
sort_dir=sort_dir,
|
||||
filters=mock.ANY,
|
||||
tenant_safe=mock.ANY,
|
||||
show_deleted=mock.ANY,
|
||||
show_nested=mock.ANY,
|
||||
show_hidden=mock.ANY,
|
||||
tags=mock.ANY,
|
||||
tags_any=mock.ANY,
|
||||
not_tags=mock.ANY,
|
||||
not_tags_any=mock.ANY)
|
||||
|
||||
@mock.patch.object(stack_object.Stack, 'get_all')
|
||||
def test_stack_list_passes_filtering_info(self, mock_stack_get_all):
|
||||
filters = {'foo': 'bar'}
|
||||
self.eng.list_stacks(self.ctx, filters=filters)
|
||||
mock_stack_get_all.assert_called_once_with(mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
filters,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
)
|
||||
mock_stack_get_all.assert_called_once_with(self.ctx,
|
||||
limit=mock.ANY,
|
||||
sort_keys=mock.ANY,
|
||||
marker=mock.ANY,
|
||||
sort_dir=mock.ANY,
|
||||
filters=filters,
|
||||
tenant_safe=mock.ANY,
|
||||
show_deleted=mock.ANY,
|
||||
show_nested=mock.ANY,
|
||||
show_hidden=mock.ANY,
|
||||
tags=mock.ANY,
|
||||
tags_any=mock.ANY,
|
||||
not_tags=mock.ANY,
|
||||
not_tags_any=mock.ANY)
|
||||
|
||||
@mock.patch.object(stack_object.Stack, 'get_all')
|
||||
def test_stack_list_passes_filter_translated(self, mock_stack_get_all):
|
||||
filters = {'stack_name': 'bar'}
|
||||
self.eng.list_stacks(self.ctx, filters=filters)
|
||||
translated = {'name': 'bar'}
|
||||
mock_stack_get_all.assert_called_once_with(mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
translated,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
)
|
||||
mock_stack_get_all.assert_called_once_with(self.ctx,
|
||||
limit=mock.ANY,
|
||||
sort_keys=mock.ANY,
|
||||
marker=mock.ANY,
|
||||
sort_dir=mock.ANY,
|
||||
filters=translated,
|
||||
tenant_safe=mock.ANY,
|
||||
show_deleted=mock.ANY,
|
||||
show_nested=mock.ANY,
|
||||
show_hidden=mock.ANY,
|
||||
tags=mock.ANY,
|
||||
tags_any=mock.ANY,
|
||||
not_tags=mock.ANY,
|
||||
not_tags_any=mock.ANY)
|
||||
|
||||
@mock.patch.object(stack_object.Stack, 'get_all')
|
||||
def test_stack_list_tenant_safe_defaults_to_true(self, mock_stack_get_all):
|
||||
self.eng.list_stacks(self.ctx)
|
||||
mock_stack_get_all.assert_called_once_with(mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
True,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
)
|
||||
mock_stack_get_all.assert_called_once_with(self.ctx,
|
||||
limit=mock.ANY,
|
||||
sort_keys=mock.ANY,
|
||||
marker=mock.ANY,
|
||||
sort_dir=mock.ANY,
|
||||
filters=mock.ANY,
|
||||
tenant_safe=True,
|
||||
show_deleted=mock.ANY,
|
||||
show_nested=mock.ANY,
|
||||
show_hidden=mock.ANY,
|
||||
tags=mock.ANY,
|
||||
tags_any=mock.ANY,
|
||||
not_tags=mock.ANY,
|
||||
not_tags_any=mock.ANY)
|
||||
|
||||
@mock.patch.object(stack_object.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)
|
||||
mock_stack_get_all.assert_called_once_with(mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
False,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
)
|
||||
mock_stack_get_all.assert_called_once_with(self.ctx,
|
||||
limit=mock.ANY,
|
||||
sort_keys=mock.ANY,
|
||||
marker=mock.ANY,
|
||||
sort_dir=mock.ANY,
|
||||
filters=mock.ANY,
|
||||
tenant_safe=False,
|
||||
show_deleted=mock.ANY,
|
||||
show_nested=mock.ANY,
|
||||
show_hidden=mock.ANY,
|
||||
tags=mock.ANY,
|
||||
tags_any=mock.ANY,
|
||||
not_tags=mock.ANY,
|
||||
not_tags_any=mock.ANY)
|
||||
|
||||
@mock.patch.object(stack_object.Stack, 'get_all')
|
||||
def test_stack_list_show_nested(self, mock_stack_get_all):
|
||||
self.eng.list_stacks(self.ctx, show_nested=True)
|
||||
mock_stack_get_all.assert_called_once_with(mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
True,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
)
|
||||
mock_stack_get_all.assert_called_once_with(self.ctx,
|
||||
limit=mock.ANY,
|
||||
sort_keys=mock.ANY,
|
||||
marker=mock.ANY,
|
||||
sort_dir=mock.ANY,
|
||||
filters=mock.ANY,
|
||||
tenant_safe=mock.ANY,
|
||||
show_deleted=mock.ANY,
|
||||
show_nested=True,
|
||||
show_hidden=mock.ANY,
|
||||
tags=mock.ANY,
|
||||
tags_any=mock.ANY,
|
||||
not_tags=mock.ANY,
|
||||
not_tags_any=mock.ANY)
|
||||
|
||||
@mock.patch.object(stack_object.Stack, 'get_all')
|
||||
def test_stack_list_show_deleted(self, mock_stack_get_all):
|
||||
self.eng.list_stacks(self.ctx, show_deleted=True)
|
||||
mock_stack_get_all.assert_called_once_with(mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
True,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
)
|
||||
mock_stack_get_all.assert_called_once_with(self.ctx,
|
||||
limit=mock.ANY,
|
||||
sort_keys=mock.ANY,
|
||||
marker=mock.ANY,
|
||||
sort_dir=mock.ANY,
|
||||
filters=mock.ANY,
|
||||
tenant_safe=mock.ANY,
|
||||
show_deleted=True,
|
||||
show_nested=mock.ANY,
|
||||
show_hidden=mock.ANY,
|
||||
tags=mock.ANY,
|
||||
tags_any=mock.ANY,
|
||||
not_tags=mock.ANY,
|
||||
not_tags_any=mock.ANY)
|
||||
|
||||
@mock.patch.object(stack_object.Stack, 'get_all')
|
||||
def test_stack_list_show_hidden(self, mock_stack_get_all):
|
||||
self.eng.list_stacks(self.ctx, show_hidden=True)
|
||||
mock_stack_get_all.assert_called_once_with(mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
True,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
)
|
||||
mock_stack_get_all.assert_called_once_with(self.ctx,
|
||||
limit=mock.ANY,
|
||||
sort_keys=mock.ANY,
|
||||
marker=mock.ANY,
|
||||
sort_dir=mock.ANY,
|
||||
filters=mock.ANY,
|
||||
tenant_safe=mock.ANY,
|
||||
show_deleted=mock.ANY,
|
||||
show_nested=mock.ANY,
|
||||
show_hidden=True,
|
||||
tags=mock.ANY,
|
||||
tags_any=mock.ANY,
|
||||
not_tags=mock.ANY,
|
||||
not_tags_any=mock.ANY)
|
||||
|
||||
@mock.patch.object(stack_object.Stack, 'get_all')
|
||||
def test_stack_list_tags(self, mock_stack_get_all):
|
||||
self.eng.list_stacks(self.ctx, tags=['foo', 'bar'])
|
||||
mock_stack_get_all.assert_called_once_with(mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
['foo', 'bar'],
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
)
|
||||
mock_stack_get_all.assert_called_once_with(self.ctx,
|
||||
limit=mock.ANY,
|
||||
sort_keys=mock.ANY,
|
||||
marker=mock.ANY,
|
||||
sort_dir=mock.ANY,
|
||||
filters=mock.ANY,
|
||||
tenant_safe=mock.ANY,
|
||||
show_deleted=mock.ANY,
|
||||
show_nested=mock.ANY,
|
||||
show_hidden=mock.ANY,
|
||||
tags=['foo', 'bar'],
|
||||
tags_any=mock.ANY,
|
||||
not_tags=mock.ANY,
|
||||
not_tags_any=mock.ANY)
|
||||
|
||||
@mock.patch.object(stack_object.Stack, 'get_all')
|
||||
def test_stack_list_tags_any(self, mock_stack_get_all):
|
||||
self.eng.list_stacks(self.ctx, tags_any=['foo', 'bar'])
|
||||
mock_stack_get_all.assert_called_once_with(mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
['foo', 'bar'],
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
)
|
||||
mock_stack_get_all.assert_called_once_with(self.ctx,
|
||||
limit=mock.ANY,
|
||||
sort_keys=mock.ANY,
|
||||
marker=mock.ANY,
|
||||
sort_dir=mock.ANY,
|
||||
filters=mock.ANY,
|
||||
tenant_safe=mock.ANY,
|
||||
show_deleted=mock.ANY,
|
||||
show_nested=mock.ANY,
|
||||
show_hidden=mock.ANY,
|
||||
tags=mock.ANY,
|
||||
tags_any=['foo', 'bar'],
|
||||
not_tags=mock.ANY,
|
||||
not_tags_any=mock.ANY)
|
||||
|
||||
@mock.patch.object(stack_object.Stack, 'get_all')
|
||||
def test_stack_list_not_tags(self, mock_stack_get_all):
|
||||
self.eng.list_stacks(self.ctx, not_tags=['foo', 'bar'])
|
||||
mock_stack_get_all.assert_called_once_with(mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
['foo', 'bar'],
|
||||
mock.ANY,
|
||||
)
|
||||
mock_stack_get_all.assert_called_once_with(self.ctx,
|
||||
limit=mock.ANY,
|
||||
sort_keys=mock.ANY,
|
||||
marker=mock.ANY,
|
||||
sort_dir=mock.ANY,
|
||||
filters=mock.ANY,
|
||||
tenant_safe=mock.ANY,
|
||||
show_deleted=mock.ANY,
|
||||
show_nested=mock.ANY,
|
||||
show_hidden=mock.ANY,
|
||||
tags=mock.ANY,
|
||||
tags_any=mock.ANY,
|
||||
not_tags=['foo', 'bar'],
|
||||
not_tags_any=mock.ANY)
|
||||
|
||||
@mock.patch.object(stack_object.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'])
|
||||
mock_stack_get_all.assert_called_once_with(mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
['foo', 'bar'],
|
||||
)
|
||||
mock_stack_get_all.assert_called_once_with(self.ctx,
|
||||
limit=mock.ANY,
|
||||
sort_keys=mock.ANY,
|
||||
marker=mock.ANY,
|
||||
sort_dir=mock.ANY,
|
||||
filters=mock.ANY,
|
||||
tenant_safe=mock.ANY,
|
||||
show_deleted=mock.ANY,
|
||||
show_nested=mock.ANY,
|
||||
show_hidden=mock.ANY,
|
||||
tags=mock.ANY,
|
||||
tags_any=mock.ANY,
|
||||
not_tags=mock.ANY,
|
||||
not_tags_any=['foo', 'bar'])
|
||||
|
||||
@mock.patch.object(stack_object.Stack, 'count_all')
|
||||
def test_count_stacks_passes_filter_info(self, mock_stack_count_all):
|
||||
|
Loading…
Reference in New Issue
Block a user