container_systemd: improve debugging if service never starts

If a service never starts, the "status" key won't exist so Ansible
raises with KeyError which is very misleading (we don't even have the
service name).

This make pass the KeyError exception, so we fail at the end of the loop
of attempts with proper Ansible raise and we give the service name.

Change-Id: I74f3d5b51bde1ec33b69b2488174eef9cc4a330d
This commit is contained in:
Emilien Macchi 2020-07-27 08:46:33 -04:00
parent 569b428498
commit 67d78a753c
1 changed files with 13 additions and 6 deletions

View File

@ -286,12 +286,19 @@ class ActionModule(ActionBase):
daemon_reload=False), daemon_reload=False),
task_vars=tvars task_vars=tvars
) )
if 'Result' in results['status']: try:
if results['status']['Result'] == 'success': if 'Result' in results['status']:
if results.get('changed', False): if results['status']['Result'] == 'success':
self.changed = True if results.get('changed', False):
self.restarted.append('tripleo_{}.service'.format(name)) self.changed = True
return self.restarted.append('tripleo_{}'
'.service'.format(name))
return
except KeyError:
# if 'systemd' task failed to start the service, the 'status'
# key doesn't exist, so we'll use the final raise to report the
# issue if the service never start after the attempts.
pass
raise AnsibleActionFail('Service {} has not started yet'.format(name)) raise AnsibleActionFail('Service {} has not started yet'.format(name))
def _restart_services(self, service_names, task_vars): def _restart_services(self, service_names, task_vars):