From b9600281d6640eb0ec40bc18f0e00af7cc540ac1 Mon Sep 17 00:00:00 2001 From: Ondra Machacek Date: Mon, 28 Aug 2017 17:15:05 +0200 Subject: [PATCH] ovirt_hosts: Add upgrade_check action (#28437) * ovirt_hosts: Add upgrade_check action * Fix pep8 issue --- .../modules/cloud/ovirt/ovirt_hosts.py | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/lib/ansible/modules/cloud/ovirt/ovirt_hosts.py b/lib/ansible/modules/cloud/ovirt/ovirt_hosts.py index 175f5b54bd..26814c1345 100644 --- a/lib/ansible/modules/cloud/ovirt/ovirt_hosts.py +++ b/lib/ansible/modules/cloud/ovirt/ovirt_hosts.py @@ -123,6 +123,12 @@ options: - "If C(state) is I(iscsilogin) it means that the iscsi attribute is being used to login to the specified targets passed as part of the iscsi attribute" version_added: "2.4" + check_upgrade: + description: + - "If I(true) and C(state) is I(upgraded) run check for upgrade + action before executing upgrade action." + default: True + version_added: 2.4 extends_documentation_fragment: ovirt ''' @@ -385,6 +391,7 @@ def main(): power_management_enabled=dict(default=None, type='bool'), activate=dict(default=True, type='bool'), iscsi=dict(default=None, type='dict'), + check_upgrade=dict(default=True, type='bool'), ) module = AnsibleModule( argument_spec=argument_spec, @@ -435,6 +442,32 @@ def main(): ret = hosts_module.create() elif state == 'upgraded': result_state = hoststate.MAINTENANCE if host.status == hoststate.MAINTENANCE else hoststate.UP + events_service = connection.system_service().events_service() + last_event = events_service.list(max=1)[0] + + if module.params['check_upgrade']: + hosts_module.action( + action='upgrade_check', + action_condition=lambda host: not host.update_available, + wait_condition=lambda host: host.update_available or ( + len([ + event + for event in events_service.list( + from_=int(last_event.id), + search='type=885 and host.name=%s' % host.name, + ) + ]) > 0 + ), + fail_condition=lambda host: len([ + event + for event in events_service.list( + from_=int(last_event.id), + search='type=839 or type=887 and host.name=%s' % host.name, + ) + ]) > 0, + ) + # Set to False, because upgrade_check isn't 'changing' action: + hosts_module._changed = False ret = hosts_module.action( action='upgrade', action_condition=lambda h: h.update_available,