From 5a807bfb3dabb1661f3ba3447bb6b235eba790e1 Mon Sep 17 00:00:00 2001 From: Jacob Callahan Date: Fri, 28 Apr 2023 10:49:53 -0400 Subject: [PATCH] Add in some new workarounds and log statements We're seeing some strang behavior in CI. These are attempts to solve them and/or get more information about what's going on. --- broker/providers/__init__.py | 5 ++-- broker/providers/ansible_tower.py | 39 ++++++++++++++++++++----------- broker/providers/container.py | 2 +- 3 files changed, 29 insertions(+), 17 deletions(-) diff --git a/broker/providers/__init__.py b/broker/providers/__init__.py index 604526d4..fe91e616 100644 --- a/broker/providers/__init__.py +++ b/broker/providers/__init__.py @@ -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) diff --git a/broker/providers/ansible_tower.py b/broker/providers/ansible_tower.py index 1fc9ec29..250173cd 100644 --- a/broker/providers/ansible_tower.py +++ b/broker/providers/ansible_tower.py @@ -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 diff --git a/broker/providers/container.py b/broker/providers/container.py index 8a4790f7..0471390f 100644 --- a/broker/providers/container.py +++ b/broker/providers/container.py @@ -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"