Skip to content

Commit

Permalink
Merge pull request #446 from suleymanakbas91/activate
Browse files Browse the repository at this point in the history
OCPVE-726: Activate inactive logical volumes
  • Loading branch information
openshift-ci[bot] authored Oct 10, 2023
2 parents 63c12a5 + b3894bb commit 61e044a
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 4 deletions.
8 changes: 6 additions & 2 deletions internal/controllers/vgmanager/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -482,8 +482,12 @@ func (r *Reconciler) validateLVs(ctx context.Context, volumeGroup *lvmv1alpha1.L
}

if lvAttr.State != StateActive {
return fmt.Errorf("found inactive logical volume, maybe external repairs are necessary/already happening or there is another"+
"entity conflicting with vg-manager, cannot proceed until volume is activated again: lv_attr: %s", lvAttr)
//If inactive, try activating it
err := r.LVM.ActivateLV(lv.Name, volumeGroup.Name)
if err != nil {
return fmt.Errorf("could not activate the inactive logical volume, maybe external repairs are necessary/already happening or there is another"+
"entity conflicting with vg-manager, cannot proceed until volume is activated again: lv_attr: %s", lvAttr)
}
}
metadataPercentage, err := strconv.ParseFloat(lv.MetadataPercent, 32)
if err != nil {
Expand Down
6 changes: 4 additions & 2 deletions internal/controllers/vgmanager/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ func testMockedBlockDeviceOnHost(ctx context.Context) {
thinPool = lvm.LogicalVolume{
Name: vg.Spec.ThinPoolConfig.Name,
VgName: vg.GetName(),
LvAttr: "twi-a-tz--",
LvAttr: "twi---tz--",
LvSize: "1.0G",
MetadataPercent: "10.0",
}
Expand All @@ -256,6 +256,7 @@ func testMockedBlockDeviceOnHost(ctx context.Context) {
Lv: []lvm.LogicalVolume{thinPool},
}}}, nil).Once()
instances.LVM.EXPECT().ListVGs().Return([]lvm.VolumeGroup{createdVG}, nil).Twice()
instances.LVM.EXPECT().ActivateLV(thinPool.Name, vg.GetName()).Return(nil).Once()
})

By("triggering the next reconciliation after the creation of the thin pool", func() {
Expand Down Expand Up @@ -284,7 +285,7 @@ func testMockedBlockDeviceOnHost(ctx context.Context) {
})

var oldReadyGeneration int64
By("verifiyng the VGStatus is now ready", func() {
By("verifying the VGStatus is now ready", func() {
checkDistributedEvent(corev1.EventTypeNormal, "all the available devices are attached to the volume group")
Expect(instances.client.Get(ctx, client.ObjectKeyFromObject(nodeStatus), nodeStatus)).To(Succeed())
Expect(nodeStatus.Spec.LVMVGStatus).ToNot(BeEmpty())
Expand Down Expand Up @@ -326,6 +327,7 @@ func testMockedBlockDeviceOnHost(ctx context.Context) {
instances.LVM.EXPECT().ListLVs(vg.GetName()).Return(&lvm.LVReport{Report: []lvm.LVReportItem{{
Lv: []lvm.LogicalVolume{thinPool},
}}}, nil).Once()
instances.LVM.EXPECT().ActivateLV(thinPool.Name, createdVG.Name).Return(nil).Once()
})

By("triggering the verification reconcile that should confirm the ready state", func() {
Expand Down
14 changes: 14 additions & 0 deletions internal/controllers/vgmanager/lvm/lvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ type LVM interface {
LVExists(lvName, vgName string) (bool, error)
CreateLV(lvName, vgName string, sizePercent int) error
ExtendLV(lvName, vgName string, sizePercent int) error
ActivateLV(lvName, vgName string) error
DeleteLV(lvName, vgName string) error
}

Expand Down Expand Up @@ -452,6 +453,19 @@ func (hlvm *HostLVM) ExtendLV(lvName, vgName string, sizePercent int) error {
return nil
}

// ActivateLV activates the logical volume
func (hlvm *HostLVM) ActivateLV(lvName, vgName string) error {
lv := fmt.Sprintf("%s/%s", vgName, lvName)

// deactivate logical volume
_, err := hlvm.ExecuteCommandWithOutputAsHost(lvChangeCmd, "-ay", lv)
if err != nil {
return fmt.Errorf("failed to activate thin pool %q in volume group %q. %w", lvName, vgName, err)
}

return nil
}

func (hlvm *HostLVM) execute(v interface{}, args ...string) error {
output, err := hlvm.ExecuteCommandWithOutputAsHost(lvmCmd, args...)
if err != nil {
Expand Down
43 changes: 43 additions & 0 deletions internal/controllers/vgmanager/lvm/mocks/mock_lvm.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 61e044a

Please sign in to comment.