From fb1610a9aca5ae02f69420500fb4300a805a8fc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ne=C4=8Das?= Date: Tue, 2 Jul 2019 12:01:52 +0200 Subject: [PATCH] Ovirt host event log (#57935) * host event log init * show more events * add time check * correct pep8 syntax * use event id as first elem * init start event in constr * update pep8 syntax * remove precreate --- lib/ansible/modules/cloud/ovirt/ovirt_host.py | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/ansible/modules/cloud/ovirt/ovirt_host.py b/lib/ansible/modules/cloud/ovirt/ovirt_host.py index 368e9f790f8..f1cbfbc9b3a 100644 --- a/lib/ansible/modules/cloud/ovirt/ovirt_host.py +++ b/lib/ansible/modules/cloud/ovirt/ovirt_host.py @@ -278,6 +278,9 @@ from ansible.module_utils.ovirt import ( class HostsModule(BaseModule): + def __init__(self, start_event=None, *args, **kwargs): + super(HostsModule, self).__init__(*args, **kwargs) + self.start_event = start_event def build_entity(self): return otypes.Host( @@ -344,13 +347,24 @@ class HostsModule(BaseModule): timeout=self.param('timeout'), ) + def raise_host_exception(self): + events = self._connection.system_service().events_service().list(from_=int(self.start_event.index)) + error_events = [ + event.description for event in events + if event.host is not None and (event.host.id == self.param('id') or event.host.name == self.param('name')) and + event.severity in [otypes.LogSeverity.WARNING, otypes.LogSeverity.ERROR] + ] + if error_events: + raise Exception("Error message: %s" % error_events) + return True + def failed_state_after_reinstall(self, host, count=0): if host.status in [ hoststate.ERROR, hoststate.INSTALL_FAILED, hoststate.NON_OPERATIONAL, ]: - return True + return self.raise_host_exception() # If host is in non-responsive state after upgrade/install # let's wait for few seconds and re-check again the state: @@ -362,7 +376,7 @@ class HostsModule(BaseModule): count + 1, ) else: - return True + return self.raise_host_exception() return False @@ -460,10 +474,12 @@ def main(): auth = module.params.pop('auth') connection = create_connection(auth) hosts_service = connection.system_service().hosts_service() + start_event = connection.system_service().events_service().list(max=1)[0] hosts_module = HostsModule( connection=connection, module=module, service=hosts_service, + start_event=start_event, ) state = module.params['state']