diff options
| author | Laurent Bonnans <laurent.bonnans@here.com> | 2018-02-20 17:43:52 +0100 |
|---|---|---|
| committer | Laurent Bonnans <laurent.bonnans@here.com> | 2018-02-20 18:35:36 +0100 |
| commit | fc84de73eb3f04f1e7600a1c86061af7f856e8d4 (patch) | |
| tree | 9a720bfdcd41cbfb6c7d6f393a0c021e469503eb | |
| parent | b9922d6eeda2f0fffadb660f80f13e4ae92ae1cd (diff) | |
| download | meta-updater-fc84de73eb3f04f1e7600a1c86061af7f856e8d4.tar.gz | |
Refactor oe selftests
Factorize the call of aktualizr-native commands in each testing class
| -rw-r--r-- | lib/oeqa/selftest/updater.py | 121 |
1 files changed, 70 insertions, 51 deletions
diff --git a/lib/oeqa/selftest/updater.py b/lib/oeqa/selftest/updater.py index 703df91..8563e3b 100644 --- a/lib/oeqa/selftest/updater.py +++ b/lib/oeqa/selftest/updater.py | |||
| @@ -16,32 +16,32 @@ 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 | |||
| 19 | logger.info('Running bitbake to build aktualizr-native tools') | 25 | logger.info('Running bitbake to build aktualizr-native tools') |
| 20 | bitbake('aktualizr-native') | 26 | bitbake('aktualizr-native') |
| 21 | 27 | ||
| 22 | def test_push_help(self): | 28 | def runNativeCmd(self, cmd, **kwargs): |
| 23 | bb_vars = get_bb_vars(['SYSROOT_DESTDIR', 'bindir', 'libdir'], 'aktualizr-native') | 29 | program, *_ = cmd.split(' ') |
| 24 | l = bb_vars['libdir'] | 30 | p = '{}/{}'.format(self.sysrootbin, program) |
| 25 | p = bb_vars['SYSROOT_DESTDIR'] + bb_vars['bindir'] + "/garage-push" | 31 | self.assertTrue(os.path.isfile(p), msg="No {} found ({})".format(program, p)) |
| 26 | self.assertTrue(os.path.isfile(p), msg = "No garage-push found (%s)" % p) | 32 | env = dict(os.environ) |
| 27 | result = runCmd('LD_LIBRARY_PATH=%s %s --help' % (l, p), ignore_status=True) | 33 | env['LD_LIBRARY_PATH'] = self.libdir |
| 34 | result = runCmd(cmd, env=env, native_sysroot=self.sysroot, ignore_status=True, **kwargs) | ||
| 28 | self.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output) | 35 | self.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output) |
| 29 | 36 | ||
| 37 | def test_push_help(self): | ||
| 38 | self.runNativeCmd('garage-push --help') | ||
| 39 | |||
| 30 | def test_deploy_help(self): | 40 | def test_deploy_help(self): |
| 31 | bb_vars = get_bb_vars(['SYSROOT_DESTDIR', 'bindir', 'libdir'], 'aktualizr-native') | 41 | self.runNativeCmd('garage-deploy --help') |
| 32 | l = bb_vars['libdir'] | ||
| 33 | p = bb_vars['SYSROOT_DESTDIR'] + bb_vars['bindir'] + "/garage-deploy" | ||
| 34 | self.assertTrue(os.path.isfile(p), msg = "No garage-deploy found (%s)" % p) | ||
| 35 | result = runCmd('LD_LIBRARY_PATH=%s %s --help' % (l, p), ignore_status=True) | ||
| 36 | self.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output) | ||
| 37 | 42 | ||
| 38 | def test_garagesign_help(self): | 43 | def test_garagesign_help(self): |
| 39 | bb_vars = get_bb_vars(['SYSROOT_DESTDIR', 'bindir', 'libdir'], 'aktualizr-native') | 44 | self.runNativeCmd('garage-sign --help') |
| 40 | l = bb_vars['libdir'] | ||
| 41 | p = bb_vars['SYSROOT_DESTDIR'] + bb_vars['bindir'] + "/garage-sign" | ||
| 42 | self.assertTrue(os.path.isfile(p), msg = "No garage-sign found (%s)" % p) | ||
| 43 | result = runCmd('LD_LIBRARY_PATH=%s %s --help' % (l, p), ignore_status=True) | ||
| 44 | self.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output) | ||
| 45 | 45 | ||
| 46 | 46 | ||
| 47 | class GeneralTests(oeSelfTest): | 47 | class GeneralTests(oeSelfTest): |
| @@ -113,24 +113,29 @@ class AktualizrToolsTests(oeSelfTest): | |||
| 113 | @classmethod | 113 | @classmethod |
| 114 | def setUpClass(cls): | 114 | def setUpClass(cls): |
| 115 | logger = logging.getLogger("selftest") | 115 | 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 | |||
| 116 | logger.info('Running bitbake to build aktualizr-native tools') | 122 | logger.info('Running bitbake to build aktualizr-native tools') |
| 117 | bitbake('aktualizr-native') | 123 | bitbake('aktualizr-native') |
| 118 | 124 | ||
| 119 | def test_implicit_writer_help(self): | 125 | def runNativeCmd(self, cmd, **kwargs): |
| 120 | bb_vars = get_bb_vars(['SYSROOT_DESTDIR', 'bindir', 'libdir'], 'aktualizr-native') | 126 | program, *_ = cmd.split(' ') |
| 121 | l = bb_vars['libdir'] | 127 | p = '{}/{}'.format(self.sysrootbin, program) |
| 122 | p = bb_vars['SYSROOT_DESTDIR'] + bb_vars['bindir'] + "/aktualizr_implicit_writer" | 128 | self.assertTrue(os.path.isfile(p), msg="No {} found ({})".format(program, p)) |
| 123 | self.assertTrue(os.path.isfile(p), msg = "No aktualizr_implicit_writer found (%s)" % p) | 129 | env = dict(os.environ) |
| 124 | result = runCmd('LD_LIBRARY_PATH=%s %s --help' % (l, p), ignore_status=True) | 130 | env['LD_LIBRARY_PATH'] = self.libdir |
| 131 | result = runCmd(cmd, env=env, native_sysroot=self.sysroot, ignore_status=True, **kwargs) | ||
| 125 | self.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output) | 132 | self.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output) |
| 126 | 133 | ||
| 134 | def test_implicit_writer_help(self): | ||
| 135 | self.runNativeCmd('aktualizr_implicit_writer --help') | ||
| 136 | |||
| 127 | def test_cert_provider_help(self): | 137 | def test_cert_provider_help(self): |
| 128 | bb_vars = get_bb_vars(['SYSROOT_DESTDIR', 'bindir', 'libdir'], 'aktualizr-native') | 138 | self.runNativeCmd('aktualizr_cert_provider --help') |
| 129 | l = bb_vars['libdir'] | ||
| 130 | p = bb_vars['SYSROOT_DESTDIR'] + bb_vars['bindir'] + "/aktualizr_cert_provider" | ||
| 131 | self.assertTrue(os.path.isfile(p), msg = "No aktualizr_cert_provider found (%s)" % p) | ||
| 132 | result = runCmd('LD_LIBRARY_PATH=%s %s --help' % (l, p), ignore_status=True) | ||
| 133 | self.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output) | ||
| 134 | 139 | ||
| 135 | def test_cert_provider_local_output(self): | 140 | def test_cert_provider_local_output(self): |
| 136 | logger = logging.getLogger("selftest") | 141 | logger = logging.getLogger("selftest") |
| @@ -138,17 +143,14 @@ class AktualizrToolsTests(oeSelfTest): | |||
| 138 | bitbake('aktualizr-implicit-prov') | 143 | bitbake('aktualizr-implicit-prov') |
| 139 | bb_vars = get_bb_vars(['SYSROOT_DESTDIR', 'bindir', 'libdir', | 144 | bb_vars = get_bb_vars(['SYSROOT_DESTDIR', 'bindir', 'libdir', |
| 140 | 'SOTA_PACKED_CREDENTIALS', 'T'], 'aktualizr-native') | 145 | 'SOTA_PACKED_CREDENTIALS', 'T'], 'aktualizr-native') |
| 141 | l = bb_vars['libdir'] | ||
| 142 | p = bb_vars['SYSROOT_DESTDIR'] + bb_vars['bindir'] + "/aktualizr_cert_provider" | ||
| 143 | creds = bb_vars['SOTA_PACKED_CREDENTIALS'] | 146 | creds = bb_vars['SOTA_PACKED_CREDENTIALS'] |
| 144 | temp_dir = bb_vars['T'] | 147 | temp_dir = bb_vars['T'] |
| 145 | bb_vars_prov = get_bb_vars(['STAGING_DIR_NATIVE', 'libdir'], 'aktualizr-implicit-prov') | 148 | bb_vars_prov = get_bb_vars(['STAGING_DIR_NATIVE', 'libdir'], 'aktualizr-implicit-prov') |
| 146 | config = bb_vars_prov['STAGING_DIR_NATIVE'] + bb_vars_prov['libdir'] + '/sota/sota_implicit_prov.toml' | 149 | config = bb_vars_prov['STAGING_DIR_NATIVE'] + bb_vars_prov['libdir'] + '/sota/sota_implicit_prov.toml' |
| 147 | self.assertTrue(os.path.isfile(p), msg = "No aktualizr_cert_provider found (%s)" % p) | 150 | |
| 148 | command = 'LD_LIBRARY_PATH=' + l + ' ' + p + ' -c ' + creds + ' -r -l ' + temp_dir + ' -g ' + config | 151 | self.runNativeCmd('aktualizr_cert_provider -c {creds} -r -l {temp} -g {config}' |
| 149 | # logger.info('Checking output of: ' + command) | 152 | .format(creds=creds, temp=temp_dir, config=config)) |
| 150 | result = runCmd(command, ignore_status=True) | 153 | |
| 151 | self.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output) | ||
| 152 | # Might be nice if these names weren't hardcoded. | 154 | # Might be nice if these names weren't hardcoded. |
| 153 | cert_path = temp_dir + '/client.pem' | 155 | cert_path = temp_dir + '/client.pem' |
| 154 | self.assertTrue(os.path.isfile(cert_path), "Client certificate not found at %s." % cert_path) | 156 | self.assertTrue(os.path.isfile(cert_path), "Client certificate not found at %s." % cert_path) |
| @@ -178,7 +180,7 @@ class QemuTests(oeSelfTest): | |||
| 178 | print('Checking machine name (hostname) of device:') | 180 | print('Checking machine name (hostname) of device:') |
| 179 | stdout, stderr, retcode = self.qemu_command('hostname') | 181 | stdout, stderr, retcode = self.qemu_command('hostname') |
| 180 | self.assertEqual(retcode, 0, "Unable to check hostname. " + | 182 | self.assertEqual(retcode, 0, "Unable to check hostname. " + |
| 181 | "Is an ssh daemon (such as dropbear or openssh) installed on the device?") | 183 | "Is an ssh daemon (such as dropbear or openssh) installed on the device?") |
| 182 | machine = get_bb_var('MACHINE', 'core-image-minimal') | 184 | machine = get_bb_var('MACHINE', 'core-image-minimal') |
| 183 | self.assertEqual(stderr, b'', 'Error: ' + stderr.decode()) | 185 | self.assertEqual(stderr, b'', 'Error: ' + stderr.decode()) |
| 184 | # Strip off line ending. | 186 | # Strip off line ending. |
| @@ -224,7 +226,7 @@ class GrubTests(oeSelfTest): | |||
| 224 | print('Checking machine name (hostname) of device:') | 226 | print('Checking machine name (hostname) of device:') |
| 225 | stdout, stderr, retcode = self.qemu_command('hostname') | 227 | stdout, stderr, retcode = self.qemu_command('hostname') |
| 226 | self.assertEqual(retcode, 0, "Unable to check hostname. " + | 228 | self.assertEqual(retcode, 0, "Unable to check hostname. " + |
| 227 | "Is an ssh daemon (such as dropbear or openssh) installed on the device?") | 229 | "Is an ssh daemon (such as dropbear or openssh) installed on the device?") |
| 228 | machine = get_bb_var('MACHINE', 'core-image-minimal') | 230 | machine = get_bb_var('MACHINE', 'core-image-minimal') |
| 229 | self.assertEqual(stderr, b'', 'Error: ' + stderr.decode()) | 231 | self.assertEqual(stderr, b'', 'Error: ' + stderr.decode()) |
| 230 | # Strip off line ending. | 232 | # Strip off line ending. |
| @@ -246,6 +248,18 @@ class GrubTests(oeSelfTest): | |||
| 246 | 248 | ||
| 247 | class HsmTests(oeSelfTest): | 249 | class HsmTests(oeSelfTest): |
| 248 | 250 | ||
| 251 | @classmethod | ||
| 252 | def setUpClass(cls): | ||
| 253 | logger = logging.getLogger("selftest") | ||
| 254 | bb_vars = get_bb_vars(['SYSROOT_DESTDIR', 'base_prefix', 'libdir', 'bindir'], | ||
| 255 | 'aktualizr-native') | ||
| 256 | cls.sysroot = bb_vars['SYSROOT_DESTDIR'] + bb_vars['base_prefix'] | ||
| 257 | cls.sysrootbin = bb_vars['SYSROOT_DESTDIR'] + bb_vars['bindir'] | ||
| 258 | cls.libdir = bb_vars['libdir'] | ||
| 259 | |||
| 260 | logger.info('Running bitbake to build aktualizr-native tools') | ||
| 261 | bitbake('aktualizr-native') | ||
| 262 | |||
| 249 | def setUpLocal(self): | 263 | def setUpLocal(self): |
| 250 | self.append_config('SOTA_CLIENT_PROV = "aktualizr-hsm-prov"') | 264 | self.append_config('SOTA_CLIENT_PROV = "aktualizr-hsm-prov"') |
| 251 | self.append_config('SOTA_CLIENT_FEATURES = "hsm"') | 265 | self.append_config('SOTA_CLIENT_FEATURES = "hsm"') |
| @@ -254,6 +268,15 @@ class HsmTests(oeSelfTest): | |||
| 254 | def tearDownLocal(self): | 268 | def tearDownLocal(self): |
| 255 | qemu_terminate(self.s) | 269 | qemu_terminate(self.s) |
| 256 | 270 | ||
| 271 | def runNativeCmd(self, cmd, **kwargs): | ||
| 272 | program, *_ = cmd.split(' ') | ||
| 273 | p = '{}/{}'.format(self.sysrootbin, program) | ||
| 274 | self.assertTrue(os.path.isfile(p), msg="No {} found ({})".format(program, p)) | ||
| 275 | env = dict(os.environ) | ||
| 276 | env['LD_LIBRARY_PATH'] = self.libdir | ||
| 277 | result = runCmd(cmd, env=env, native_sysroot=self.sysroot, ignore_status=True, **kwargs) | ||
| 278 | self.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output) | ||
| 279 | |||
| 257 | def qemu_command(self, command): | 280 | def qemu_command(self, command): |
| 258 | return qemu_send_command(self.qemu.ssh_port, command) | 281 | return qemu_send_command(self.qemu.ssh_port, command) |
| 259 | 282 | ||
| @@ -261,7 +284,7 @@ class HsmTests(oeSelfTest): | |||
| 261 | print('Checking machine name (hostname) of device:') | 284 | print('Checking machine name (hostname) of device:') |
| 262 | stdout, stderr, retcode = self.qemu_command('hostname') | 285 | stdout, stderr, retcode = self.qemu_command('hostname') |
| 263 | self.assertEqual(retcode, 0, "Unable to check hostname. " + | 286 | self.assertEqual(retcode, 0, "Unable to check hostname. " + |
| 264 | "Is an ssh daemon (such as dropbear or openssh) installed on the device?") | 287 | "Is an ssh daemon (such as dropbear or openssh) installed on the device?") |
| 265 | machine = get_bb_var('MACHINE', 'core-image-minimal') | 288 | machine = get_bb_var('MACHINE', 'core-image-minimal') |
| 266 | self.assertEqual(stderr, b'', 'Error: ' + stderr.decode()) | 289 | self.assertEqual(stderr, b'', 'Error: ' + stderr.decode()) |
| 267 | # Strip off line ending. | 290 | # Strip off line ending. |
| @@ -291,7 +314,7 @@ class HsmTests(oeSelfTest): | |||
| 291 | pkcs11_command = 'pkcs11-tool --module=/usr/lib/softhsm/libsofthsm2.so -O' | 314 | pkcs11_command = 'pkcs11-tool --module=/usr/lib/softhsm/libsofthsm2.so -O' |
| 292 | stdout, stderr, retcode = self.qemu_command(pkcs11_command) | 315 | stdout, stderr, retcode = self.qemu_command(pkcs11_command) |
| 293 | self.assertNotEqual(retcode, 0, 'pkcs11-tool succeeded before initialization: ' + | 316 | self.assertNotEqual(retcode, 0, 'pkcs11-tool succeeded before initialization: ' + |
| 294 | stdout.decode() + stderr.decode()) | 317 | stdout.decode() + stderr.decode()) |
| 295 | softhsm2_command = 'softhsm2-util --show-slots' | 318 | softhsm2_command = 'softhsm2-util --show-slots' |
| 296 | stdout, stderr, retcode = self.qemu_command(softhsm2_command) | 319 | stdout, stderr, retcode = self.qemu_command(softhsm2_command) |
| 297 | self.assertNotEqual(retcode, 0, 'softhsm2-tool succeeded before initialization: ' + | 320 | self.assertNotEqual(retcode, 0, 'softhsm2-tool succeeded before initialization: ' + |
| @@ -300,18 +323,12 @@ class HsmTests(oeSelfTest): | |||
| 300 | # Run cert_provider. | 323 | # Run cert_provider. |
| 301 | bb_vars = get_bb_vars(['SYSROOT_DESTDIR', 'bindir', 'libdir', | 324 | bb_vars = get_bb_vars(['SYSROOT_DESTDIR', 'bindir', 'libdir', |
| 302 | 'SOTA_PACKED_CREDENTIALS'], 'aktualizr-native') | 325 | 'SOTA_PACKED_CREDENTIALS'], 'aktualizr-native') |
| 303 | l = bb_vars['libdir'] | ||
| 304 | p = bb_vars['SYSROOT_DESTDIR'] + bb_vars['bindir'] + "/aktualizr_cert_provider" | ||
| 305 | creds = bb_vars['SOTA_PACKED_CREDENTIALS'] | 326 | creds = bb_vars['SOTA_PACKED_CREDENTIALS'] |
| 306 | bb_vars_prov = get_bb_vars(['STAGING_DIR_NATIVE', 'libdir'], 'aktualizr-hsm-prov') | 327 | bb_vars_prov = get_bb_vars(['STAGING_DIR_NATIVE', 'libdir'], 'aktualizr-hsm-prov') |
| 307 | config = bb_vars_prov['STAGING_DIR_NATIVE'] + bb_vars_prov['libdir'] + '/sota/sota_implicit_prov.toml' | 328 | config = bb_vars_prov['STAGING_DIR_NATIVE'] + bb_vars_prov['libdir'] + '/sota/sota_implicit_prov.toml' |
| 308 | self.assertTrue(os.path.isfile(p), msg = "No aktualizr_cert_provider found (%s)" % p) | 329 | |
| 309 | command = ('LD_LIBRARY_PATH=' + l + ' ' + p + ' -c ' + creds + ' -t root@localhost -p ' + | 330 | self.runNativeCmd('aktualizr_cert_provider -c {creds} -t root@localhost -p {port} -r -s -g {config}' |
| 310 | str(self.qemu.ssh_port) + ' -r -s -g ' + config) | 331 | .format(creds=creds, port=self.qemu.ssh_port, config=config)) |
| 311 | logger = logging.getLogger("selftest") | ||
| 312 | # logger.info('Checking output of: ' + command) | ||
| 313 | result = runCmd(command, ignore_status=True) | ||
| 314 | self.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output) | ||
| 315 | 332 | ||
| 316 | # Verify that HSM is able to initialize. | 333 | # Verify that HSM is able to initialize. |
| 317 | ran_ok = False | 334 | ran_ok = False |
| @@ -361,7 +378,7 @@ class HsmTests(oeSelfTest): | |||
| 361 | m = p.search(stdout.decode()) | 378 | m = p.search(stdout.decode()) |
| 362 | self.assertTrue(m, 'Device ID could not be read: ' + stderr.decode() + stdout.decode()) | 379 | self.assertTrue(m, 'Device ID could not be read: ' + stderr.decode() + stdout.decode()) |
| 363 | self.assertGreater(m.lastindex, 0, 'Device ID could not be read: ' + stderr.decode() + stdout.decode()) | 380 | self.assertGreater(m.lastindex, 0, 'Device ID could not be read: ' + stderr.decode() + stdout.decode()) |
| 364 | logger.info('Device successfully provisioned with ID: ' + m.group(1)) | 381 | self.logger.info('Device successfully provisioned with ID: ' + m.group(1)) |
| 365 | 382 | ||
| 366 | 383 | ||
| 367 | def qemu_launch(efi=False, machine=None): | 384 | def qemu_launch(efi=False, machine=None): |
| @@ -391,12 +408,14 @@ def qemu_launch(efi=False, machine=None): | |||
| 391 | sleep(10) | 408 | sleep(10) |
| 392 | return qemu, s | 409 | return qemu, s |
| 393 | 410 | ||
| 411 | |||
| 394 | def qemu_terminate(s): | 412 | def qemu_terminate(s): |
| 395 | try: | 413 | try: |
| 396 | s.terminate() | 414 | s.terminate() |
| 397 | except KeyboardInterrupt: | 415 | except KeyboardInterrupt: |
| 398 | pass | 416 | pass |
| 399 | 417 | ||
| 418 | |||
| 400 | def qemu_send_command(port, command): | 419 | def qemu_send_command(port, command): |
| 401 | command = ['ssh -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@localhost -p ' + | 420 | command = ['ssh -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@localhost -p ' + |
| 402 | str(port) + ' "' + command + '"'] | 421 | str(port) + ' "' + command + '"'] |
