Skip to content

Commit

Permalink
Fixed format issues
Browse files Browse the repository at this point in the history
  • Loading branch information
fernando79513 committed Mar 19, 2024
1 parent 39e3274 commit 3ea6ef5
Show file tree
Hide file tree
Showing 8 changed files with 428 additions and 331 deletions.
157 changes: 69 additions & 88 deletions contrib/genio/bin/boot_partition.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@


def runcmd(command):
ret = subprocess.run(command,
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
encoding="utf-8",
timeout=1)
ret = subprocess.run(
command,
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
encoding="utf-8",
timeout=1,
)
return ret


class TestPartedBootDevice():
class TestPartedBootDevice:

def __init__(self):
self.path = None
Expand All @@ -27,78 +29,41 @@ def __init__(self):
"logical-sector-size": 4096,
"physical-sector-size": 4096,
"partitions": [
{
"number": 1,
"name": "bootloaders"
}, {
"number": 2,
"name": "bootloaders_b"
}, {
"number": 3,
"name": "firmware"
}, {
"number": 4,
"name": "firmware_b"
}, {
"number": 5,
"name": "dramk"
}, {
"number": 6,
"name": "misc"
}, {
"number": 7,
"name": "bootassets"
}, {
"number": 8,
"name": "ubuntu-boot"
}, {
"number": 9,
"name": "writable"
}
]
{"number": 1, "name": "bootloaders"},
{"number": 2, "name": "bootloaders_b"},
{"number": 3, "name": "firmware"},
{"number": 4, "name": "firmware_b"},
{"number": 5, "name": "dramk"},
{"number": 6, "name": "misc"},
{"number": 7, "name": "bootassets"},
{"number": 8, "name": "ubuntu-boot"},
{"number": 9, "name": "writable"},
],
}
self.expected_result_EMMC = {
"logical-sector-size": 512,
"physical-sector-size": 512,
"partitions": [
{
"number": 1,
"name": "bootloaders"
}, {
"number": 2,
"name": "bootloaders_b"
}, {
"number": 3,
"name": "firmware"
}, {
"number": 4,
"name": "firmware_b"
}, {
"number": 5,
"name": "dramk"
}, {
"number": 6,
"name": "misc"
}, {
"number": 7,
"name": "bootassets"
}, {
"number": 8,
"name": "ubuntu-boot"
}, {
"number": 9,
"name": "writable"
}
]
{"number": 1, "name": "bootloaders"},
{"number": 2, "name": "bootloaders_b"},
{"number": 3, "name": "firmware"},
{"number": 4, "name": "firmware_b"},
{"number": 5, "name": "dramk"},
{"number": 6, "name": "misc"},
{"number": 7, "name": "bootassets"},
{"number": 8, "name": "ubuntu-boot"},
{"number": 9, "name": "writable"},
],
}

def check_is_block_device(self):
print("\nChecking if it is block device...")
if pathlib.Path(self.path).is_block_device():
print("PASS: {} is a block device!".format(self.path))
else:
raise SystemExit("FAIL: {} is not a block device!"
.format(self.path))
raise SystemExit(
"FAIL: {} is not a block device!".format(self.path)
)

def check_disk(self):
print("\nChecking Parted...")
Expand All @@ -119,21 +84,31 @@ def get_disk_information(self):
def check_sector_size(self):
print("\nChecking Logical Sector Size...")
try:
if self.actual_result["logical-sector-size"] == \
self.expected_result["logical-sector-size"]:
print("logical sector size: {}"
.format(self.actual_result["logical-sector-size"]))
if (
self.actual_result["logical-sector-size"]
== self.expected_result["logical-sector-size"]
):
print(
"logical sector size: {}".format(
self.actual_result["logical-sector-size"]
)
)
print("PASS: Logical sector size is correct!")
else:
raise SystemExit("FAIL: Logical sector size is incorrect!")
except KeyError:
raise SystemExit("ERROR: logical-sector-size is not found")
print("\nChecking Physical Sector Size...")
try:
if self.actual_result["physical-sector-size"] == \
self.expected_result["physical-sector-size"]:
print("physical sector size: {}"
.format(self.actual_result["physical-sector-size"]))
if (
self.actual_result["physical-sector-size"]
== self.expected_result["physical-sector-size"]
):
print(
"physical sector size: {}".format(
self.actual_result["physical-sector-size"]
)
)
print("PASS: Physical sector size is correct!")
else:
raise SystemExit("FAIL: Physical sector size is incorrect!")
Expand All @@ -147,8 +122,9 @@ def check_partitions(self):
expected_partitions = self.expected_result["partitions"]
if len(actual_partitions) != len(expected_partitions):
raise SystemExit("ERROR: Partitions count is incorrect!")
for actual_partition, expected_partition in \
zip(actual_partitions, expected_partitions):
for actual_partition, expected_partition in zip(
actual_partitions, expected_partitions
):
if actual_partition["number"] != expected_partition["number"]:
raise SystemExit("ERROR: Partition number is incorrect!")
if actual_partition["name"] != expected_partition["name"]:
Expand All @@ -171,17 +147,22 @@ def check_device(self, exit_when_check_fail):
raise SystemExit("ERROR: Cannot find sdc or mmcblk0 in dev")

def main(self):
parser = ArgumentParser(description="Check if the disk information\
is correct")
parser.add_argument('--path',
help='the device path for checking')
parser.add_argument("--check_device_name",
help="To check the device name",
action="store_true")
parser.add_argument("--exit_when_check_fail",
help="Exit with error code when the device check \
parser = ArgumentParser(
description="Check if the disk information\
is correct"
)
parser.add_argument("--path", help="the device path for checking")
parser.add_argument(
"--check_device_name",
help="To check the device name",
action="store_true",
)
parser.add_argument(
"--exit_when_check_fail",
help="Exit with error code when the device check \
failed",
action="store_true")
action="store_true",
)
args = parser.parse_args()
if args.check_device_name:
self.check_device(args.exit_when_check_fail)
Expand All @@ -192,5 +173,5 @@ def main(self):
self.check_disk()


if __name__ == '__main__':
if __name__ == "__main__":
TestPartedBootDevice().main()
Loading

0 comments on commit 3ea6ef5

Please sign in to comment.