equinix-labs / ansible-collection-equinix

Ansible content to help automate the management of Equinix resources
https://deploy.equinix.com/labs/ansible-collection-equinix/
GNU General Public License v3.0
2 stars 8 forks source link

feat: metal virtual circuit #141

Closed antoninrykalsky closed 3 months ago

antoninrykalsky commented 7 months ago

Fixes #70 Fixes #33

t0mk commented 7 months ago

@antoninrykalsky Thanks for the PR. We will wait for an Interconnection to test this properly.

displague commented 4 months ago

Heads up that there is an upcoming requirement for VLAN in the requests: https://feedback.equinixmetal.com/changelog/virtual-circuits-will-require-vlans-on-feb-29-2024

Since this PR allows for vlan to be defined (as nni_vlan, vlan_id, also vrf_id), it is fine that the user will receive a 422 from the API server prompting them to add vlan in their Ansible configuration.

displague commented 4 months ago

The e2e tests would be possible, reusing the same dedicated connection used by Terraform e2e testing. We are a little worried about racing between the two tests. This may not be problematic if Terraform created VCs on the dedicated connection have no impact on Ansible created VCs (resources are swept accordingly by name prefixes, and VC quantity is not impacted by parallel test runners). We can probably run with this and approach and keep an eye out for test failures as described.

@ctreatma suggested that we could make this test conditional based on a dedicated connection environment variable being defined, ANSIBLE_ACC_METAL_DEDICATED_CONNECTION_ID, perhaps. I've defined this variable as a GitHub Action Repository secret. This project's E2E runner should be able to access it.

Alternatively, dedicated connection mocks would be helpful here because dedicated connections have harder setup requirements and we don't want to accidentally delete them or misconfigure them.

displague commented 4 months ago

I'd like to be able to include this in the v0.4.0 release in the next few weeks.

displague commented 4 months ago

Error in metal_virtual_circuit: No match found when deserializing the JSON string into VirtualCircuitCreateInput with oneOf schemas: VlanVirtualCircuitCreateInput, VrfVirtualCircuitCreateInput.

Details:

  • 1 validation error for VlanVirtualCircuitCreateInput

    • nni_vlan value is not a valid integer (type=type_error.integer)
  • 4 validation errors for VrfVirtualCircuitCreateInput

    • nni_vlan value is not a valid integer (type=type_error.integer)
    • peer_asn none is not an allowed value (type=type_error.none.not_allowed)
    • subnet none is not an allowed value (type=type_error.none.not_allowed)
    • vrf none is not an allowed value (type=type_error.none.not_allowed)

https://github.com/equinix-labs/ansible-collection-equinix/pull/141/files#diff-f66d1a8381458f8e62c2cb40b979f693ae7697846f1b6cbe0edd4fcbc33c3421R71-R79

ansible-test integration metal_virtual_circuit
Running metal_virtual_circuit integration test role

PLAY [testhost] ****************************************************************

TASK [Gathering Facts] *********************************************************
ok: [testhost]

TASK [metal_virtual_circuit : set_fact] ****************************************
ok: [testhost]

TASK [metal_virtual_circuit : set_fact] ****************************************
ok: [testhost]

TASK [metal_virtual_circuit : set_fact] ****************************************
ok: [testhost]

TASK [metal_virtual_circuit : set_fact] ****************************************
ok: [testhost]

TASK [metal_virtual_circuit : set_fact] ****************************************
ok: [testhost]

TASK [metal_virtual_circuit : create first project for test] *******************
changed: [testhost]

TASK [metal_virtual_circuit : create connection for test] **********************
changed: [testhost]

TASK [metal_virtual_circuit : Display test_connection] *************************
ok: [testhost] => {
    "test_connection": {
        "changed": true,
        "contact_email": "marques+tfacctest@packet.com",
        "description": "My new VLAN",
        "failed": false,
        "id": "8a2e639f-7efa-43b7-a8d4-26b2b99e61f4",
        "metro": {
            "code": "am",
            "country": "NL",
            "id": "108b2cfb-246b-45e3-885a-bf3e82fce1a0",
            "name": "Amsterdam"
        },
        "mode": "standard",
        "name": "ansible-integration-test-project-ar-denfnszy-TestConn",
        "ports": [
            {
                "href": "/metal/v1/connections/8a2e639f-7efa-43b7-a8d4-26b2b99e61f4/ports/7cb170a3-c254-4b5d-8abd-508e7dc87562",
                "id": "7cb170a3-c254-4b5d-8abd-508e7dc87562",
                "link_status": "unknown",
                "name": "ansible-integration-test-project-ar-denfnszy-TestConn-primary",
                "organization": {
                    "href": "/metal/v1/organizations/e965d662-e182-4f84-a43b-ff16c5d320bd"
                },
                "role": "primary",
                "speed": 50000000,
                "status": "requested",
                "virtual_circuits": []
            }
        ],
        "redundancy": "primary",
        "requested_by": {
            "href": "/metal/v1/users/72fe6383-b41f-4373-9f67-4bd5ec9a74a7",
            "id": "72fe6383-b41f-4373-9f67-4bd5ec9a74a7"
        },
        "status": "pending",
        "tags": [],
        "type": "dedicated"
    }
}

TASK [metal_virtual_circuit : Display test_metro_id] ***************************
ok: [testhost] => {
    "test_metro_id": "VARIABLE IS NOT DEFINED!"
}

TASK [metal_virtual_circuit : create VLAN resource no.1] ***********************
changed: [testhost]

TASK [metal_virtual_circuit : Display test_vlan] *******************************
ok: [testhost] => {
    "test_vlan": {
        "changed": true,
        "description": "This is my new VLAN 1.",
        "failed": false,
        "id": "9573b1af-97c3-493b-a674-9bd026db01ed",
        "metro": {
            "href": "/metal/v1/locations/metros/108b2cfb-246b-45e3-885a-bf3e82fce1a0",
            "id": "108b2cfb-246b-45e3-885a-bf3e82fce1a0"
        },
        "vxlan": 1234
    }
}

TASK [metal_virtual_circuit : create first virtual circuit for test] ***********
An exception occurred during task execution. To see the full traceback, use -vvv. The error was:   none is not an allowed value (type=type_error.none.not_allowed)
fatal: [testhost]: FAILED! => {"changed": false, "msg": "Error in metal_virtual_circuit: No match found when deserializing the JSON string into VirtualCircuitCreateInput with oneOf schemas: VlanVirtualCircuitCreateInput, VrfVirtualCircuitCreateInput. Details: 1 validation error for VlanVirtualCircuitCreateInput\nnni_vlan\n  value is not a valid integer (type=type_error.integer), 4 validation errors for VrfVirtualCircuitCreateInput\nnni_vlan\n  value is not a valid integer (type=type_error.integer)\npeer_asn\n  none is not an allowed value (type=type_error.none.not_allowed)\nsubnet\n  none is not an allowed value (type=type_error.none.not_allowed)\nvrf\n  none is not an allowed value (type=type_error.none.not_allowed)"}

TASK [metal_virtual_circuit : Announce teardown start] *************************
ok: [testhost] => {
    "msg": "***** TESTING COMPLETE. COMMENCE TEARDOWN *****"
}

TASK [metal_virtual_circuit : list test projects] ******************************
ok: [testhost]

TASK [metal_virtual_circuit : delete test projects] ****************************
changed: [testhost] => (item={'backend_transfer_enabled': True, 'customdata': {}, 'description': '', 'id': '08f99f1a-ed09-4149-a16e-87f37665a423', 'name': 'ansible-integration-test-project-ar-denfnszy-project1', 'organization_id': 'e965d662-e182-4f84-a43b-ff16c5d320bd', 'payment_method_id': ''})

PLAY RECAP *********************************************************************
testhost                   : ok=15   changed=4    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   
displague commented 4 months ago

It should be possible to test reading in the virtual circuit returned by a shared interconnection.

t0mk commented 4 months ago

@displague Can you please check that ANSIBLE_ACC_METAL_DEDICATED_CONNECTION_ID was indeed set? Is it in the same "namespace" as the access token? We need to read it as envvar and it seems empty.

displague commented 4 months ago

https://github.com/equinix-labs/ansible-collection-equinix/actions/runs/8112585936/job/22174149489?pr=141#step:9:1974

TASK [metal_virtual_circuit : create first project for test] *******************
changed: [testhost]

TASK [metal_virtual_circuit : Display test_connection] *************************
ok: [testhost] => {
    "test_connection": "VARIABLE IS NOT DEFINED!"
}

TASK [metal_virtual_circuit : create VLAN resource no.1] ***********************
changed: [testhost]

TASK [metal_virtual_circuit : Display test_vlan] *******************************
ok: [testhost] => {
    "test_vlan": {
        "changed": true,
        "description": "This is my new VLAN 1.",
        "failed": false,
        "id": "6fbb33c1-bc30-45da-a04e-06f64c1ee388",
        "metro": {
            "href": "/metal/v1/locations/metros/108b2cfb-246b-45e3-885a-bf3e82fce1a0",
            "id": "108b2cfb-246b-45e3-885a-bf3e82fce1a0"
        },
        "vxlan": 1234
    }
}

TASK [metal_virtual_circuit : create first virtual circuit for test] ***********
fatal: [testhost]: FAILED! => {"changed": false, "msg": "Invalid UUID for connection_id: "}
displague commented 4 months ago

Needs a rebase @antoninrykalsky

displague commented 3 months ago
fatal: [testhost]: FAILED! => {"changed": false, "msg": "Error in metal_virtual_circuit: (422)\nReason: Unprocessable Entity\nHTTP response headers: HTTPHeaderDict({'Content-Type': 'application/json; charset=utf-8', 'X-Frame-Options': 'SAMEORIGIN', 'X-XSS-Protection': '1; mode=block', 'X-Content-Type-Options': 'nosniff', 'X-Download-Options': 'noopen', 'X-Permitted-Cross-Domain-Policies': 'none', 'Referrer-Policy': 'strict-origin-when-cross-origin', 'Cache-Control': 'no-cache', 'X-Request-Id': '9abf2fc49cfc86bab000d14dd78157e9', 'Strict-Transport-Security': 'max-age=15724800; includeSubDomains', 'Content-Length': '73', 'Date': 'Fri, 08 Mar 2024 13:01:21 GMT', 'Connection': 'close'})\nHTTP response body: {\"errors\":[\"Metro VLAN 9b5fdbb3-f0a8-492e-b7b8-a4d27b3a7087 not found.\"]}\n"}

Is this a flake or was the wrong VLAN ID referenced (or perhaps the wrong VLAN/VXLAN format?)

ctreatma commented 3 months ago

@antoninrykalsky the metal-python SDK was recently upgraded and this will need a rebase to pull in those changes. The upgraded SDK is able to differentiate between VLAN and VRF virtual circuits.

github-actions[bot] commented 3 months ago

This PR is included in version 0.6.0 :tada: