2019-01-28 18:11:57 -05:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/outscale/osc-go/oapi"
|
|
|
|
)
|
|
|
|
|
2019-02-20 19:41:47 -05:00
|
|
|
func TestBlockDevice_LaunchDevices(t *testing.T) {
|
2019-03-07 13:33:48 -05:00
|
|
|
tr := new(bool)
|
|
|
|
f := new(bool)
|
|
|
|
|
|
|
|
*tr = true
|
|
|
|
*f = false
|
|
|
|
|
2019-01-28 18:11:57 -05:00
|
|
|
cases := []struct {
|
|
|
|
Config *BlockDevice
|
2019-02-20 19:41:47 -05:00
|
|
|
Result oapi.BlockDeviceMappingVmCreation
|
2019-01-28 18:11:57 -05:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
Config: &BlockDevice{
|
|
|
|
DeviceName: "/dev/sdb",
|
|
|
|
SnapshotId: "snap-1234",
|
|
|
|
VolumeType: "standard",
|
|
|
|
VolumeSize: 8,
|
|
|
|
DeleteOnVmDeletion: true,
|
|
|
|
},
|
|
|
|
|
2019-02-20 19:41:47 -05:00
|
|
|
Result: oapi.BlockDeviceMappingVmCreation{
|
2019-01-28 18:11:57 -05:00
|
|
|
DeviceName: "/dev/sdb",
|
2019-02-20 19:41:47 -05:00
|
|
|
Bsu: oapi.BsuToCreate{
|
2019-01-28 18:11:57 -05:00
|
|
|
SnapshotId: "snap-1234",
|
|
|
|
VolumeType: "standard",
|
|
|
|
VolumeSize: 8,
|
2019-03-07 13:33:48 -05:00
|
|
|
DeleteOnVmDeletion: tr,
|
2019-01-28 18:11:57 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Config: &BlockDevice{
|
|
|
|
DeviceName: "/dev/sdb",
|
|
|
|
VolumeSize: 8,
|
|
|
|
},
|
|
|
|
|
2019-02-20 19:41:47 -05:00
|
|
|
Result: oapi.BlockDeviceMappingVmCreation{
|
2019-01-28 18:11:57 -05:00
|
|
|
DeviceName: "/dev/sdb",
|
2019-02-20 19:41:47 -05:00
|
|
|
Bsu: oapi.BsuToCreate{
|
2019-01-28 18:11:57 -05:00
|
|
|
VolumeSize: 8,
|
2019-03-07 13:33:48 -05:00
|
|
|
DeleteOnVmDeletion: f,
|
2019-01-28 18:11:57 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Config: &BlockDevice{
|
|
|
|
DeviceName: "/dev/sdb",
|
|
|
|
VolumeType: "io1",
|
|
|
|
VolumeSize: 8,
|
|
|
|
DeleteOnVmDeletion: true,
|
|
|
|
IOPS: 1000,
|
|
|
|
},
|
|
|
|
|
2019-02-20 19:41:47 -05:00
|
|
|
Result: oapi.BlockDeviceMappingVmCreation{
|
2019-01-28 18:11:57 -05:00
|
|
|
DeviceName: "/dev/sdb",
|
2019-02-20 19:41:47 -05:00
|
|
|
Bsu: oapi.BsuToCreate{
|
2019-01-28 18:11:57 -05:00
|
|
|
VolumeType: "io1",
|
|
|
|
VolumeSize: 8,
|
2019-03-07 13:33:48 -05:00
|
|
|
DeleteOnVmDeletion: tr,
|
2019-01-28 18:11:57 -05:00
|
|
|
Iops: 1000,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Config: &BlockDevice{
|
|
|
|
DeviceName: "/dev/sdb",
|
|
|
|
VolumeType: "gp2",
|
|
|
|
VolumeSize: 8,
|
|
|
|
DeleteOnVmDeletion: true,
|
|
|
|
},
|
|
|
|
|
2019-02-20 19:41:47 -05:00
|
|
|
Result: oapi.BlockDeviceMappingVmCreation{
|
2019-01-28 18:11:57 -05:00
|
|
|
DeviceName: "/dev/sdb",
|
2019-02-20 19:41:47 -05:00
|
|
|
Bsu: oapi.BsuToCreate{
|
2019-01-28 18:11:57 -05:00
|
|
|
VolumeType: "gp2",
|
|
|
|
VolumeSize: 8,
|
2019-03-07 13:33:48 -05:00
|
|
|
DeleteOnVmDeletion: tr,
|
2019-01-28 18:11:57 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Config: &BlockDevice{
|
|
|
|
DeviceName: "/dev/sdb",
|
|
|
|
VolumeType: "gp2",
|
|
|
|
VolumeSize: 8,
|
|
|
|
DeleteOnVmDeletion: true,
|
|
|
|
},
|
|
|
|
|
2019-02-20 19:41:47 -05:00
|
|
|
Result: oapi.BlockDeviceMappingVmCreation{
|
2019-01-28 18:11:57 -05:00
|
|
|
DeviceName: "/dev/sdb",
|
2019-02-20 19:41:47 -05:00
|
|
|
Bsu: oapi.BsuToCreate{
|
2019-01-28 18:11:57 -05:00
|
|
|
VolumeType: "gp2",
|
|
|
|
VolumeSize: 8,
|
2019-03-07 13:33:48 -05:00
|
|
|
DeleteOnVmDeletion: tr,
|
2019-01-28 18:11:57 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Config: &BlockDevice{
|
|
|
|
DeviceName: "/dev/sdb",
|
|
|
|
VolumeType: "standard",
|
|
|
|
DeleteOnVmDeletion: true,
|
|
|
|
},
|
|
|
|
|
2019-02-20 19:41:47 -05:00
|
|
|
Result: oapi.BlockDeviceMappingVmCreation{
|
2019-01-28 18:11:57 -05:00
|
|
|
DeviceName: "/dev/sdb",
|
2019-02-20 19:41:47 -05:00
|
|
|
Bsu: oapi.BsuToCreate{
|
2019-01-28 18:11:57 -05:00
|
|
|
VolumeType: "standard",
|
2019-03-07 13:33:48 -05:00
|
|
|
DeleteOnVmDeletion: tr,
|
2019-01-28 18:11:57 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Config: &BlockDevice{
|
|
|
|
DeviceName: "/dev/sdb",
|
|
|
|
VirtualName: "ephemeral0",
|
|
|
|
},
|
|
|
|
|
2019-02-20 19:41:47 -05:00
|
|
|
Result: oapi.BlockDeviceMappingVmCreation{
|
2019-01-28 18:11:57 -05:00
|
|
|
DeviceName: "/dev/sdb",
|
|
|
|
VirtualDeviceName: "ephemeral0",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Config: &BlockDevice{
|
|
|
|
DeviceName: "/dev/sdb",
|
|
|
|
NoDevice: true,
|
|
|
|
},
|
|
|
|
|
2019-02-20 19:41:47 -05:00
|
|
|
Result: oapi.BlockDeviceMappingVmCreation{
|
2019-01-28 18:11:57 -05:00
|
|
|
DeviceName: "/dev/sdb",
|
|
|
|
NoDevice: "",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range cases {
|
|
|
|
|
|
|
|
launchBlockDevices := LaunchBlockDevices{
|
|
|
|
LaunchMappings: []BlockDevice{*tc.Config},
|
|
|
|
}
|
|
|
|
|
2019-02-20 19:41:47 -05:00
|
|
|
expected := []oapi.BlockDeviceMappingVmCreation{tc.Result}
|
2019-01-28 18:11:57 -05:00
|
|
|
|
|
|
|
launchResults := launchBlockDevices.BuildLaunchDevices()
|
|
|
|
if !reflect.DeepEqual(expected, launchResults) {
|
|
|
|
t.Fatalf("Bad block device, \nexpected: %#v\n\ngot: %#v",
|
|
|
|
expected, launchResults)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-02-20 19:41:47 -05:00
|
|
|
|
|
|
|
func TestBlockDevice_OMI(t *testing.T) {
|
2019-03-07 13:33:48 -05:00
|
|
|
tr := new(bool)
|
|
|
|
f := new(bool)
|
|
|
|
|
|
|
|
*tr = true
|
|
|
|
*f = false
|
|
|
|
|
2019-02-20 19:41:47 -05:00
|
|
|
cases := []struct {
|
|
|
|
Config *BlockDevice
|
|
|
|
Result oapi.BlockDeviceMappingImage
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
Config: &BlockDevice{
|
|
|
|
DeviceName: "/dev/sdb",
|
|
|
|
SnapshotId: "snap-1234",
|
|
|
|
VolumeType: "standard",
|
|
|
|
VolumeSize: 8,
|
|
|
|
DeleteOnVmDeletion: true,
|
|
|
|
},
|
|
|
|
|
|
|
|
Result: oapi.BlockDeviceMappingImage{
|
|
|
|
DeviceName: "/dev/sdb",
|
|
|
|
Bsu: oapi.BsuToCreate{
|
|
|
|
SnapshotId: "snap-1234",
|
|
|
|
VolumeType: "standard",
|
|
|
|
VolumeSize: 8,
|
2019-03-07 13:33:48 -05:00
|
|
|
DeleteOnVmDeletion: tr,
|
2019-02-20 19:41:47 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Config: &BlockDevice{
|
|
|
|
DeviceName: "/dev/sdb",
|
|
|
|
VolumeSize: 8,
|
|
|
|
},
|
|
|
|
|
|
|
|
Result: oapi.BlockDeviceMappingImage{
|
|
|
|
DeviceName: "/dev/sdb",
|
|
|
|
Bsu: oapi.BsuToCreate{
|
|
|
|
VolumeSize: 8,
|
2019-03-07 13:33:48 -05:00
|
|
|
DeleteOnVmDeletion: f,
|
2019-02-20 19:41:47 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Config: &BlockDevice{
|
|
|
|
DeviceName: "/dev/sdb",
|
|
|
|
VolumeType: "io1",
|
|
|
|
VolumeSize: 8,
|
|
|
|
DeleteOnVmDeletion: true,
|
|
|
|
IOPS: 1000,
|
|
|
|
},
|
|
|
|
|
|
|
|
Result: oapi.BlockDeviceMappingImage{
|
|
|
|
DeviceName: "/dev/sdb",
|
|
|
|
Bsu: oapi.BsuToCreate{
|
|
|
|
VolumeType: "io1",
|
|
|
|
VolumeSize: 8,
|
2019-03-07 13:33:48 -05:00
|
|
|
DeleteOnVmDeletion: tr,
|
2019-02-20 19:41:47 -05:00
|
|
|
Iops: 1000,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Config: &BlockDevice{
|
|
|
|
DeviceName: "/dev/sdb",
|
|
|
|
VolumeType: "gp2",
|
|
|
|
VolumeSize: 8,
|
|
|
|
DeleteOnVmDeletion: true,
|
|
|
|
},
|
|
|
|
|
|
|
|
Result: oapi.BlockDeviceMappingImage{
|
|
|
|
DeviceName: "/dev/sdb",
|
|
|
|
Bsu: oapi.BsuToCreate{
|
|
|
|
VolumeType: "gp2",
|
|
|
|
VolumeSize: 8,
|
2019-03-07 13:33:48 -05:00
|
|
|
DeleteOnVmDeletion: tr,
|
2019-02-20 19:41:47 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Config: &BlockDevice{
|
|
|
|
DeviceName: "/dev/sdb",
|
|
|
|
VolumeType: "gp2",
|
|
|
|
VolumeSize: 8,
|
|
|
|
DeleteOnVmDeletion: true,
|
|
|
|
},
|
|
|
|
|
|
|
|
Result: oapi.BlockDeviceMappingImage{
|
|
|
|
DeviceName: "/dev/sdb",
|
|
|
|
Bsu: oapi.BsuToCreate{
|
|
|
|
VolumeType: "gp2",
|
|
|
|
VolumeSize: 8,
|
2019-03-07 13:33:48 -05:00
|
|
|
DeleteOnVmDeletion: tr,
|
2019-02-20 19:41:47 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Config: &BlockDevice{
|
|
|
|
DeviceName: "/dev/sdb",
|
|
|
|
VolumeType: "standard",
|
|
|
|
DeleteOnVmDeletion: true,
|
|
|
|
},
|
|
|
|
|
|
|
|
Result: oapi.BlockDeviceMappingImage{
|
|
|
|
DeviceName: "/dev/sdb",
|
|
|
|
Bsu: oapi.BsuToCreate{
|
|
|
|
VolumeType: "standard",
|
2019-03-07 13:33:48 -05:00
|
|
|
DeleteOnVmDeletion: tr,
|
2019-02-20 19:41:47 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Config: &BlockDevice{
|
|
|
|
DeviceName: "/dev/sdb",
|
|
|
|
VirtualName: "ephemeral0",
|
|
|
|
},
|
|
|
|
|
|
|
|
Result: oapi.BlockDeviceMappingImage{
|
|
|
|
DeviceName: "/dev/sdb",
|
|
|
|
VirtualDeviceName: "ephemeral0",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range cases {
|
|
|
|
omiBlockDevices := OMIBlockDevices{
|
|
|
|
OMIMappings: []BlockDevice{*tc.Config},
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := []oapi.BlockDeviceMappingImage{tc.Result}
|
|
|
|
|
|
|
|
omiResults := omiBlockDevices.BuildOMIDevices()
|
|
|
|
if !reflect.DeepEqual(expected, omiResults) {
|
2019-03-07 13:33:48 -05:00
|
|
|
t.Fatalf("Bad block device, \nexpected: %+#v\n\ngot: %+#v",
|
2019-02-20 19:41:47 -05:00
|
|
|
expected, omiResults)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|