From 4dff6d6fad3e43a5ebb68e5348ec9e106cc6804e Mon Sep 17 00:00:00 2001 From: Nikita Mikhnenko Date: Wed, 15 Dec 2021 14:16:57 +0300 Subject: [PATCH] feature: remove set partition uuid as separate method Signed-off-by: Nikita Mikhnenko --- .../partitionhelper/partition_helper.go | 22 +------------------ .../partitionhelper/partitionhelper_test.go | 13 +++-------- pkg/mocks/commands.go | 12 +++++----- pkg/mocks/linuxutils/partitionhelper.go | 7 ------ pkg/node/Dockerfile | 6 ----- pkg/node/Dockerfile.build | 12 +++++++++- 6 files changed, 20 insertions(+), 52 deletions(-) diff --git a/pkg/base/linuxutils/partitionhelper/partition_helper.go b/pkg/base/linuxutils/partitionhelper/partition_helper.go index 6871cf86d..6f0cf3579 100644 --- a/pkg/base/linuxutils/partitionhelper/partition_helper.go +++ b/pkg/base/linuxutils/partitionhelper/partition_helper.go @@ -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) @@ -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" @@ -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" ) @@ -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 @@ -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 { diff --git a/pkg/base/linuxutils/partitionhelper/partitionhelper_test.go b/pkg/base/linuxutils/partitionhelper/partitionhelper_test.go index 2f5a4479a..27561f9f4 100644 --- a/pkg/base/linuxutils/partitionhelper/partitionhelper_test.go +++ b/pkg/base/linuxutils/partitionhelper/partitionhelper_test.go @@ -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) { @@ -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) diff --git a/pkg/mocks/commands.go b/pkg/mocks/commands.go index 0b3eddf8a..657d050df 100644 --- a/pkg/mocks/commands.go +++ b/pkg/mocks/commands.go @@ -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 diff --git a/pkg/mocks/linuxutils/partitionhelper.go b/pkg/mocks/linuxutils/partitionhelper.go index 4d6f404d0..dfedfdea9 100644 --- a/pkg/mocks/linuxutils/partitionhelper.go +++ b/pkg/mocks/linuxutils/partitionhelper.go @@ -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) diff --git a/pkg/node/Dockerfile b/pkg/node/Dockerfile index 3560ddcd1..de32470e5 100644 --- a/pkg/node/Dockerfile +++ b/pkg/node/Dockerfile @@ -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"] diff --git a/pkg/node/Dockerfile.build b/pkg/node/Dockerfile.build index 34eb31c59..2d93c16ff 100644 --- a/pkg/node/Dockerfile.build +++ b/pkg/node/Dockerfile.build @@ -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