Skip to content

Commit

Permalink
set connection_id to id if it isn't provided, add test
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexBacho committed Sep 20, 2023
1 parent cc40e32 commit 4cbc965
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
11 changes: 7 additions & 4 deletions plugins/modules/metal_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@
""","""
- name: Fetch the connection
hosts: localhost
tasks:
tasks:
- equinix.cloud.metal_connection:
project_id: "Bhf47603-7a09-4ca1-af67-4087c13ab5b6"
name: "new connection"
Expand Down Expand Up @@ -323,12 +323,15 @@
def main():
module = EquinixModule(
argument_spec=SPECDOC_META.ansible_spec,
required_one_of=[("name", "connection_id"), ("project_id", "organization_id")],
required_one_of=[("name", "connection_id", "id"), ("project_id", "organization_id")],
)

vlans = module.params.get("vlans")
vlans = module.params.get("vlans")
connection_type = module.params.get("type")

if not module.params.get("connection_id") and module.params.get("id"):
module.params["connection_id"] = module.params["id"]


if connection_type == "dedicated":
if vlans:
module.fail_json(msg="A 'dedicated' connection can't have vlans.")
Expand Down
13 changes: 10 additions & 3 deletions tests/integration/targets/metal_connection/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,25 @@
project_id: "{{ project.id }}"
name: "{{ test_connection.name }}"
register: test_connection_fetched


- name: fetch existing connection using id
equinix.cloud.metal_connection:
project_id: "{{ project.id }}"
id: "{{ test_connection.id }}"
register: test_connection_fetched_with_id

- assert:
that:
- test_connection.name == "{{ test_name }}"
- test_connection.id == "{{ test_connection_fetched.id }}"

- test_connection.id == "{{ test_connection_fetched_with_id.id }}"

- name: list test connections
equinix.cloud.metal_connection_info:
project_id: "{{ project.id }}"
name: "{{ test_name }}"
register: test_connections_list

- assert:
that:
- "test_connections_list.resources | length >= 1"
Expand Down

0 comments on commit 4cbc965

Please sign in to comment.