Ovirt host event log backport (#59432)

* 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

* add changelog
This commit is contained in:
Martin Nečas 2019-07-29 21:05:22 +02:00 committed by Toshio Kuratomi
parent 9a3dc5f798
commit 5410128801
2 changed files with 20 additions and 2 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- ovirt_host - add event log on failure (https://github.com/oVirt/ovirt-ansible-infra/issues/8)

View file

@ -287,6 +287,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(
@ -353,13 +356,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:
@ -371,7 +385,7 @@ class HostsModule(BaseModule):
count + 1,
)
else:
return True
return self.raise_host_exception()
return False
@ -469,10 +483,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']