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

Fix handling of ProviderException #181

Merged
merged 3 commits into from
Jan 20, 2023
Merged
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
10 changes: 4 additions & 6 deletions broker/broker.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ def _checkout(self):
host = self._act(provider, method, checkout=True)
except exceptions.ProviderError as err:
host = err
hosts.append(host)
if host and not isinstance(host, exceptions.ProviderError):
hosts.append(host)
logger.info(f"{host.__class__.__name__}: {host.hostname}")
return hosts

Expand All @@ -147,11 +147,9 @@ def checkout(self):
:return: Host obj or list of Host objects
"""
hosts = self._checkout()
err, to_emit = None, []
for host in hosts:
if not isinstance(host, exceptions.ProviderError):
to_emit.append(host.to_dict())
else:
err = None
for host in hosts[:]:
if isinstance(host, exceptions.ProviderError):
err = host
hosts.remove(host)
helpers.emit(hosts=[host.to_dict() for host in hosts])
Expand Down
8 changes: 4 additions & 4 deletions broker/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def resolve_file_args(broker_args):
if data := load_file(val):
final_args.update({key: data})
else:
final_arg.update({key: val})
final_args.update({key: val})
else:
final_args.update({key: val})
return final_args
Expand Down Expand Up @@ -599,9 +599,9 @@ def __getstate__(self):
try:
self._purify()
except RecursionError:
logger.warning(f"Recursion limit reached on {self._purify_target}")
self.__dict__[self._purify_target] = None
self.__getstate__()
logger.warning(f"Recursion limit reached on {self._purify_target}")
self.__dict__[self._purify_target] = None
self.__getstate__()
self.__dict__.pop("_purify_target", None)
return self.__dict__

Expand Down
8 changes: 4 additions & 4 deletions broker/providers/ansible_tower.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

try:
import awxkit
except:
except ImportError:
raise exceptions.ProviderError(
provider="AnsibleTower", message="Unable to import awxkit. Is it installed?"
)
Expand Down Expand Up @@ -342,7 +342,7 @@ def _get_expire_date(self, host_id):
.expire_date
)
return str(datetime.fromtimestamp(int(time_stamp)))
except:
except Exception:
return None

def _compile_host_info(self, host):
Expand Down Expand Up @@ -372,7 +372,7 @@ def _compile_host_info(self, host):
host_info["_broker_args"]["workflow"] = host.get_related(
"last_job"
).summary_fields.source_workflow_job.name
except:
except Exception:
JacobCallahan marked this conversation as resolved.
Show resolved Hide resolved
logger.warning(
f"Unable to determine workflow for {host_info['hostname']}"
)
Expand Down Expand Up @@ -619,7 +619,7 @@ def nick_help(self, **kwargs):
logger.warning("That action is not yet implemented.")

def release(self, name, broker_args=None):
if broker_args == None:
if broker_args is None:
broker_args = {}
return self.execute(
workflow=settings.ANSIBLETOWER.release_workflow,
Expand Down
2 changes: 1 addition & 1 deletion broker/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
validators=validators,
)
# to make doubly sure, remove the vault loader if set somehow
settings._loaders = [loader for loader in settings._loaders if not "vault" in loader]
settings._loaders = [loader for loader in settings._loaders if "vault" not in loader]

try:
settings.validators.validate()
Expand Down
5 changes: 4 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ classifiers =
License :: OSI Approved :: GNU General Public License v3 (GPLv3)
Natural Language :: English
Programming Language :: Python :: 3
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.10
Programming Language :: Python :: 3.11

[options]
install_requires =
Expand Down Expand Up @@ -45,3 +45,6 @@ podman = podman-py
[options.entry_points]
console_scripts =
broker = broker.commands:cli

[flake8]
max-line-length = 110
1 change: 1 addition & 0 deletions tests/functional/test_satlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def test_tower_host():
res = r_host.execute("ls /tmp/fake")
assert "broker_settings.yaml" in res.stdout


def test_tower_host_mp():
with Broker(workflow="deploy-base-rhel", _count=3) as r_hosts:
for r_host in r_hosts:
Expand Down
1 change: 0 additions & 1 deletion tests/providers/test_container.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from asyncio import QueueEmpty
import json
import pytest
from broker.broker import Broker
Expand Down
4 changes: 2 additions & 2 deletions tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ def test_find_origin_simple():
origin = helpers.find_origin()
assert len(origin) == 2
assert origin[0].startswith("test_find_origin")
assert origin[1] == None
assert origin[1] is None


def test_find_origin_fixture(basic_origin):
def test_find_origin_fixture_basic(basic_origin):
assert basic_origin[0].startswith("basic_origin")


Expand Down