Skip to content

Commit bdcabfa

Browse files
committed
testscript: replace assert int(..... with self.assert* helpers
Superior error reporting. On-behalf-of: SAP philipp.schuster@sap.com Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
1 parent 7c75bd3 commit bdcabfa

File tree

1 file changed

+42
-28
lines changed

1 file changed

+42
-28
lines changed

tests/testscript.py

Lines changed: 42 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -572,12 +572,16 @@ def test_live_migration_with_hugepages(self):
572572
status, out = controllerVM.execute(
573573
"awk '/HugePages_Free/ { print $2; exit }' /proc/meminfo"
574574
)
575-
assert int(out) == NR_HUGEPAGES, "unable to allocate hugepages"
575+
self.assertEqual(
576+
int(out), NR_HUGEPAGES, "unable to allocate hugepages on controllerVM"
577+
)
576578

577579
status, out = computeVM.execute(
578580
"awk '/HugePages_Free/ { print $2; exit }' /proc/meminfo"
579581
)
580-
assert int(out) == NR_HUGEPAGES, "unable to allocate hugepages"
582+
self.assertEqual(
583+
int(out), NR_HUGEPAGES, "unable to allocate hugepages on computeVM"
584+
)
581585

582586
controllerVM.succeed("virsh define /etc/domain-chv-hugepages-prefault.xml")
583587
controllerVM.succeed("virsh start testvm")
@@ -587,7 +591,9 @@ def test_live_migration_with_hugepages(self):
587591
status, out = controllerVM.execute(
588592
"awk '/HugePages_Free/ { print $2; exit }' /proc/meminfo"
589593
)
590-
assert int(out) == 0, "not enough huge pages are in-use"
594+
self.assertEqual(
595+
int(out), 0, "not enough huge pages are in-use on controllerVM"
596+
)
591597

592598
controllerVM.succeed(
593599
"virsh migrate --domain testvm --desturi ch+tcp://computeVM/session --persistent --live --p2p --parallel --parallel-connections 4"
@@ -598,12 +604,14 @@ def test_live_migration_with_hugepages(self):
598604
status, out = computeVM.execute(
599605
"awk '/HugePages_Free/ { print $2; exit }' /proc/meminfo"
600606
)
601-
assert int(out) == 0, "not enough huge pages are in-use"
607+
self.assertEqual(int(out), 0, "not enough huge pages are in-use on computeVM")
602608

603609
status, out = controllerVM.execute(
604610
"awk '/HugePages_Free/ { print $2; exit }' /proc/meminfo"
605611
)
606-
assert int(out) == NR_HUGEPAGES, "not all huge pages have been freed"
612+
self.assertEqual(
613+
int(out), NR_HUGEPAGES, "not all huge pages have been freed on controllerVM"
614+
)
607615

608616
def test_live_migration_with_hugepages_failure_case(self):
609617
"""
@@ -614,7 +622,9 @@ def test_live_migration_with_hugepages_failure_case(self):
614622
status, out = controllerVM.execute(
615623
"awk '/HugePages_Free/ { print $2; exit }' /proc/meminfo"
616624
)
617-
assert int(out) == NR_HUGEPAGES, "unable to allocate hugepages"
625+
self.assertEqual(
626+
int(out), NR_HUGEPAGES, "not all huge pages have been freed on controllerVM"
627+
)
618628

619629
controllerVM.succeed("virsh define /etc/domain-chv-hugepages-prefault.xml")
620630
controllerVM.succeed("virsh start testvm")
@@ -648,11 +658,11 @@ def test_numa_topology(self):
648658
# Check that there are 2 CPU sockets and 2 threads per core
649659
status, out = ssh(controllerVM, "lscpu | grep Socket | awk '{print $2}'")
650660
self.assertEqual(status, 0)
651-
assert int(out) == 2, "Expect to find 2 sockets"
661+
self.assertEqual(int(out), 2, "could not find two sockets")
652662

653663
status, out = ssh(controllerVM, "lscpu | grep Thread\\( | awk '{print $4}'")
654664
self.assertEqual(status, 0)
655-
assert int(out) == 2, "Expect to find 2 threads per core"
665+
self.assertEqual(int(out), 2, "could not find two threads per core")
656666

657667
def test_cirros_image(self):
658668
"""
@@ -679,7 +689,7 @@ def test_hugepages(self):
679689
status, out = controllerVM.execute(
680690
"awk '/HugePages_Free/ { print $2; exit }' /proc/meminfo"
681691
)
682-
assert int(out) < NR_HUGEPAGES, "No huge pages have been used"
692+
self.assertLess(int(out), NR_HUGEPAGES, "no huge pages have been used")
683693

684694
def test_hugepages_prefault(self):
685695
"""
@@ -696,7 +706,7 @@ def test_hugepages_prefault(self):
696706
status, out = controllerVM.execute(
697707
"awk '/HugePages_Free/ { print $2; exit }' /proc/meminfo"
698708
)
699-
assert int(out) == 0, "Invalid hugepage usage"
709+
self.assertEqual(int(out), 0, "not all huge pages are in use")
700710

701711
def test_numa_hugepages(self):
702712
"""
@@ -720,7 +730,7 @@ def test_numa_hugepages(self):
720730
status, out = controllerVM.execute(
721731
"awk '/HugePages_Free/ { print $2; exit }' /proc/meminfo"
722732
)
723-
assert int(out) < NR_HUGEPAGES, "No huge pages have been used"
733+
self.assertLess(int(out), NR_HUGEPAGES, "no huge pages have been used")
724734

725735
def test_numa_hugepages_prefault(self):
726736
"""
@@ -744,7 +754,7 @@ def test_numa_hugepages_prefault(self):
744754
status, out = controllerVM.execute(
745755
"awk '/HugePages_Free/ { print $2; exit }' /proc/meminfo"
746756
)
747-
assert int(out) == 0, "Invalid huge page usage"
757+
self.assertEqual(int(out), 0, "not all huge pages are in use")
748758

749759
def test_serial_file_output(self):
750760
"""
@@ -757,7 +767,7 @@ def test_serial_file_output(self):
757767
wait_for_ssh(controllerVM)
758768

759769
status, out = controllerVM.execute("cat /tmp/vm_serial.log | wc -l")
760-
assert int(out) > 50
770+
self.assertGreater(int(out), 50, "no serial log output")
761771

762772
status, out = controllerVM.execute("grep 'Welcome to NixOS' /tmp/vm_serial.log")
763773

@@ -1119,8 +1129,8 @@ def test_disk_resize_raw(self):
11191129
disk_size_host = controllerVM.succeed("ls /tmp/disk.img -l | awk '{print $5}'")
11201130

11211131
self.assertEqual(status, 0)
1122-
assert int(disk_size_guest) == disk_size_bytes_100M
1123-
assert int(disk_size_host) == disk_size_bytes_100M
1132+
self.assertEqual(int(disk_size_guest), disk_size_bytes_100M)
1133+
self.assertEqual(int(disk_size_host), disk_size_bytes_100M)
11241134

11251135
# Use full file path instead of virtual device name here because both should work with --path
11261136
controllerVM.succeed(
@@ -1133,8 +1143,8 @@ def test_disk_resize_raw(self):
11331143
disk_size_host = controllerVM.succeed("ls /tmp/disk.img -l | awk '{print $5}'")
11341144

11351145
self.assertEqual(status, 0)
1136-
assert int(disk_size_guest) == disk_size_bytes_10M
1137-
assert int(disk_size_host) == disk_size_bytes_10M
1146+
self.assertEqual(int(disk_size_guest), disk_size_bytes_10M)
1147+
self.assertEqual(int(disk_size_host), disk_size_bytes_10M)
11381148

11391149
# Use virtual device name as --path
11401150
controllerVM.succeed(
@@ -1147,8 +1157,8 @@ def test_disk_resize_raw(self):
11471157
disk_size_host = controllerVM.succeed("ls /tmp/disk.img -l | awk '{print $5}'")
11481158

11491159
self.assertEqual(status, 0)
1150-
assert int(disk_size_guest) == disk_size_bytes_200M
1151-
assert int(disk_size_host) == disk_size_bytes_200M
1160+
self.assertEqual(int(disk_size_guest), disk_size_bytes_200M)
1161+
self.assertEqual(int(disk_size_host), disk_size_bytes_200M)
11521162

11531163
# Use bytes instead of KiB
11541164
controllerVM.succeed(
@@ -1161,8 +1171,8 @@ def test_disk_resize_raw(self):
11611171
disk_size_host = controllerVM.succeed("ls /tmp/disk.img -l | awk '{print $5}'")
11621172

11631173
self.assertEqual(status, 0)
1164-
assert int(disk_size_guest) == disk_size_bytes_100M
1165-
assert int(disk_size_host) == disk_size_bytes_100M
1174+
self.assertEqual(int(disk_size_guest), disk_size_bytes_100M)
1175+
self.assertEqual(int(disk_size_host), disk_size_bytes_100M)
11661176

11671177
# Changing to capacity must fail and not change the disk size because it
11681178
# is not supported for file-based disk images.
@@ -1174,8 +1184,8 @@ def test_disk_resize_raw(self):
11741184
disk_size_host = controllerVM.succeed("ls /tmp/disk.img -l | awk '{print $5}'")
11751185

11761186
self.assertEqual(status, 0)
1177-
assert int(disk_size_guest) == disk_size_bytes_100M
1178-
assert int(disk_size_host) == disk_size_bytes_100M
1187+
self.assertEqual(int(disk_size_guest), disk_size_bytes_100M)
1188+
self.assertEqual(int(disk_size_host), disk_size_bytes_100M)
11791189

11801190
def test_disk_is_locked(self):
11811191
"""
@@ -1235,7 +1245,7 @@ def test_disk_resize_qcow2(self):
12351245
)
12361246

12371247
self.assertEqual(status, 0)
1238-
assert int(disk_size_guest) == disk_size_bytes_100M
1248+
self.assertEqual(int(disk_size_guest), disk_size_bytes_100M)
12391249

12401250
controllerVM.fail(
12411251
f"virsh blockresize --domain testvm --path vdb --size {disk_size_bytes_10M // 1024}"
@@ -1294,8 +1304,8 @@ def test_live_migration_with_vcpu_pinning(self):
12941304
f"taskset -p {tid_vcpu2_controller} | awk '{{print $6}}'"
12951305
).rstrip()
12961306

1297-
assert int(taskset_vcpu0_controller, 16) == 0x3
1298-
assert int(taskset_vcpu2_controller, 16) == 0xC
1307+
self.assertEqual(int(taskset_vcpu0_controller, 16), 0x3)
1308+
self.assertEqual(int(taskset_vcpu2_controller, 16), 0xC)
12991309

13001310
controllerVM.succeed(
13011311
"virsh migrate --domain testvm --desturi ch+tcp://computeVM/session --persistent --live --p2p --parallel --parallel-connections 4"
@@ -1318,8 +1328,12 @@ def test_live_migration_with_vcpu_pinning(self):
13181328
f"taskset -p {tid_vcpu2_compute} | awk '{{print $6}}'"
13191329
).rstrip()
13201330

1321-
assert int(taskset_vcpu0_controller, 16) == int(taskset_vcpu0_compute, 16)
1322-
assert int(taskset_vcpu2_controller, 16) == int(taskset_vcpu2_compute, 16)
1331+
self.assertEqual(
1332+
int(taskset_vcpu0_controller, 16), int(taskset_vcpu0_compute, 16)
1333+
)
1334+
self.assertEqual(
1335+
int(taskset_vcpu2_controller, 16), int(taskset_vcpu2_compute, 16)
1336+
)
13231337

13241338
def test_live_migration_kill_chv_on_sender_side(self):
13251339
"""

0 commit comments

Comments
 (0)