Skip to content

Commit

Permalink
Allow getting the state chunk by __id__ on MultiStateResult
Browse files Browse the repository at this point in the history
Fixes saltstack#140

Signed-off-by: Pedro Algarvio <palgarvio@vmware.com>
  • Loading branch information
s0undt3ch committed Nov 4, 2022
1 parent 55add98 commit cdb791c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions changelog/140.improvement.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Allow getting the state chunk by `__id__` on MultiStateResult
13 changes: 10 additions & 3 deletions src/saltfactories/utils/functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,12 +364,19 @@ def run_num(self):
"""
return self.full_return["__run_num__"] or 0

@property
def id(self):
"""
The ``__id__`` key on the full state return dictionary.
"""
return self.full_return.get("__id__")

@property
def name(self):
"""
The ``name`` key on the full state return dictionary.
"""
return self.full_return["name"]
return self.full_return.get("name")

@property
def result(self):
Expand Down Expand Up @@ -520,7 +527,7 @@ def __contains__(self, key):
Check the presence of ``key`` in the state return.
"""
for state_result in self:
if state_result.state_id == key:
if key in (state_result.id, state_result.state_id, state_result.name):
return True
return False

Expand All @@ -532,7 +539,7 @@ def __getitem__(self, state_id_or_index):
# We're trying to get the state run by index
return self._structured[state_id_or_index]
for state_result in self:
if state_result.state_id == state_id_or_index:
if state_id_or_index in (state_result.id, state_result.state_id, state_result.name):
return state_result
raise KeyError("No state by the ID of '{}' was found".format(state_id_or_index))

Expand Down

0 comments on commit cdb791c

Please sign in to comment.