From ee26ecfcfde9a2a71853aee217b3928e52ce68b8 Mon Sep 17 00:00:00 2001 From: Ondra Machacek Date: Thu, 2 Nov 2017 14:24:42 +0100 Subject: [PATCH] ovirt_templates: wait for OK state when importing (#31634) --- lib/ansible/module_utils/ovirt.py | 4 ++-- lib/ansible/modules/cloud/ovirt/ovirt_templates.py | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/ansible/module_utils/ovirt.py b/lib/ansible/module_utils/ovirt.py index 9ec7d9b3e7..314d29946f 100644 --- a/lib/ansible/module_utils/ovirt.py +++ b/lib/ansible/module_utils/ovirt.py @@ -746,14 +746,14 @@ class BaseModule(object): 'diff': self._diff, } - def wait_for_import(self): + def wait_for_import(self, condition=lambda e: True): if self._module.params['wait']: start = time.time() timeout = self._module.params['timeout'] poll_interval = self._module.params['poll_interval'] while time.time() < start + timeout: entity = self.search_entity() - if entity: + if entity and condition(entity): return entity time.sleep(poll_interval) diff --git a/lib/ansible/modules/cloud/ovirt/ovirt_templates.py b/lib/ansible/modules/cloud/ovirt/ovirt_templates.py index e17492f475..2acb766080 100644 --- a/lib/ansible/modules/cloud/ovirt/ovirt_templates.py +++ b/lib/ansible/modules/cloud/ovirt/ovirt_templates.py @@ -351,7 +351,10 @@ def main(): ) if module.params['cluster'] else None, **kwargs ) - template = templates_module.wait_for_import() + # Wait for template to appear in system: + template = templates_module.wait_for_import( + condition=lambda t: t.status == otypes.TemplateStatus.OK + ) ret = { 'changed': True, 'id': template.id,