diff --git a/pytest_fixtures/component/http_proxy.py b/pytest_fixtures/component/http_proxy.py index a98e7409699..baf1941412d 100644 --- a/pytest_fixtures/component/http_proxy.py +++ b/pytest_fixtures/component/http_proxy.py @@ -1,3 +1,5 @@ +from urllib.parse import urlparse + import pytest from robottelo.config import settings @@ -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""" diff --git a/tests/foreman/cli/test_http_proxy.py b/tests/foreman/cli/test_http_proxy.py index 68ea95559ca..9ab734128d9 100644 --- a/tests/foreman/cli/test_http_proxy.py +++ b/tests/foreman/cli/test_http_proxy.py @@ -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