Skip to content

Commit

Permalink
Add fixture to cut Satellite off nameservers
Browse files Browse the repository at this point in the history
  • Loading branch information
vsedmik committed Apr 12, 2024
1 parent e3b8137 commit 874a78c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
30 changes: 30 additions & 0 deletions pytest_fixtures/component/http_proxy.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from urllib.parse import urlparse

import pytest

from robottelo.config import settings
Expand All @@ -10,6 +12,34 @@ def session_auth_proxy(session_target_sat):
return ProxyHost(settings.http_proxy.auth_proxy_url)


@pytest.fixture
def satellite_cut_off(target_sat):
"""Cuts the Satellite off the DNS, leaving it with HTTP proxy only"""
# First create entries in /etc/hosts for HTTP proxies and Satellite itself
ips = []
for url in [
settings.http_proxy.un_auth_proxy_url,
settings.http_proxy.auth_proxy_url,
target_sat.url,
]:
hostname = urlparse(url).hostname
adr = target_sat.execute(
f"nslookup {hostname} | awk '/^Address: / {{ print $2 }}'"
).stdout.strip()
target_sat.execute(f'echo "{adr} {hostname}" >> /etc/hosts')
ips.append(adr)
# Cut off the nameservers
target_sat.execute('sed -i "s/nameserver/;nameserver/g" /etc/resolv.conf')

yield

# Restore the nameservers
target_sat.execute('sed -i "s/;nameserver/nameserver/g" /etc/resolv.conf')
# Remove the added entries from /etc/hosts
for adr in ips:
target_sat.execute(f'sed -i "/^{adr}/d" /etc/hosts')


@pytest.fixture
def setup_http_proxy(request, module_manifest_org, target_sat):
"""Create a new HTTP proxy and set related settings based on proxy"""
Expand Down
2 changes: 1 addition & 1 deletion tests/foreman/cli/test_http_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def test_positive_environment_variable_unset_set():
@pytest.mark.e2e
@pytest.mark.tier2
@pytest.mark.skipif((not settings.robottelo.REPOS_HOSTING_URL), reason='Missing repos_hosting_url')
def test_positive_assign_http_proxy_to_products(module_org, module_target_sat):
def test_positive_assign_http_proxy_to_products(module_org, module_target_sat, satellite_cut_off):
"""Assign http_proxy to Products and perform product sync.
:id: 6af7b2b8-15d5-4d9f-9f87-e76b404a966f
Expand Down

0 comments on commit 874a78c

Please sign in to comment.