Skip to content

Commit 9607e6f

Browse files
author
Guénaël Pépin
committed
fix(scaleway): use organization parameter, remove check_image_id, fix until for Ansible 12+
1 parent 3542a17 commit 9607e6f

3 files changed

Lines changed: 13 additions & 47 deletions

File tree

library/scaleway_compute.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -167,19 +167,6 @@
167167
SCALEWAY_TRANSITIONS_STATES = ("stopping", "starting", "pending")
168168

169169

170-
def check_image_id(compute_api, image_id):
171-
response = compute_api.get(path="images")
172-
173-
if response.ok and response.json:
174-
image_ids = [image["id"] for image in response.json["images"]]
175-
if image_id not in image_ids:
176-
compute_api.module.fail_json(
177-
msg="Error in getting image %s on %s" % (image_id, compute_api.module.params.get("api_url"))
178-
)
179-
else:
180-
compute_api.module.fail_json(msg="Error in getting images from: %s" % compute_api.module.params.get("api_url"))
181-
182-
183170
def fetch_state(compute_api, server):
184171
compute_api.module.debug("fetch_state of server: %s" % server["id"])
185172
response = compute_api.get(path="servers/%s" % server["id"])
@@ -634,9 +621,6 @@ def core(module):
634621

635622
compute_api = Scaleway(module=module)
636623

637-
if wished_server["state"] != "absent":
638-
check_image_id(compute_api, wished_server["image"])
639-
640624
# IP parameters of the wished server depends on the configuration
641625
ip_payload = public_ip_payload(compute_api=compute_api, public_ip=module.params["public_ip"])
642626
wished_server.update(ip_payload)

roles/cloud-scaleway/tasks/main.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
boot_type: local
3434
state: present
3535
image: "{{ scaleway_image_id }}"
36-
project: "{{ algo_scaleway_org_id }}"
36+
organization: "{{ algo_scaleway_org_id }}"
3737
region: "{{ algo_region }}"
3838
commercial_type: "{{ cloud_providers.scaleway.size }}"
3939
wait: true
@@ -60,15 +60,15 @@
6060
boot_type: local
6161
state: running
6262
image: "{{ scaleway_image_id }}"
63-
project: "{{ algo_scaleway_org_id }}"
63+
organization: "{{ algo_scaleway_org_id }}"
6464
region: "{{ algo_region }}"
6565
commercial_type: "{{ cloud_providers.scaleway.size }}"
6666
wait: true
6767
tags:
6868
- Environment:Algo
6969
- AUTHORIZED_KEY={{ lookup('file', SSH_keys.public) | regex_replace(' ', '_') }}
7070
register: algo_instance
71-
until: algo_instance.msg.public_ip
71+
until: algo_instance.msg.public_ip is not none
7272
retries: 3
7373
delay: 3
7474

tests/unit/test_scaleway_fix.py

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,34 +20,21 @@ def load_yaml_file(file_path):
2020
return yaml.safe_load(f)
2121

2222

23-
def test_scaleway_main_uses_project_parameter():
24-
"""Test that main.yml uses 'project' instead of deprecated 'organization' parameter"""
23+
def test_scaleway_main_uses_organization_parameter():
24+
"""Test that main.yml uses 'organization' parameter (custom module, not community.general)"""
2525
main_yml = Path("roles/cloud-scaleway/tasks/main.yml")
2626
assert main_yml.exists(), "Scaleway main.yml not found"
2727

2828
with open(main_yml) as f:
2929
content = f.read()
3030

31-
# Should NOT use the broken scaleway_organization_info module
32-
assert "scaleway_organization_info" not in content, (
33-
"Still using broken scaleway_organization_info module (issue #14846)"
34-
)
35-
36-
# Should NOT use the broken scaleway_image_info module
31+
assert "scaleway_organization_info" not in content, "Still using broken scaleway_organization_info module"
3732
assert "scaleway_image_info" not in content, "Still using broken scaleway_image_info module"
38-
39-
# Should use project parameter (modern approach)
40-
assert "project:" in content, "Missing 'project:' parameter in scaleway_compute calls"
33+
assert "organization:" in content, "Missing 'organization:' parameter in scaleway_compute calls"
4134
assert "algo_scaleway_org_id" in content, "Missing algo_scaleway_org_id variable reference"
35+
assert "project:" not in content, "Using unsupported 'project' parameter (not in custom module)"
4236

43-
# Should NOT use deprecated organization parameter
44-
assert 'organization: "{{' not in content, "Still using deprecated 'organization' parameter"
45-
46-
# Should use Marketplace API v2 for image lookup
47-
assert "api.scaleway.com/marketplace/v2" in content, "Not using Scaleway Marketplace API v2 for image lookup"
48-
assert "api-marketplace.scaleway.com" not in content, "Still using deprecated api-marketplace.scaleway.com domain"
49-
50-
print("✓ Scaleway main.yml uses modern 'project' parameter")
37+
print("✓ Scaleway main.yml uses 'organization' parameter")
5138

5239

5340
def test_scaleway_prompts_collect_org_id():
@@ -93,31 +80,26 @@ def test_scaleway_config_has_valid_settings():
9380

9481

9582
def test_scaleway_marketplace_api_usage():
96-
"""Test that the role correctly uses Scaleway Marketplace API v2"""
83+
"""Test that the role correctly uses Scaleway Marketplace API v2 for image lookup"""
9784
main_yml = Path("roles/cloud-scaleway/tasks/main.yml")
9885

9986
with open(main_yml) as f:
10087
content = f.read()
10188

102-
# Should use uri module to fetch from Marketplace API v2
10389
assert "uri:" in content, "Not using uri module for API calls"
104-
105-
# Should use local-images endpoint with image_label
90+
assert "marketplace/v2" in content, "Not using Marketplace API v2"
10691
assert "local-images" in content, "Not using local-images endpoint"
10792
assert "image_label" in content, "Not using image_label parameter"
108-
109-
# Should filter for instance_local type
11093
assert "instance_local" in content, "Not filtering for instance_local image type"
111-
112-
# Should set scaleway_image_id variable
11394
assert "scaleway_image_id" in content, "Missing scaleway_image_id variable for image UUID"
95+
assert "instance/v1" not in content, "Still using Instance API v1 for image lookup"
11496

11597
print("✓ Scaleway role uses Marketplace API v2 correctly")
11698

11799

118100
if __name__ == "__main__":
119101
tests = [
120-
test_scaleway_main_uses_project_parameter,
102+
test_scaleway_main_uses_organization_parameter,
121103
test_scaleway_prompts_collect_org_id,
122104
test_scaleway_config_has_valid_settings,
123105
test_scaleway_marketplace_api_usage,

0 commit comments

Comments
 (0)