Skip to content

ESD-1615: add matrix-aware NAT gateway speed/session validation#507

Merged
Phil-Browne merged 3 commits into
mainfrom
esd-1615-nat-gateway-matrix-validation
Jul 10, 2026
Merged

ESD-1615: add matrix-aware NAT gateway speed/session validation#507
Phil-Browne merged 3 commits into
mainfrom
esd-1615-nat-gateway-matrix-validation

Conversation

@Phil-Browne

Copy link
Copy Markdown
Contributor

NAT gateway create only checked that speed and session count were positive, so an unsupported speed/session combination reached the API instead of failing pre-flight. This bumps megaportgo to v1.15.0 and uses its NATGatewaySpeedSessionSupported helper to check the pair against the live availability matrix before ordering, listing the valid speeds and session counts if it's rejected.

  • Fetch the matrix via ListNATGatewaySessions and validate the requested speed/session pair against it in nat-gateway create
  • Fail open on a matrix fetch failure or empty matrix (the API still enforces the rule at order time), matching the Terraform provider's handling
  • Add stub mock methods for the new MCR ping/traceroute interface methods that came in with the same SDK bump, so mcr keeps compiling (the commands themselves are ESD-1614)

Bump megaportgo to v1.15.0 for NATGatewaySpeedSessionSupported and use it
in nat-gateway create to reject unsupported speed/session pairs before
ordering, listing the valid speeds and session counts from the matrix.
A matrix fetch failure or empty matrix fails open, matching the Terraform
provider's handling, since the API still enforces the rule at order time.

Also adds stub mock methods for the new MCRLookingGlassService ping/
traceroute interface methods introduced in the same SDK release, so the
mcr package keeps compiling; implementing those commands is ESD-1614.
Copilot AI review requested due to automatic review settings July 8, 2026 14:07
@Phil-Browne Phil-Browne requested review from a team and penzeliz-megaport as code owners July 8, 2026 14:07
@Phil-Browne Phil-Browne requested a review from mp1-tomclancy July 8, 2026 14:07
@codecov

codecov Bot commented Jul 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.53%. Comparing base (85c4a85) to head (0eba9d5).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #507   +/-   ##
=======================================
  Coverage   78.52%   78.53%           
=======================================
  Files         192      192           
  Lines       18474    18493   +19     
=======================================
+ Hits        14507    14523   +16     
- Misses       2902     2904    +2     
- Partials     1065     1066    +1     
Files with missing lines Coverage Δ
...ternal/commands/nat_gateway/nat_gateway_actions.go 81.79% <100.00%> (+0.96%) ⬆️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds pre-flight validation for NAT Gateway create so unsupported speed/session-count combinations are rejected client-side (using the SDK’s matrix-aware helper) before an order is sent to the API, while still “failing open” if the availability matrix can’t be fetched.

Changes:

  • Validate requested speed + session-count against the live NAT Gateway availability matrix during nat-gateway create, returning a validation error that lists supported values when rejected.
  • Add unit tests covering matrix rejection (unsupported speed or session count), acceptance (supported pair), and fail-open behavior on matrix fetch failure.
  • Bump github.com/megaport/megaportgo to v1.15.0 and add stub methods to the MCR looking glass mock to match the updated SDK interfaces.

Reviewed changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
internal/commands/nat_gateway/nat_gateway_actions.go Adds matrix-aware speed/session validation during NAT Gateway create (fail-open on fetch/empty).
internal/commands/nat_gateway/nat_gateway_test.go Adds tests for matrix validation behavior (reject/allow/fail-open).
internal/commands/mcr/mcr_mock.go Adds stub methods for new SDK MCR looking glass ping/traceroute interfaces to keep tests/build green.
go.mod Bumps megaportgo dependency to v1.15.0.
go.sum Updates checksums for the megaportgo v1.15.0 bump.

Comment thread internal/commands/nat_gateway/nat_gateway_actions.go
@Phil-Browne Phil-Browne merged commit 34f86a0 into main Jul 10, 2026
10 checks passed
@Phil-Browne Phil-Browne deleted the esd-1615-nat-gateway-matrix-validation branch July 10, 2026 00:15
@penzeliz-megaport

Copy link
Copy Markdown
Collaborator

Reviewed this together with #506/#508/#493 as part of a broader pass. Solid fix overall, and nice catch by the earlier reviewer on the SessionCount == 0 boundary.

One gap I want to flag explicitly: validateNATGatewaySpeedSessionMatrix (nat_gateway_actions.go:114) is only called from CreateNATGateway (nat_gateway_actions.go:64). UpdateNATGateway (nat_gateway_actions.go:245) also accepts --speed/--session-count changes via the update flags but never calls the validator, so:

nat-gateway update <uid> --speed 5000 --session-count 99

still sails past client-side checks straight to the API — the same class of "unsupported speed/session combination reached the API" issue this PR's description says it's closing, just still open on the update path.

Do you want to pull the validation into UpdateNATGateway here, or would you rather ship this as-is (scoped to create) and track update in a follow-up ticket? Happy either way, just want it to be a conscious call rather than an oversight.

@Phil-Browne

Copy link
Copy Markdown
Contributor Author

Reviewed this together with #506/#508/#493 as part of a broader pass. Solid fix overall, and nice catch by the earlier reviewer on the SessionCount == 0 boundary.

One gap I want to flag explicitly: validateNATGatewaySpeedSessionMatrix (nat_gateway_actions.go:114) is only called from CreateNATGateway (nat_gateway_actions.go:64). UpdateNATGateway (nat_gateway_actions.go:245) also accepts --speed/--session-count changes via the update flags but never calls the validator, so:

nat-gateway update <uid> --speed 5000 --session-count 99

still sails past client-side checks straight to the API — the same class of "unsupported speed/session combination reached the API" issue this PR's description says it's closing, just still open on the update path.

Do you want to pull the validation into UpdateNATGateway here, or would you rather ship this as-is (scoped to create) and track update in a follow-up ticket? Happy either way, just want it to be a conscious call rather than an oversight.

Submitting a follow-up PR shortly, thanks!

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