Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cloud: ovirt: Ignore 404 error when getting entity #20386

Merged
merged 1 commit into from
Jan 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 15 additions & 1 deletion lib/ansible/module_utils/ovirt.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,20 @@ def search_by_name(service, name, **kwargs):
return res[0]


def get_entity(service):
"""
Ignore SDK Error in case of getting an entity from service.
"""
entity = None
try:
entity = service.get()
except sdk.Error:
# We can get here 404, we should ignore it, in case
# of removing entity for example.
pass
return entity


def wait(
service,
condition,
Expand All @@ -270,7 +284,7 @@ def wait(
start = time.time()
while time.time() < start + timeout:
# Exit if the condition of entity is valid:
entity = service.get()
entity = get_entity(service)
if condition(entity):
return
elif fail_condition(entity):
Expand Down
3 changes: 2 additions & 1 deletion lib/ansible/modules/cloud/ovirt/ovirt_host_networks.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
create_connection,
equal,
get_dict_of_struct,
get_entity,
get_link_name,
ovirt_full_argument_spec,
search_by_name,
Expand Down Expand Up @@ -192,7 +193,7 @@ def has_update(self, nic_service):
update = False
bond = self._module.params['bond']
networks = self._module.params['networks']
nic = nic_service.get()
nic = get_entity(nic_service)

if nic is None:
return update
Expand Down
7 changes: 4 additions & 3 deletions lib/ansible/modules/cloud/ovirt/ovirt_storage_domains.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
check_sdk,
create_connection,
equal,
get_entity,
ovirt_full_argument_spec,
search_by_name,
wait,
Expand Down Expand Up @@ -285,7 +286,7 @@ def _maintenance(self, storage_domain):
return

attached_sd_service = attached_sds_service.storage_domain_service(storage_domain.id)
attached_sd = attached_sd_service.get()
attached_sd = get_entity(attached_sd_service)

if attached_sd and attached_sd.status != sdstate.MAINTENANCE:
if not self._module.check_mode:
Expand All @@ -305,7 +306,7 @@ def _unattach(self, storage_domain):
return

attached_sd_service = attached_sds_service.storage_domain_service(storage_domain.id)
attached_sd = attached_sd_service.get()
attached_sd = get_entity(attached_sd_service)

if attached_sd and attached_sd.status == sdstate.MAINTENANCE:
if not self._module.check_mode:
Expand Down Expand Up @@ -333,7 +334,7 @@ def post_create_check(self, sd_id):

# If storage domain isn't attached, attach it:
attached_sd_service = self._service.service(storage_domain.id)
if attached_sd_service.get() is None:
if get_entity(attached_sd_service) is None:
self._service.add(
otypes.StorageDomain(
id=storage_domain.id,
Expand Down