Skip to content

Commit

Permalink
Ovirt host event log (ansible#57935)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
mnecas authored and ansibot committed Jul 2, 2019
1 parent 2e25638 commit fb1610a
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions lib/ansible/modules/cloud/ovirt/ovirt_host.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,9 @@


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(
Expand Down Expand Up @@ -344,13 +347,24 @@ def post_reinstall(self, host):
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:
Expand All @@ -362,7 +376,7 @@ def failed_state_after_reinstall(self, host, count=0):
count + 1,
)
else:
return True
return self.raise_host_exception()

return False

Expand Down Expand Up @@ -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']
Expand Down

0 comments on commit fb1610a

Please sign in to comment.