From a3219baee7fec5dd1efb16ae2b232f46c2627eff Mon Sep 17 00:00:00 2001 From: Lukas Hellebrandt Date: Thu, 7 Nov 2024 00:15:01 +0100 Subject: [PATCH] Improve structure - CLI, API --- tests/foreman/api/test_templatesync.py | 28 ++++---------------------- tests/foreman/cli/test_templatesync.py | 28 ++------------------------ 2 files changed, 6 insertions(+), 50 deletions(-) diff --git a/tests/foreman/api/test_templatesync.py b/tests/foreman/api/test_templatesync.py index 2ffe39650ac..c9d86bf17c7 100644 --- a/tests/foreman/api/test_templatesync.py +++ b/tests/foreman/api/test_templatesync.py @@ -18,7 +18,6 @@ import pytest import requests -from robottelo import ssh from robottelo.config import settings from robottelo.constants import ( FOREMAN_TEMPLATE_IMPORT_API_URL, @@ -1137,19 +1136,9 @@ def test_positive_export_all_templates_to_repo( } if use_proxy: proxy_hostname = proxy.url.split('/')[2].split(':')[0] - log_path = '/var/log/squid/access.log' - old_log = ssh.command('echo /tmp/$RANDOM').stdout.strip() - ssh.command( - f'sshpass -p "{settings.server.ssh_password}" scp -o StrictHostKeyChecking=no root@{proxy_hostname}:{log_path} {old_log}' + old_log = module_target_sat.cutoff_host_setup_log( + proxy_hostname, settings.git.hostname ) - # make sure the system can't communicate with the git directly, without proxy - assert ( - module_target_sat.execute( - f'firewall-cmd --permanent --direct --add-rule ipv4 filter OUTPUT 1 -d $(dig +short A {settings.git.hostname}) -j REJECT && firewall-cmd --reload' - ).status - == 0 - ) - assert module_target_sat.execute(f'ping -c 2 {settings.git.hostname}').status != 0 data['http_proxy_policy'] = 'selected' data['http_proxy_id'] = proxy.id output = module_target_sat.api.Template().exports(data=data) @@ -1163,8 +1152,8 @@ def test_positive_export_all_templates_to_repo( res.raise_for_status() finally: if use_proxy: - module_target_sat.execute( - f'firewall-cmd --permanent --direct --remove-rule ipv4 filter OUTPUT 1 -d $(dig +short A {settings.git.hostname}) -j REJECT && firewall-cmd --reload' + module_target_sat.restore_host_check_log( + proxy_hostname, settings.git.hostname, old_log ) try: @@ -1174,15 +1163,6 @@ def test_positive_export_all_templates_to_repo( pytest.fail(f"Failed to parse output from git. Response: '{res.text}'") git_count = [row['path'].endswith('.erb') for row in tree].count(True) assert len(output['message']['templates']) == git_count - # assert that proxy has been used - if use_proxy: - new_log = ssh.command('echo /tmp/$RANDOM').stdout.strip() - ssh.command( - f'sshpass -p "{settings.server.ssh_password}" scp -o StrictHostKeyChecking=no root@{proxy_hostname}:{log_path} {new_log}' - ) - diff = ssh.command(f'diff {old_log} {new_log}').stdout - satellite_ip = ssh.command('dig A +short $(hostname)').stdout.strip() - assert satellite_ip in diff @pytest.mark.tier2 def test_positive_import_all_templates_from_repo(self, module_org, module_target_sat): diff --git a/tests/foreman/cli/test_templatesync.py b/tests/foreman/cli/test_templatesync.py index e231d3179d4..1b67bf60c81 100644 --- a/tests/foreman/cli/test_templatesync.py +++ b/tests/foreman/cli/test_templatesync.py @@ -21,7 +21,6 @@ FOREMAN_TEMPLATE_IMPORT_URL, FOREMAN_TEMPLATE_TEST_TEMPLATE, ) -from robottelo.utils import ssh from robottelo.utils.issue_handlers import is_open git = settings.git @@ -178,39 +177,16 @@ def test_positive_import_dir_filtered( if '@' not in proxy else proxy.split('@')[1].split(':')[0] ) - log_path = '/var/log/squid/access.log' - old_log = ssh.command('echo /tmp/$RANDOM').stdout.strip() - ssh.command( - f'sshpass -p "{settings.server.ssh_password}" scp -o StrictHostKeyChecking=no root@{proxy_hostname}:{log_path} {old_log}' - ) - # make sure the system can't communicate with the git directly, without proxy - assert ( - target_sat.execute( - f'firewall-cmd --permanent --direct --add-rule ipv4 filter OUTPUT 1 -d $(dig +short A {settings.git.hostname}) -j REJECT && firewall-cmd --reload' - ).status - == 0 - ) - assert target_sat.execute(f'ping -c 2 {settings.git.hostname}').status != 0 + old_log = target_sat.cutoff_host_setup_log(proxy_hostname, settings.git.hostname) data['http-proxy-policy'] = 'global' target_sat.cli.TemplateSync.imports(data) finally: if use_proxy_global: - target_sat.execute( - f'firewall-cmd --permanent --direct --remove-rule ipv4 filter OUTPUT 1 -d $(dig +short A {settings.git.hostname}) -j REJECT && firewall-cmd --reload' - ) + target_sat.restore_host_check_log(proxy_hostname, settings.git.hostname, old_log) # assert that template has been synced -> is present on the Satellite pt = target_sat.cli.PartitionTable.list({'search': f'name=\\"{pt_name}\\"'}) assert len(pt) == 1 assert pt_name == pt[0]['name'] - # assert that proxy has been used - if use_proxy_global: - new_log = ssh.command('echo /tmp/$RANDOM').stdout.strip() - ssh.command( - f'sshpass -p "{settings.server.ssh_password}" scp -o StrictHostKeyChecking=no root@{proxy_hostname}:{log_path} {new_log}' - ) - diff = ssh.command(f'diff {old_log} {new_log}').stdout - satellite_ip = ssh.command('dig A +short $(hostname)').stdout.strip() - assert satellite_ip in diff @pytest.mark.e2e @pytest.mark.tier2