-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🧹 Rename functions in blockdevices.go. Add more tests, sort suitable partitions by size before choosing one. #4110
Conversation
…partitions by size before choosing one. Signed-off-by: Preslav <[email protected]>
ce145b2
to
ab24526
Compare
Test Results3 007 tests +7 3 006 ✅ +7 1m 25s ⏱️ ±0s Results for commit 827ec6b. ± Comparison against base commit be98dcb. This pull request removes 1 and adds 8 tests. Note that renamed tests count towards both.
♻️ This comment has been updated with latest results. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @preslavgerchev
@@ -19,12 +20,12 @@ type BlockDevices struct { | |||
|
|||
type BlockDevice struct { | |||
Name string `json:"name,omitempty"` | |||
FsType string `json:"FsType,omitempty"` | |||
FsType string `json:"fstype,omitempty"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is that caused by the fact that we switch to specific fields?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am really not sure. This is also fstype
if you run lsblk -f --json
. Don't know why this was specified like that
@@ -33,7 +34,7 @@ type PartitionInfo struct { | |||
} | |||
|
|||
func (cmdRunner *LocalCommandRunner) GetBlockDevices() (*BlockDevices, error) { | |||
cmd, err := cmdRunner.RunCommand("lsblk -f --json") | |||
cmd, err := cmdRunner.RunCommand("lsblk -bo NAME,SIZE,FSTYPE,MOUNTPOINT,LABEL,UUID --json") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just for my understanding, why are we adding those additional arguments? Are those fields are not covered with the default output?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, if you do lsblk -f --json
the size isnt there. This also lets us extend this in the future. For example, some partitions have a PARTLABEL
which we can use (e.g. in Azure some partitions can be labeled with the BOOT PARTLABEL so we can omit those)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This just makes it easier for us in the future since all we neeed is a an extra column and an extra field in the struct.
log.Debug().Str("name", name).Msg("get matching block entry") | ||
// Searches all the partitions in the target device and finds one that can be mounted. It must be unmounted, non-boot partition | ||
// If multiple partitions meet this criteria, the largest one is returned. | ||
func (blockEntries BlockDevices) GetMountablePartitionByDevice(device string) (*PartitionInfo, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the rename to device
Signed-off-by: Preslav <[email protected]>
GetDeviceForMounting
toGetMountablePartition
GetBlockByEntryName
toGetMountablePartitionByDevice
lsblk -o OPTS
allows us to include things easily.