Skip to content

Commit

Permalink
feature: remove set partition uuid as separate method
Browse files Browse the repository at this point in the history
Signed-off-by: Nikita Mikhnenko <nikita_mikhnenko@dell.com>
  • Loading branch information
Nikita Mikhnenko committed Dec 16, 2021
1 parent c96a2ee commit 4dff6d6
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 52 deletions.
22 changes: 1 addition & 21 deletions pkg/base/linuxutils/partitionhelper/partition_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ type WrapPartition interface {
CreatePartitionTable(device, partTableType string) (err error)
CreatePartition(device, label, partUUID string, setUUID bool) (err error)
DeletePartition(device, partNum string) (err error)
SetPartitionUUID(device, partNum, partUUID string) error
GetPartitionUUID(device, partNum string) (string, error)
SyncPartitionTable(device string) error
GetPartitionNameByUUID(device, partUUID string) (string, error)
Expand All @@ -59,8 +58,6 @@ const (

// PartprobeDeviceCmdTmpl check that device has partition cmd
PartprobeDeviceCmdTmpl = partprobe + "-d -s %s"
// PartprobeCmdTmpl check device has partition with partprobe cmd
PartprobeCmdTmpl = partprobe + "%s"
// BlockdevCmdTmpl synchronize the partition table
BlockdevCmdTmpl = blockdev + "--rereadpt -v %s"

Expand All @@ -77,8 +74,6 @@ const (
// DetectPartitionTableCmdTmpl is used to print information, which contain partition table
DetectPartitionTableCmdTmpl = fdisk + "--list %s"

// SetPartitionUUIDCmdTmpl command for set GUID of the partition, fill device, part number and part UUID
SetPartitionUUIDCmdTmpl = sgdisk + "%s --partition-guid=%s:%s"
// GetPartitionUUIDCmdTmpl command for read GUID of the first partition, fill device and part number
GetPartitionUUIDCmdTmpl = sgdisk + "%s --info=%s"
)
Expand Down Expand Up @@ -221,21 +216,6 @@ func (p *WrapPartitionImpl) DeletePartition(device, partNum string) error {
return nil
}

// SetPartitionUUID writes partUUID as GUID for the partition partNum of a provided device
// Receives device path and partUUID as strings
// Returns error if something went wrong
func (p *WrapPartitionImpl) SetPartitionUUID(device, partNum, partUUID string) error {
cmd := fmt.Sprintf(SetPartitionUUIDCmdTmpl, device, partNum, partUUID)

if _, _, err := p.e.RunCmd(cmd,
command.UseMetrics(true),
command.CmdName(strings.TrimSpace(fmt.Sprintf(SetPartitionUUIDCmdTmpl, "", "", "")))); err != nil {
return err
}

return nil
}

// GetPartitionUUID reads partition unique GUID from the partition partNum of a provided device
// Receives device path from which to read
// Returns unique GUID as a string or error if something went wrong
Expand Down Expand Up @@ -283,7 +263,7 @@ func (p *WrapPartitionImpl) SyncPartitionTable(device string) error {
p.opMutex.Lock()
_, _, err := p.e.RunCmd(cmd,
command.UseMetrics(true),
command.CmdName(strings.TrimSpace(fmt.Sprintf(PartprobeCmdTmpl, ""))))
command.CmdName(strings.TrimSpace(fmt.Sprintf(BlockdevCmdTmpl, ""))))
p.opMutex.Unlock()

if err != nil {
Expand Down
13 changes: 3 additions & 10 deletions pkg/base/linuxutils/partitionhelper/partitionhelper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ func TestCreatePartitionTableFail(t *testing.T) {
func TestCreatePartition(t *testing.T) {
err := testPartitioner.CreatePartition("/dev/sde", testCSILabel, testPartUUID, true)
assert.Nil(t, err)

err = testPartitioner.CreatePartition("/dev/sde", testCSILabel, "", false)
assert.Nil(t, err)
}

func TestCreatePartitionFail(t *testing.T) {
Expand All @@ -98,16 +101,6 @@ func TestDeletePartitionFail(t *testing.T) {
assert.NotNil(t, err)
}

func TestSetPartitionUUID(t *testing.T) {
err := testPartitioner.SetPartitionUUID("/dev/sda", testPartNum, testPartUUID)
assert.Nil(t, err)
}

func TestSetPartitionUUIDFail(t *testing.T) {
err := testPartitioner.SetPartitionUUID("/dev/sdb", testPartNum, testPartUUID)
assert.NotNil(t, err)
}

func TestGetPartitionUUID(t *testing.T) {
uuid, err := testPartitioner.GetPartitionUUID("/dev/sda", testPartNum)
assert.Equal(t, "64be631b-62a5-11e9-a756-00505680d67f", uuid)
Expand Down
12 changes: 5 additions & 7 deletions pkg/mocks/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,14 @@ The operation has completed successfully`,
Stderr: "",
Err: nil,
},
"sgdisk /dev/sda --partition-guid=1:64be631b-62a5-11e9-a756-00505680d67f": {
Stdout: "The operation has completed successfully.",
"sgdisk -a1 -n 1:0:0 -c 1:CSI /dev/sde": {
Stdout: `Creating new GPT entries.
Setting name!
partNum is 0
The operation has completed successfully`,
Stderr: "",
Err: nil,
},
"sgdisk /dev/sdb --partition-guid=1:64be631b-62a5-11e9-a756-00505680d67f": {
Stdout: "The operation has completed successfully.",
Stderr: "",
Err: Err,
},
"sgdisk /dev/sda --info=1": {
Stdout: `Partition GUID code: 0FC63DAF-8483-4772-8E79-3D69D8477DE4 (Linux filesystem)
Partition unique GUID: 64BE631B-62A5-11E9-A756-00505680D67F
Expand Down
7 changes: 0 additions & 7 deletions pkg/mocks/linuxutils/partitionhelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,6 @@ func (m *MockWrapPartition) DeletePartition(device, partNum string) (err error)
return args.Error(0)
}

// SetPartitionUUID is a mock implementations
func (m *MockWrapPartition) SetPartitionUUID(device, partNum, partUUID string) error {
args := m.Mock.Called(device, partNum, partUUID)

return args.Error(0)
}

// GetPartitionUUID is a mock implementations
func (m *MockWrapPartition) GetPartitionUUID(device, partNum string) (string, error) {
args := m.Mock.Called(device, partNum)
Expand Down
6 changes: 0 additions & 6 deletions pkg/node/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,4 @@ ADD node node

EXPOSE 9999

RUN sed -i \
-e 's/udev_sync = 1/udev_sync = 0/' \
-e 's/udev_rules = 1/udev_rules = 0/' \
-e 's/obtain_device_list_from_udev = 1/obtain_device_list_from_udev = 0/' \
/etc/lvm/lvm.conf

ENTRYPOINT ["/node"]
12 changes: 11 additions & 1 deletion pkg/node/Dockerfile.build
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,14 @@ ADD health_probe health_probe
# Remove bash packet to get rid of related CVEs
RUN apt update --no-install-recommends -y -q; apt remove --no-install-recommends -y --allow-remove-essential -q bash; apt install --no-install-recommends -y -q util-linux parted xfsprogs lvm2 gdisk strace udev net-tools


# Don't rely on udevd, it isn't available in some combinations of host/guest kernels.
# So lvcreate/lvremove commands hangs on it.
# Here we are:
# 1. Turning off synchronization with udev;
# 2. Turning off udev rules, so libdevmapper is directly responsible for creating files and links
# 3. Turning off udev database usage, so interact with /dev directly
RUN sed -i \
-e 's/udev_sync = 1/udev_sync = 0/' \
-e 's/udev_rules = 1/udev_rules = 0/' \
-e 's/obtain_device_list_from_udev = 1/obtain_device_list_from_udev = 0/' \
/etc/lvm/lvm.conf

0 comments on commit 4dff6d6

Please sign in to comment.