Skip to content

Commit

Permalink
fix(filter): add partition and device mapper check to validity filter (
Browse files Browse the repository at this point in the history
…#519)

add validation check for blockdevices of type partition and device mapper

Signed-off-by: Akhil Mohan <[email protected]>
  • Loading branch information
akhilerm authored and kmova committed Dec 10, 2020
1 parent e509472 commit 788ad22
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelogs/unreleased/519-akhilerm
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add checks for validity of partition and dm device resources created
24 changes: 24 additions & 0 deletions cmd/ndm_daemonset/filter/devicevalidityfilter.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package filter
import (
"github.com/openebs/node-disk-manager/blockdevice"
"github.com/openebs/node-disk-manager/cmd/ndm_daemonset/controller"
"github.com/openebs/node-disk-manager/pkg/util"

"k8s.io/klog"
)

Expand Down Expand Up @@ -73,6 +75,8 @@ func (dvf *deviceValidityFilter) Start() {
dvf.excludeValidationFuncs = append(dvf.excludeValidationFuncs,
isValidDevPath,
isValidCapacity,
isValidDMDevice,
isValidPartition,
)
}

Expand Down Expand Up @@ -110,3 +114,23 @@ func isValidCapacity(bd *blockdevice.BlockDevice) bool {
}
return true
}

// isValidPartition checks if the blockdevice for the partition has a valid partition UUID
func isValidPartition(bd *blockdevice.BlockDevice) bool {
if bd.DeviceAttributes.DeviceType == blockdevice.BlockDeviceTypePartition &&
len(bd.PartitionInfo.PartitionEntryUUID) == 0 {
klog.V(4).Infof("device: %s of device-type partition has invalid partition UUID", bd.DevPath)
return false
}
return true
}

// isValidDMDevice checks if the blockdevice is a valid dm device
func isValidDMDevice(bd *blockdevice.BlockDevice) bool {
if util.Contains(blockdevice.DeviceMapperDeviceTypes, bd.DeviceAttributes.DeviceType) &&
len(bd.DMInfo.DMUUID) == 0 {
klog.V(4).Infof("device: %s of device mapper type has invalid DM_UUID", bd.DevPath)
return false
}
return true
}
78 changes: 78 additions & 0 deletions cmd/ndm_daemonset/filter/devicevalidityfilter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,81 @@ func Test_isValidCapacity(t *testing.T) {
})
}
}

func TestIsValidPartition(t *testing.T) {
tests := map[string]struct {
bd *blockdevice.BlockDevice
want bool
}{
"valid blockdevice of type partition": {
bd: &blockdevice.BlockDevice{
Identifier: blockdevice.Identifier{
DevPath: "/dev/sda1",
},
DeviceAttributes: blockdevice.DeviceAttribute{
DeviceType: blockdevice.BlockDeviceTypePartition,
},
PartitionInfo: blockdevice.PartitionInformation{
PartitionEntryUUID: "065e2357-05",
},
},
want: true,
},
"invalid blockdevice of type partition": {
bd: &blockdevice.BlockDevice{
Identifier: blockdevice.Identifier{
DevPath: "/dev/sda1",
},
DeviceAttributes: blockdevice.DeviceAttribute{
DeviceType: blockdevice.BlockDeviceTypePartition,
},
},
want: false,
},
}
for name, tt := range tests {
t.Run(name, func(t *testing.T) {
got := isValidPartition(tt.bd)
assert.Equal(t, tt.want, got)
})
}
}

func TestIsValidDMDevice(t *testing.T) {
tests := map[string]struct {
bd *blockdevice.BlockDevice
want bool
}{
"valid blockdevice of type device mapper": {
bd: &blockdevice.BlockDevice{
Identifier: blockdevice.Identifier{
DevPath: "/dev/dm-0",
},
DeviceAttributes: blockdevice.DeviceAttribute{
DeviceType: blockdevice.BlockDeviceTypeLVM,
},
DMInfo: blockdevice.DeviceMapperInformation{
DMUUID: "LVM-j2xmqvbcVWBQK9Jdttte3CyeVTGgxtVV5VcCi3nxdwihZDxSquMOBaGL5eymBNvk",
},
},
want: true,
},
"invalid blockdevice of type device mapper": {
bd: &blockdevice.BlockDevice{
Identifier: blockdevice.Identifier{
DevPath: "/dev/dm-1",
},
DeviceAttributes: blockdevice.DeviceAttribute{
DeviceType: blockdevice.BlockDeviceTypeLVM,
},
},
want: false,
},
}
for name, tt := range tests {
t.Run(name, func(t *testing.T) {
got := isValidDMDevice(tt.bd)
assert.Equal(t, tt.want, got)
})
}
}

0 comments on commit 788ad22

Please sign in to comment.