diff --git a/pkg/disk/lvm.go b/pkg/disk/lvm.go index 54fc2523d5..7181b53ce9 100644 --- a/pkg/disk/lvm.go +++ b/pkg/disk/lvm.go @@ -110,12 +110,15 @@ func (vg *LVMVolumeGroup) CreateLogicalVolume(lvName string, size uint64, payloa if lvName == "" { // generate a name based on the payload's mountpoint - mntble, ok := payload.(Mountable) - if !ok { + switch ent := payload.(type) { + case Mountable: + lvName = ent.GetMountpoint() + case *Swap: + lvName = "swap" + default: return nil, fmt.Errorf("could not create logical volume: no name provided and payload is not mountable") } - mountpoint := mntble.GetMountpoint() - autoName, err := vg.genLVName(mountpoint) + autoName, err := vg.genLVName(lvName) if err != nil { return nil, err } diff --git a/pkg/disk/lvm_test.go b/pkg/disk/lvm_test.go index e75dc9304c..eb66036322 100644 --- a/pkg/disk/lvm_test.go +++ b/pkg/disk/lvm_test.go @@ -39,6 +39,21 @@ func TestLVMVCreateMountpoint(t *testing.T) { assert.Error(err) } +func TestLVMVCreateLogicalVolumeSwap(t *testing.T) { + vg := &LVMVolumeGroup{ + Name: "root", + Description: "root volume group", + } + swap := &Swap{} + lv, err := vg.CreateLogicalVolume("", 12345, swap) + assert.NoError(t, err) + assert.Equal(t, "swaplv", lv.Name) + // one more + lv2, err := vg.CreateLogicalVolume("", 12345, swap) + assert.NoError(t, err) + assert.Equal(t, "swaplv00", lv2.Name) +} + func TestImplementsInterfacesCompileTimeCheckLVM(t *testing.T) { var _ = Container(&LVMVolumeGroup{}) var _ = Sizeable(&LVMLogicalVolume{})