Fix config issue loaded default config and ignoring overrides
When dlrn_url is overridden it is being ignored and instead the default is used. This makes it that the passed config is honored. Adds molecule test case to check vanilla invocation and test that passed dlrn_url is honored - test cases brought from WIP patch in [1]. Co-Authored-By: Sorin Sbarnea <ssbarnea@redhat.com> [1] https://review.opendev.org/c/openstack/tripleo-repos/+/807700 Change-Id: Ie5354421a470e5a528307694b49f4e8d2bc24ddc
This commit is contained in:
parent
f1e7092812
commit
7d591854b9
|
@ -12,3 +12,13 @@
|
|||
# TODO: fix yum_config to correctly report changed state and uncomment
|
||||
# the line below which disables molecule idemptotence test.
|
||||
- molecule-idempotence-notest
|
||||
|
||||
- name: "Check get_hash"
|
||||
tripleo.repos.get_hash:
|
||||
release: master
|
||||
- name: "Check get_hash with invalid url"
|
||||
tripleo.repos.get_hash:
|
||||
release: master
|
||||
dlrn_url: 'https://httpbin.org/status/404'
|
||||
register: result
|
||||
failed_when: result is success
|
||||
|
|
|
@ -29,17 +29,23 @@ try:
|
|||
from ansible.module_utils.urls import open_url
|
||||
|
||||
def http_get(url: str) -> Tuple[str, int]:
|
||||
response = open_url(url, method='GET')
|
||||
return (response.read(), response.status)
|
||||
try:
|
||||
response = open_url(url, method='GET')
|
||||
return (response.read(), response.status)
|
||||
except Exception as e:
|
||||
return (str(e), -1)
|
||||
except ImportError:
|
||||
from urllib.request import urlopen
|
||||
|
||||
def http_get(url: str) -> Tuple[str, int]:
|
||||
# https://stackoverflow.com/questions/35122232/urllib-request-urlopen-return-bytes-but-i-cannot-decode-it
|
||||
response = urlopen(url)
|
||||
return (
|
||||
response.read().decode('utf-8'),
|
||||
int(response.status))
|
||||
try:
|
||||
response = urlopen(url)
|
||||
return (
|
||||
response.read().decode('utf-8'),
|
||||
int(response.status))
|
||||
except Exception as e:
|
||||
return (str(e), -1)
|
||||
|
||||
__metaclass__ = type
|
||||
|
||||
|
@ -145,10 +151,11 @@ class TripleOHashInfo:
|
|||
config_path = local_config
|
||||
else:
|
||||
logging.info("Using embedded config file")
|
||||
return DEFAULT_CONFIG
|
||||
loaded_config = DEFAULT_CONFIG
|
||||
logging.info("Using config file at %s", config_path)
|
||||
with open(config_path, 'r') as config_yaml:
|
||||
loaded_config = cls.load_yaml(config_yaml)
|
||||
if config_path != '':
|
||||
with open(config_path, 'r') as config_yaml:
|
||||
loaded_config = cls.load_yaml(config_yaml)
|
||||
for k in CONFIG_KEYS:
|
||||
if k not in loaded_config:
|
||||
error_str = (
|
||||
|
|
Loading…
Reference in New Issue