Fix: CloudFormation support status filter in list stacks (#3115)
* Fix: CloudFormation support status filter in list stacks * Added test for non decorator Co-authored-by: usmankb <usman@krazybee.com>
This commit is contained in:
parent
069c159492
commit
c5de56ce70
4 changed files with 41 additions and 3 deletions
|
|
@ -449,6 +449,16 @@ class FakeEvent(BaseModel):
|
|||
self.event_id = uuid.uuid4()
|
||||
|
||||
|
||||
def filter_stacks(all_stacks, status_filter):
|
||||
filtered_stacks = []
|
||||
if not status_filter:
|
||||
return all_stacks
|
||||
for stack in all_stacks:
|
||||
if stack.status in status_filter:
|
||||
filtered_stacks.append(stack)
|
||||
return filtered_stacks
|
||||
|
||||
|
||||
class CloudFormationBackend(BaseBackend):
|
||||
def __init__(self):
|
||||
self.stacks = OrderedDict()
|
||||
|
|
@ -681,10 +691,11 @@ class CloudFormationBackend(BaseBackend):
|
|||
def list_change_sets(self):
|
||||
return self.change_sets.values()
|
||||
|
||||
def list_stacks(self):
|
||||
return [v for v in self.stacks.values()] + [
|
||||
def list_stacks(self, status_filter=None):
|
||||
total_stacks = [v for v in self.stacks.values()] + [
|
||||
v for v in self.deleted_stacks.values()
|
||||
]
|
||||
return filter_stacks(total_stacks, status_filter)
|
||||
|
||||
def get_stack(self, name_or_stack_id):
|
||||
all_stacks = dict(self.deleted_stacks, **self.stacks)
|
||||
|
|
|
|||
|
|
@ -233,7 +233,8 @@ class CloudFormationResponse(BaseResponse):
|
|||
return template.render(change_sets=change_sets)
|
||||
|
||||
def list_stacks(self):
|
||||
stacks = self.cloudformation_backend.list_stacks()
|
||||
status_filter = self._get_multi_param("StackStatusFilter.member")
|
||||
stacks = self.cloudformation_backend.list_stacks(status_filter)
|
||||
template = self.response_template(LIST_STACKS_RESPONSE)
|
||||
return template.render(stacks=stacks)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue