Skip to content

Commit 5c14cac

Browse files
committed
Store scenario results.
1 parent 63788df commit 5c14cac

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

src/molecule/provisioner/ansible_playbook.py

+11
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
from molecule import util
3030
from molecule.api import MoleculeRuntimeWarning
31+
from molecule.types import ScenarioResult
3132

3233

3334
if TYPE_CHECKING:
@@ -120,6 +121,9 @@ def execute(self, action_args: list[str] | None = None) -> str: # noqa: ARG002
120121

121122
if not self._playbook:
122123
LOG.warning("Skipping, %s action has no playbook.", self._config.action)
124+
self._config.scenario.results.append(
125+
ScenarioResult(subcommand=self._config.action, state="SKIPPED"),
126+
)
123127
return ""
124128

125129
with warnings.catch_warnings(record=True) as warns:
@@ -134,6 +138,10 @@ def execute(self, action_args: list[str] | None = None) -> str: # noqa: ARG002
134138
)
135139

136140
if result.returncode != 0:
141+
self._config.scenario.results.append(
142+
ScenarioResult(subcommand=self._config.action, state="FAILED"),
143+
)
144+
137145
from rich.markup import escape
138146

139147
util.sysexit_with_message(
@@ -142,6 +150,9 @@ def execute(self, action_args: list[str] | None = None) -> str: # noqa: ARG002
142150
warns=warns,
143151
)
144152

153+
self._config.scenario.results.append(
154+
ScenarioResult(subcommand=self._config.action, state="PASSED"),
155+
)
145156
return result.stdout
146157

147158
def add_cli_arg(self, name: str, value: str | bool) -> None:

src/molecule/scenario.py

+2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838

3939
if TYPE_CHECKING:
4040
from molecule.config import Config
41+
from molecule.types import ScenarioResult
4142

4243

4344
LOG = logging.getLogger(__name__)
@@ -54,6 +55,7 @@ def __init__(self, config: Config) -> None:
5455
"""
5556
self._lock = None
5657
self.config = config
58+
self.results: list[ScenarioResult] = []
5759
self._setup()
5860

5961
def __repr__(self) -> str:

src/molecule/types.py

+12
Original file line numberDiff line numberDiff line change
@@ -277,3 +277,15 @@ class CommandArgs(TypedDict, total=False):
277277
platform_name: str
278278
scenario_name: str
279279
subcommand: str
280+
281+
282+
class ScenarioResult(TypedDict):
283+
"""Dictionary containing the result of a Scenario run.
284+
285+
Attributes:
286+
subcommand: The action that ran.
287+
state: The outcome of the action ("PASSED", "FAILED", or "SKIPPED).
288+
"""
289+
290+
subcommand: str | None
291+
state: Literal["PASSED", "FAILED", "SKIPPED"]

0 commit comments

Comments
 (0)