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

[6.16.z] Rely on dynaconf to render the config based on is_ipv6 setting #16923

Open
wants to merge 1 commit into
base: 6.16.z
Choose a base branch
from
Open
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
3 changes: 1 addition & 2 deletions conf/dynaconf_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from robottelo.logging import logger
from robottelo.utils.ohsnap import dogfood_repository
from robottelo.utils.url import ipv6_hostname_translation, is_url
from robottelo.utils.url import is_url


def post(settings):
Expand All @@ -30,7 +30,6 @@ def post(settings):
)
data = get_repos_config(settings)
write_cache(settings_cache_path, data)
ipv6_hostname_translation(settings, data)
config_migrations(settings, data)
data['dynaconf_merge'] = True
return data
Expand Down
1 change: 0 additions & 1 deletion robottelo/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ def get_settings():
load_dotenv=True,
)
settings.validators.register(**VALIDATORS)

try:
settings.validators.validate()
except ValidationError as err:
Expand Down
42 changes: 0 additions & 42 deletions robottelo/utils/url.py
Original file line number Diff line number Diff line change
@@ -1,51 +1,9 @@
from urllib.parse import urlparse

from robottelo.logging import logger


def is_url(url):
try:
result = urlparse(url)
return all([result.scheme, result.netloc])
except (ValueError, AttributeError):
return False


def is_ipv4_url(text):
"""Verify if the URL is IPv4 url"""
return isinstance(text, str) and 'ipv4' in text and 'redhat.com' in text


def ipv6_translator(settings_list, setting_major, data):
"""Translates the hostname containing IPv4 to IPv6 and updates the settings object"""
setting_major = list(map(str, setting_major))
dotted_settings = '.'.join(setting_major)
for _key, _val in settings_list.items():
if is_ipv4_url(_val):
data[f'{dotted_settings}.{_key}'] = str(_val).replace('ipv4', 'ipv6')
logger.debug(f'Setting translated to IPv6, Path: {dotted_settings}.{_key}')
elif isinstance(_val, list):
updated = False
new_list = _val
for i in range(len(new_list)):
if is_ipv4_url(new_list[i]):
new_list[i] = new_list[i].replace('ipv4', 'ipv6')
updated = True
if updated:
data[f'{dotted_settings}.{_key}'] = new_list
logger.debug(f'Setting translated to IPv6, Path: {dotted_settings}.{_key}')
elif isinstance(_val, dict):
new_setting_major = setting_major + [_key]
ipv6_translator(settings_list=_val, setting_major=new_setting_major, data=data)


def ipv6_hostname_translation(settings, data):
"""Migrates any IPv4 containing hostname in conf to IPv6 hostname"""
settings_path = []
if settings.server.is_ipv6:
all_settings = settings.loaded_by_loaders.items()
for loader_name, loader_settings in tuple(all_settings):
if loader_name.loader == 'yaml':
ipv6_translator(loader_settings, settings_path, data)
else:
logger.debug('IPv6 Hostname dynaconf migration hook is skipped for IPv4 testing')