-
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -57,6 +57,53 @@ def get_partition_path(parent_dev, number): | |||||
| return f'{parent_dev}{id_separator}{number}' | ||||||
|
|
||||||
|
|
||||||
| def discover_partition(device) -> list: | ||||||
| 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] | ||||||
|
|
||||||
| # needs to be placed here (circular dependency) | ||||||
| from storage_devices.partition import Partition | ||||||
|
|
||||||
| partitions_on_device_list = [] | ||||||
|
|
||||||
| cmd = f"fdisk -l --bytes {device_name}" + r"| grep -E '^/dev/[a-z]+[0-9]+'" | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| output = TestRun.executor.run(cmd).stdout.split("\n") | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. check here if stdout is empty (and return if so) |
||||||
|
|
||||||
| for partition in partition_list: | ||||||
| disk_params = [ | ||||||
| x for x in next(param for param in output if partition in param).split(" ") if x | ||||||
| ] | ||||||
|
Comment on lines
+83
to
+85
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. part_params = re.split("\s+", line) |
||||||
| partition_number = int(re.search(r"(\d+)(?!.*\d)", disk_params[0]).group()) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
|
||||||
| part_number = int(partition_number) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's already cast to int |
||||||
| begin = Size(int(disk_params[1]), Unit.Byte) | ||||||
| end = Size( | ||||||
| (int(disk_params[2])), | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| Unit.Byte, | ||||||
| ) | ||||||
| partitions_on_device_list.append( | ||||||
| Partition( | ||||||
| parent_dev=device, | ||||||
| type=PartitionType.logical, | ||||||
| number=part_number, | ||||||
| begin=begin, | ||||||
| end=end, | ||||||
| ) | ||||||
| ) | ||||||
|
|
||||||
| return partitions_on_device_list | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe set device.partitions instead of returning the list? |
||||||
|
|
||||||
|
|
||||||
| def remove_parition(device, part_number): | ||||||
| TestRun.LOGGER.info(f"Removing part {part_number} from {device.path}") | ||||||
| cmd = f'parted --script {device.path} rm {part_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.
remove (redundant)