Repository navigation
fix(ec2): parse every network interface a launch declares (#455) - #558
Merged
Merged
Conversation
NetworkInterface.N.* was read for N=1 only, in both runInstances and createLaunchTemplate, and EC2Instance had no interface list to hold a second one — so a launch or a template declaring two interfaces was answered 200 and quietly became a one-interface instance. Both sites now parse all N by the indexedParams convention: contiguously from 1, stopping at the first missing index. Identity is keyed on DeviceIndex rather than the parameter index, which the reference defines as the position in the attachment order and does not require to agree with the position the request writes the interface at. RunInstances and DescribeInstances both report networkInterfaceSet — the RunInstances reference's own sample response carries it. The flat subnetId, privateIpAddress and groupSet continue to describe the primary interface, as real EC2 does, so an instance or launch-template version stored by an earlier substrate reads back with an empty slice and its flat fields still describe its one interface. Signed-off-by: Scott Friedman <[email protected]>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #455.
NetworkInterface.N.*was parsed for N=1 only, at both sites that read it —runInstancesandcreateLaunchTemplate— andEC2Instancehad no interface list tohold a second one. So a launch or a template declaring two interfaces was accepted,
answered
200, and quietly became a one-interface instance: no error, and nothing inthe response to reveal the loss. That is this release's shape, reached by a sixth
route.
What changed
Both sites parse all N, by the convention every other indexed list in the plugin
follows — contiguously from 1, stopping at the first missing index (
indexedParams),extended from a string per index to a struct per index. An index counts as present
when any of its members is, since a specification naming only
DeviceIndexandSubnetIdis as real as one naming ten, and requiring a chosen member would drop aninterface for spelling reasons.
Identity is keyed on
DeviceIndex, not the parameter index. The reference definesDeviceIndexas "the position of the network interface in the attachment order" anddoes not require it to agree with the position the request writes the interface at, so
NetworkInterface.1.DeviceIndex=3withNetworkInterface.2.DeviceIndex=0makes thesecond one primary. An implementation using the parameter index would name the wrong
interface primary and put the wrong subnet on the instance — verified live:
RunInstancesandDescribeInstancesnow reportnetworkInterfaceSet>item.That was decided from the reference rather than assumed: the
RunInstancessampleresponse carries the member, so a caller parsing the documented shape found it
missing. Reporting it on both means the interfaces a launch declared are readable back
without a follow-up describe.
The instance's flat
subnetId,privateIpAddressandgroupSetcontinue to describethe primary interface, which is what real EC2 puts at the top level — they are not
superseded by the new set.
AssociatePublicIpAddressis still honored only on theprimary, as the reference requires ("can only be assigned to a network interface for
eth0"); a secondary interface asking for a public IP is not a statement about the
instance's.
DeleteOnTerminationdefaults per the reference's reasoning rather than to one value:truefor an interface the launch creates,falsefor an existing one it attaches byNetworkInterfaceId, since deleting an interface the caller brought would destroysomething the launch did not make. An explicit value wins over either.
Replay
Both the instance and the launch-template shapes grew a slice, so both keep their flat
fields as the primary's values. An instance or a template version stored by an earlier
substrate reads back with an empty slice, and
ec2LTVersionData's single-interfacesynthesis from the flat fields still runs for it — so a replayed event log still
launches into the right subnet with the right groups and still describes its
networking rather than reporting an empty set over a record that plainly holds a
subnet.
TestEC2NetworkInterfaces_PreSliceTemplateStateStillWorkswrites that storedshape by hand, because
CreateLaunchTemplatecan no longer produce it — which is whatmakes it a migration gate rather than a round-trip.
Substrate's own choices
Recorded in
docs/services.md, since the API model does not decide them:PrivateIpAddressis given one derived from itsinstance index and device index, so every interface of every instance in a
multi-
Countlaunch has a distinct, replay-stable address a test can assert on. AWSrefuses a launch that names an address with a count above one; substrate does not,
so it has to make them differ.
CreateNetworkInterfaceis not modeled,so an interface exists only as part of the instance that declared it and an
eni-ID is minted for one the request did not name. A launch declaring no interface
reports an empty set rather than a synthesized phantom eth0.
status: in-useand attachmentstatus: attachedimmediately,because substrate's instances are already
runningwhenRunInstancesanswers; anattachingattachment would contradict the instance state reported beside it.Tests
16 tests in
emulator/ec2_network_interfaces_test.go, asserting on the wire XMLrather than the stored record — an interface substrate parses and stores but does not
report is a write with no observable, which is the defect shape this release is about.
The gate was proven both ways: with the four source files at
HEAD, 13 of 16 fail;the 3 that pass are the deliberate no-regression guards. The whole existing EC2 suite
passes unedited, which is what proves the index-1 path is unchanged.
Mutation testing: 24 mutants, 23 CAUGHT, 1 EQUIVALENT with a written proof, 0
survivors. Both mutants the plan named by name are caught by a single test each — the
parse loop not stopping at the first gap (
_GapStopsTheParse) andDeviceIndexignored in favour of the parameter index (
_DeviceIndexKeysIdentity). The equivalentone replaces
ec2PrimaryInterface's lowest-device-index comparison with "first entry":all three call sites sort ascending immediately before calling it, so
interfaces[0]is the lowest at every call and no observable distinguishes them. The comparison is
defense in depth against a future caller that does not sort, and the sort it leans on
is itself covered by a mutant that reverses it, caught by 8 tests.
networkInterfaceSetwas mutated out of each response builder separately, since atest that only reads one of them would not prove the other.
Verification
gofmt -l .,go build ./...,go vet ./...,golangci-lint run ./...→ 0issues,
make test(race) green,make docs-reference docs-reference-check docs-versionsclean (no plugin added, so the generated tables are unchanged),npm --prefix docs run build,go vet -C test/e2e ./...,go test -C test/e2e ./....Live against
substrate server: a two-interfacerun-instancesreports 2interfaces in both the
RunInstancesresponse anddescribe-instances(was 1), atwo-interface template describes both versions' interfaces and launches with both, a
brought ENI reports
DeleteOnTermination: falsebeside a created one'strue, and alaunch declaring none reports 0.
Compatibility
A test asserting that a multi-interface launch yields one interface, or that an
instance item has no
networkInterfaceSet, will go red — that is the fix.