summaryrefslogtreecommitdiffstats
path: root/lib/oeqa/selftest/updater.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/oeqa/selftest/updater.py')
-rw-r--r--lib/oeqa/selftest/updater.py118
1 files changed, 43 insertions, 75 deletions
diff --git a/lib/oeqa/selftest/updater.py b/lib/oeqa/selftest/updater.py
index cad5b2a..f237364 100644
--- a/lib/oeqa/selftest/updater.py
+++ b/lib/oeqa/selftest/updater.py
@@ -16,32 +16,17 @@ class SotaToolsTests(oeSelfTest):
16 @classmethod 16 @classmethod
17 def setUpClass(cls): 17 def setUpClass(cls):
18 logger = logging.getLogger("selftest") 18 logger = logging.getLogger("selftest")
19 bb_vars = get_bb_vars(['SYSROOT_DESTDIR', 'base_prefix', 'libdir', 'bindir'],
20 'aktualizr-native')
21 cls.sysroot = bb_vars['SYSROOT_DESTDIR'] + bb_vars['base_prefix']
22 cls.sysrootbin = bb_vars['SYSROOT_DESTDIR'] + bb_vars['bindir']
23 cls.libdir = bb_vars['libdir']
24
25 logger.info('Running bitbake to build aktualizr-native tools') 19 logger.info('Running bitbake to build aktualizr-native tools')
26 bitbake('aktualizr-native') 20 bitbake('aktualizr-native')
27 21
28 def runNativeCmd(self, cmd, **kwargs):
29 program, *_ = cmd.split(' ')
30 p = '{}/{}'.format(self.sysrootbin, program)
31 self.assertTrue(os.path.isfile(p), msg="No {} found ({})".format(program, p))
32 env = dict(os.environ)
33 env['LD_LIBRARY_PATH'] = self.libdir
34 result = runCmd(cmd, env=env, native_sysroot=self.sysroot, ignore_status=True, **kwargs)
35 self.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output)
36
37 def test_push_help(self): 22 def test_push_help(self):
38 self.runNativeCmd('garage-push --help') 23 akt_native_run(self, 'garage-push --help')
39 24
40 def test_deploy_help(self): 25 def test_deploy_help(self):
41 self.runNativeCmd('garage-deploy --help') 26 akt_native_run(self, 'garage-deploy --help')
42 27
43 def test_garagesign_help(self): 28 def test_garagesign_help(self):
44 self.runNativeCmd('garage-sign --help') 29 akt_native_run(self, 'garage-sign --help')
45 30
46 31
47class GeneralTests(oeSelfTest): 32class GeneralTests(oeSelfTest):
@@ -113,43 +98,27 @@ class AktualizrToolsTests(oeSelfTest):
113 @classmethod 98 @classmethod
114 def setUpClass(cls): 99 def setUpClass(cls):
115 logger = logging.getLogger("selftest") 100 logger = logging.getLogger("selftest")
116 bb_vars = get_bb_vars(['SYSROOT_DESTDIR', 'base_prefix', 'libdir', 'bindir'],
117 'aktualizr-native')
118 cls.sysroot = bb_vars['SYSROOT_DESTDIR'] + bb_vars['base_prefix']
119 cls.sysrootbin = bb_vars['SYSROOT_DESTDIR'] + bb_vars['bindir']
120 cls.libdir = bb_vars['libdir']
121
122 logger.info('Running bitbake to build aktualizr-native tools') 101 logger.info('Running bitbake to build aktualizr-native tools')
123 bitbake('aktualizr-native') 102 bitbake('aktualizr-native')
124 103
125 def runNativeCmd(self, cmd, **kwargs):
126 program, *_ = cmd.split(' ')
127 p = '{}/{}'.format(self.sysrootbin, program)
128 self.assertTrue(os.path.isfile(p), msg="No {} found ({})".format(program, p))
129 env = dict(os.environ)
130 env['LD_LIBRARY_PATH'] = self.libdir
131 result = runCmd(cmd, env=env, native_sysroot=self.sysroot, ignore_status=True, **kwargs)
132 self.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output)
133
134 def test_implicit_writer_help(self): 104 def test_implicit_writer_help(self):
135 self.runNativeCmd('aktualizr_implicit_writer --help') 105 akt_native_run(self, 'aktualizr_implicit_writer --help')
136 106
137 def test_cert_provider_help(self): 107 def test_cert_provider_help(self):
138 self.runNativeCmd('aktualizr_cert_provider --help') 108 akt_native_run(self, 'aktualizr_cert_provider --help')
139 109
140 def test_cert_provider_local_output(self): 110 def test_cert_provider_local_output(self):
141 logger = logging.getLogger("selftest") 111 logger = logging.getLogger("selftest")
142 logger.info('Running bitbake to build aktualizr-implicit-prov') 112 logger.info('Running bitbake to build aktualizr-implicit-prov')
143 bitbake('aktualizr-implicit-prov') 113 bitbake('aktualizr-implicit-prov')
144 bb_vars = get_bb_vars(['SYSROOT_DESTDIR', 'bindir', 'libdir', 114 bb_vars = get_bb_vars(['SOTA_PACKED_CREDENTIALS', 'T'], 'aktualizr-native')
145 'SOTA_PACKED_CREDENTIALS', 'T'], 'aktualizr-native')
146 creds = bb_vars['SOTA_PACKED_CREDENTIALS'] 115 creds = bb_vars['SOTA_PACKED_CREDENTIALS']
147 temp_dir = bb_vars['T'] 116 temp_dir = bb_vars['T']
148 bb_vars_prov = get_bb_vars(['STAGING_DIR_NATIVE', 'libdir'], 'aktualizr-implicit-prov') 117 bb_vars_prov = get_bb_vars(['STAGING_DIR_NATIVE', 'libdir'], 'aktualizr-implicit-prov')
149 config = bb_vars_prov['STAGING_DIR_NATIVE'] + bb_vars_prov['libdir'] + '/sota/sota_implicit_prov.toml' 118 config = bb_vars_prov['STAGING_DIR_NATIVE'] + bb_vars_prov['libdir'] + '/sota/sota_implicit_prov.toml'
150 119
151 self.runNativeCmd('aktualizr_cert_provider -c {creds} -r -l {temp} -g {config}' 120 akt_native_run(self, 'aktualizr_cert_provider -c {creds} -r -l {temp} -g {config}'
152 .format(creds=creds, temp=temp_dir, config=config)) 121 .format(creds=creds, temp=temp_dir, config=config))
153 122
154 # Might be nice if these names weren't hardcoded. 123 # Might be nice if these names weren't hardcoded.
155 cert_path = temp_dir + '/client.pem' 124 cert_path = temp_dir + '/client.pem'
@@ -250,11 +219,9 @@ class ImplProvTests(oeSelfTest):
250 219
251 @classmethod 220 @classmethod
252 def setUpClass(cls): 221 def setUpClass(cls):
253 bb_vars = get_bb_vars(['SYSROOT_DESTDIR', 'base_prefix', 'libdir', 'bindir'], 222 logger = logging.getLogger("selftest")
254 'aktualizr-native') 223 logger.info('Running bitbake to build aktualizr-native tools')
255 cls.sysroot = bb_vars['SYSROOT_DESTDIR'] + bb_vars['base_prefix'] 224 bitbake('aktualizr-native')
256 cls.sysrootbin = bb_vars['SYSROOT_DESTDIR'] + bb_vars['bindir']
257 cls.libdir = bb_vars['libdir']
258 225
259 def setUpLocal(self): 226 def setUpLocal(self):
260 self.append_config('SOTA_CLIENT_PROV = " aktualizr-implicit-prov "') 227 self.append_config('SOTA_CLIENT_PROV = " aktualizr-implicit-prov "')
@@ -263,15 +230,6 @@ class ImplProvTests(oeSelfTest):
263 def tearDownLocal(self): 230 def tearDownLocal(self):
264 qemu_terminate(self.s) 231 qemu_terminate(self.s)
265 232
266 def runNativeCmd(self, cmd, **kwargs):
267 program, *_ = cmd.split(' ')
268 p = '{}/{}'.format(self.sysrootbin, program)
269 self.assertTrue(os.path.isfile(p), msg="No {} found ({})".format(program, p))
270 env = dict(os.environ)
271 env['LD_LIBRARY_PATH'] = self.libdir
272 result = runCmd(cmd, env=env, native_sysroot=self.sysroot, ignore_status=True, **kwargs)
273 self.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output)
274
275 def qemu_command(self, command): 233 def qemu_command(self, command):
276 return qemu_send_command(self.qemu.ssh_port, command) 234 return qemu_send_command(self.qemu.ssh_port, command)
277 235
@@ -306,14 +264,13 @@ class ImplProvTests(oeSelfTest):
306 'Device already provisioned!? ' + stderr.decode() + stdout.decode()) 264 'Device already provisioned!? ' + stderr.decode() + stdout.decode())
307 265
308 # Run cert_provider. 266 # Run cert_provider.
309 bb_vars = get_bb_vars(['SYSROOT_DESTDIR', 'bindir', 'libdir', 267 bb_vars = get_bb_vars(['SOTA_PACKED_CREDENTIALS'], 'aktualizr-native')
310 'SOTA_PACKED_CREDENTIALS'], 'aktualizr-native')
311 creds = bb_vars['SOTA_PACKED_CREDENTIALS'] 268 creds = bb_vars['SOTA_PACKED_CREDENTIALS']
312 bb_vars_prov = get_bb_vars(['STAGING_DIR_NATIVE', 'libdir'], 'aktualizr-implicit-prov') 269 bb_vars_prov = get_bb_vars(['STAGING_DIR_NATIVE', 'libdir'], 'aktualizr-implicit-prov')
313 config = bb_vars_prov['STAGING_DIR_NATIVE'] + bb_vars_prov['libdir'] + '/sota/sota_implicit_prov.toml' 270 config = bb_vars_prov['STAGING_DIR_NATIVE'] + bb_vars_prov['libdir'] + '/sota/sota_implicit_prov.toml'
314 271
315 self.runNativeCmd('aktualizr_cert_provider -c {creds} -t root@localhost -p {port} -s -g {config}' \ 272 akt_native_run(self, 'aktualizr_cert_provider -c {creds} -t root@localhost -p {port} -s -g {config}'
316 .format(creds=creds, port=self.qemu.ssh_port, config=config)) 273 .format(creds=creds, port=self.qemu.ssh_port, config=config))
317 274
318 # Verify that device HAS provisioned. 275 # Verify that device HAS provisioned.
319 ran_ok = False 276 ran_ok = False
@@ -339,11 +296,9 @@ class HsmTests(oeSelfTest):
339 296
340 @classmethod 297 @classmethod
341 def setUpClass(cls): 298 def setUpClass(cls):
342 bb_vars = get_bb_vars(['SYSROOT_DESTDIR', 'base_prefix', 'libdir', 'bindir'], 299 logger = logging.getLogger("selftest")
343 'aktualizr-native') 300 logger.info('Running bitbake to build aktualizr-native tools')
344 cls.sysroot = bb_vars['SYSROOT_DESTDIR'] + bb_vars['base_prefix'] 301 bitbake('aktualizr-native')
345 cls.sysrootbin = bb_vars['SYSROOT_DESTDIR'] + bb_vars['bindir']
346 cls.libdir = bb_vars['libdir']
347 302
348 def setUpLocal(self): 303 def setUpLocal(self):
349 self.append_config('SOTA_CLIENT_PROV = "aktualizr-hsm-prov"') 304 self.append_config('SOTA_CLIENT_PROV = "aktualizr-hsm-prov"')
@@ -353,15 +308,6 @@ class HsmTests(oeSelfTest):
353 def tearDownLocal(self): 308 def tearDownLocal(self):
354 qemu_terminate(self.s) 309 qemu_terminate(self.s)
355 310
356 def runNativeCmd(self, cmd, **kwargs):
357 program, *_ = cmd.split(' ')
358 p = '{}/{}'.format(self.sysrootbin, program)
359 self.assertTrue(os.path.isfile(p), msg="No {} found ({})".format(program, p))
360 env = dict(os.environ)
361 env['LD_LIBRARY_PATH'] = self.libdir
362 result = runCmd(cmd, env=env, native_sysroot=self.sysroot, ignore_status=True, **kwargs)
363 self.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output)
364
365 def qemu_command(self, command): 311 def qemu_command(self, command):
366 return qemu_send_command(self.qemu.ssh_port, command) 312 return qemu_send_command(self.qemu.ssh_port, command)
367 313
@@ -406,14 +352,13 @@ class HsmTests(oeSelfTest):
406 stdout.decode() + stderr.decode()) 352 stdout.decode() + stderr.decode())
407 353
408 # Run cert_provider. 354 # Run cert_provider.
409 bb_vars = get_bb_vars(['SYSROOT_DESTDIR', 'bindir', 'libdir', 355 bb_vars = get_bb_vars(['SOTA_PACKED_CREDENTIALS'], 'aktualizr-native')
410 'SOTA_PACKED_CREDENTIALS'], 'aktualizr-native')
411 creds = bb_vars['SOTA_PACKED_CREDENTIALS'] 356 creds = bb_vars['SOTA_PACKED_CREDENTIALS']
412 bb_vars_prov = get_bb_vars(['STAGING_DIR_NATIVE', 'libdir'], 'aktualizr-hsm-prov') 357 bb_vars_prov = get_bb_vars(['STAGING_DIR_NATIVE', 'libdir'], 'aktualizr-hsm-prov')
413 config = bb_vars_prov['STAGING_DIR_NATIVE'] + bb_vars_prov['libdir'] + '/sota/sota_implicit_prov.toml' 358 config = bb_vars_prov['STAGING_DIR_NATIVE'] + bb_vars_prov['libdir'] + '/sota/sota_implicit_prov.toml'
414 359
415 self.runNativeCmd('aktualizr_cert_provider -c {creds} -t root@localhost -p {port} -r -s -g {config}' 360 akt_native_run(self, 'aktualizr_cert_provider -c {creds} -t root@localhost -p {port} -r -s -g {config}'
416 .format(creds=creds, port=self.qemu.ssh_port, config=config)) 361 .format(creds=creds, port=self.qemu.ssh_port, config=config))
417 362
418 # Verify that HSM is able to initialize. 363 # Verify that HSM is able to initialize.
419 ran_ok = False 364 ran_ok = False
@@ -509,4 +454,27 @@ def qemu_send_command(port, command):
509 stdout, stderr = s2.communicate() 454 stdout, stderr = s2.communicate()
510 return stdout, stderr, s2.returncode 455 return stdout, stderr, s2.returncode
511 456
457
458def akt_native_run(testInst, cmd, **kwargs):
459 # run a command supplied by aktualizr-native and checks that:
460 # - the executable exists
461 # - the command runs without error
462 # NOTE: the base test class must have built aktualizr-native (in
463 # setUpClass, for example)
464 bb_vars = get_bb_vars(['SYSROOT_DESTDIR', 'base_prefix', 'libdir', 'bindir'],
465 'aktualizr-native')
466 sysroot = bb_vars['SYSROOT_DESTDIR'] + bb_vars['base_prefix']
467 sysrootbin = bb_vars['SYSROOT_DESTDIR'] + bb_vars['bindir']
468 libdir = bb_vars['libdir']
469
470 program, *_ = cmd.split(' ')
471 p = '{}/{}'.format(sysrootbin, program)
472 testInst.assertTrue(os.path.isfile(p), msg="No {} found ({})".format(program, p))
473 env = dict(os.environ)
474 env['LD_LIBRARY_PATH'] = libdir
475 result = runCmd(cmd, env=env, native_sysroot=sysroot, ignore_status=True, **kwargs)
476 testInst.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output)
477
478
479
512# vim:set ts=4 sw=4 sts=4 expandtab: 480# vim:set ts=4 sw=4 sts=4 expandtab: