Merge "Updated absent and role_unassign states behavior." into release/2019.2.0
diff --git a/_states/keystoneng.py b/_states/keystoneng.py
index dcefbd9..82ce494 100644
--- a/_states/keystoneng.py
+++ b/_states/keystoneng.py
@@ -802,7 +802,7 @@
profile=profile,
interface=interface,
**connection_args)
- if not endpoint:
+ if endpoint and 'Error' in endpoint:
return ret
else:
if __opts__.get('test'):
diff --git a/_states/keystonev3.py b/_states/keystonev3.py
index 55d14e9..2dd651d 100644
--- a/_states/keystonev3.py
+++ b/_states/keystonev3.py
@@ -63,9 +63,15 @@
def endpoint_absent(name, service_id, interface, cloud_name):
- service_id = _keystonev3_call(
- 'service_get_details', service_id,
- cloud_name=cloud_name)['service']['id']
+
+ try:
+ service_id = _keystonev3_call(
+ 'service_get_details', service_id,
+ cloud_name=cloud_name)['service']['id']
+
+ except Exception as e:
+ if 'ResourceNotFound' in repr(e):
+ return _absent(name, 'service')
endpoints = _keystonev3_call(
'endpoint_list', name=name, service_id=service_id, interface=interface,
@@ -361,9 +367,18 @@
def user_role_unassign(name, role_id, cloud_name, project_id=None,
domain_id=None, role_domain_id=None):
- user_id = _keystonev3_call(
- 'user_get_details', name,
- cloud_name=cloud_name)['user']['id']
+
+ try:
+ user_id = _keystonev3_call(
+ 'user_get_details', name,
+ cloud_name=cloud_name)['user']['id']
+
+ except Exception as e:
+ if 'ResourceNotFound' in repr(e):
+ return _no_changes(name, 'user')
+ else:
+ log.error('Failed to get user {}'.format(e))
+ return _find_failed(name, 'user')
if project_id:
project_id = _keystonev3_call(
@@ -527,7 +542,7 @@
return _find_failed(name, 'domain')
-def domain_absent(name, cloud_name):
+def domain_absent(name, cloud_name, force_delete=False):
try:
_keystonev3_call('domain_get_details',
domain_id=name, cloud_name=cloud_name)
@@ -537,7 +552,14 @@
else:
log.error('Failed to get a domain {}'.format(e))
return _find_failed(name, 'domain')
+
try:
+ if force_delete:
+ _keystonev3_call(
+ 'domain_update', domain_id=name,
+ enabled=False, cloud_name=cloud_name
+ )
+
_keystonev3_call('domain_delete', domain_id=name,
cloud_name=cloud_name)
except Exception:
@@ -578,9 +600,9 @@
def _deleted(name, resource):
changes_dict = {
'name': name,
- 'changes': {},
+ 'changes': {"resource": resource, "name": name, "status": 'deleted'},
'result': True,
- 'comment': '{}{} removed'.format(resource, name)
+ 'comment': '{} {} removed'.format(resource, name)
}
return changes_dict