fix: accept the snapshot-id filter on DescribeVolumes and match it against the volume's source snapshot (#1229)

This commit is contained in:
Julian Sommer
2026-10-20 11:21:02 +11:00
committed by GitHub
parent 29770dc798
commit 84df82c26f
2 changed files with 39 additions and 0 deletions
@@ -289,6 +289,7 @@ var describeVolumesValidFilters = map[string]bool{
"attachment.status": true,
"attachment.device": true,
"availability-zone": true,
"snapshot-id": true,
}
// DescribeVolumes lists EBS volumes by reading config.json files from S3.
@@ -401,6 +402,10 @@ func volumeMatchesFilters(vol *ec2.Volume, filters map[string][]string) bool {
if vol.AvailabilityZone != nil {
field = *vol.AvailabilityZone
}
case "snapshot-id":
if vol.SnapshotId != nil {
field = *vol.SnapshotId
}
default:
return false
}
@@ -2081,6 +2081,40 @@ func TestDescribeVolumes_FilterByAZ(t *testing.T) {
assert.Equal(t, "vol-az1", *out.Volumes[0].VolumeId)
}
func TestDescribeVolumes_FilterBySnapshotId(t *testing.T) {
store := objectstore.NewMemoryObjectStore()
svc := newTestVolumeServiceWithStore("ap-southeast-2a", store)
createVolumeInStoreWithMeta(t, svc, store, "vol-fromsnap", ebsmetadata.Volume{
VolumeID: "vol-fromsnap", CapacityGiB: 10, State: "available",
SnapshotID: "snap-src", TenantID: "000000000001",
})
createVolumeInStoreWithMeta(t, svc, store, "vol-othersnap", ebsmetadata.Volume{
VolumeID: "vol-othersnap", CapacityGiB: 10, State: "available",
SnapshotID: "snap-other", TenantID: "000000000001",
})
createVolumeInStoreWithMeta(t, svc, store, "vol-blank", ebsmetadata.Volume{
VolumeID: "vol-blank", CapacityGiB: 10, State: "available", TenantID: "000000000001",
})
describe := func(values ...string) []string {
t.Helper()
out, err := svc.DescribeVolumes(context.Background(), &ec2.DescribeVolumesInput{
Filters: []*ec2.Filter{{Name: aws.String("snapshot-id"), Values: aws.StringSlice(values)}},
}, "000000000001")
require.NoError(t, err)
ids := make([]string, 0, len(out.Volumes))
for _, v := range out.Volumes {
ids = append(ids, *v.VolumeId)
}
return ids
}
assert.Equal(t, []string{"vol-fromsnap"}, describe("snap-src"))
assert.ElementsMatch(t, []string{"vol-fromsnap", "vol-othersnap"}, describe("snap-src", "snap-other"))
assert.Empty(t, describe("snap-unknown"))
}
func TestDescribeVolumes_FilterMultipleValues_OR(t *testing.T) {
store := objectstore.NewMemoryObjectStore()
svc := newTestVolumeServiceWithStore("ap-southeast-2a", store)