From 96399fa79dc9d700238f72cf90417d244aad666b Mon Sep 17 00:00:00 2001 From: Rick Elrod Date: Thu, 8 Aug 2024 23:07:49 +0200 Subject: [PATCH] Make proper use of service_id Signed-off-by: Rick Elrod --- .../resource_registry/utils/sync_to_resource_server.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/ansible_base/resource_registry/utils/sync_to_resource_server.py b/ansible_base/resource_registry/utils/sync_to_resource_server.py index 7181bd165..dba5d06e8 100644 --- a/ansible_base/resource_registry/utils/sync_to_resource_server.py +++ b/ansible_base/resource_registry/utils/sync_to_resource_server.py @@ -76,17 +76,20 @@ def sync_to_resource_server(instance, action, ansible_id=None): body = ResourceRequestBody( resource_type=resource_type.name, ansible_id=ansible_id, - service_id=instance.resource.service_id, resource_data=data, ) try: if action == "create": - client.create_resource(body) + response = client.create_resource(body) + json = response.json() + if isinstance(json, dict): # Mainly for tests... to avoid getting here with mock + instance.resource.service_id = json['service_id'] + instance.resource.save() elif action == "update": client.update_resource(ansible_id, body) elif action == "delete": client.delete_resource(ansible_id) except Exception as e: - logger.exception(f"Failed to sync {action} of resource {ansible_id} to resource server: {e}") + logger.exception(f"Failed to sync {action} of resource {instance} ({ansible_id}) to resource server: {e}") raise ValidationError(_("Failed to sync resource to resource server")) from e