Skip to content

Commit

Permalink
Add in some new workarounds and log statements
Browse files Browse the repository at this point in the history
We're seeing some strang behavior in CI. These are attempts to solve them
and/or get more information about what's going on.
  • Loading branch information
JacobCallahan committed May 1, 2023
1 parent 3f0ce58 commit 5a807bf
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 17 deletions.
5 changes: 3 additions & 2 deletions broker/providers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,9 @@ def _validate_settings(self, instance_name=None):
if not inst_vals.get("override_envars"):
# if a provider instance doesn't want to override envars, load them
settings.execute_loaders(loaders=[dynaconf.loaders.env_loader])

settings.validators.extend([v for v in self._validators if v not in settings.validators])
new_validators = [v for v in self._validators if v not in settings.validators]
logger.debug(f"Adding new validators: {[v.names[0] for v in new_validators]}")
settings.validators.extend(new_validators)
# use selective validation to only validate the instance settings
try:
settings.validators.validate(only=section_name)
Expand Down
39 changes: 25 additions & 14 deletions broker/providers/ansible_tower.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,20 +205,31 @@ def _translate_inventory(self, inventory):
provider="AnsibleTower",
message=f"Unknown AnsibleTower inventory by id {inventory}",
)
if inventory_info := self.v2.inventory.get(search=inventory):
if inventory_info.count > 1:
raise exceptions.ProviderError(
provider="AnsibleTower",
message=f"Ambigious AnsibleTower inventory name {inventory}",
)
elif inventory_info.count == 1:
inv_struct = inventory_info.results.pop()
return inv_struct.id
else:
raise exceptions.ProviderError(
provider="AnsibleTower",
message=f"Unknown AnsibleTower inventory {inventory}",
)
elif isinstance(inventory, str):
if inventory_info := self.v2.inventory.get(search=inventory):
if inventory_info.count > 1:
raise exceptions.ProviderError(
provider="AnsibleTower",
message=f"Ambigious AnsibleTower inventory name {inventory}",
)
elif inventory_info.count == 1:
inv_struct = inventory_info.results.pop()
return inv_struct.id
else:
raise exceptions.ProviderError(
provider="AnsibleTower",
message=f"Unknown AnsibleTower inventory {inventory}",
)
elif inv_id := getattr(inventory, "id", None):
return inv_id
elif inv_name := getattr(inventory, "name", None):
return inv_name
else:
caller_context = inspect.stack()[1][0].f_locals
raise exceptions.ProviderError(
provider="AnsibleTower",
message=f"Ambiguous AnsibleTower inventory {inventory} passed from {caller_context}",
)

def _merge_artifacts(self, at_object, strategy="last", artifacts=None):
"""Gather and merge all artifacts associated with an object and its children
Expand Down
2 changes: 1 addition & 1 deletion broker/providers/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def construct_host(self, provider_params, host_classes, **kwargs):

def nick_help(self, **kwargs):
"""Useful information about container images"""
results_limit = kwargs.get("results_limit", settings.CONTAINER.results_limit)
results_limit = kwargs.get("results_limit", settings.container.results_limit)
if image := kwargs.get("container_host"):
logger.info(
f"Information for {image} container-host:\n"
Expand Down

0 comments on commit 5a807bf

Please sign in to comment.