Skip to content

Commit

Permalink
Improve structure - WebUI
Browse files Browse the repository at this point in the history
  • Loading branch information
lhellebr committed Nov 6, 2024
1 parent d776835 commit 38d8fc9
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 26 deletions.
34 changes: 34 additions & 0 deletions robottelo/host_helpers/capsule_mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from box import Box
from dateutil.parser import parse

from robottelo import ssh
from robottelo.config import settings
from robottelo.constants import (
PULP_ARTIFACT_DIR,
PUPPET_CAPSULE_INSTALLER,
Expand Down Expand Up @@ -189,3 +191,35 @@ def get_artifact_info(self, checksum=None, path=None):
info = self.execute(f'file {path}').stdout.strip().split(': ')[1]

return Box(path=path, size=size, sum=real_sum, info=info)

def cutoff_host_setup_log(self, proxy_hostname, hostname):
"""For testing of HTTP Proxy, disable direct connection to some host using firewall. On the Proxy, setup logs for later comparison that the Proxy was used."""
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 (
self.execute(
f'firewall-cmd --permanent --direct --add-rule ipv4 filter OUTPUT 1 -d $(dig +short A {hostname}) -j REJECT && firewall-cmd --reload'
).status
== 0
)
assert self.execute(f'ping -c 2 {hostname}').status != 0
return old_log

def restore_host_check_log(self, proxy_hostname, hostname, old_log):
"""For testing of HTTP Proxy, call after running the thing that should use Proxy."""
log_path = '/var/log/squid/access.log'
self.execute(
f'firewall-cmd --permanent --direct --remove-rule ipv4 filter OUTPUT 1 -d $(dig +short A {hostname}) -j REJECT && firewall-cmd --reload'
)
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 that proxy has been used
assert satellite_ip in diff
28 changes: 2 additions & 26 deletions tests/foreman/ui/test_templatesync.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import pytest
import requests

from robottelo import ssh
from robottelo.config import settings
from robottelo.constants import FOREMAN_TEMPLATE_IMPORT_URL, FOREMAN_TEMPLATE_ROOT_DIR

Expand Down Expand Up @@ -104,19 +103,7 @@ def test_positive_import_templates(
}
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}'
)
# 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['template.http_proxy_policy'] = 'Use selected HTTP proxy'
data['template.http_proxy_id'] = proxy.name
with session:
Expand All @@ -129,24 +116,13 @@ def test_positive_import_templates(
pt = session.provisioningtemplate.read(imported_template)
finally:
if use_proxy:
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 pt['template']['name'] == imported_template
assert pt['template']['default'] is False
assert pt['type']['snippet'] is False
assert pt['locations']['resources']['assigned'][0] == templates_loc.name
assert pt['organizations']['resources']['assigned'][0] == templates_org.name
assert f'name: {import_template}' in pt['template']['template_editor']['editor']
# 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
Expand Down

0 comments on commit 38d8fc9

Please sign in to comment.