amazon: validate IOPS max and min values
This commit is contained in:
parent
0cf9b55c5c
commit
09c2620c48
|
@ -13,6 +13,11 @@ import (
|
|||
"github.com/hashicorp/packer/template/interpolate"
|
||||
)
|
||||
|
||||
const (
|
||||
minIops = 100
|
||||
maxIops = 64000
|
||||
)
|
||||
|
||||
// These will be attached when launching your instance. Your
|
||||
// options here may vary depending on the type of VM you use.
|
||||
//
|
||||
|
@ -173,11 +178,16 @@ func (b *BlockDevice) Prepare(ctx *interpolate.Context) error {
|
|||
|
||||
if ratio, ok := iopsRatios[b.VolumeType]; b.VolumeSize != 0 && ok {
|
||||
if b.IOPS/b.VolumeSize > ratio {
|
||||
return fmt.Errorf("The maximum ratio of provisioned IOPS to requested volume size "+
|
||||
"(in GiB) is %v:1 for %s volumes", ratio, b.VolumeType)
|
||||
return fmt.Errorf("%s: the maximum ratio of provisioned IOPS to requested volume size "+
|
||||
"(in GiB) is %v:1 for %s volumes", b.DeviceName, ratio, b.VolumeType)
|
||||
}
|
||||
}
|
||||
|
||||
if b.IOPS < minIops || b.IOPS > maxIops {
|
||||
return fmt.Errorf("IOPS must be between %d and %d for device %s",
|
||||
minIops, maxIops, b.DeviceName)
|
||||
}
|
||||
|
||||
_, err := interpolate.RenderInterface(&b, ctx)
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -236,7 +236,7 @@ func TestIOPSValidation(t *testing.T) {
|
|||
IOPS: 2000,
|
||||
},
|
||||
ok: false,
|
||||
msg: "The maximum ratio of provisioned IOPS to requested volume size (in GiB) is 50:1 for io1 volumes",
|
||||
msg: "/dev/sdb: the maximum ratio of provisioned IOPS to requested volume size (in GiB) is 50:1 for io1 volumes",
|
||||
},
|
||||
{
|
||||
device: BlockDevice{
|
||||
|
@ -246,7 +246,29 @@ func TestIOPSValidation(t *testing.T) {
|
|||
IOPS: 30000,
|
||||
},
|
||||
ok: false,
|
||||
msg: "The maximum ratio of provisioned IOPS to requested volume size (in GiB) is 500:1 for io2 volumes",
|
||||
msg: "/dev/sdb: the maximum ratio of provisioned IOPS to requested volume size (in GiB) is 500:1 for io2 volumes",
|
||||
},
|
||||
// exceed max iops
|
||||
{
|
||||
device: BlockDevice{
|
||||
DeviceName: "/dev/sdb",
|
||||
VolumeType: "io2",
|
||||
VolumeSize: 500,
|
||||
IOPS: 99999,
|
||||
},
|
||||
ok: false,
|
||||
msg: "IOPS must be between 100 and 64000 for device /dev/sdb",
|
||||
},
|
||||
// lower than min iops
|
||||
{
|
||||
device: BlockDevice{
|
||||
DeviceName: "/dev/sdb",
|
||||
VolumeType: "io2",
|
||||
VolumeSize: 50,
|
||||
IOPS: 10,
|
||||
},
|
||||
ok: false,
|
||||
msg: "IOPS must be between 100 and 64000 for device /dev/sdb",
|
||||
},
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue