Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Properly handle return code after error #172

Closed
lpramuk opened this issue Nov 4, 2022 · 5 comments · Fixed by #181
Closed

Properly handle return code after error #172

lpramuk opened this issue Nov 4, 2022 · 5 comments · Fixed by #181
Labels
bug Something isn't working

Comments

@lpramuk
Copy link
Contributor

lpramuk commented Nov 4, 2022

Broker should properly handle RC after hitting errors.
Deploy WFs are not in any way special in this.

I won't go grepping broker output for ERROR - that's purpose of return codes

[INFO 221104 15:39:26] Using provider AnsibleTower to checkout
[INFO 221104 15:39:26] Using username and password authentication
[INFO 221104 15:39:28] Waiting for job: 
    API: https://infra-ansible-tower-01/api/v2/workflow_jobs/142076/
    UI: https://infra-ansible-tower-01/#/jobs/workflow/142076/output
[ERROR 221104 15:40:00] ProviderError: AnsibleTower encountered the following error: {'reason': 'Unable to determine failure cause for deploy-satellite-upgrade ar /api/v2/workflow_jobs/142076/'}
[Pipeline] echo
Broker RC for checkout: 0

Actual Result:
RC = 0

Expected Result:
RC != 0

@lpramuk lpramuk changed the title Properly handle return code after errors Properly handle return code after error Nov 4, 2022
@lpramuk lpramuk added the bug Something isn't working label Nov 4, 2022
@lpramuk
Copy link
Contributor Author

lpramuk commented Nov 23, 2022

Bump !
@jyejare Do we have a progress on this ? Accepted issue ?

@jyejare
Copy link
Member

jyejare commented Nov 23, 2022

I dont see anywhere in discussions this issue is popped up. Could add some more details on severity of this issue please. That should help us to prioritize this fix.

@ogajduse
Copy link
Member

ogajduse commented Jan 17, 2023

I have just hit this issue by running the following command:

# passing non-existent RHEL version
$broker checkout --workflow deploy-base-rhel --deploy_rhel_version 99
[E 230117 17:13:40 exceptions:12] ProviderError: AnsibleTower encountered the following error: {'job': 'satlab-tower-deploy-version-choice', 'task': 'Take Deploy Workflow inputs and output correct set-stats for the remainder of workflow', 'reason': 'No template found for passed arguments'}
$ echo $?
0

Or just pass a wrong workflow name.

@ogajduse
Copy link
Member

We are suppressing the actual exception, which is why the ExceptionHandler does not get it and therefore does not set the correct return code.

Here is the code snippet of _checkout and checkout functions where the changes need to happen.

broker/broker/broker.py

Lines 123 to 162 in 6881543

@mp_decorator
def _checkout(self):
"""checkout one or more VMs
:return: List of Host objects
"""
hosts = []
if not self._provider_actions:
raise self.BrokerError("Could not determine an appropriate provider")
for action in self._provider_actions.keys():
provider, method = PROVIDER_ACTIONS[action]
logger.info(f"Using provider {provider.__name__} to checkout")
try:
host = self._act(provider, method, checkout=True)
except exceptions.ProviderError as err:
host = err
if host and not isinstance(host, exceptions.ProviderError):
hosts.append(host)
logger.info(f"{host.__class__.__name__}: {host.hostname}")
return hosts
def checkout(self):
"""checkout one or more VMs
: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 = host
hosts.remove(host)
helpers.emit(hosts=[host.to_dict() for host in hosts])
self._hosts.extend(hosts)
helpers.update_inventory([host.to_dict() for host in hosts])
if err:
raise err
return hosts if not len(hosts) == 1 else hosts[0]

@JacobCallahan
Copy link
Member

This was previously a workaround when Broker was using multiprocessing instead of multithreading. It should no longer be an issue to bubble this up again.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants