From 70fff13a6eafb4b39641e8eda65c9092239b5033 Mon Sep 17 00:00:00 2001 From: abarbare Date: Wed, 21 Nov 2018 12:40:15 +0100 Subject: [PATCH] feat: meaningful error message scaleway image not found (#48829) --- .../modules/cloud/scaleway/scaleway_compute.py | 13 +++++++++++++ .../legacy/roles/scaleway_compute/defaults/main.yml | 2 +- test/legacy/roles/scaleway_compute/tasks/state.yml | 1 + 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/ansible/modules/cloud/scaleway/scaleway_compute.py b/lib/ansible/modules/cloud/scaleway/scaleway_compute.py index 11925232237..94dd8a93e5a 100644 --- a/lib/ansible/modules/cloud/scaleway/scaleway_compute.py +++ b/lib/ansible/modules/cloud/scaleway/scaleway_compute.py @@ -225,6 +225,17 @@ SCALEWAY_TRANSITIONS_STATES = ( ) +def check_image_id(compute_api, image_id): + response = compute_api.get(path="images") + + if response.ok and response.json: + image_ids = [image["id"] for image in response.json["images"]] + if image_id not in image_ids: + compute_api.module.fail_json(msg='Error in getting image %s on %s' % (image_id, compute_api.module.params.get('api_url'))) + else: + compute_api.module.fail_json(msg="Error in getting images from: %s" % compute_api.module.params.get('api_url')) + + def fetch_state(compute_api, server): compute_api.module.debug("fetch_state of server: %s" % server["id"]) response = compute_api.get(path="servers/%s" % server["id"]) @@ -662,6 +673,8 @@ def core(module): compute_api = Scaleway(module=module) + check_image_id(compute_api, wished_server["image"]) + # IP parameters of the wished server depends on the configuration ip_payload = public_ip_payload(compute_api=compute_api, public_ip=module.params["public_ip"]) wished_server.update(ip_payload) diff --git a/test/legacy/roles/scaleway_compute/defaults/main.yml b/test/legacy/roles/scaleway_compute/defaults/main.yml index 269c367bd78..4b2b2799c37 100644 --- a/test/legacy/roles/scaleway_compute/defaults/main.yml +++ b/test/legacy/roles/scaleway_compute/defaults/main.yml @@ -1,6 +1,6 @@ # Below information has been taken from https://developer.scaleway.com/#servers --- -scaleway_image_id: 89ee4018-f8c3-4dc4-a6b5-bca14f985ebe +scaleway_image_id: 6a601340-19c1-4ca7-9c1c-0704bcc9f5fe scaleway_organization: '{{ scw_org }}' scaleway_region: ams1 scaleway_commerial_type: START1-S diff --git a/test/legacy/roles/scaleway_compute/tasks/state.yml b/test/legacy/roles/scaleway_compute/tasks/state.yml index da7ef4dfedd..effd27e85fd 100644 --- a/test/legacy/roles/scaleway_compute/tasks/state.yml +++ b/test/legacy/roles/scaleway_compute/tasks/state.yml @@ -384,3 +384,4 @@ that: - unexisting_image_check is not success - unexisting_image_check is not changed + - unexisting_image_check.msg == "Error in getting image this-image-does-not-exists on https://cp-{{scaleway_region}}.scaleway.com"