Skip to content

Commit

Permalink
disk: support automatic name generation for swap devices
Browse files Browse the repository at this point in the history
This commit adds support for automatic geneation of names for
an lv swap devices. This saves the users of advanced blueprints
some typing.
  • Loading branch information
mvo5 committed Dec 5, 2024
1 parent 7600a5a commit 1397c9e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
11 changes: 7 additions & 4 deletions pkg/disk/lvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
15 changes: 15 additions & 0 deletions pkg/disk/lvm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{})
Expand Down

0 comments on commit 1397c9e

Please sign in to comment.