Repository navigation
feat(ec2): a snapshot has a real size, and a nonexistent one is refused (#689) - #701
Merged
Merged
Conversation
…ed (#689) Substrate had no CreateSnapshot, and every snapshot it did hold — the ones CreateImage mints for an AMI's root device — recorded volumeSize as the literal 8. Two independent literals, in fact: createImage wrote one and describeImages rendered a second for the same snapshot. So every size-dependent rule was a comparison against a constant, which is why v0.105.0 deferred the rule that a mapping's size must not be smaller than its snapshot's. CreateSnapshot reads VolumeId (required, checked against state), Description and TagSpecification.N, and takes volumeSize and encrypted from the source volume. status is completed at once: substrate advances no snapshot asynchronously, so a waiter succeeds on its first poll rather than depending on wall-clock time. With a real size to compare against, a block device mapping naming a snapshot that does not exist is refused (InvalidSnapshotID.Malformed or InvalidSnapshot.NotFound), a size below the snapshot's is refused (InvalidBlockDeviceMapping), and a mapping naming a snapshot and no size inherits the snapshot's size instead of the 8 GiB default. CreateVolume had the identical gap independently and now applies both rules through the same comparison. CreateTags gains the snap- arm it was missing, so tagging a snapshot stops silently no-opping.
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.
Closes #689.
EC2Snapshot.VolumeSizewas the literal8, and substrate had noCreateSnapshotat all(
InvalidAction/ HTTP 400) — so the only snapshots it held were the onesCreateImagemints foran AMI's root device, all of them 8 GiB whatever the instance's root volume was. Every
size-dependent rule was therefore a comparison against a constant, which is precisely why v0.105.0
deferred the block-device-mapping rule that a size must not be smaller than its snapshot's, and why
#685's
volume-sizefilter had a single value to select on.Four changes, one theme: the constant
8becomes a real value, and a snapshot ID gets checked.CreateSnapshotVolumeIdis required and resolved against state through the existingec2VolumeIDKindmachinery:absent is
MissingParameter, a syntactically invalid ID isInvalidVolumeID.Malformed, one thatnames nothing is
InvalidVolume.NotFound— so a snapshot cannot exist for a volume that does not.volumeSizeandencryptedcome from the source volume rather than the request, which is what AWSdocuments ("the size of the volume, in GiB"; "snapshots that are taken from encrypted volumes are
automatically encrypted").
DescriptionandTagSpecification.Nare read, the tags through thesame walk and the same two rules as every other tag-on-create, checked before anything is
written.
The response element is
status, notstate— verified against theCreateSnapshotreference,whose documented values are
pending | completed | error | recoverable | recovering. It iscompletedat once, not thependingAWS's own sample shows: substrate advances no snapshotasynchronously, so a caller's waiter succeeds on its first poll rather than depending on wall-clock
time. A seedable
pending → completedprogression is the shape that would let a test exercise thewaiting path, and is a follow-up rather than nondeterministic behaviour.
LocationandOutpostArnare not read — both are documented as supported only for a Local Zone or an Outpost, neither of
which substrate models.
The two literal
8screateImagewrotevolumeSize: 8, anddescribeImagesrendered a second, independent literal8for the same snapshot in its ownebsmember (the one this issue does not mention). Twoconstants that agreed only for as long as neither knew a real size. Both now read the volume
record —
ec2InstanceRootVolumescans for the volume attached at a device passingec2IsRootDevice— so an AMI made from a 40 GiB root volume reports 40 GiB throughDescribeSnapshotsand throughDescribeImages. The snapshot also records the source volume'sID, which finally gives
DescribeSnapshots'volume-idfilter something to select on for the onlysnapshots substrate could previously produce. An AMI whose snapshot was since deleted falls back to
the 8 GiB default rather than reporting
0.The snapshot checks on a block device mapping
A mapping naming a snapshot was accepted unconditionally and materialized an 8 GiB volume, so a
launch real EC2 rejects succeeded here and left state a consumer then asserted against — the same
class of defect #671 closed for the six mapping rules it added.
InvalidSnapshotID.Malformed; names nothing →InvalidSnapshot.NotFound.Both come from
ec2SnapshotIDKind, which already produced the exact code, message and status.Ebs.VolumeSizebelow the snapshot's →InvalidBlockDeviceMapping, the refusal v0.105.0deferred. AWS documents the rule verbatim on
EbsBlockDevice.VolumeSize: "You can specify avolume size that is equal to or larger than the snapshot size."
The two carry different codes on purpose: a snapshot substrate cannot find is a mistake about the
ID — which is what naming a snapshot from a previous run looks like — while a size below it is a
mistake about the mapping. A refusal leaves no state behind, because the check sits where #671 put
the validator: after the launch-template merge, before the default-VPC branch.
ec2CheckBlockDeviceMappingswas pure and snapshot existence needs state, so it takes aresolveSnapshot func(string) (EC2Snapshot, bool)rather than a*StateManager— the validatorstays unit-testable with a two-line closure, and #693's collecting variant can wrap the same
signature. Rule order is load-bearing and the doc comment states both halves: the snapshot
checks run after the size-or-snapshot requirement (a mapping naming neither has no snapshot to
look up) and before the Throughput/Iops rules, which
return nilearly on an absentVolumeTypeand would otherwise skip the snapshot check entirely.
And the mirror of the same defect
A mapping with a present
SnapshotIdand absentVolumeSizeyieldedec2DefaultVolumeSizeGiB= 8, because
ec2VolumeFromMappingtook nothing from the snapshot.EC2BlockDeviceMapping's ownfield doc already stated the correct rule — the doc was ahead of the code — and AWS states it on the
same member it states the refusal on: "If you specify a snapshot, the default is the snapshot size."
ec2ResolveSnapshotSizesfills it in a pre-resolution step beforeec2CreateLaunchVolumes, whichkeeps both pure functions pure and fixes
DescribeVolumes' reportedsizefor free. It keys offVolumeSizeRaw == "", which is what makes an absent value distinguishable from an unparseable one.createVolumehad the identical gap independently — a restore from a 30 GiB snapshot produced an8 GiB volume there too, and one naming a snapshot no account holds succeeded outright — and now
applies both rules through the same comparison.
CreateTagsreaches a snapshotA
snap-ID had no arm inec2TaggableResource, soCreateTagson a snapshot answered<return>true</return>having written nothing — the same silent no-op #670 fixed forvol-, andimmediately relevant now that
CreateSnapshot'sTagSpecificationgives a caller a snapshot oftheir own. Until this change
DescribeTags(#688, this release) could report a snapshot's tags thatCreateTagshad no way to write. Theimage/lt/fleetarms each need their own ARN-formatverification and stay in #695.
Provenance
statusand its five values,VolumeId's Required: Yes, the size-inheritance default and theequal-or-larger refusal are all from the
CreateSnapshotandEbsBlockDevicereferences, fetchedthis session — both "If you specify a snapshot, the default is the snapshot size" and "You can
specify a volume size that is equal to or larger than the snapshot size" appear verbatim on
CreateVolume.SizeandEbsBlockDevice.VolumeSize, so the same rule is applied through bothdoors. Neither operation's Errors section lists anything beyond the common errors, so the specific
codes come from EC2's errors-overview page (
InvalidSnapshot.NotFound,InvalidSnapshotID.Malformed,InvalidVolume.NotFound,InvalidVolumeID.Malformedare alldocumented there) rather than from the per-operation pages.
completedat once is substrate's,not AWS's sample; so is which code applies to which of the two mapping mistakes.
Fail-before
emulator/ec2_snapshots_test.goandtest/e2e/journey_ec2_snapshots_test.gorun againstmain(85a01b4), all seven tests and thirteen subtests failing:
The nonexistent-snapshot case is the one worth reading twice: not only was the launch accepted, it
materialized a volume carrying
snap-0123456789abcdef0— a snapshot no account holds — at the8 GiB default.
And at the SDK tier:
Two tests rewritten rather than extended
TestEC2_BlockDeviceMapping_ValidIsAccepted/a_snapshot_with_no_sizeasserted that a mappingnaming
snap-0123456789abcdef0is accepted. Under the existence check it is refused, so therow now seeds a real 30 GiB snapshot — and a sibling row asserts a size equal to the snapshot's
is accepted, since the rule is equal-or-larger.
TestEC2_DescribeTags_ScanIsWiderThanCreateTagsasserted "CreateTagshas nosnap-arm yet".That is now false; it asserts both the
CreateTags-written andTagSpecification-written tagscome back.
Two assertions I expected to break still pass, and now for the right reason: the
int64(8)inec2_plugin_test.goand thevolume-size "8"filter row. The seeded instances genuinely have 8 GiBroot volumes, so
8went from a constant to a real value. Both got a comment saying so, plus arequire.NotEmptyon the newly-recordedVolumeIDand a realvolume-idselection row, so nothingpasses by coinciding with a constant.
Verification
gofmt -l .,go build ./...,go vet ./...,golangci-lint run ./...(0 issues),make test(race, all packages),
make docs-reference-check,make docs-versions, andgo vet -C test/e2e ./... && go test -C test/e2e ./...all clean. Coverage unchanged in shape: thenew file arrives with the seven tests above plus the journey.