summaryrefslogtreecommitdiffstats
path: root/lib/oeqa/selftest/cases/updater_qemux86_64.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/oeqa/selftest/cases/updater_qemux86_64.py')
-rw-r--r--lib/oeqa/selftest/cases/updater_qemux86_64.py107
1 files changed, 44 insertions, 63 deletions
diff --git a/lib/oeqa/selftest/cases/updater_qemux86_64.py b/lib/oeqa/selftest/cases/updater_qemux86_64.py
index e26a022..80d135f 100644
--- a/lib/oeqa/selftest/cases/updater_qemux86_64.py
+++ b/lib/oeqa/selftest/cases/updater_qemux86_64.py
@@ -2,6 +2,7 @@
2import os 2import os
3import logging 3import logging
4import re 4import re
5import subprocess
5import unittest 6import unittest
6from time import sleep 7from time import sleep
7from uuid import uuid4 8from uuid import uuid4
@@ -9,7 +10,8 @@ from uuid import uuid4
9from oeqa.selftest.case import OESelftestTestCase 10from oeqa.selftest.case import OESelftestTestCase
10from oeqa.utils.commands import runCmd, bitbake, get_bb_var, get_bb_vars 11from oeqa.utils.commands import runCmd, bitbake, get_bb_var, get_bb_vars
11from testutils import qemu_launch, qemu_send_command, qemu_terminate, \ 12from testutils import qemu_launch, qemu_send_command, qemu_terminate, \
12 akt_native_run, verifyNotProvisioned, verifyProvisioned, qemu_bake_image, qemu_boot_image 13 metadir, akt_native_run, verifyNotProvisioned, verifyProvisioned, \
14 qemu_bake_image, qemu_boot_image
13 15
14 16
15class GeneralTests(OESelftestTestCase): 17class GeneralTests(OESelftestTestCase):
@@ -17,6 +19,9 @@ class GeneralTests(OESelftestTestCase):
17 logger = logging.getLogger("selftest") 19 logger = logging.getLogger("selftest")
18 logger.info('Running bitbake to build core-image-minimal') 20 logger.info('Running bitbake to build core-image-minimal')
19 self.append_config('SOTA_CLIENT_PROV = "aktualizr-shared-prov"') 21 self.append_config('SOTA_CLIENT_PROV = "aktualizr-shared-prov"')
22
23 # note: this also tests ostreepush/garagesign/garagecheck which are
24 # omitted from other test cases
20 bitbake('core-image-minimal') 25 bitbake('core-image-minimal')
21 credentials = get_bb_var('SOTA_PACKED_CREDENTIALS') 26 credentials = get_bb_var('SOTA_PACKED_CREDENTIALS')
22 # skip the test if the variable SOTA_PACKED_CREDENTIALS is not set 27 # skip the test if the variable SOTA_PACKED_CREDENTIALS is not set
@@ -39,20 +44,18 @@ class AktualizrToolsTests(OESelftestTestCase):
39 super(AktualizrToolsTests, cls).setUpClass() 44 super(AktualizrToolsTests, cls).setUpClass()
40 logger = logging.getLogger("selftest") 45 logger = logging.getLogger("selftest")
41 logger.info('Running bitbake to build aktualizr-native tools') 46 logger.info('Running bitbake to build aktualizr-native tools')
42 bitbake('aktualizr-native') 47 bitbake('aktualizr-native aktualizr-device-prov')
48 bitbake('build-sysroots -c build_native_sysroot')
43 49
44 def test_cert_provider_help(self): 50 def test_cert_provider_help(self):
45 akt_native_run(self, 'aktualizr-cert-provider --help') 51 akt_native_run(self, 'aktualizr-cert-provider --help')
46 52
47 def test_cert_provider_local_output(self): 53 def test_cert_provider_local_output(self):
48 logger = logging.getLogger("selftest")
49 logger.info('Running bitbake to build aktualizr-device-prov')
50 bitbake('aktualizr-device-prov')
51 bb_vars = get_bb_vars(['SOTA_PACKED_CREDENTIALS', 'T'], 'aktualizr-native') 54 bb_vars = get_bb_vars(['SOTA_PACKED_CREDENTIALS', 'T'], 'aktualizr-native')
52 creds = bb_vars['SOTA_PACKED_CREDENTIALS'] 55 creds = bb_vars['SOTA_PACKED_CREDENTIALS']
53 temp_dir = bb_vars['T'] 56 temp_dir = bb_vars['T']
54 bb_vars_prov = get_bb_vars(['STAGING_DIR_HOST', 'libdir'], 'aktualizr-device-prov') 57 bb_vars_prov = get_bb_vars(['WORKDIR', 'libdir'], 'aktualizr-device-prov')
55 config = bb_vars_prov['STAGING_DIR_HOST'] + bb_vars_prov['libdir'] + '/sota/sota-device-cred.toml' 58 config = bb_vars_prov['WORKDIR'] + '/sysroot-destdir' + bb_vars_prov['libdir'] + '/sota/conf.d/20-sota-device-cred.toml'
56 59
57 akt_native_run(self, 'aktualizr-cert-provider -c {creds} -r -l {temp} -g {config}' 60 akt_native_run(self, 'aktualizr-cert-provider -c {creds} -r -l {temp} -g {config}'
58 .format(creds=creds, temp=temp_dir, config=config)) 61 .format(creds=creds, temp=temp_dir, config=config))
@@ -75,17 +78,13 @@ class SharedCredProvTests(OESelftestTestCase):
75 layer = "meta-updater-qemux86-64" 78 layer = "meta-updater-qemux86-64"
76 result = runCmd('bitbake-layers show-layers') 79 result = runCmd('bitbake-layers show-layers')
77 if re.search(layer, result.output) is None: 80 if re.search(layer, result.output) is None:
78 # Assume the directory layout for finding other layers. We could also 81 self.meta_qemu = metadir() + layer
79 # make assumptions by using 'show-layers', but either way, if the
80 # layers we need aren't where we expect them, we are out of luck.
81 path = os.path.abspath(os.path.dirname(__file__))
82 metadir = path + "/../../../../../"
83 self.meta_qemu = metadir + layer
84 runCmd('bitbake-layers add-layer "%s"' % self.meta_qemu) 82 runCmd('bitbake-layers add-layer "%s"' % self.meta_qemu)
85 else: 83 else:
86 self.meta_qemu = None 84 self.meta_qemu = None
87 self.append_config('MACHINE = "qemux86-64"') 85 self.append_config('MACHINE = "qemux86-64"')
88 self.append_config('SOTA_CLIENT_PROV = " aktualizr-shared-prov "') 86 self.append_config('SOTA_CLIENT_PROV = " aktualizr-shared-prov "')
87 self.append_config('IMAGE_FSTYPES_remove = "ostreepush garagesign garagecheck"')
89 self.qemu, self.s = qemu_launch(machine='qemux86-64') 88 self.qemu, self.s = qemu_launch(machine='qemux86-64')
90 89
91 def tearDownLocal(self): 90 def tearDownLocal(self):
@@ -117,18 +116,14 @@ class ManualControlTests(OESelftestTestCase):
117 layer = "meta-updater-qemux86-64" 116 layer = "meta-updater-qemux86-64"
118 result = runCmd('bitbake-layers show-layers') 117 result = runCmd('bitbake-layers show-layers')
119 if re.search(layer, result.output) is None: 118 if re.search(layer, result.output) is None:
120 # Assume the directory layout for finding other layers. We could also 119 self.meta_qemu = metadir() + layer
121 # make assumptions by using 'show-layers', but either way, if the
122 # layers we need aren't where we expect them, we are out of like.
123 path = os.path.abspath(os.path.dirname(__file__))
124 metadir = path + "/../../../../../"
125 self.meta_qemu = metadir + layer
126 runCmd('bitbake-layers add-layer "%s"' % self.meta_qemu) 120 runCmd('bitbake-layers add-layer "%s"' % self.meta_qemu)
127 else: 121 else:
128 self.meta_qemu = None 122 self.meta_qemu = None
129 self.append_config('MACHINE = "qemux86-64"') 123 self.append_config('MACHINE = "qemux86-64"')
130 self.append_config('SOTA_CLIENT_PROV = " aktualizr-shared-prov "') 124 self.append_config('SOTA_CLIENT_PROV = " aktualizr-shared-prov "')
131 self.append_config('SYSTEMD_AUTO_ENABLE_aktualizr = "disable"') 125 self.append_config('SYSTEMD_AUTO_ENABLE_aktualizr = "disable"')
126 self.append_config('IMAGE_FSTYPES_remove = "ostreepush garagesign garagecheck"')
132 self.qemu, self.s = qemu_launch(machine='qemux86-64') 127 self.qemu, self.s = qemu_launch(machine='qemux86-64')
133 128
134 def tearDownLocal(self): 129 def tearDownLocal(self):
@@ -161,20 +156,16 @@ class DeviceCredProvTests(OESelftestTestCase):
161 layer = "meta-updater-qemux86-64" 156 layer = "meta-updater-qemux86-64"
162 result = runCmd('bitbake-layers show-layers') 157 result = runCmd('bitbake-layers show-layers')
163 if re.search(layer, result.output) is None: 158 if re.search(layer, result.output) is None:
164 # Assume the directory layout for finding other layers. We could also 159 self.meta_qemu = metadir() + layer
165 # make assumptions by using 'show-layers', but either way, if the
166 # layers we need aren't where we expect them, we are out of luck.
167 path = os.path.abspath(os.path.dirname(__file__))
168 metadir = path + "/../../../../../"
169 self.meta_qemu = metadir + layer
170 runCmd('bitbake-layers add-layer "%s"' % self.meta_qemu) 160 runCmd('bitbake-layers add-layer "%s"' % self.meta_qemu)
171 else: 161 else:
172 self.meta_qemu = None 162 self.meta_qemu = None
173 self.append_config('MACHINE = "qemux86-64"') 163 self.append_config('MACHINE = "qemux86-64"')
174 self.append_config('SOTA_CLIENT_PROV = " aktualizr-device-prov "') 164 self.append_config('SOTA_CLIENT_PROV = " aktualizr-device-prov "')
175 self.append_config('SOTA_DEPLOY_CREDENTIALS = "0"') 165 self.append_config('SOTA_DEPLOY_CREDENTIALS = "0"')
176 runCmd('bitbake -c cleanall aktualizr aktualizr-device-prov') 166 self.append_config('IMAGE_FSTYPES_remove = "ostreepush garagesign garagecheck"')
177 self.qemu, self.s = qemu_launch(machine='qemux86-64') 167 self.qemu, self.s = qemu_launch(machine='qemux86-64')
168 bitbake('build-sysroots -c build_native_sysroot')
178 169
179 def tearDownLocal(self): 170 def tearDownLocal(self):
180 qemu_terminate(self.s) 171 qemu_terminate(self.s)
@@ -201,8 +192,8 @@ class DeviceCredProvTests(OESelftestTestCase):
201 # Run aktualizr-cert-provider. 192 # Run aktualizr-cert-provider.
202 bb_vars = get_bb_vars(['SOTA_PACKED_CREDENTIALS'], 'aktualizr-native') 193 bb_vars = get_bb_vars(['SOTA_PACKED_CREDENTIALS'], 'aktualizr-native')
203 creds = bb_vars['SOTA_PACKED_CREDENTIALS'] 194 creds = bb_vars['SOTA_PACKED_CREDENTIALS']
204 bb_vars_prov = get_bb_vars(['STAGING_DIR_HOST', 'libdir'], 'aktualizr-device-prov') 195 bb_vars_prov = get_bb_vars(['WORKDIR', 'libdir'], 'aktualizr-device-prov')
205 config = bb_vars_prov['STAGING_DIR_HOST'] + bb_vars_prov['libdir'] + '/sota/sota-device-cred.toml' 196 config = bb_vars_prov['WORKDIR'] + '/sysroot-destdir' + bb_vars_prov['libdir'] + '/sota/conf.d/20-sota-device-cred.toml'
206 197
207 print('Provisining at root@localhost:%d' % self.qemu.ssh_port) 198 print('Provisining at root@localhost:%d' % self.qemu.ssh_port)
208 akt_native_run(self, 'aktualizr-cert-provider -c {creds} -t root@localhost -p {port} -s -u -r -g {config}' 199 akt_native_run(self, 'aktualizr-cert-provider -c {creds} -t root@localhost -p {port} -s -u -r -g {config}'
@@ -217,12 +208,7 @@ class DeviceCredProvHsmTests(OESelftestTestCase):
217 layer = "meta-updater-qemux86-64" 208 layer = "meta-updater-qemux86-64"
218 result = runCmd('bitbake-layers show-layers') 209 result = runCmd('bitbake-layers show-layers')
219 if re.search(layer, result.output) is None: 210 if re.search(layer, result.output) is None:
220 # Assume the directory layout for finding other layers. We could also 211 self.meta_qemu = metadir() + layer
221 # make assumptions by using 'show-layers', but either way, if the
222 # layers we need aren't where we expect them, we are out of luck.
223 path = os.path.abspath(os.path.dirname(__file__))
224 metadir = path + "/../../../../../"
225 self.meta_qemu = metadir + layer
226 runCmd('bitbake-layers add-layer "%s"' % self.meta_qemu) 212 runCmd('bitbake-layers add-layer "%s"' % self.meta_qemu)
227 else: 213 else:
228 self.meta_qemu = None 214 self.meta_qemu = None
@@ -231,8 +217,9 @@ class DeviceCredProvHsmTests(OESelftestTestCase):
231 self.append_config('SOTA_DEPLOY_CREDENTIALS = "0"') 217 self.append_config('SOTA_DEPLOY_CREDENTIALS = "0"')
232 self.append_config('SOTA_CLIENT_FEATURES = "hsm"') 218 self.append_config('SOTA_CLIENT_FEATURES = "hsm"')
233 self.append_config('IMAGE_INSTALL_append = " softhsm-testtoken"') 219 self.append_config('IMAGE_INSTALL_append = " softhsm-testtoken"')
234 runCmd('bitbake -c cleanall aktualizr aktualizr-device-prov-hsm') 220 self.append_config('IMAGE_FSTYPES_remove = "ostreepush garagesign garagecheck"')
235 self.qemu, self.s = qemu_launch(machine='qemux86-64') 221 self.qemu, self.s = qemu_launch(machine='qemux86-64')
222 bitbake('build-sysroots -c build_native_sysroot')
236 223
237 def tearDownLocal(self): 224 def tearDownLocal(self):
238 qemu_terminate(self.s) 225 qemu_terminate(self.s)
@@ -269,25 +256,24 @@ class DeviceCredProvHsmTests(OESelftestTestCase):
269 # Run aktualizr-cert-provider. 256 # Run aktualizr-cert-provider.
270 bb_vars = get_bb_vars(['SOTA_PACKED_CREDENTIALS'], 'aktualizr-native') 257 bb_vars = get_bb_vars(['SOTA_PACKED_CREDENTIALS'], 'aktualizr-native')
271 creds = bb_vars['SOTA_PACKED_CREDENTIALS'] 258 creds = bb_vars['SOTA_PACKED_CREDENTIALS']
272 bb_vars_prov = get_bb_vars(['STAGING_DIR_HOST', 'libdir'], 'aktualizr-device-prov-hsm') 259 bb_vars_prov = get_bb_vars(['WORKDIR', 'libdir'], 'aktualizr-device-prov-hsm')
273 config = bb_vars_prov['STAGING_DIR_HOST'] + bb_vars_prov['libdir'] + '/sota/sota-device-cred-hsm.toml' 260 config = bb_vars_prov['WORKDIR'] + '/sysroot-destdir' + bb_vars_prov['libdir'] + '/sota/conf.d/20-sota-device-cred-hsm.toml'
274 261
275 akt_native_run(self, 'aktualizr-cert-provider -c {creds} -t root@localhost -p {port} -r -s -u -g {config}' 262 akt_native_run(self, 'aktualizr-cert-provider -c {creds} -t root@localhost -p {port} -r -s -u -g {config}'
276 .format(creds=creds, port=self.qemu.ssh_port, config=config)) 263 .format(creds=creds, port=self.qemu.ssh_port, config=config))
277 264
278 # Verify that HSM is able to initialize. 265 # Verify that HSM is able to initialize.
279 ran_ok = False
280 for delay in [5, 5, 5, 5, 10]: 266 for delay in [5, 5, 5, 5, 10]:
281 sleep(delay) 267 sleep(delay)
282 p11_out, p11_err, p11_ret = self.qemu_command(pkcs11_command) 268 p11_out, p11_err, p11_ret = self.qemu_command(pkcs11_command)
283 hsm_out, hsm_err, hsm_ret = self.qemu_command(softhsm2_command) 269 hsm_out, hsm_err, hsm_ret = self.qemu_command(softhsm2_command)
284 if p11_ret == 0 and hsm_ret == 0 and hsm_err == b'': 270 if (p11_ret == 0 and hsm_ret == 0 and hsm_err == b'' and
285 ran_ok = True 271 b'X.509 cert' in p11_out and b'present token' in p11_err):
286 break 272 break
287 self.assertTrue(ran_ok, 'pkcs11-tool or softhsm2-tool failed: ' + p11_err.decode() + 273 else:
288 p11_out.decode() + hsm_err.decode() + hsm_out.decode()) 274 self.fail('pkcs11-tool or softhsm2-tool failed: ' + p11_err.decode() +
289 self.assertIn(b'present token', p11_err, 'pkcs11-tool failed: ' + p11_err.decode() + p11_out.decode()) 275 p11_out.decode() + hsm_err.decode() + hsm_out.decode())
290 self.assertIn(b'X.509 cert', p11_out, 'pkcs11-tool failed: ' + p11_err.decode() + p11_out.decode()) 276
291 self.assertIn(b'Initialized: yes', hsm_out, 'softhsm2-tool failed: ' + 277 self.assertIn(b'Initialized: yes', hsm_out, 'softhsm2-tool failed: ' +
292 hsm_err.decode() + hsm_out.decode()) 278 hsm_err.decode() + hsm_out.decode())
293 self.assertIn(b'User PIN init.: yes', hsm_out, 'softhsm2-tool failed: ' + 279 self.assertIn(b'User PIN init.: yes', hsm_out, 'softhsm2-tool failed: ' +
@@ -328,8 +314,8 @@ class IpSecondaryTests(OESelftestTestCase):
328 self.configure() 314 self.configure()
329 qemu_bake_image(self.imagename) 315 qemu_bake_image(self.imagename)
330 316
331 def send_command(self, cmd): 317 def send_command(self, cmd, timeout=60):
332 stdout, stderr, retcode = qemu_send_command(self.qemu.ssh_port, cmd, timeout=60) 318 stdout, stderr, retcode = qemu_send_command(self.qemu.ssh_port, cmd, timeout=timeout)
333 return str(stdout), str(stderr), retcode 319 return str(stdout), str(stderr), retcode
334 320
335 def __enter__(self): 321 def __enter__(self):
@@ -344,7 +330,7 @@ class IpSecondaryTests(OESelftestTestCase):
344 def wait_till_sshable(self): 330 def wait_till_sshable(self):
345 # qemu_send_command tries to ssh into the qemu VM and blocks until it gets there or timeout happens 331 # qemu_send_command tries to ssh into the qemu VM and blocks until it gets there or timeout happens
346 # so it helps us to block q control flow until the VM is booted and a target binary/daemon is running there 332 # so it helps us to block q control flow until the VM is booted and a target binary/daemon is running there
347 self.stdout, self.stderr, self.retcode = self.send_command(self.binaryname + ' --help') 333 self.stdout, self.stderr, self.retcode = self.send_command(self.binaryname + ' --help', timeout=300)
348 334
349 def was_successfully_booted(self): 335 def was_successfully_booted(self):
350 return self.retcode == 0 336 return self.retcode == 0
@@ -399,16 +385,12 @@ class IpSecondaryTests(OESelftestTestCase):
399 layer = "meta-updater-qemux86-64" 385 layer = "meta-updater-qemux86-64"
400 result = runCmd('bitbake-layers show-layers') 386 result = runCmd('bitbake-layers show-layers')
401 if re.search(layer, result.output) is None: 387 if re.search(layer, result.output) is None:
402 # Assume the directory layout for finding other layers. We could also 388 self.meta_qemu = metadir() + layer
403 # make assumptions by using 'show-layers', but either way, if the
404 # layers we need aren't where we expect them, we are out of luck.
405 path = os.path.abspath(os.path.dirname(__file__))
406 metadir = path + "/../../../../../"
407 self.meta_qemu = metadir + layer
408 runCmd('bitbake-layers add-layer "%s"' % self.meta_qemu) 389 runCmd('bitbake-layers add-layer "%s"' % self.meta_qemu)
409 else: 390 else:
410 self.meta_qemu = None 391 self.meta_qemu = None
411 392
393 self.append_config('IMAGE_FSTYPES_remove = "ostreepush garagesign garagecheck"')
412 self.primary = IpSecondaryTests.Primary(self) 394 self.primary = IpSecondaryTests.Primary(self)
413 self.secondary = IpSecondaryTests.Secondary(self) 395 self.secondary = IpSecondaryTests.Secondary(self)
414 396
@@ -446,17 +428,13 @@ class ResourceControlTests(OESelftestTestCase):
446 layer = "meta-updater-qemux86-64" 428 layer = "meta-updater-qemux86-64"
447 result = runCmd('bitbake-layers show-layers') 429 result = runCmd('bitbake-layers show-layers')
448 if re.search(layer, result.output) is None: 430 if re.search(layer, result.output) is None:
449 # Assume the directory layout for finding other layers. We could also 431 self.meta_qemu = metadir() + layer
450 # make assumptions by using 'show-layers', but either way, if the
451 # layers we need aren't where we expect them, we are out of luck.
452 path = os.path.abspath(os.path.dirname(__file__))
453 metadir = path + "/../../../../../"
454 self.meta_qemu = metadir + layer
455 runCmd('bitbake-layers add-layer "%s"' % self.meta_qemu) 432 runCmd('bitbake-layers add-layer "%s"' % self.meta_qemu)
456 else: 433 else:
457 self.meta_qemu = None 434 self.meta_qemu = None
458 self.append_config('MACHINE = "qemux86-64"') 435 self.append_config('MACHINE = "qemux86-64"')
459 self.append_config('SOTA_CLIENT_PROV = " aktualizr-shared-prov "') 436 self.append_config('SOTA_CLIENT_PROV = " aktualizr-shared-prov "')
437 self.append_config('IMAGE_FSTYPES_remove = "ostreepush garagesign garagecheck"')
460 self.append_config('IMAGE_INSTALL_append += " aktualizr-resource-control "') 438 self.append_config('IMAGE_INSTALL_append += " aktualizr-resource-control "')
461 self.append_config('RESOURCE_CPU_WEIGHT_pn-aktualizr = "1000"') 439 self.append_config('RESOURCE_CPU_WEIGHT_pn-aktualizr = "1000"')
462 self.append_config('RESOURCE_MEMORY_HIGH_pn-aktualizr = "50M"') 440 self.append_config('RESOURCE_MEMORY_HIGH_pn-aktualizr = "50M"')
@@ -476,10 +454,13 @@ class ResourceControlTests(OESelftestTestCase):
476 ran_ok = False 454 ran_ok = False
477 for delay in [5, 5, 5, 5]: 455 for delay in [5, 5, 5, 5]:
478 sleep(delay) 456 sleep(delay)
479 stdout, stderr, retcode = self.qemu_command('systemctl --no-pager show aktualizr') 457 try:
480 if retcode == 0 and b'ExecMainStatus=9' in stdout: 458 stdout, stderr, retcode = self.qemu_command('systemctl --no-pager show aktualizr')
481 ran_ok = True 459 if retcode == 0 and b'ExecMainStatus=9' in stdout:
482 break 460 ran_ok = True
461 break
462 except subprocess.TimeoutExpired:
463 pass
483 self.assertTrue(ran_ok, 'Aktualizr was not killed') 464 self.assertTrue(ran_ok, 'Aktualizr was not killed')
484 465
485 self.assertIn(b'CPUWeight=1000', stdout, 'CPUWeight was not set correctly') 466 self.assertIn(b'CPUWeight=1000', stdout, 'CPUWeight was not set correctly')