Skip to content
This repository was archived by the owner on Aug 5, 2022. It is now read-only.

Commit 443a91b

Browse files
committed
refkit_swupd.py: test script return code
We need to check the exact return code now. Also ensure that we always remove the .swupd-contenturl file, even after a failure. In addition, we simulate network issues. Only one of the two test cases are currently handled as expected by swupd. Signed-off-by: Patrick Ohly <patrick.ohly@intel.com>
1 parent 7252438 commit 443a91b

1 file changed

Lines changed: 115 additions & 4 deletions

File tree

meta-refkit-core/lib/oeqa/selftest/cases/refkit_swupd.py

Lines changed: 115 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -301,19 +301,20 @@ def normalize_partition_output(self, output, unknown_missing=False):
301301
# Number of files may vary.
302302
output, _ = re.subn(r'Inspected \d+ files', 'Inspected xxx files', output)
303303
# Timing varies.
304-
output, _ = re.subn(r'Update took \d.\d seconds', 'Update took x.y seconds', output)
304+
output, _ = re.subn(r'Update took \d+.\d seconds', 'Update took x.y seconds', output)
305305
# Re-installing from scratch means we don't know how many files actually miss (depends on OS).
306306
if unknown_missing:
307307
output, _ = re.subn(r'\d+ files were missing', 'xxx files were missing', output)
308308
output, _ = re.subn(r'\d+ of \d+ missing files were replaced', 'xxx of xxx missing files were replaced', output)
309309
output, _ = re.subn(r'0 of \d+ missing files were not replaced', '0 of xxx missing files were not replaced', output)
310310
return output
311311

312-
def update_partition(self, qemu, cmd, expected, version, **kwargs):
312+
def update_partition(self, qemu, cmd, expected, version, network_error=None, **kwargs):
313313
"""
314314
Run a single swupd-update-partition command and check the result, including the HTTP log.
315315
"""
316316
self.http_log.clear()
317+
self.stop_serving_http_at = network_error
317318
self.logger.info(cmd)
318319
status, output = qemu.run_serial(cmd, timeout=600)
319320
self.assertEqual(1, status, 'Failed to run command "%s":\n%s' % (cmd, output))
@@ -654,7 +655,7 @@ def update_image_via_http(qemu):
654655
# Update, with source, with formatting. For this we need to
655656
# set the content URL in the source partition for this and
656657
# remove it when done.
657-
cmd = 'echo "{0}" >/.swupd-contenturl && swupd-update-partition -c {0} -p /dev/disk/by-partuuid/{1} -m 20 -f "mkfs.ext4 -F /dev/disk/by-partuuid/{1}" -F -s / && rm /.swupd-contenturl'.format(url, self.PARTUUID)
658+
cmd = 'echo "{0}" >/.swupd-contenturl && swupd-update-partition -c {0} -p /dev/disk/by-partuuid/{1} -m 20 -f "mkfs.ext4 -F /dev/disk/by-partuuid/{1}" -F -s /; ret=$?; /.swupd-contenturl; [ $ret -eq 0 ]'.format(url, self.PARTUUID)
658659
# Some /etc files get modified at runtime due to the writable
659660
# rootfs and thus do not match.
660661
expected = '''swupd-update-partition: Bind-mounting source tree.
@@ -764,7 +765,7 @@ def update_image_via_http(qemu):
764765

765766
# Update, with source, with formatting, but wrong content URL
766767
# and thus using file fixing instead of the delta pack.
767-
cmd = 'echo "http://example.org" >/.swupd-contenturl && swupd-update-partition -c {0} -p /dev/disk/by-partuuid/{1} -m 20 -f "mkfs.ext4 -F /dev/disk/by-partuuid/{1}" -F -s / && rm /.swupd-contenturl'.format(url, self.PARTUUID)
768+
cmd = 'echo "http://example.org" >/.swupd-contenturl && swupd-update-partition -c {0} -p /dev/disk/by-partuuid/{1} -m 20 -f "mkfs.ext4 -F /dev/disk/by-partuuid/{1}" -F -s /; ret=$?; rm /.swupd-contenturl; [ $ret -eq 0 ]'.format(url, self.PARTUUID)
768769
# Some /etc files get modified at runtime due to the writable
769770
# rootfs and thus do not match.
770771
expected = '''swupd-update-partition: Bind-mounting source tree.
@@ -865,3 +866,113 @@ def update_image_via_http(qemu):
865866

866867
setattr(self, 'update_image_via_http', update_image_via_http)
867868
self.do_update('test_update_partition', self.IMAGE_MODIFY.UPDATES, have_zero_packs=True)
869+
870+
def test_update_same_url_network_0(self):
871+
"""
872+
Same as test_update_same_url, but with network errors before first HTTP request.
873+
"""
874+
875+
def update_image_via_http(qemu):
876+
self.maxDiff = None
877+
url = 'http://%s' % self.HTTPD_SERVER
878+
879+
# Update, with source, with formatting. For this we need to
880+
# set the content URL in the source partition for this and
881+
# remove it when done.
882+
cmd = 'echo "{0}" >/.swupd-contenturl && swupd-update-partition -c {0} -p /dev/disk/by-partuuid/{1} -m 20 -f "mkfs.ext4 -F /dev/disk/by-partuuid/{1}" -F -s /; ret=$?; rm /.swupd-contenturl; [ $ret -eq 2 ]'.format(url, self.PARTUUID)
883+
# Some /etc files get modified at runtime due to the writable
884+
# rootfs and thus do not match.
885+
expected = '''swupd-update-partition: Bind-mounting source tree.
886+
swupd-update-partition: mount -obind,ro / /tmp/swupd-mount-source.X
887+
swupd-update-partition: Updating to 20 from {url}.
888+
swupd-update-partition: Reinstalling from scratch.
889+
swupd-update-partition: Formatting partition.
890+
swupd-update-partition: mkfs.ext4 -F /dev/disk/by-partuuid/87654321-9abc-def0-0fed-cba987654320
891+
...
892+
swupd-update-partition: mount /dev/disk/by-partuuid/{uuid} /tmp/swupd-mount.X
893+
swupd-update-partition: Copy from source /.
894+
swupd-update-partition: Content URL unchanged, trying to update.
895+
swupd-update-partition: swupd update -c {url} -v file:///tmp/swupd-version.X -S /tmp/swupd-mount.X/swupd-state -p /tmp/swupd-mount.X
896+
swupd-client software ...
897+
898+
Attempting to download version string to memory
899+
Update started.
900+
Preparing to update from 10 to 20
901+
Failed to retrieve 10 MoM manifest
902+
Retry #1 downloading from/to MoM Manifests
903+
Failed to retrieve 10 MoM manifest
904+
Retry #2 downloading from/to MoM Manifests
905+
Failed to retrieve 10 MoM manifest
906+
Retry #3 downloading from/to MoM Manifests
907+
Failed to retrieve 10 MoM manifest
908+
Failure retrieving manifest from server
909+
Update took x.y seconds
910+
swupd-update-partition: swupd: EMOM_NOTFOUND = 4 = MoM cannot be loaded into memory (this could imply network issue)
911+
swupd-update-partition: Update failed temporarily.
912+
913+
code 500, message test server is intentionally down
914+
"GET /10/Manifest.MoM.tar HTTP/1.1" 500 -
915+
code 500, message test server is intentionally down
916+
"GET /10/Manifest.MoM.tar HTTP/1.1" 500 -
917+
code 500, message test server is intentionally down
918+
"GET /10/Manifest.MoM.tar HTTP/1.1" 500 -
919+
code 500, message test server is intentionally down
920+
"GET /10/Manifest.MoM.tar HTTP/1.1" 500 -
921+
'''.format(
922+
uuid=self.PARTUUID,
923+
url=url
924+
)
925+
self.update_partition(qemu, cmd, expected, 20, network_error=0)
926+
927+
# No reboot, we are done.
928+
return False
929+
930+
setattr(self, 'update_image_via_http', update_image_via_http)
931+
self.do_update('test_update_partition', self.IMAGE_MODIFY.UPDATES, have_zero_packs=True)
932+
933+
def test_update_same_url_network_4(self):
934+
"""
935+
Same as test_update_same_url, but with network errors before fifth HTTP request.
936+
"""
937+
938+
def update_image_via_http(qemu):
939+
self.skipTest('swupd does not detect this network error as it should - https://github.com/clearlinux/swupd-client/issues/323')
940+
941+
self.maxDiff = None
942+
url = 'http://%s' % self.HTTPD_SERVER
943+
944+
# Update, with source, with formatting. For this we need to
945+
# set the content URL in the source partition for this and
946+
# remove it when done.
947+
cmd = 'echo "{0}" >/.swupd-contenturl && swupd-update-partition -c {0} -p /dev/disk/by-partuuid/{1} -m 20 -f "mkfs.ext4 -F /dev/disk/by-partuuid/{1}" -F -s /; ret=$?; rm /.swupd-contenturl; [ $ret -eq 2 ]'.format(url, self.PARTUUID)
948+
# Some /etc files get modified at runtime due to the writable
949+
# rootfs and thus do not match.
950+
expected = '''swupd-update-partition: Bind-mounting source tree.
951+
swupd-update-partition: mount -obind,ro / /tmp/swupd-mount-source.X
952+
swupd-update-partition: Updating to 20 from {url}.
953+
swupd-update-partition: Reinstalling from scratch.
954+
swupd-update-partition: Formatting partition.
955+
swupd-update-partition: mkfs.ext4 -F /dev/disk/by-partuuid/87654321-9abc-def0-0fed-cba987654320
956+
...
957+
swupd-update-partition: mount /dev/disk/by-partuuid/{uuid} /tmp/swupd-mount.X
958+
swupd-update-partition: Copy from source /.
959+
swupd-update-partition: Content URL unchanged, trying to update.
960+
swupd-update-partition: swupd update -c {url} -v file:///tmp/swupd-version.X -S /tmp/swupd-mount.X/swupd-state -p /tmp/swupd-mount.X
961+
swupd-client software ...
962+
963+
Attempting to download version string to memory
964+
Update started.
965+
Preparing to update from 10 to 20
966+
967+
TODO: insert actual output.
968+
'''.format(
969+
uuid=self.PARTUUID,
970+
url=url
971+
)
972+
self.update_partition(qemu, cmd, expected, 20, network_error=4)
973+
974+
# No reboot, we are done.
975+
return False
976+
977+
setattr(self, 'update_image_via_http', update_image_via_http)
978+
self.do_update('test_update_partition', self.IMAGE_MODIFY.UPDATES, have_zero_packs=True)

0 commit comments

Comments
 (0)