From a0af523da04bed2688e5dc90b0f81c5c0a63acd0 Mon Sep 17 00:00:00 2001 From: Nick Deligiannis Date: Thu, 12 Sep 2024 18:59:04 +0300 Subject: [PATCH] Added allow kwarg to fault_simulate() --- src/unit_tests/test_zoix.py | 6 ++++++ src/zoix.py | 21 ++++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/unit_tests/test_zoix.py b/src/unit_tests/test_zoix.py index 2a99b33..24f6cbf 100644 --- a/src/unit_tests/test_zoix.py +++ b/src/unit_tests/test_zoix.py @@ -329,6 +329,12 @@ def test_fault_simulate(self): fault_simulation = test_obj.fault_simulate("mock_fsim_instruction1", "mock_fsim_instruction2") self.assertEqual(fault_simulation, zoix.FaultSimulation.SUCCESS) + with mock.patch("zoix.ZoixInvoker.execute", return_value = ("Some fault sim text", "Stderr text but must be ignored!")) as mocked_execute: + + fault_simulation = test_obj.fault_simulate("mock_fsim_instruction1", "mock_fsim_instruction2", + allow = [re.compile(r"Stderr text but must be ignored\!")]) + self.assertEqual(fault_simulation, zoix.FaultSimulation.SUCCESS) + # FSIM Error with mock.patch("zoix.ZoixInvoker.execute", return_value = ("Some fault sim text", "Stderr has text!")) as mocked_execute: diff --git a/src/zoix.py b/src/zoix.py index 27556ff..16ad6cc 100755 --- a/src/zoix.py +++ b/src/zoix.py @@ -586,7 +586,10 @@ def fault_simulate(self, *instructions: str, **kwargs) -> FaultSimulation: **kwargs: User-defined options for fault simulation control. - timeout (float): A timeout in **seconds** for each fsim - instruction. + instruction. + - allow (list[re.Pattern]): Series of regexps to look for in + ``stderr`` and allow continuation without raising any error + messages. Returns: FaultSimulation: A status Enum which is: @@ -601,6 +604,7 @@ def fault_simulate(self, *instructions: str, **kwargs) -> FaultSimulation: fault_simulation_status = FaultSimulation.SUCCESS timeout: float = kwargs.get("timeout", None) + allow: list[re.Pattern] = kwargs.get("allow", None) for cmd in instructions: @@ -608,6 +612,21 @@ def fault_simulate(self, *instructions: str, **kwargs) -> FaultSimulation: if stderr and stderr != "TimeoutExpired": + if allow: + + continue_execution = False + + for regexp in allow: + + if regexp.search(stderr): + + continue_execution = True + break + + if continue_execution: + + continue + log.debug(f"Error during execution of {cmd}\n\ ------[STDERR STREAM]------\n\ {'-'.join(stderr.splitlines(keepends=True))}\n\