From 5aa885860025735109015ca3cede9953a8addfa7 Mon Sep 17 00:00:00 2001 From: Emilien Macchi Date: Mon, 27 Jul 2020 08:46:33 -0400 Subject: [PATCH] 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 (cherry picked from commit 67d78a753ccf0cc925627c6acc3fabad9905a03b) --- .../action/container_systemd.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/tripleo_ansible/ansible_plugins/action/container_systemd.py b/tripleo_ansible/ansible_plugins/action/container_systemd.py index d46553e44..d2cae44c7 100644 --- a/tripleo_ansible/ansible_plugins/action/container_systemd.py +++ b/tripleo_ansible/ansible_plugins/action/container_systemd.py @@ -286,12 +286,19 @@ class ActionModule(ActionBase): daemon_reload=False), task_vars=tvars ) - if 'Result' in results['status']: - if results['status']['Result'] == 'success': - if results.get('changed', False): - self.changed = True - self.restarted.append('tripleo_{}.service'.format(name)) - return + try: + if 'Result' in results['status']: + if results['status']['Result'] == 'success': + if results.get('changed', False): + self.changed = True + 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)) def _restart_services(self, service_names, task_vars):