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 15, 2021
1 parent c96a2ee commit ba70393
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 42 deletions.
18 changes: 0 additions & 18 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 Down Expand Up @@ -77,8 +76,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 +218,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
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

0 comments on commit ba70393

Please sign in to comment.