Skip to content

Conversation

@Kamoppl
Copy link
Contributor

@Kamoppl Kamoppl commented Mar 28, 2025

Add detection for partitions.

@Kamoppl Kamoppl force-pushed the kamilg/add_partition_detection branch 2 times, most recently from 2f25721 to b930a50 Compare March 28, 2025 01:43
Signed-off-by: Kamil Gierszewski <kamil.gierszewski@huawei.com>
@Kamoppl Kamoppl force-pushed the kamilg/add_partition_detection branch from b930a50 to b229326 Compare March 28, 2025 13:00
Comment on lines +61 to +72
cmd = (
f"lsblk -ln -o NAME,TYPE {device.path} " + r"""| awk '$2 == "part" { print "/dev/" $1 }'"""
)

output = TestRun.executor.run(cmd).stdout
partition_list = [line for line in output.split("\n") if line]
if not partition_list:
return []

device_name = re.search(r"^(/dev/\S+)(?=\d+)", partition_list[0]).group()
if "nvme" in partition_list[0]:
device_name = device_name[:-1]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove (redundant)


partitions_on_device_list = []

cmd = f"fdisk -l --bytes {device_name}" + r"| grep -E '^/dev/[a-z]+[0-9]+'"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
cmd = f"fdisk -l --bytes {device_name}" + r"| grep -E '^/dev/[a-z]+[0-9]+'"
cmd = f"fdisk -l --bytes {device.path} | grep ^/dev/"

partitions_on_device_list = []

cmd = f"fdisk -l --bytes {device_name}" + r"| grep -E '^/dev/[a-z]+[0-9]+'"
output = TestRun.executor.run(cmd).stdout.split("\n")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check here if stdout is empty (and return if so)

Comment on lines +83 to +85
disk_params = [
x for x in next(param for param in output if partition in param).split(" ") if x
]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

part_params = re.split("\s+", line)

disk_params = [
x for x in next(param for param in output if partition in param).split(" ") if x
]
partition_number = int(re.search(r"(\d+)(?!.*\d)", disk_params[0]).group())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
partition_number = int(re.search(r"(\d+)(?!.*\d)", disk_params[0]).group())
partition_number = int(re.search(r"(\d+)$", disk_params[0]).group())

]
partition_number = int(re.search(r"(\d+)(?!.*\d)", disk_params[0]).group())

part_number = int(partition_number)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's already cast to int

part_number = int(partition_number)
begin = Size(int(disk_params[1]), Unit.Byte)
end = Size(
(int(disk_params[2])),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
(int(disk_params[2])),
int(disk_params[2]),

)
)

return partitions_on_device_list
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe set device.partitions instead of returning the list?

@Deixx
Copy link
Contributor

Deixx commented Mar 28, 2025

Update the description as it is no longer relevant

@Kamoppl Kamoppl marked this pull request as draft April 17, 2025 11:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants