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

Commit ae2f822

Browse files
committed
TEST: various fixes for testing in the CI
1 parent 53e8d82 commit ae2f822

5 files changed

Lines changed: 75 additions & 26 deletions

File tree

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ class RefkitOSTreeUpdateBase(HTTPUpdate):
1414
IMAGE_BBAPPEND = IMAGE_PN + '.bbappend'
1515
IMAGE_BBAPPEND_UPDATE = IMAGE_BBAPPEND
1616

17-
# We cannot get the actual OSTREE_REPO for the
18-
# image here, so we just assume that it is in the usual place.
19-
REPO_DIR = os.path.join(HTTPUpdate.BB_VARS['DEPLOY_DIR'], 'ostree-repo')
17+
def setUp(self):
18+
# We cannot get the actual OSTREE_REPO for the
19+
# image here, so we just assume that it is in the usual place.
20+
self.REPO_DIR = os.path.join(HTTPUpdate.BB_VARS['DEPLOY_DIR'], 'ostree-repo')
21+
super().setUp()
2022

2123
def stop_update_service(self, qemu):
2224
cmd = '''systemctl stop refkit-update.service'''

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

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ class RefkitSwupdUpdateBase(HTTPUpdate):
1818
IMAGE_BBAPPEND = IMAGE_PN + '.bbappend'
1919
IMAGE_BBAPPEND_UPDATE = IMAGE_BBAPPEND
2020

21-
SWUPD_DIR = os.path.join(HTTPUpdate.BB_VARS['DEPLOY_DIR'], 'swupd', HTTPUpdate.BB_VARS['MACHINE'], IMAGE_PN)
22-
REPO_DIR = os.path.join(SWUPD_DIR, 'www')
21+
def setUp(self):
22+
self.SWUPD_DIR = os.path.join(HTTPUpdate.BB_VARS['DEPLOY_DIR'], 'swupd', HTTPUpdate.BB_VARS['MACHINE'], self.IMAGE_PN)
23+
self.REPO_DIR = os.path.join(self.SWUPD_DIR, 'www')
24+
super().setUp()
2325

2426
IMAGE_MODIFY = copy.copy(HTTPUpdate.IMAGE_MODIFY)
2527

@@ -138,13 +140,15 @@ def update_image_via_http(self, qemu):
138140

139141
def update_image(self, qemu):
140142
# Dump some information about changes in version 20.
141-
print('Changes in 20/Manifest.full:')
143+
lines = []
144+
lines.append('Changes in 20/Manifest.full:\n')
142145
entry_re = re.compile('^(?P<type>\S+)\s+(?P<hash>[0-9a-f]+)\s+(?P<version>\d+)\s+(?P<path>.*)$')
143146
with open(os.path.join(self.REPO_DIR, '20', 'Manifest.full')) as f:
144147
for line in f:
145148
m = entry_re.match(line)
146149
if m and m.group('version') == '20':
147-
print(line, end='')
150+
lines.append(line)
151+
self.logger.info(''.join(lines))
148152
super().update_image(qemu)
149153

150154
class RefkitSwupdUpdateTestAll(RefkitSwupdUpdateBase):
@@ -171,9 +175,8 @@ def test_update_all(self):
171175
if any(map(lambda x: x in line, hashes)):
172176
file_names.append(line)
173177
self.fail('should have %d files, got %d:\n%s\n\nManifest.full:\n%s' % (expected, len(files), '\n'.join(files), ' '.join(file_names)))
174-
# In two cases, a delta made sense.
175178
deltas = [x for x in repo_items if x.startswith('20/delta/')]
176-
self.assertEqual(len(deltas), 2, msg='should have 1 delta, got: %s' % deltas)
179+
self.assertEqual(len(deltas), 1, msg='should have 1 delta for modify_files_large, got: %s' % deltas)
177180

178181
class RefkitSwupdUpdateTestIncremental(RefkitSwupdUpdateBase):
179182

@@ -201,6 +204,7 @@ def modify_image_build(self, testname, updates, is_update):
201204
def setUp(self):
202205
self.wwwdir = os.path.abspath('test-swupd-www')
203206
# self.track_for_cleanup(self.wwwdir)
207+
super().setUp()
204208

205209
def test_update_incremental(self):
206210
"""
@@ -256,6 +260,8 @@ def modify_image_build(self, testname, updates, is_update):
256260
bbappend.append('REFKIT_EXTRA_PARTITION = "part ${REFKIT_IMAGE_SIZE} --fstype=ext4 --label inactive --align 1024 --uuid %s"' % self.PARTUUID)
257261
# Needed for installing from scratch.
258262
bbappend.append('SWUPD_GENERATE_OS_CORE_ZERO_PACK = "true"')
263+
# Needed for formatting the partition.
264+
bbappend.append('REFKIT_IMAGE_EXTRA_INSTALL_append = " e2fsprogs"')
259265
return '\n'.join(bbappend)
260266

261267
def normalize_partition_output(self, output, zero_missing=False):
@@ -287,10 +293,10 @@ def update_partition(self, qemu, cmd, expected, version, **kwargs):
287293
Run a single swupd-update-partition command and check the result, including the HTTP log.
288294
"""
289295
self.http_log.clear()
290-
print(cmd)
296+
self.logger.info(cmd)
291297
status, output = qemu.run_serial(cmd, timeout=600)
292298
self.assertEqual(1, status, 'Failed to run command "%s":\n%s' % (cmd, output))
293-
print(output)
299+
self.logger.info(output)
294300
output = self.normalize_partition_output(output, **kwargs)
295301
# Normalize the HTTP log by replacing /10/files/57de850a026aee38bb06a2a8d6c014a773c2dc3268032b44c0b5b3e7e4ec53f2.tar
296302
# with

meta-refkit-core/lib/oeqa/selftest/systemupdate/httpupdate.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,25 @@ class HTTPUpdate(SystemUpdateBase):
2323

2424
# Global variables are the same for all recipes,
2525
# but RECIPE_SYSROOT_NATIVE is specific to socat-native.
26-
BB_VARS = get_bb_vars([
27-
'DEPLOY_DIR',
28-
'MACHINE',
29-
'RECIPE_SYSROOT_NATIVE',
30-
],
31-
'socat-native')
32-
33-
# To be set by derived class.
26+
# We store that in the class because then it can be shared by
27+
# multiple derived instances.
28+
class DelayedGetVars:
29+
def __init__(self):
30+
self._cache = None
31+
32+
def __getitem__(self, key):
33+
if self._cache is None:
34+
self._cache = get_bb_vars([
35+
'DEPLOY_DIR',
36+
'MACHINE',
37+
'RECIPE_SYSROOT_NATIVE',
38+
],
39+
'socat-native')
40+
return self._cache[key]
41+
42+
BB_VARS = DelayedGetVars()
43+
44+
# To be set by derived class or instance.
3445
REPO_DIR = None
3546

3647
def track_for_cleanup(self, name):

meta-refkit-core/lib/oeqa/selftest/systemupdate/systemupdatebase.py

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ class SystemUpdateModify(object):
4343
( 'udev/udev.conf', None ),
4444
]
4545

46+
LARGE_FILE_CONTENT = '!"#$%&()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_abcdefghijklmnopqrstuvwxyz{|}~'
47+
LARGE_FILE_CONTENT_APPEND = 'hello'
48+
4649
def modify_kernel(self, testname, is_update, rootfs):
4750
"""
4851
Patch the kernel in an existing rootfs. Called during rootfs construction,
@@ -66,14 +69,29 @@ def modify_files(self, testname, is_update, rootfs):
6669
"""
6770
Simulate simple adding, removing and modifying of files under /usr/bin.
6871
"""
69-
testdir = os.path.join(rootfs, 'usr', 'bin')
72+
testdir = pathlib.Path(rootfs) / 'usr' / 'bin'
73+
remove_me = testdir / 'modify_files_remove_me'
74+
update_me = testdir / 'modify_files_update_me'
75+
was_added = testdir / 'modify_files_was_added'
76+
large = testdir / 'modify_files_large'
77+
78+
# Add/remove file cases.
7079
if not is_update:
71-
pathlib.Path(os.path.join(testdir, 'modify_files_remove_me')).touch()
72-
pathlib.Path(os.path.join(testdir, 'modify_files_update_me')).touch()
80+
remove_me.touch()
7381
else:
74-
with open(os.path.join(testdir, 'modify_files_update_me'), 'w') as f:
82+
was_added.touch()
83+
84+
# This is case where the full new file is smaller than a delta.
85+
with update_me.open('w') as f:
86+
if is_update:
7587
f.write('updated\n')
76-
pathlib.Path(os.path.join(testdir, 'modify_files_was_added')).touch()
88+
89+
# Whereas for a large file, a binary delta is more efficient.
90+
with large.open('w') as f:
91+
f.write(self.LARGE_FILE_CONTENT)
92+
if is_update:
93+
f.write(self.LARGE_FILE_CONTENT_APPEND)
94+
f.write('\n')
7795

7896
def verify_files(self, testname, is_update, qemu, test):
7997
"""
@@ -83,14 +101,22 @@ def verify_files(self, testname, is_update, qemu, test):
83101
status, output = qemu.run_serial(cmd)
84102
test.assertEqual(1, status, 'Failed to run command "%s":\n%s' % (cmd, output))
85103
if not is_update:
86-
test.assertEqual(output, '/usr/bin/modify_files_remove_me\r\n/usr/bin/modify_files_update_me')
104+
test.assertEqual(output, '/usr/bin/modify_files_large\r\n/usr/bin/modify_files_remove_me\r\n/usr/bin/modify_files_update_me')
87105
else:
88-
test.assertEqual(output, '/usr/bin/modify_files_update_me\r\n/usr/bin/modify_files_was_added')
106+
test.assertEqual(output, '/usr/bin/modify_files_large\r\n/usr/bin/modify_files_update_me\r\n/usr/bin/modify_files_was_added')
89107
cmd = 'cat /usr/bin/modify_files_update_me'
90108
status, output = qemu.run_serial(cmd)
91109
test.assertEqual(1, status, 'Failed to run command "%s":\n%s' % (cmd, output))
92110
test.assertEqual(output, 'updated')
93111

112+
cmd = 'cat /usr/bin/modify_files_large'
113+
status, output = qemu.run_serial(cmd)
114+
test.assertEqual(1, status, 'Failed to run command "%s":\n%s' % (cmd, output))
115+
expected = self.LARGE_FILE_CONTENT
116+
if is_update:
117+
expected += self.LARGE_FILE_CONTENT_APPEND
118+
test.assertEqual(expected, output)
119+
94120
def modify_etc(self, testname, is_update, rootfs):
95121
"""
96122
If there are files in /etc, then it should be possible to update

meta-refkit-core/recipes-selftest/images/refkit-image-update-swupd.bb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,7 @@ REFKIT_IMAGE_EXTRA_FEATURES += "connectivity"
1111
# Speed up testing by disabling the os-core zero pack.
1212
# It is only needed for "swupd verify --install".
1313
SWUPD_GENERATE_OS_CORE_ZERO_PACK = "false"
14+
15+
# BUILD_ID is fixed in the CI system and variable in local builds (=
16+
# ${DATETIME}). To ensure consistent test results, we keep it fixed here.
17+
BUILD_ID = "swupd-test-build"

0 commit comments

Comments
 (0)