Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fixture to cut Satellite off nameservers #14754

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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