diff --git a/config/examples/nnf_nnfstorageprofile.yaml b/config/examples/nnf_nnfstorageprofile.yaml index 73b0a676..d8c39dec 100644 --- a/config/examples/nnf_nnfstorageprofile.yaml +++ b/config/examples/nnf_nnfstorageprofile.yaml @@ -50,7 +50,7 @@ data: lvChange: activate: --activate ys $VG_NAME/$LV_NAME deactivate: --activate n $VG_NAME/$LV_NAME - lvRemove: $VG_NAME + lvRemove: $VG_NAME/$LV_NAME mkfs: -j2 -p $PROTOCOL -t $CLUSTER_NAME:$LOCK_SPACE $DEVICE mountRabbit: $DEVICE $MOUNT_PATH mountCompute: $DEVICE $MOUNT_PATH @@ -70,7 +70,7 @@ data: lvChange: activate: --activate y $VG_NAME/$LV_NAME deactivate: --activate n $VG_NAME/$LV_NAME - lvRemove: $VG_NAME + lvRemove: $VG_NAME/$LV_NAME mkfs: $DEVICE mountRabbit: $DEVICE $MOUNT_PATH mountCompute: $DEVICE $MOUNT_PATH @@ -90,4 +90,4 @@ data: lvChange: activate: --activate y $VG_NAME/$LV_NAME deactivate: --activate n $VG_NAME/$LV_NAME - lvRemove: $VG_NAME + lvRemove: $VG_NAME/$LV_NAME diff --git a/pkg/blockdevice/lvm.go b/pkg/blockdevice/lvm.go index f02f48e8..52a2e9d5 100644 --- a/pkg/blockdevice/lvm.go +++ b/pkg/blockdevice/lvm.go @@ -140,12 +140,18 @@ func (l *Lvm) Destroy(ctx context.Context) (bool, error) { destroyed, err := l.LogicalVolume.Remove(ctx, l.CommandArgs.LvArgs.Remove) if err != nil { return false, err - } if destroyed { objectDestroyed = true } + // Check to ensure the VG has no LVs before removing + if count, err := l.VolumeGroup.NumLVs(ctx); err != nil { + return false, err + } else if count != 0 { + return objectDestroyed, nil + } + destroyed, err = l.VolumeGroup.Remove(ctx, l.CommandArgs.VgArgs.Remove) if err != nil { return false, err diff --git a/pkg/blockdevice/lvm/volume_groups.go b/pkg/blockdevice/lvm/volume_groups.go index acff13d2..334d4fd8 100644 --- a/pkg/blockdevice/lvm/volume_groups.go +++ b/pkg/blockdevice/lvm/volume_groups.go @@ -174,7 +174,7 @@ func (vg *VolumeGroup) LockStop(ctx context.Context, rawArgs string) (bool, erro return false, err } - if exists == false { + if !exists { return false, nil } @@ -211,3 +211,19 @@ func (vg *VolumeGroup) Remove(ctx context.Context, rawArgs string) (bool, error) return false, nil } + +func (vg *VolumeGroup) NumLVs(ctx context.Context) (int, error) { + count := 0 + + lvs, err := lvsListVolumes(ctx, vg.Log) + if err != nil { + return count, err + } + for _, lv := range lvs { + if lv.VGName == vg.Name { + count += 1 + } + } + + return count, nil +}