From 83b263ee96d78a1d05a65ae0d57bdb5415328063 Mon Sep 17 00:00:00 2001 From: Michael Engel Date: Fri, 19 Apr 2024 08:18:21 +0200 Subject: [PATCH 1/4] switch order of restoring created and changed files Relates to: https://github.com/eclipse-bluechi/bluechi/issues/879 When creating files, we first keep track of them in the list for newly created ones. If a file is already in that list and another file with the same path (dir+name) is created we keep create a backup and track it. For clean-up we need to reverse that order - first restore tracked backup files and then remove created files. This ensures that there are no dangling files. Signed-off-by: Michael Engel --- tests/bluechi_test/test.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/bluechi_test/test.py b/tests/bluechi_test/test.py index 027e8e84a0..2029066400 100644 --- a/tests/bluechi_test/test.py +++ b/tests/bluechi_test/test.py @@ -443,15 +443,15 @@ def _cleanup(self, machine: BluechiMachine, other_tracked_service: List[str] = [ machine.systemctl.stop_unit(service, check_result=False) machine.systemctl.reset_failed_for_unit(service, check_result=False) - LOGGER.info("Removing created files...") - cmd_rm_created_files = "rm " + " ".join(machine.created_files) - machine.client.exec_run(cmd_rm_created_files) - LOGGER.info("Restoring changed files...") for changed_file in machine.changed_files: backup_file = changed_file + BluechiMachine.backup_file_suffix machine.client.exec_run(f"mv {backup_file} {changed_file}") + LOGGER.info("Removing created files...") + cmd_rm_created_files = "rm " + " ".join(machine.created_files) + machine.client.exec_run(cmd_rm_created_files) + # ensure changed systemd services are reloaded machine.systemctl.daemon_reload() From d1ac071f73ad33a5855f75e38968f9dfcf02d452 Mon Sep 17 00:00:00 2001 From: Michael Engel Date: Fri, 19 Apr 2024 09:16:47 +0200 Subject: [PATCH 2/4] actively check if bluechi_machine_lib exists Relates to: https://github.com/eclipse-bluechi/bluechi/issues/879 In order to avoid failing mkdir calls on subsequent tests for the bluechi_machine_lib, an active check is being made. If it doesn't exist yet, we create the directory and the library files. These files are not tracked and thus not deleted after a test. This way, we only create the lib once. Signed-off-by: Michael Engel --- tests/bluechi_test/machine.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/tests/bluechi_test/machine.py b/tests/bluechi_test/machine.py index 53bc5f9836..a45f62d004 100644 --- a/tests/bluechi_test/machine.py +++ b/tests/bluechi_test/machine.py @@ -171,16 +171,20 @@ def copy_machine_lib(self): # This message is relevant for `finish` phase, where code coverage report is being created LOGGER.info("bluechilib directory not found, proceeding") return - ret, _ = self.exec_run("mkdir /tmp/bluechi_machine_lib") - if ret == 0: - # If the directory was successfully created, then fill it with files - # If not - it must already exist + + machine_lib_dir = "/tmp/bluechi_machine_lib" + _, output = self.client.exec_run(f"[ -d {machine_lib_dir} ] && echo 'exists'") + if output != "exists": + self.exec_run(f"mkdir {machine_lib_dir}") for filename in os.listdir(source_dir): source_path = os.path.join(source_dir, filename) if os.path.isfile(source_path) and source_path.endswith(".py"): content = read_file(source_path) - target_dir = os.path.join("/", "tmp", "bluechi_machine_lib") - self.create_file(target_dir, filename, content) + target_dir = os.path.join("/", "tmp", machine_lib_dir) + + # Use client directly to bypass the tracking mechanism + # We don't want to clean up the bluechi_machine_lib files once created + self.client.create_file(target_dir, filename, content) def wait_for_bluechi_agent(self): should_wait = True From 1ef3b701ff76e876db606b56d33ef28c05462d20 Mon Sep 17 00:00:00 2001 From: Michael Engel Date: Fri, 19 Apr 2024 09:19:30 +0200 Subject: [PATCH 3/4] concatenate stderr and stdout in sshclient Relates to: https://github.com/eclipse-bluechi/bluechi/issues/879 The client for the podman container seems to concatenate stderr and stdout in its output parameter. In the SSH client stderr and stdout are different return variables. In order to not break the `exec_run` API of the Client class and still get a uniform behavior of both clients, lets concat stderr and stdout in the SSH client. Signed-off-by: Michael Engel --- tests/bluechi_test/client.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/bluechi_test/client.py b/tests/bluechi_test/client.py index 689b86e228..3f14916884 100644 --- a/tests/bluechi_test/client.py +++ b/tests/bluechi_test/client.py @@ -179,7 +179,10 @@ def exec_run( LOGGER.debug( f"Executed command '{command}' with result '{result}' and output '{output}' and error '{err}'" ) - return result, output + + # concatenate stderr and stdout so exec_run of SSHClient + # outputs the same content as ContainerClient + return result, err + output finally: if stdin is not None: stdin.close() From bc59f01ab26f240ec5356364f2ed4e3f77b656a7 Mon Sep 17 00:00:00 2001 From: Michael Engel Date: Fri, 19 Apr 2024 10:46:59 +0200 Subject: [PATCH 4/4] Use different file name for ctrl config Relates to: https://github.com/eclipse-bluechi/bluechi/issues/879 Signed-off-by: Michael Engel --- .../tests/tier0/bluechi-invalid-port/test_agent_invalid_port.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/tests/tier0/bluechi-invalid-port/test_agent_invalid_port.py b/tests/tests/tier0/bluechi-invalid-port/test_agent_invalid_port.py index 4a2c3c79eb..88ee12d535 100644 --- a/tests/tests/tier0/bluechi-invalid-port/test_agent_invalid_port.py +++ b/tests/tests/tier0/bluechi-invalid-port/test_agent_invalid_port.py @@ -15,6 +15,7 @@ def exec(ctrl: BluechiControllerMachine, _: Dict[str, BluechiAgentMachine]): assert ctrl.wait_for_unit_state_to_be("bluechi-controller", "active") original_cfg = ctrl.config.deep_copy() + original_cfg.file_name = "zzz-ctrl.conf" # port contains an 'O' instead of a '0' new_cfg = original_cfg.deep_copy()