From 5fa99d931deb60c2a001e73d4dca48c36b06226d Mon Sep 17 00:00:00 2001 From: Tasos Papaioannou Date: Tue, 16 Apr 2024 12:55:38 -0400 Subject: [PATCH] Use correct broker settings path in functional tests. --- tests/functional/test_containers.py | 27 ++++++++++++----------- tests/functional/test_satlab.py | 33 ++++++++++++++--------------- 2 files changed, 29 insertions(+), 31 deletions(-) diff --git a/tests/functional/test_containers.py b/tests/functional/test_containers.py index 89d86fab..027d99e4 100644 --- a/tests/functional/test_containers.py +++ b/tests/functional/test_containers.py @@ -6,6 +6,7 @@ from broker.commands import cli from broker.providers.container import Container from broker.settings import inventory_path +from broker.settings import settings_path as SETTINGS_PATH SCENARIO_DIR = Path("tests/data/cli_scenarios/containers") @@ -70,21 +71,20 @@ def test_container_e2e(): assert c_host._cont_inst.top()["Processes"] res = c_host.execute("hostname") assert res.stdout.strip() == c_host.hostname - loc_settings_path = Path("broker_settings.yaml") remote_dir = "/tmp/fake" - c_host.session.sftp_write(loc_settings_path.name, f"{remote_dir}/") + c_host.session.sftp_write(str(SETTINGS_PATH), f"{remote_dir}/") res = c_host.execute(f"ls {remote_dir}") - assert str(loc_settings_path) in res.stdout + assert SETTINGS_PATH.name in res.stdout with NamedTemporaryFile() as tmp: - c_host.session.sftp_read(f"{remote_dir}/{loc_settings_path.name}", tmp.file.name) + c_host.session.sftp_read(f"{remote_dir}/{SETTINGS_PATH.name}", tmp.file.name) data = c_host.session.sftp_read( - f"{remote_dir}/{loc_settings_path.name}", return_data=True + f"{remote_dir}/{SETTINGS_PATH.name}", return_data=True ) assert ( - loc_settings_path.read_bytes() == Path(tmp.file.name).read_bytes() + SETTINGS_PATH.read_bytes() == Path(tmp.file.name).read_bytes() ), "Local file is different from the received one" assert ( - loc_settings_path.read_bytes() == data + SETTINGS_PATH.read_bytes() == data ), "Local file is different from the received one (return_data=True)" assert data == Path(tmp.file.name).read_bytes(), "Received files do not match" # test the tail_file context manager @@ -102,21 +102,20 @@ def test_container_e2e_mp(): assert c_host._cont_inst.top()["Processes"] res = c_host.execute("hostname") assert res.stdout.strip() == c_host.hostname - loc_settings_path = Path("broker_settings.yaml") remote_dir = "/tmp/fake" - c_host.session.sftp_write(loc_settings_path.name, f"{remote_dir}/") + c_host.session.sftp_write(str(SETTINGS_PATH), f"{remote_dir}/") res = c_host.execute(f"ls {remote_dir}") - assert str(loc_settings_path) in res.stdout + assert SETTINGS_PATH.name in res.stdout with NamedTemporaryFile() as tmp: - c_host.session.sftp_read(f"{remote_dir}/{loc_settings_path.name}", tmp.file.name) + c_host.session.sftp_read(f"{remote_dir}/{SETTINGS_PATH.name}", tmp.file.name) data = c_host.session.sftp_read( - f"{remote_dir}/{loc_settings_path.name}", return_data=True + f"{remote_dir}/{SETTINGS_PATH.name}", return_data=True ) assert ( - loc_settings_path.read_bytes() == Path(tmp.file.name).read_bytes() + SETTINGS_PATH.read_bytes() == Path(tmp.file.name).read_bytes() ), "Local file is different from the received one" assert ( - loc_settings_path.read_bytes() == data + SETTINGS_PATH.read_bytes() == data ), "Local file is different from the received one (return_data=True)" assert data == Path(tmp.file.name).read_bytes(), "Received files do not match" diff --git a/tests/functional/test_satlab.py b/tests/functional/test_satlab.py index 9652d4e8..a2997915 100644 --- a/tests/functional/test_satlab.py +++ b/tests/functional/test_satlab.py @@ -9,6 +9,7 @@ from broker.hosts import Host from broker.providers.ansible_tower import AnsibleTower from broker.settings import inventory_path +from broker.settings import settings_path as SETTINGS_PATH SCENARIO_DIR = Path("tests/data/cli_scenarios/satlab") @@ -69,21 +70,20 @@ def test_tower_host(): with Broker(workflow="deploy-rhel") as r_host: res = r_host.execute("hostname") assert res.stdout.strip() == r_host.hostname - loc_settings_path = Path("broker_settings.yaml") remote_dir = "/tmp/fake" - r_host.session.sftp_write(loc_settings_path.name, f"{remote_dir}/", ensure_dir=True) + r_host.session.sftp_write(str(SETTINGS_PATH), f"{remote_dir}/", ensure_dir=True) res = r_host.execute(f"ls {remote_dir}") - assert str(loc_settings_path) in res.stdout + assert SETTINGS_PATH.name in res.stdout with NamedTemporaryFile() as tmp: - r_host.session.sftp_read(f"{remote_dir}/{loc_settings_path.name}", tmp.file.name) + r_host.session.sftp_read(f"{remote_dir}/{SETTINGS_PATH.name}", tmp.file.name) data = r_host.session.sftp_read( - f"{remote_dir}/{loc_settings_path.name}", return_data=True + f"{remote_dir}/{SETTINGS_PATH.name}", return_data=True ) assert ( - loc_settings_path.read_bytes() == Path(tmp.file.name).read_bytes() + SETTINGS_PATH.read_bytes() == Path(tmp.file.name).read_bytes() ), "Local file is different from the received one" assert ( - loc_settings_path.read_bytes() == data + SETTINGS_PATH.read_bytes() == data ), "Local file is different from the received one (return_data=True)" assert data == Path(tmp.file.name).read_bytes(), "Received files do not match" # test the tail_file context manager @@ -100,28 +100,27 @@ def test_tower_host_mp(): for r_host in r_hosts: res = r_host.execute("hostname") assert res.stdout.strip() == r_host.hostname - loc_settings_path = Path("broker_settings.yaml") remote_dir = "/tmp/fake" - r_host.session.sftp_write(loc_settings_path.name, f"{remote_dir}/", ensure_dir=True) + r_host.session.sftp_write(str(SETTINGS_PATH), f"{remote_dir}/", ensure_dir=True) res = r_host.execute(f"ls {remote_dir}") - assert str(loc_settings_path) in res.stdout + assert SETTINGS_PATH.name in res.stdout with NamedTemporaryFile() as tmp: - r_host.session.sftp_read(f"{remote_dir}/{loc_settings_path.name}", tmp.file.name) + r_host.session.sftp_read(f"{remote_dir}/{SETTINGS_PATH.name}", tmp.file.name) data = r_host.session.sftp_read( - f"{remote_dir}/{loc_settings_path.name}", return_data=True + f"{remote_dir}/{SETTINGS_PATH.name}", return_data=True ) assert ( - loc_settings_path.read_bytes() == Path(tmp.file.name).read_bytes() + SETTINGS_PATH.read_bytes() == Path(tmp.file.name).read_bytes() ), "Local file is different from the received one" assert ( - loc_settings_path.read_bytes() == data + SETTINGS_PATH.read_bytes() == data ), "Local file is different from the received one (return_data=True)" assert data == Path(tmp.file.name).read_bytes(), "Received files do not match" # test remote copy from one host to another r_hosts[0].session.remote_copy( - source=f"{remote_dir}/{loc_settings_path.name}", + source=f"{remote_dir}/{SETTINGS_PATH.name}", dest_host=r_hosts[1], - dest_path=f"/root/{loc_settings_path.name}", + dest_path=f"/root/{SETTINGS_PATH.name}", ) res = r_hosts[1].execute(f"ls /root") - assert loc_settings_path.name in res.stdout + assert SETTINGS_PATH.name in res.stdout