From a26827af4e4621e1e9803a5c2e22c8ead888163b Mon Sep 17 00:00:00 2001 From: hiltonlima <116589806+hiltonlima@users.noreply.github.com> Date: Thu, 26 Sep 2024 12:10:02 -0300 Subject: [PATCH] Merge v2.11 beta3.1+fall2024 (#149) * [FIX] Handle Python test execution runtime errors (#145) * Handle Python test execution runtime errors * Update test_collections/matter/sdk_tests/support/python_testing/models/test_case.py Co-authored-by: hiltonlima <116589806+hiltonlima@users.noreply.github.com> --------- Co-authored-by: hiltonlima <116589806+hiltonlima@users.noreply.github.com> * [FIX] Force container removal at destroy (#143) * Force container removal * Remove __wait_for_server_exit * Surround __wait_for_server_exit with try except * Fix mypy * Fix data_model mapped volume * Update test_collections/matter/sdk_tests/support/sdk_container.py Co-authored-by: Romulo Quidute Filho <116586593+rquidute@users.noreply.github.com> --------- Co-authored-by: Romulo Quidute Filho <116586593+rquidute@users.noreply.github.com> Co-authored-by: Romulo Quidute Filho --- .version_information | 2 +- app/container_manager/container_manager.py | 2 +- .../matter/sdk_tests/support/chip/chip_server.py | 16 ++++++++++++---- .../models/rpc_client/test_harness_client.py | 16 +++++++++++----- .../support/python_testing/models/test_case.py | 6 +++++- .../matter/sdk_tests/support/sdk_container.py | 8 ++++++++ 6 files changed, 38 insertions(+), 12 deletions(-) diff --git a/.version_information b/.version_information index dd8de46b..6eeb9501 100644 --- a/.version_information +++ b/.version_information @@ -1 +1 @@ -v2.11-beta3+fall2024 +v2.11-beta3.1+fall2024 diff --git a/app/container_manager/container_manager.py b/app/container_manager/container_manager.py index 5b26a72a..cc3be8b7 100644 --- a/app/container_manager/container_manager.py +++ b/app/container_manager/container_manager.py @@ -45,7 +45,7 @@ async def create_container( def destroy(self, container: Container) -> None: if self.is_running(container): container.kill() - container.remove() + container.remove(force=True) def get_container(self, id_or_name: str) -> Optional[Container]: try: diff --git a/test_collections/matter/sdk_tests/support/chip/chip_server.py b/test_collections/matter/sdk_tests/support/chip/chip_server.py index bd27147b..7c8082a8 100644 --- a/test_collections/matter/sdk_tests/support/chip/chip_server.py +++ b/test_collections/matter/sdk_tests/support/chip/chip_server.py @@ -175,11 +175,19 @@ async def stop(self) -> None: if not self.__server_started: return - self.sdk_container.send_command( - f'-SIGTERM -f "{self.__server_full_command}"', prefix="pkill" - ) + try: + self.sdk_container.send_command( + f'-SIGTERM -f "{self.__server_full_command}"', prefix="pkill" + ) + self.__wait_for_server_exit() + except Exception as e: + # Issue: https://github.com/project-chip/certification-tool/issues/414 + self.logger.info( + "Could not get exit code after pkill command " + f"{self.__server_full_command}." + ) + self.logger.debug(str(e)) - self.__wait_for_server_exit() self.__server_started = False def trace_file_params(self, topic: str) -> str: diff --git a/test_collections/matter/sdk_tests/support/python_testing/models/rpc_client/test_harness_client.py b/test_collections/matter/sdk_tests/support/python_testing/models/rpc_client/test_harness_client.py index fa37ba22..98761476 100644 --- a/test_collections/matter/sdk_tests/support/python_testing/models/rpc_client/test_harness_client.py +++ b/test_collections/matter/sdk_tests/support/python_testing/models/rpc_client/test_harness_client.py @@ -53,16 +53,22 @@ def main() -> None: def run_test(script_path: str, class_name: str, config: MatterTestConfig) -> None: - # For a script_path like 'custom/TC_XYZ' the module is 'custom.TC_XYZ' - module = importlib.import_module(script_path.replace("/", ".")) - TestClassReference = getattr(module, class_name) - BaseManager.register(TestRunnerHooks.__name__) manager = BaseManager(address=("0.0.0.0", 50000), authkey=b"abc") manager.connect() test_runner_hooks = manager.TestRunnerHooks() # shared object proxy # type: ignore - run_tests(TestClassReference, config, test_runner_hooks) + try: + # For a script_path like 'custom/TC_XYZ' the module is 'custom.TC_XYZ' + module = importlib.import_module(script_path.replace("/", ".")) + TestClassReference = getattr(module, class_name) + + run_tests(TestClassReference, config, test_runner_hooks) + except Exception as e: + test_runner_hooks.step_failure( + logger=None, logs=str(e), duration=0, request=None, received=None + ) + test_runner_hooks.stop(duration=0) def commission(config: MatterTestConfig) -> None: diff --git a/test_collections/matter/sdk_tests/support/python_testing/models/test_case.py b/test_collections/matter/sdk_tests/support/python_testing/models/test_case.py index c39ff974..0863c074 100644 --- a/test_collections/matter/sdk_tests/support/python_testing/models/test_case.py +++ b/test_collections/matter/sdk_tests/support/python_testing/models/test_case.py @@ -126,7 +126,11 @@ def step_success(self, logger: Any, logs: str, duration: int, request: Any) -> N def step_failure( self, logger: Any, logs: str, duration: int, request: Any, received: Any ) -> None: - self.mark_step_failure("Python test step failure") + failure_msg = "Python test step failure" + if logs: + failure_msg += f": {logs}" + + self.mark_step_failure(failure_msg) # Python tests with only 2 steps are the ones that don't follow the template. # In the case of a test file with multiple test cases, more than one of these diff --git a/test_collections/matter/sdk_tests/support/sdk_container.py b/test_collections/matter/sdk_tests/support/sdk_container.py index 59d50ae5..b0f6c8e2 100644 --- a/test_collections/matter/sdk_tests/support/sdk_container.py +++ b/test_collections/matter/sdk_tests/support/sdk_container.py @@ -52,6 +52,10 @@ ) DOCKER_PYTHON_TESTING_PATH = "/root/python_testing" +MAPPED_DATA_MODEL_VOLUME = "mapped_data_model_volume" +DOCKER_DATA_MODEL_PATH = DOCKER_PYTHON_TESTING_PATH + "/data_model" + + # RPC Client Running on SDK Container LOCAL_RPC_PYTHON_TESTING_PATH = Path( LOCAL_TEST_COLLECTIONS_PATH + "/sdk_tests/support/python_testing/models/rpc_client/" @@ -108,6 +112,10 @@ class SDKContainer(metaclass=Singleton): "bind": DOCKER_PYTHON_TESTING_PATH, "mode": "rw", }, + MAPPED_DATA_MODEL_VOLUME: { + "bind": DOCKER_DATA_MODEL_PATH, + "mode": "rw", + }, LOCAL_RPC_PYTHON_TESTING_PATH: { "bind": DOCKER_RPC_PYTHON_TESTING_PATH, "mode": "rw",