summaryrefslogtreecommitdiffstats
path: root/awxkit
diff options
context:
space:
mode:
authorAlan Rominger <arominge@redhat.com>2023-05-16 22:12:18 +0200
committerGitHub <noreply@github.com>2023-05-16 22:12:18 +0200
commit433c28caa8687d33502a6b1c09d28a1586d33734 (patch)
tree07ab643cd8d74b54d20d6b7508bd01da977817b9 /awxkit
parent[collection] Fix sanity tests on ansible-core 2.15 (#14007) (diff)
downloadawx-433c28caa8687d33502a6b1c09d28a1586d33734.tar.xz
awx-433c28caa8687d33502a6b1c09d28a1586d33734.zip
Materialize label page after getting 204 code (#14010)
Diffstat (limited to 'awxkit')
-rw-r--r--awxkit/awxkit/api/pages/api.py15
1 files changed, 12 insertions, 3 deletions
diff --git a/awxkit/awxkit/api/pages/api.py b/awxkit/awxkit/api/pages/api.py
index 01d1878387..5b001ae560 100644
--- a/awxkit/awxkit/api/pages/api.py
+++ b/awxkit/awxkit/api/pages/api.py
@@ -288,7 +288,18 @@ class ApiV2(base.Base):
if asset['natural_key']['type'] == 'user':
# We should only impose a default password if the resource doesn't exist.
post_data.setdefault('password', 'abc123')
- _page = endpoint.post(post_data)
+ try:
+ _page = endpoint.post(post_data)
+ except exc.NoContent:
+ # desired exception under some circumstances, e.g. labels that already exist
+ if _page is None and 'name' in post_data:
+ results = endpoint.get(all_pages=True).results
+ for item in results:
+ if item['name'] == post_data['name']:
+ _page = item.get()
+ break
+ else:
+ raise
changed = True
if asset['natural_key']['type'] == 'project':
# When creating a project, we need to wait for its
@@ -308,8 +319,6 @@ class ApiV2(base.Base):
_page = _page.put(post_data)
changed = True
- except exc.NoContent: # desired exception under some circumstances, e.g. labels that already exist
- pass
except (exc.Common, AssertionError) as e:
identifier = asset.get("name", None) or asset.get("username", None) or asset.get("hostname", None)
log.error(f'{endpoint} "{identifier}": {e}.')