-
Notifications
You must be signed in to change notification settings - Fork 5
Add detection for partitions on devices. #37
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
base: master
Are you sure you want to change the base?
Conversation
2f25721 to
b930a50
Compare
Signed-off-by: Kamil Gierszewski <kamil.gierszewski@huawei.com>
b930a50 to
b229326
Compare
| 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] |
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.
remove (redundant)
|
|
||
| partitions_on_device_list = [] | ||
|
|
||
| cmd = f"fdisk -l --bytes {device_name}" + r"| grep -E '^/dev/[a-z]+[0-9]+'" |
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.
| 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") |
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.
check here if stdout is empty (and return if so)
| disk_params = [ | ||
| x for x in next(param for param in output if partition in param).split(" ") if x | ||
| ] |
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.
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()) |
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.
| 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) |
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.
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])), |
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.
| (int(disk_params[2])), | |
| int(disk_params[2]), |
| ) | ||
| ) | ||
|
|
||
| return partitions_on_device_list |
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.
maybe set device.partitions instead of returning the list?
|
Update the description as it is no longer relevant |
Add detection for partitions.