Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: convert metal_port to equinix-sdk-go #709

Merged
merged 6 commits into from
Jul 8, 2024
Merged

feat: convert metal_port to equinix-sdk-go #709

merged 6 commits into from
Jul 8, 2024

Conversation

ctreatma
Copy link
Contributor

This replaces packngo with equinix-sdk-go in the metal_port resource and datasource as part of #402. While I'm in these files I also opted to move them into internal/resources/metal/port to align with #106.

@ctreatma ctreatma marked this pull request as ready for review June 25, 2024 15:09
@ctreatma ctreatma requested review from a team as code owners June 25, 2024 15:09
State: packngo.VLANAssignmentUnassigned,
vacr.VlanAssignments = append(vacr.VlanAssignments, metalv1.PortVlanAssignmentBatchCreateInputVlanAssignmentsInner{
Vlan: &v,
State: metalv1.PORTVLANASSIGNMENTBATCHVLANASSIGNMENTSINNERSTATE_UNASSIGNED.Ptr(),
Copy link
Member

@displague displague Jun 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:cough:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤷

@@ -127,20 +130,20 @@ func resourceMetalPort() *schema.Resource {

func resourceMetalPortUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
start := time.Now()
cpr, _, err := getClientPortResource(d, meta)
cpr, _, err := getClientPortResource(ctx, d, meta)
if err != nil {
return diag.FromErr(equinix_errors.FriendlyError(err))
}

for _, f := range [](func(*ClientPortResource) error){
portSanityChecks,
Copy link
Member

@displague displague Jun 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm tempted to ask for a contextDisposal wrapper so that this one function can fit the pattern, accept a context, and noop the supplied context.

The other functions wouldn't need to be created with a context and context would be supplied at time of use.

something like:

func contextDisposal(f func(*ClientPortResource) error) func(_ context.Context, *ClientPortResource) error){
  return func(_ context.Context, *ClientPortResource) error) {
    return f
  }
}
	for _, f := range [](func(context.Context, *ClientPortResource) error){
		contextDisposal(portSanityChecks),
... (the other lines would not change, so function names without arguments)
	} {
		if err := f(ctx, cpr); err != nil {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A wrapper function wouldn't be sufficient here because the existing function bodies need to be updated to reference the context. Instead I updated the various helper functions to accept a context and a ClientPortResource so that the PR diff is easier to parse.

@displague
Copy link
Member

displague commented Jun 27, 2024

There were a few tests that failed that seem related to the changes in this PR, seemingly around VLANs not being able to be removed because of active port links.

=== NAME  TestAccMetalPort_L2IndividualNativeVlan
    resource_test.go:271: Step 2/3 error: Error running apply: exit status 1
        
        Error: Error deleting Vlan
        
        API Error HTTP 422 Cannot delete Virtual Network when port is assigned
        
        Error: Error deleting Vlan
        
        API Error HTTP 422 Cannot delete Virtual Network when port is assigned
2024/06/25 16:29:20 [DEBUG] GET https://api.equinix.com/metal/v1/virtual-networks/60307dc8-4cf6-43ed-9c18-1453885b5efc?include=instances%2Cmeta_gateway
2024/06/25 16:29:20 [DEBUG] GET https://api.equinix.com/metal/v1/virtual-networks/cbc18c7a-0471-456e-9b7e-79b5f1556b29?include=instances%2Cmeta_gateway
2024/06/25 16:29:20 [DEBUG] DELETE https://api.equinix.com/metal/v1/virtual-networks/60307dc8-4cf6-43ed-9c18-1453885b5efc
2024/06/25 16:29:20 [DEBUG] DELETE https://api.equinix.com/metal/v1/virtual-networks/cbc18c7a-0471-456e-9b7e-79b5f1556b29
    panic.go:626: Error running post-test destroy, there may be dangling resources: exit status 1
        
        Error: Error deleting Vlan
        
        API Error HTTP 422 Cannot delete Virtual Network when port is assigned
        
        Error: Error deleting Vlan
        
        API Error HTTP 422 Cannot delete Virtual Network when port is assigned
--- FAIL: TestAccMetalPort_L2IndividualNativeVlan (169.56s)
=== NAME  TestAccMetalPortUpdate_hybridBonded_timeout
    resource_test.go:468: Step 2/5, expected an error with pattern, no match on: Error running apply: exit status 1
        
        Error: Error deleting Vlan
        
        API Error HTTP 422 Cannot delete Virtual Network when port is assigned
2024/06/25 16:29:41 [DEBUG] GET https://api.equinix.com/metal/v1//ports/1b8a98c6-a5e7-4a10-9dec-80bbf2cb9e24?include=native_virtual_network%2Cvirtual_networks
2024/06/25 16:29:42 [DEBUG] GET https://api.equinix.com/metal/v1/virtual-networks/26137bca-de21-4189-891b-fe1a68ec8315?include=instances%2Cmeta_gateway
2024/06/25 16:29:42 [DEBUG] GET https://api.equinix.com/metal/v1//devices/e14bc454-2323-4221-9952-adbc74b1909d?include=project
2024/06/25 16:29:42 [DEBUG] GET https://api.equinix.com/metal/v1//devices/18a5804a-4092-49f9-8e9c-0d05245d8517?include=project
2024/06/25 16:29:42 [DEBUG] DELETE https://api.equinix.com/metal/v1/virtual-networks/26137bca-de21-4189-891b-fe1a68ec8315
2024/06/25 16:29:42 [DEBUG] GET https://api.equinix.com/metal/v1//ports/b26c7481-205a-4324-b3c3-ac3baf469345/vlan-assignments/batches/4eca37a4-6a23-4f0b-9b6f-b304d0c26f99
    panic.go:626: Error running post-test destroy, there may be dangling resources: exit status 1
        
        Error: Error deleting Vlan
        
        API Error HTTP 422 Cannot delete Virtual Network when port is assigned
--- FAIL: TestAccMetalPortUpdate_hybridBonded_timeout (191.27s)
 === NAME  TestAccMetalPort_L2Bonded
    resource_test.go:304: Step 4/5 error: After applying this test step, the non-refresh plan was not empty.
        stdout:
        
        
        Terraform used the selected providers to generate the following execution
        plan. Resource actions are indicated with the following symbols:
          ~ update in-place
        
        Terraform will perform the following actions:
        
          # equinix_metal_port.bond0 will be updated in-place
          ~ resource "equinix_metal_port" "bond0" {
                id                = "04d7e48a-719b-4bfc-91ef-58a0a834575a"
              - layer2            = true -> null
                name              = "bond0"
                # (7 unchanged attributes hidden)
            }
        
        Plan: 0 to add, 1 to change, 0 to destroy.
2024/06/25 16:29:55 [DEBUG] DELETE https://api.equinix.com/metal/v1//devices/f036932d-1f2e-4c91-a28f-2a7fd68c1f08?force_delete=false
2024/06/25 16:29:56 [DEBUG] GET https://api.equinix.com/metal/v1//devices/e356ff68-6012-404a-a9df-82482b0aa19f?include=project
2024/06/25 16:29:57 [DEBUG] DELETE https://api.equinix.com/metal/v1//projects/d9fbd4ae-530e-4696-92f4-60ad27d45941
2024/06/25 16:29:57 [DEBUG] GET https://api.equinix.com/metal/v1//ports/b26c7481-205a-4324-b3c3-ac3baf469345/vlan-assignments/batches/4eca37a4-6a23-4f0b-9b6f-b304d0c26f99
--- FAIL: TestAccMetalPort_L2Bonded (206.86s)
=== NAME  TestAccMetalPort_hybridBondedVxlan
    resource_test.go:242: Step 2/3 error: Error running apply: exit status 1
        
        Error: Error deleting Vlan
        
        API Error HTTP 422 Cannot delete Virtual Network when port is assigned
        
        Error: Error deleting Vlan
        
        API Error HTTP 422 Cannot delete Virtual Network when port is assigned
2024/06/25 16:30:05 [DEBUG] GET https://api.equinix.com/metal/v1//devices/2bd0b86a-f5b6-4e7c-b399-f6d19470b23e?include=project
2024/06/25 16:30:05 [DEBUG] GET https://api.equinix.com/metal/v1/virtual-networks/d5894c5f-3079-4a80-bf52-254f45bae88e?include=instances%2Cmeta_gateway
2024/06/25 16:30:05 [DEBUG] GET https://api.equinix.com/metal/v1/virtual-networks/7cfa7c38-ca36-4a93-9ca0-30f33dec9b65?include=instances%2Cmeta_gateway
2024/06/25 16:30:05 [DEBUG] DELETE https://api.equinix.com/metal/v1/virtual-networks/d5894c5f-3079-4a80-bf52-254f45bae88e
2024/06/25 16:30:05 [DEBUG] DELETE https://api.equinix.com/metal/v1/virtual-networks/7cfa7c38-ca36-4a93-9ca0-30f33dec9b65
    panic.go:626: Error running post-test destroy, there may be dangling resources: exit status 1
        
        Error: Error deleting Vlan
        
        API Error HTTP 422 Cannot delete Virtual Network when port is assigned
        
        Error: Error deleting Vlan
        
        API Error HTTP 422 Cannot delete Virtual Network when port is assigned
--- FAIL: TestAccMetalPort_hybridBondedVxlan (215.04s)
=== NAME  TestAccMetalPortCreate_hybridBonded_timeout
    resource_test.go:427: Step 5/5 error: Error running destroy: exit status 1
        
        Error: Error deleting Vlan
        
        API Error HTTP 422 Cannot delete Virtual Network when port is assigned
2024/06/25 16:30:40 [DEBUG] GET https://api.equinix.com/metal/v1/virtual-networks/f986ad39-9f22-43f7-9e11-fb62b3d3a95d?include=instances%2Cmeta_gateway
2024/06/25 16:30:40 [DEBUG] GET https://api.equinix.com/metal/v1//ports/464a0808-d9ae-4e7a-a193-a8a45392b38d?include=native_virtual_network%2Cvirtual_networks
2024/06/25 16:30:40 [DEBUG] DELETE https://api.equinix.com/metal/v1/virtual-networks/f986ad39-9f22-43f7-9e11-fb62b3d3a95d
    panic.go:626: Error running post-test destroy, there may be dangling resources: exit status 1
        
        Error: Error deleting Vlan
        
        API Error HTTP 422 Cannot delete Virtual Network when port is assigned
--- FAIL: TestAccMetalPortCreate_hybridBonded_timeout (249.68s)
=== NAME  TestAccMetalPort_hybridBonded
    resource_test.go:304: Step 3/5 error: Error running apply: exit status 1
        
        Error: Error deleting Vlan
        
        API Error HTTP 422 Cannot delete Virtual Network when port is assigned
2024/06/25 16:33:02 [DEBUG] GET https://api.equinix.com/metal/v1//devices/e356ff68-6012-404a-a9df-82482b0aa19f?include=project
2024/06/25 16:33:02 [DEBUG] GET https://api.equinix.com/metal/v1/virtual-networks/ab45d0f3-d739-43c3-a342-b24c07668228?include=instances%2Cmeta_gateway
2024/06/25 16:33:03 [DEBUG] DELETE https://api.equinix.com/metal/v1/virtual-networks/ab45d0f3-d739-43c3-a342-b24c07668228
    panic.go:626: Error running post-test destroy, there may be dangling resources: exit status 1
        
        Error: Error deleting Vlan
        
        API Error HTTP 422 Cannot delete Virtual Network when port is assigned
--- FAIL: TestAccMetalPort_hybridBonded (245.36s)

@displague
Copy link
Member

TestAccMetalPortCreate_hybridBonded_timeout was also present in #713, but not the others

@ctreatma
Copy link
Contributor Author

There were a few tests that failed that seem related to the changes in this PR, seemingly around VLANs not being able to be removed because of active port links.

This PR was, until recently, a WIP, but I left it out of draft out of laziness (have to click a whole button to run CI for a draft PR branch) and neglected to update the PR title. In any case, it is no longer a WIP and the tests should be passing as of now.

@codecov-commenter
Copy link

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

Attention: Patch coverage is 2.75862% with 141 lines in your changes missing coverage. Please review.

Project coverage is 34.39%. Comparing base (503d9e1) to head (3ecc54f).
Report is 84 commits behind head on main.

Files Patch % Lines
internal/resources/metal/port/helpers.go 0.00% 89 Missing ⚠️
internal/resources/metal/port/resource.go 1.88% 52 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #709      +/-   ##
==========================================
- Coverage   37.91%   34.39%   -3.52%     
==========================================
  Files         120      151      +31     
  Lines       19476    20640    +1164     
==========================================
- Hits         7384     7100     -284     
- Misses      11884    13378    +1494     
+ Partials      208      162      -46     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ctreatma ctreatma requested a deployment to internal July 3, 2024 20:33 — with GitHub Actions Abandoned
@ctreatma ctreatma merged commit f8c2ab9 into main Jul 8, 2024
6 checks passed
@ctreatma ctreatma deleted the port-refactor branch July 8, 2024 16:22
ctreatma added a commit that referenced this pull request Oct 23, 2024
Some packngo usage was missed in #709. This completely removes packngo
from metal_port, as well as calls to `FriendlyError` because that
function has no impact for non-packngo errors.
srushti-patl pushed a commit that referenced this pull request Oct 28, 2024
Some packngo usage was missed in #709. This completely removes packngo
from metal_port, as well as calls to `FriendlyError` because that
function has no impact for non-packngo errors.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants