Repository navigation
fix(ec2): a launch materializes the volumes its block device mappings describe (#666) - #668
Merged
Merged
Conversation
… describe (#666) RunInstances read thirteen parameter groups and none of them was a block device mapping, so BlockDeviceMapping.1.Ebs.VolumeSize=60 was accepted and discarded and DescribeVolumes reported nothing for the instance. The value was not merely hidden, it was unreachable: AWS's EbsInstanceBlockDevice carries no size member, so DescribeVolumes is the only API surface on which a launch-specified size is observable. A launch now writes real EC2Volume records to the same store CreateVolume writes to, attached to the new instance. TerminateInstances settles them, which is what made the parsing safe to land — otherwise a volume would report deleteOnTermination=true while sitting in-use on a terminated instance forever. Closes #666
Codecov Report❌ Patch coverage is
📢 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.
RunInstancesacceptedBlockDeviceMapping.N.*and parsed none of it.runInstancesWithTagsread thirteen parameter groups and no block device mapping wasamong them, so a request naming a 60 GiB
/dev/xvdaroot volume succeeded andDescribeVolumesreported nothing for the instance — substrate silently accepting aparameter it did not model, the shape #97 exists to remove.
The value was not merely hidden, it was unreachable. AWS's
EbsInstanceBlockDevice— the shape an instance renders per device — carriesvolumeId,attachTime,deleteOnTerminationandstatus, but no size. SoDescribeVolumesis the only API surface on which a launch-specified size can beobserved at all, which is why exposing
blockDeviceMappingonDescribeInstanceswould not have closed this.
What changed
A launch now materializes real
EC2Volumerecords in the samevolume:namespaceCreateVolumewrites to, each attached to the new instance, soDescribeVolumesisthe single source of truth for provisioned and launch-created volumes alike — how
real EC2 unifies the two.
emulator/ec2_block_devices.go(new) — the parser and the materializer.ec2ParseBlockDeviceMappings(params, prefix)followsec2ParseNetworkInterfaces'idiom exactly: 1-indexed, contiguous, terminating on a
presentbool that ORsevery member, with the
prefixargument that lets one parser serveRunInstances(
"") andCreateLaunchTemplate("LaunchTemplateData.").TerminateInstancesdeletes a volume whose attachmentdeletes on termination and makes one that does not
availablewith no attachment.This half is what made the parsing safe to land: without it a volume would report
deleteOnTermination=truewhile sittingin-useon a terminated instance forever— a state real EC2 never reaches, a new inaccuracy in place of the old silence.
iopsandthroughputreach the wire.EC2Volumealready storedIOPSandnever rendered it;
Throughputhad nowhere to be stored.DescribeVolumesgained six filters —attachment.device,attachment.delete-on-termination,volume-type,size,availability-zone,snapshot-id— beside the three it had. Each is one the reference documents, andeach is a question the new state makes answerable.
AttachVolumesets and rendersdeleteOnTermination: falseexplicitly.ec2_fleet.goneeded no change becauseCreateFleetforwards the templatereference rather than the caller's own parameters.
The two decisions, and the evidence
Every launch produces at least one volume. A real instance always has a root
volume whether or not the request mentions one, and
DescribeImagesalready reportedan 8 GiB
/dev/sda1mapping for every AMI substrate serves, so producing none leftthe two disagreeing about the same instance. Root devices are recognized by name:
/dev/sda1and/dev/xvda, the two spellings AWS's device-naming reference givesfor the HVM root ("Differs by AMI"). Recognizing only
/dev/sda1would have answeredthis issue's own
/dev/xvdarepro with two volumes — a 60 GiB one plus a spurious8 GiB root.
DeleteOnTerminationdefaults totruefor data volumes too. Counter-intuitive,and AWS's documented behaviour: the
preserving-volumes-on-terminationtable splitson how the volume was attached, not on what it is — a data volume attached at
launch through the console preserves, but through the CLI it is deleted, and
an API emulator is the CLI path.
AttachVolumekeeps the other default,false.Two things AWS does not settle, recorded rather than papered over:
EbsBlockDevicedocuments no
VolumeTypedefault (substrate usesgp2, matchingCreateVolume, sothere is one default in one place — real AMIs specify
gp3in a mapping substrate'sAMIs do not carry); and
EC2Imagestores no per-AMI root device, so an AMI whosereal root device is neither documented spelling is out of reach, which
docs/services.mdnow says.
Deliberately out of scope
blockDeviceMappingonDescribeInstances/DescribeInstanceAttribute(the shapecarries no size, so it would not answer the question this does);
Ebs.KmsKeyId(leftout rather than stored and hidden); volume tag specifications, which are a
CreateVolumeparity gap; andInvalidBlockDeviceMappingvalidation, which neededthis state to exist first. Follow-ups filed against v0.104.0.
Verification
gofmt -l .,go build ./...,go vet ./...,golangci-lint run ./...(0 issues),make test(race),make coverage(82.1% total,emulator82.7%),make docs-reference-check docs-versions,npm --prefix docs run build,go vet -C test/e2e ./... && go test -C test/e2e ./...— all green.New tests.
emulator/ec2_block_devices_test.gocovers the parser and materializerin isolation (25 cases).
emulator/ec2_block_devices_http_test.gocovers ninescenarios through HTTP, unmarshalling the response into a struct rather than searching
the body for
vol-— the existing volume tests'strings.Indexidiom cannot tell twovolumes apart, and a launch now routinely produces two.
test/e2e/journey_ec2_block_devices_test.gois the tier this was reported from, and
test/e2ehad no EBS coverage at all; it goesthrough the real SDK, because
BlockDeviceMappingsis a structured input the SDKserializes itself, so a hand-built form body proves only that substrate parses the
spelling the test's author chose.
Mutation pass, nine targets, full-package
go test -raceper mutant with agofmt/go vetgate: 8 CAUGHT, 1 EQUIVALENT, 0 survivors that matter.ec2LaunchVolumesForreturns nil (the bug itself)DeleteOnTerminationdefaults tofalse/dev/sda1region+"a"terminateInstancesdeletes every attached volume regardless of the flag"pricing"maps toerrProtoQueryXML(#653's guard)volume_idsindex is not cleaned on terminationThe EQUIVALENT one, disclosed rather than glossed:
volume_idsis a write-onlyindex.
createVolumeand the new launch path append to it anddeleteVolumeremovesfrom it, but nothing reads it —
describeVolumeslists thevolume:key prefixdirectly. So no API observation can distinguish the mutant, and no test can catch it
without asserting on state rather than behaviour. The removal call stays because
deleteVolumemakes it, and a stale entry would become wrong the moment somethingdoes read it. (A test comment claiming the index was what the assertion proved has
been corrected to say what it actually proves: the record left the namespace
DescribeVolumeslists.)Live run through the AWS CLI on
:4678, the issue's repro verbatim:And the data-volume path, showing the synthesized root beside it and the performance
members on the wire:
after terminate, the preserved one alone:
vol-45f7b9d0… 100 available 0 attachments.Compatibility
DescribeVolumesnow returns volumes for launched instances. A fixture thatlisted all volumes and expected only what it created with
CreateVolumewill see aroot volume per instance — filter by
volume-idorattachment.instance-idfor theold answer.
TerminateInstancesnow deletes those volumes; a fixture that terminatedan instance and then read a volume attached at launch will find it gone unless it set
DeleteOnTermination: false. A volume attached after launch is untouched bytermination, per AWS.
Closes #666