Skip to content

Commit

Permalink
Improve structure - CLI, API
Browse files Browse the repository at this point in the history
  • Loading branch information
lhellebr committed Dec 12, 2024
1 parent b0e6328 commit f090398
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 50 deletions.
28 changes: 4 additions & 24 deletions tests/foreman/api/test_templatesync.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand All @@ -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:
Expand All @@ -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):
Expand Down
28 changes: 2 additions & 26 deletions tests/foreman/cli/test_templatesync.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f090398

Please sign in to comment.