From 9a404b4e60c3a9166d98491fed778c64a67150bc Mon Sep 17 00:00:00 2001 From: Patrick Vacek Date: Tue, 13 Feb 2018 17:23:08 +0100 Subject: Only expect credentials in the image if using autoprov. The credentials test was failing if any other provisioning recipe was specified. --- lib/oeqa/selftest/updater.py | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/oeqa/selftest/updater.py b/lib/oeqa/selftest/updater.py index 0962cb7..7e8a615 100644 --- a/lib/oeqa/selftest/updater.py +++ b/lib/oeqa/selftest/updater.py @@ -57,6 +57,7 @@ class GeneralTests(oeSelfTest): self.assertNotEqual(result, -1, 'Feature "systemd" not set at DISTRO_FEATURES') def test_credentials(self): + self.write_config('SOTA_CLIENT_PROV = " aktualizr-auto-prov "') bitbake('core-image-minimal') credentials = get_bb_var('SOTA_PACKED_CREDENTIALS') # skip the test if the variable SOTA_PACKED_CREDENTIALS is not set -- cgit v1.2.3-54-g00ecf From 7bcbb8046672ff66ca7aa0bdf48460d1a11000c3 Mon Sep 17 00:00:00 2001 From: Patrick Vacek Date: Wed, 14 Feb 2018 17:08:52 +0100 Subject: Test that implicit_writer and cert_provider work. This required setting the LD_LIBRARY_PATH to get some dependencies that are liable to conflict with the host's normal installation. I adapted that for the sota_tools tests as well for good measure. Also, we now actually install cert_provider in the native build. --- lib/oeqa/selftest/updater.py | 42 +++++++++++++++++++++++---------- recipes-sota/aktualizr/aktualizr_git.bb | 3 ++- 2 files changed, 32 insertions(+), 13 deletions(-) diff --git a/lib/oeqa/selftest/updater.py b/lib/oeqa/selftest/updater.py index 7e8a615..9a3efee 100644 --- a/lib/oeqa/selftest/updater.py +++ b/lib/oeqa/selftest/updater.py @@ -19,24 +19,27 @@ class SotaToolsTests(oeSelfTest): bitbake('aktualizr-native') def test_push_help(self): - bb_vars = get_bb_vars(['SYSROOT_DESTDIR', 'bindir'], 'aktualizr-native') - p = bb_vars['SYSROOT_DESTDIR'] + bb_vars['bindir'] + "/" + "garage-push" + bb_vars = get_bb_vars(['SYSROOT_DESTDIR', 'bindir', 'libdir'], 'aktualizr-native') + l = bb_vars['libdir'] + p = bb_vars['SYSROOT_DESTDIR'] + bb_vars['bindir'] + "/garage-push" self.assertTrue(os.path.isfile(p), msg = "No garage-push found (%s)" % p) - result = runCmd('%s --help' % p, ignore_status=True) + result = runCmd('LD_LIBRARY_PATH=%s %s --help' % (l, p), ignore_status=True) self.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output) def test_deploy_help(self): - bb_vars = get_bb_vars(['SYSROOT_DESTDIR', 'bindir'], 'aktualizr-native') - p = bb_vars['SYSROOT_DESTDIR'] + bb_vars['bindir'] + "/" + "garage-deploy" + bb_vars = get_bb_vars(['SYSROOT_DESTDIR', 'bindir', 'libdir'], 'aktualizr-native') + l = bb_vars['libdir'] + p = bb_vars['SYSROOT_DESTDIR'] + bb_vars['bindir'] + "/garage-deploy" self.assertTrue(os.path.isfile(p), msg = "No garage-deploy found (%s)" % p) - result = runCmd('%s --help' % p, ignore_status=True) + result = runCmd('LD_LIBRARY_PATH=%s %s --help' % (l, p), ignore_status=True) self.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output) def test_garagesign_help(self): - bb_vars = get_bb_vars(['SYSROOT_DESTDIR', 'bindir'], 'aktualizr-native') - p = bb_vars['SYSROOT_DESTDIR'] + bb_vars['bindir'] + "/" + "garage-sign" + bb_vars = get_bb_vars(['SYSROOT_DESTDIR', 'bindir', 'libdir'], 'aktualizr-native') + l = bb_vars['libdir'] + p = bb_vars['SYSROOT_DESTDIR'] + bb_vars['bindir'] + "/garage-sign" self.assertTrue(os.path.isfile(p), msg = "No garage-sign found (%s)" % p) - result = runCmd('%s --help' % p, ignore_status=True) + result = runCmd('LD_LIBRARY_PATH=%s %s --help' % (l, p), ignore_status=True) self.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output) class HsmTests(oeSelfTest): @@ -76,6 +79,22 @@ class GeneralTests(oeSelfTest): result = runCmd('which java', ignore_status=True) self.assertEqual(result.status, 0, "Java not found.") + def test_implicit_writer_help(self): + bb_vars = get_bb_vars(['SYSROOT_DESTDIR', 'bindir', 'libdir'], 'aktualizr-native') + l = bb_vars['libdir'] + p = bb_vars['SYSROOT_DESTDIR'] + bb_vars['bindir'] + "/aktualizr_implicit_writer" + self.assertTrue(os.path.isfile(p), msg = "No aktualizr_implicit_writer found (%s)" % p) + result = runCmd('LD_LIBRARY_PATH=%s %s --help' % (l, p), ignore_status=True) + self.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output) + + def test_cert_provider_help(self): + bb_vars = get_bb_vars(['SYSROOT_DESTDIR', 'bindir', 'libdir'], 'aktualizr-native') + l = bb_vars['libdir'] + p = bb_vars['SYSROOT_DESTDIR'] + bb_vars['bindir'] + "/aktualizr_cert_provider" + self.assertTrue(os.path.isfile(p), msg = "No aktualizr_cert_provider found (%s)" % p) + result = runCmd('LD_LIBRARY_PATH=%s %s --help' % (l, p), ignore_status=True) + self.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output) + def test_add_package(self): print('') deploydir = get_bb_var('DEPLOY_DIR_IMAGE') @@ -152,9 +171,8 @@ class QemuTests(oeSelfTest): break except IOError as e: print(e) - if not ran_ok: - print(stdout.decode()) - print(stderr.decode()) + self.assertTrue(ran_ok, 'aktualizr-info failed: ' + stdout.decode() + stderr.decode()) + class GrubTests(oeSelfTest): diff --git a/recipes-sota/aktualizr/aktualizr_git.bb b/recipes-sota/aktualizr/aktualizr_git.bb index 0194dbb..bcc1438 100644 --- a/recipes-sota/aktualizr/aktualizr_git.bb +++ b/recipes-sota/aktualizr/aktualizr_git.bb @@ -37,10 +37,10 @@ EXTRA_OECMAKE_append_class-target = " -DBUILD_OSTREE=ON -DBUILD_ISOTP=ON ${@bb.u EXTRA_OECMAKE_append_class-native = " -DBUILD_SOTA_TOOLS=ON -DBUILD_OSTREE=OFF " do_install_append () { - rm -f ${D}${bindir}/aktualizr_cert_provider rm -fr ${D}${libdir}/systemd } do_install_append_class-target () { + rm -f ${D}${bindir}/aktualizr_cert_provider rm -f ${D}${bindir}/aktualizr_implicit_writer rm -f ${D}${libdir}/sota/sota.toml ${@bb.utils.contains('SOTA_CLIENT_FEATURES', 'secondary-example', '', 'rm -f ${D}${bindir}/example-interface', d)} @@ -76,6 +76,7 @@ FILES_${PN}_class-target = " \ FILES_${PN}_append_class-target = " ${@bb.utils.contains('SOTA_CLIENT_FEATURES', 'secondary-example', ' ${bindir}/example-interface', '', d)} " FILES_${PN}_append_class-target = " ${@bb.utils.contains('SOTA_CLIENT_FEATURES', 'secondary-isotp-example', ' ${bindir}/isotp-test-interface', '', d)} " FILES_${PN}_class-native = " \ + ${bindir}/aktualizr_cert_provider \ ${bindir}/aktualizr_implicit_writer \ ${bindir}/garage-deploy \ ${bindir}/garage-push \ -- cgit v1.2.3-54-g00ecf From 9e4918cff53c6154b5bcee2e28deca08280aff75 Mon Sep 17 00:00:00 2001 From: Patrick Vacek Date: Thu, 15 Feb 2018 12:05:55 +0100 Subject: Add test_cert_provider_local_output. Improve some organization and logging. --- lib/oeqa/selftest/updater.py | 71 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 55 insertions(+), 16 deletions(-) diff --git a/lib/oeqa/selftest/updater.py b/lib/oeqa/selftest/updater.py index 9a3efee..83febb1 100644 --- a/lib/oeqa/selftest/updater.py +++ b/lib/oeqa/selftest/updater.py @@ -60,6 +60,8 @@ class GeneralTests(oeSelfTest): self.assertNotEqual(result, -1, 'Feature "systemd" not set at DISTRO_FEATURES') def test_credentials(self): + logger = logging.getLogger("selftest") + logger.info('Running bitbake to build core-image-minimal') self.write_config('SOTA_CLIENT_PROV = " aktualizr-auto-prov "') bitbake('core-image-minimal') credentials = get_bb_var('SOTA_PACKED_CREDENTIALS') @@ -79,22 +81,6 @@ class GeneralTests(oeSelfTest): result = runCmd('which java', ignore_status=True) self.assertEqual(result.status, 0, "Java not found.") - def test_implicit_writer_help(self): - bb_vars = get_bb_vars(['SYSROOT_DESTDIR', 'bindir', 'libdir'], 'aktualizr-native') - l = bb_vars['libdir'] - p = bb_vars['SYSROOT_DESTDIR'] + bb_vars['bindir'] + "/aktualizr_implicit_writer" - self.assertTrue(os.path.isfile(p), msg = "No aktualizr_implicit_writer found (%s)" % p) - result = runCmd('LD_LIBRARY_PATH=%s %s --help' % (l, p), ignore_status=True) - self.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output) - - def test_cert_provider_help(self): - bb_vars = get_bb_vars(['SYSROOT_DESTDIR', 'bindir', 'libdir'], 'aktualizr-native') - l = bb_vars['libdir'] - p = bb_vars['SYSROOT_DESTDIR'] + bb_vars['bindir'] + "/aktualizr_cert_provider" - self.assertTrue(os.path.isfile(p), msg = "No aktualizr_cert_provider found (%s)" % p) - result = runCmd('LD_LIBRARY_PATH=%s %s --help' % (l, p), ignore_status=True) - self.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output) - def test_add_package(self): print('') deploydir = get_bb_var('DEPLOY_DIR_IMAGE') @@ -126,6 +112,59 @@ class GeneralTests(oeSelfTest): self.assertNotEqual(size1, size2, "Image sizes are identical; image was not rebuilt.") +class AktualizrToolsTests(oeSelfTest): + + @classmethod + def setUpClass(cls): + logger = logging.getLogger("selftest") + logger.info('Running bitbake to build aktualizr-native tools') + bitbake('aktualizr-native') + + def test_implicit_writer_help(self): + bb_vars = get_bb_vars(['SYSROOT_DESTDIR', 'bindir', 'libdir'], 'aktualizr-native') + l = bb_vars['libdir'] + p = bb_vars['SYSROOT_DESTDIR'] + bb_vars['bindir'] + "/aktualizr_implicit_writer" + self.assertTrue(os.path.isfile(p), msg = "No aktualizr_implicit_writer found (%s)" % p) + result = runCmd('LD_LIBRARY_PATH=%s %s --help' % (l, p), ignore_status=True) + self.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output) + + def test_cert_provider_help(self): + bb_vars = get_bb_vars(['SYSROOT_DESTDIR', 'bindir', 'libdir'], 'aktualizr-native') + l = bb_vars['libdir'] + p = bb_vars['SYSROOT_DESTDIR'] + bb_vars['bindir'] + "/aktualizr_cert_provider" + self.assertTrue(os.path.isfile(p), msg = "No aktualizr_cert_provider found (%s)" % p) + result = runCmd('LD_LIBRARY_PATH=%s %s --help' % (l, p), ignore_status=True) + self.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output) + + def test_cert_provider_local_output(self): + logger = logging.getLogger("selftest") + logger.info('Running bitbake to build aktualizr-implicit-prov') + bitbake('aktualizr-implicit-prov') + bb_vars = get_bb_vars(['SYSROOT_DESTDIR', 'bindir', 'libdir', + 'SOTA_PACKED_CREDENTIALS', 'T'], 'aktualizr-native') + l = bb_vars['libdir'] + p = bb_vars['SYSROOT_DESTDIR'] + bb_vars['bindir'] + "/aktualizr_cert_provider" + creds = bb_vars['SOTA_PACKED_CREDENTIALS'] + temp_dir = bb_vars['T'] + bb_vars_prov = get_bb_vars(['STAGING_DIR_NATIVE', 'libdir'], 'aktualizr-implicit-prov') + config = bb_vars_prov['STAGING_DIR_NATIVE'] + bb_vars_prov['libdir'] + '/sota/sota_implicit_prov.toml' + self.assertTrue(os.path.isfile(p), msg = "No aktualizr_cert_provider found (%s)" % p) + command = 'LD_LIBRARY_PATH=' + l + ' ' + p + ' -c ' + creds + ' -r -l ' + temp_dir + ' -g ' + config + # logger.info('Checking output of: ' + command) + result = runCmd(command, ignore_status=True) + self.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output) + # Might be nice if these names weren't hardcoded. + cert_path = temp_dir + '/client.pem' + self.assertTrue(os.path.isfile(cert_path), "Client certificate not found at %s." % cert_path) + self.assertTrue(os.path.getsize(cert_path) > 0, "Client certificate at %s is empty." % cert_path) + pkey_path = temp_dir + '/pkey.pem' + self.assertTrue(os.path.isfile(pkey_path), "Private key not found at %s." % pkey_path) + self.assertTrue(os.path.getsize(pkey_path) > 0, "Private key at %s is empty." % pkey_path) + ca_path = temp_dir + '/root.crt' + self.assertTrue(os.path.isfile(ca_path), "Client certificate not found at %s." % ca_path) + self.assertTrue(os.path.getsize(ca_path) > 0, "Client certificate at %s is empty." % ca_path) + + class QemuTests(oeSelfTest): @classmethod -- cgit v1.2.3-54-g00ecf From 586394dc9f7b5e97c827ea982dd69692f3ca0c97 Mon Sep 17 00:00:00 2001 From: Patrick Vacek Date: Tue, 13 Feb 2018 18:08:39 +0100 Subject: Test provisioning with HSM. --- lib/oeqa/selftest/updater.py | 95 ++++++++++++++++++++++++++++++--- recipes-sota/aktualizr/aktualizr_git.bb | 2 +- 2 files changed, 89 insertions(+), 8 deletions(-) diff --git a/lib/oeqa/selftest/updater.py b/lib/oeqa/selftest/updater.py index 83febb1..8ee8378 100644 --- a/lib/oeqa/selftest/updater.py +++ b/lib/oeqa/selftest/updater.py @@ -42,12 +42,6 @@ class SotaToolsTests(oeSelfTest): result = runCmd('LD_LIBRARY_PATH=%s %s --help' % (l, p), ignore_status=True) self.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output) -class HsmTests(oeSelfTest): - - def test_hsm(self): - self.write_config('SOTA_CLIENT_FEATURES="hsm"') - bitbake('core-image-minimal') - class GeneralTests(oeSelfTest): @@ -210,7 +204,7 @@ class QemuTests(oeSelfTest): break except IOError as e: print(e) - self.assertTrue(ran_ok, 'aktualizr-info failed: ' + stdout.decode() + stderr.decode()) + self.assertTrue(ran_ok, 'aktualizr-info failed: ' + stderr.decode() + stdout.decode()) class GrubTests(oeSelfTest): @@ -247,6 +241,93 @@ class GrubTests(oeSelfTest): print(value_str) +class HsmTests(oeSelfTest): + + def setUpLocal(self): + self.write_config('SOTA_CLIENT_PROV = " aktualizr-hsm-prov "') + self.write_config('SOTA_CLIENT_FEATURES="hsm"') + self.qemu, self.s = qemu_launch(machine='qemux86-64') + + def tearDownLocal(self): + qemu_terminate(self.s) + + def run_command(self, command): + return qemu_send_command(self.qemu.ssh_port, command) + + def test_provisioning(self): + print('') + ran_ok = False + for delay in [0, 1, 2, 5, 10, 15]: + stdout, stderr, retcode = self.run_command('aktualizr-info') + if retcode == 0 and stderr == b'': + ran_ok = True + break + self.assertTrue(ran_ok, 'aktualizr-info failed: ' + stderr.decode() + stdout.decode()) + # Verify that device has NOT yet provisioned. + self.assertIn(b'Couldn\'t load device ID', stdout, + 'Device already provisioned!? ' + stderr.decode() + stdout.decode()) + self.assertIn(b'Couldn\'t load ECU serials', stdout, + 'Device already provisioned!? ' + stderr.decode() + stdout.decode()) + self.assertIn(b'Provisioned on server: no', stdout, + 'Device already provisioned!? ' + stderr.decode() + stdout.decode()) + self.assertIn(b'Fetched metadata: no', stdout, + 'Device already provisioned!? ' + stderr.decode() + stdout.decode()) + + pkcs11_command = 'pkcs11-tool --module=/usr/lib/softhsm/libsofthsm2.so -O' + stdout, stderr, retcode = self.run_command(pkcs11_command) + self.assertNotEqual(retcode, 0, 'pkcs11-tool succeeded before initialization: ' + + stdout.decode() + stderr.decode()) + softhsm2_command = 'softhsm2-util --show-slots' + stdout, stderr, retcode = self.run_command(softhsm2_command) + self.assertNotEqual(retcode, 0, 'softhsm2-tool succeeded before initialization: ' + + stdout.decode() + stderr.decode()) + + bb_vars = get_bb_vars(['SYSROOT_DESTDIR', 'bindir', 'libdir', + 'SOTA_PACKED_CREDENTIALS'], 'aktualizr-native') + l = bb_vars['libdir'] + p = bb_vars['SYSROOT_DESTDIR'] + bb_vars['bindir'] + "/aktualizr_cert_provider" + creds = bb_vars['SOTA_PACKED_CREDENTIALS'] + bb_vars_prov = get_bb_vars(['STAGING_DIR_NATIVE', 'libdir'], 'aktualizr-hsm-prov') + config = bb_vars_prov['STAGING_DIR_NATIVE'] + bb_vars_prov['libdir'] + '/sota/sota_implicit_prov.toml' + self.assertTrue(os.path.isfile(p), msg = "No aktualizr_cert_provider found (%s)" % p) + command = ('LD_LIBRARY_PATH=' + l + ' ' + p + ' -c ' + creds + ' -t root@localhost -p ' + + str(self.qemu.ssh_port) + ' -r -s -g ' + config) + logger = logging.getLogger("selftest") + # logger.info('Checking output of: ' + command) + result = runCmd(command, ignore_status=True) + self.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output) + + ran_ok = False + for delay in [5, 5, 5, 5, 10]: + sleep(delay) + p11_out, p11_err, p11_ret = self.run_command(pkcs11_command) + hsm_out, hsm_err, hsm_ret = self.run_command(softhsm2_command) + if p11_ret == 0 and hsm_ret == 0 and hsm_err == b'': + ran_ok = True + break + self.assertTrue(ran_ok, 'pkcs11-tool or softhsm2-tool failed: ' + p11_err.decode() + + p11_out.decode() + hsm_err.decode() + hsm_out.decode()) + self.assertIn(b'present token', p11_err, 'pkcs11-tool failed: ' + p11_err.decode() + p11_out.decode()) + self.assertIn(b'X.509 cert', p11_out, 'pkcs11-tool failed: ' + p11_err.decode() + p11_out.decode()) + self.assertIn(b'Initialized: yes', hsm_out, 'softhsm2-tool failed: ' + + hsm_err.decode() + hsm_out.decode()) + self.assertIn(b'User PIN init.: yes', hsm_out, 'softhsm2-tool failed: ' + + hsm_err.decode() + hsm_out.decode()) + + # Verify that device HAS provisioned. + ran_ok = False + for delay in [5, 5, 5, 5, 10]: + sleep(delay) + stdout, stderr, retcode = self.run_command('aktualizr-info') + if retcode == 0 and stderr == b'' and stdout.decode().find('Provisioned on server: yes') >= 0: + ran_ok = True + break + self.assertIn(b'Device ID: ', stdout, 'Provisioning failed: ' + stderr.decode() + stdout.decode()) + self.assertIn(b'Primary ecu hardware ID: qemux86-64', stdout, + 'Provisioning failed: ' + stderr.decode() + stdout.decode()) + self.assertIn(b'Fetched metadata: yes', stdout, 'Provisioning failed: ' + stderr.decode() + stdout.decode()) + + def qemu_launch(efi=False, machine=None): logger = logging.getLogger("selftest") logger.info('Running bitbake to build core-image-minimal') diff --git a/recipes-sota/aktualizr/aktualizr_git.bb b/recipes-sota/aktualizr/aktualizr_git.bb index bcc1438..ab9a8dc 100644 --- a/recipes-sota/aktualizr/aktualizr_git.bb +++ b/recipes-sota/aktualizr/aktualizr_git.bb @@ -20,7 +20,7 @@ SRC_URI = " \ file://aktualizr.service \ file://aktualizr-serialcan.service \ " -SRCREV = "715dfc3410d46670174ee2f55613e8d953fbb1ae" +SRCREV = "abd0db4e503cbe647fbe3a6e70d28456c2ad7ea4" BRANCH ?= "master" S = "${WORKDIR}/git" -- cgit v1.2.3-54-g00ecf From 1f5d44911e608d809ac1e6987542c8909dfc464f Mon Sep 17 00:00:00 2001 From: Patrick Vacek Date: Thu, 15 Feb 2018 17:20:35 +0100 Subject: Use some regex to get a little fancier. --- lib/oeqa/selftest/updater.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/lib/oeqa/selftest/updater.py b/lib/oeqa/selftest/updater.py index 8ee8378..690dae5 100644 --- a/lib/oeqa/selftest/updater.py +++ b/lib/oeqa/selftest/updater.py @@ -1,6 +1,7 @@ # pylint: disable=C0111,C0325 import os import logging +import re import subprocess import unittest from time import sleep @@ -273,6 +274,7 @@ class HsmTests(oeSelfTest): self.assertIn(b'Fetched metadata: no', stdout, 'Device already provisioned!? ' + stderr.decode() + stdout.decode()) + # Verify that HSM is not yet initialized. pkcs11_command = 'pkcs11-tool --module=/usr/lib/softhsm/libsofthsm2.so -O' stdout, stderr, retcode = self.run_command(pkcs11_command) self.assertNotEqual(retcode, 0, 'pkcs11-tool succeeded before initialization: ' + @@ -282,6 +284,7 @@ class HsmTests(oeSelfTest): self.assertNotEqual(retcode, 0, 'softhsm2-tool succeeded before initialization: ' + stdout.decode() + stderr.decode()) + # Run cert_provider. bb_vars = get_bb_vars(['SYSROOT_DESTDIR', 'bindir', 'libdir', 'SOTA_PACKED_CREDENTIALS'], 'aktualizr-native') l = bb_vars['libdir'] @@ -297,6 +300,7 @@ class HsmTests(oeSelfTest): result = runCmd(command, ignore_status=True) self.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output) + # Verify that HSM is able to initialize. ran_ok = False for delay in [5, 5, 5, 5, 10]: sleep(delay) @@ -314,6 +318,20 @@ class HsmTests(oeSelfTest): self.assertIn(b'User PIN init.: yes', hsm_out, 'softhsm2-tool failed: ' + hsm_err.decode() + hsm_out.decode()) + # Check that pkcs11 output matches sofhsm output. + p11_p = re.compile(r'Using slot [0-9] with a present token \((0x[0-9a-f]*)\)\s') + p11_m = p11_p.search(p11_err.decode()) + self.assertTrue(p11_m, 'Slot number not found with pkcs11-tool: ' + p11_err.decode() + p11_out.decode()) + self.assertGreater(p11_m.lastindex, 0, 'Slot number not found with pkcs11-tool: ' + + p11_err.decode() + p11_out.decode()) + hsm_p = re.compile(r'Description:\s*SoftHSM slot ID (0x[0-9a-f]*)\s') + hsm_m = hsm_p.search(hsm_out.decode()) + self.assertTrue(hsm_m, 'Slot number not found with softhsm2-tool: ' + hsm_err.decode() + hsm_out.decode()) + self.assertGreater(hsm_m.lastindex, 0, 'Slot number not found with softhsm2-tool: ' + + hsm_err.decode() + hsm_out.decode()) + self.assertEqual(p11_m.group(1), hsm_m.group(1), 'Slot number does not match: ' + + p11_err.decode() + p11_out.decode() + hsm_err.decode() + hsm_out.decode()) + # Verify that device HAS provisioned. ran_ok = False for delay in [5, 5, 5, 5, 10]: @@ -326,6 +344,11 @@ class HsmTests(oeSelfTest): self.assertIn(b'Primary ecu hardware ID: qemux86-64', stdout, 'Provisioning failed: ' + stderr.decode() + stdout.decode()) self.assertIn(b'Fetched metadata: yes', stdout, 'Provisioning failed: ' + stderr.decode() + stdout.decode()) + p = re.compile(r'Device ID: ([a-z0-9-]*)\n') + m = p.search(stdout.decode()) + self.assertTrue(m, 'Device ID could not be read: ' + stderr.decode() + stdout.decode()) + self.assertGreater(m.lastindex, 0, 'Device ID could not be read: ' + stderr.decode() + stdout.decode()) + logger.info('Device successfully provisioned with ID: ' + m.group(1)) def qemu_launch(efi=False, machine=None): -- cgit v1.2.3-54-g00ecf From c6690b907a0a4525848dfed6cde2d89d8554b5f1 Mon Sep 17 00:00:00 2001 From: Patrick Vacek Date: Mon, 19 Feb 2018 14:10:16 +0100 Subject: Rename run_command to qemu_command. This helps distinguish it from runCmd, which is how you run commands in the shell. --- lib/oeqa/selftest/updater.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/oeqa/selftest/updater.py b/lib/oeqa/selftest/updater.py index 690dae5..c8ec711 100644 --- a/lib/oeqa/selftest/updater.py +++ b/lib/oeqa/selftest/updater.py @@ -170,13 +170,13 @@ class QemuTests(oeSelfTest): def tearDownClass(cls): qemu_terminate(cls.s) - def run_command(self, command): + def qemu_command(self, command): return qemu_send_command(self.qemu.ssh_port, command) def test_hostname(self): print('') print('Checking machine name (hostname) of device:') - stdout, stderr, retcode = self.run_command('hostname') + stdout, stderr, retcode = self.qemu_command('hostname') machine = get_bb_var('MACHINE', 'core-image-minimal') self.assertEqual(stderr, b'', 'Error: ' + stderr.decode()) # Strip off line ending. @@ -188,7 +188,7 @@ class QemuTests(oeSelfTest): def test_var_sota(self): print('') print('Checking contents of /var/sota:') - stdout, stderr, retcode = self.run_command('ls /var/sota') + stdout, stderr, retcode = self.qemu_command('ls /var/sota') self.assertEqual(stderr, b'', 'Error: ' + stderr.decode()) self.assertEqual(retcode, 0) print(stdout.decode()) @@ -199,7 +199,7 @@ class QemuTests(oeSelfTest): for delay in [0, 1, 2, 5, 10, 15]: sleep(delay) try: - stdout, stderr, retcode = self.run_command('aktualizr-info') + stdout, stderr, retcode = self.qemu_command('aktualizr-info') if retcode == 0 and stderr == b'': ran_ok = True break @@ -252,14 +252,14 @@ class HsmTests(oeSelfTest): def tearDownLocal(self): qemu_terminate(self.s) - def run_command(self, command): + def qemu_command(self, command): return qemu_send_command(self.qemu.ssh_port, command) def test_provisioning(self): print('') ran_ok = False for delay in [0, 1, 2, 5, 10, 15]: - stdout, stderr, retcode = self.run_command('aktualizr-info') + stdout, stderr, retcode = self.qemu_command('aktualizr-info') if retcode == 0 and stderr == b'': ran_ok = True break @@ -276,11 +276,11 @@ class HsmTests(oeSelfTest): # Verify that HSM is not yet initialized. pkcs11_command = 'pkcs11-tool --module=/usr/lib/softhsm/libsofthsm2.so -O' - stdout, stderr, retcode = self.run_command(pkcs11_command) + stdout, stderr, retcode = self.qemu_command(pkcs11_command) self.assertNotEqual(retcode, 0, 'pkcs11-tool succeeded before initialization: ' + stdout.decode() + stderr.decode()) softhsm2_command = 'softhsm2-util --show-slots' - stdout, stderr, retcode = self.run_command(softhsm2_command) + stdout, stderr, retcode = self.qemu_command(softhsm2_command) self.assertNotEqual(retcode, 0, 'softhsm2-tool succeeded before initialization: ' + stdout.decode() + stderr.decode()) @@ -304,8 +304,8 @@ class HsmTests(oeSelfTest): ran_ok = False for delay in [5, 5, 5, 5, 10]: sleep(delay) - p11_out, p11_err, p11_ret = self.run_command(pkcs11_command) - hsm_out, hsm_err, hsm_ret = self.run_command(softhsm2_command) + p11_out, p11_err, p11_ret = self.qemu_command(pkcs11_command) + hsm_out, hsm_err, hsm_ret = self.qemu_command(softhsm2_command) if p11_ret == 0 and hsm_ret == 0 and hsm_err == b'': ran_ok = True break @@ -336,7 +336,7 @@ class HsmTests(oeSelfTest): ran_ok = False for delay in [5, 5, 5, 5, 10]: sleep(delay) - stdout, stderr, retcode = self.run_command('aktualizr-info') + stdout, stderr, retcode = self.qemu_command('aktualizr-info') if retcode == 0 and stderr == b'' and stdout.decode().find('Provisioned on server: yes') >= 0: ran_ok = True break -- cgit v1.2.3-54-g00ecf From eb173b6cba56c5b97465a6506a9a69b2f1c858f7 Mon Sep 17 00:00:00 2001 From: Patrick Vacek Date: Mon, 19 Feb 2018 16:51:48 +0100 Subject: Better oe-selftest documentation. Also clean up some minor formatting. --- README.adoc | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/README.adoc b/README.adoc index fbd3239..e074913 100644 --- a/README.adoc +++ b/README.adoc @@ -17,10 +17,10 @@ If you don't already have a Yocto project that you want to add OTA to, you can u If you already have a Yocto-based project and you want to add atomic filesystem updates to it, you just need to do three things: 1. Clone the `meta-updater` layer and add it to your https://www.yoctoproject.org/docs/2.1/ref-manual/ref-manual.html#structure-build-conf-bblayers.conf[bblayers.conf]. -2. Clone BSP integration layer (meta-updater-$\{PLATFORM}, e.g. https://github.com/advancedtelematic/meta-updater-raspberrypi[meta-updater-raspberrypi]) and add it to your conf/bblayers.conf. If your board isn't supported yet, you could write a BSP integration for it yourself. See the <> section for the details. -3. Set up your https://www.yoctoproject.org/docs/2.1/ref-manual/ref-manual.html#var-DISTRO[distro]. If you are using "poky", the default distro in Yocto, you can change it in your conf/local.conf to "poky-sota". Alternatively, if you are using your own or third party distro configuration, you can add 'INHERIT += " sota"' to it, thus combining capabilities of your distro with meta-updater features. +2. Clone BSP integration layer (`meta-updater-$\{PLATFORM}`, e.g. https://github.com/advancedtelematic/meta-updater-raspberrypi[meta-updater-raspberrypi]) and add it to your `conf/bblayers.conf`. If your board isn't supported yet, you could write a BSP integration for it yourself. See the <> section for the details. +3. Set up your https://www.yoctoproject.org/docs/2.1/ref-manual/ref-manual.html#var-DISTRO[distro]. If you are using "poky", the default distro in Yocto, you can change it in your `conf/local.conf` to "poky-sota". Alternatively, if you are using your own or third party distro configuration, you can add `INHERIT += " sota"` to it, thus combining capabilities of your distro with meta-updater features. -You can then build your image as usual, with bitbake. After building the root file system, bitbake will then create an https://ostree.readthedocs.io/en/latest/manual/adapting-existing/[OSTree-enabled version] of it, commit it to your local OSTree repo and (optionally) push it to a remote server. Additionally, a live disk image will be created (normally named $\{IMAGE_NAME}.-sdimg-ota e.g. core-image-raspberrypi3.rpi-sdimg-ota). You can control this behaviour through <>. +You can then build your image as usual, with bitbake. After building the root file system, bitbake will then create an https://ostree.readthedocs.io/en/latest/manual/adapting-existing/[OSTree-enabled version] of it, commit it to your local OSTree repo and (optionally) push it to a remote server. Additionally, a live disk image will be created (normally named `$\{IMAGE_NAME}.-sdimg-ota` e.g. `core-image-raspberrypi3.rpi-sdimg-ota`). You can control this behaviour through <>. === Build in AGL @@ -30,19 +30,19 @@ With AGL you can just add agl-sota feature while configuring your build environm source meta-agl/scripts/aglsetup.sh -m porter agl-demo agl-appfw-smack agl-devel agl-sota .... -you can then run +You can then run: .... bitbake agl-demo-platform .... -and get as a result an "ostree_repo" folder in your images directory (tmp/deploy/images/$\{MACHINE}/ostree_repo). It will contain +and get as a result an `ostree_repo` folder in your images directory (`tmp/deploy/images/$\{MACHINE}/ostree_repo`). It will contain: * your OSTree repository, with the rootfs committed as an OSTree deployment, -* an 'otaimg' bootstrap image, which is an OSTree physical sysroot as a burnable filesystem image, and optionally -* some machine-dependent live images (e.g. '_.rpi-sdimg-ota' for Raspberry Pi or '_.porter-sdimg-ota' Renesas Porter board). +* an `otaimg` bootstrap image, which is an OSTree physical sysroot as a burnable filesystem image, and optionally +* some machine-dependent live images (e.g. `.rpi-sdimg-ota` for Raspberry Pi or `.porter-sdimg-ota` Renesas Porter board). -Although aglsetup.sh hooks provide reasonable defaults for SOTA-related variables, you may want to tune some of them. +Although `aglsetup.sh` hooks provide reasonable defaults for SOTA-related variables, you may want to tune some of them. == Supported boards @@ -63,7 +63,7 @@ You may take a look into https://github.com/advancedtelematic/meta-updater-minno Although we have used U-Boot so far, other boot loaders can be configured work with OSTree as well. -== SOTA-related variables in local.conf +== SOTA-related variables in `local.conf` * `OSTREE_REPO` - path to your OSTree repository. Defaults to `$\{DEPLOY_DIR_IMAGE}/ostree_repo` * `OSTREE_OSNAME` - OS deployment name on your target device. For more information about deployments and osnames see the https://ostree.readthedocs.io/en/latest/manual/deployment/[OSTree documentation]. Defaults to "poky". @@ -125,18 +125,32 @@ garage-push --repo=/path/to/ostree-repo --ref=mybranch --credentials=/path/to/cr You can set SOTA_PACKED_CREDENTIALS in your local.conf to make your build results be automatically synchronized with a remote server. Credentials are stored in the JSON format described in the https://github.com/advancedtelematic/aktualizr/blob/master/README.sotatools.adoc[garage-push README]. This JSON file can be optionally stored inside a zip file, although if it is stored this way, the JSON file must be named treehub.json. -=== QA +== QA with `oe-selftest` This layer relies on the test framework oe-selftest for quality assurance. Follow the steps below to run the tests: -* Append the line below to conf/local.conf +1. Append the line below to `conf/local.conf` to disable the warning about supported operating systems: ++ +``` +SANITY_TESTED_DISTROS = "" +``` +2. If your image does not already include an ssh daemon such as dropbear or openssh, add this line to `conf/local.conf` as well: ++ ``` -SANITY_TESTED_DISTROS="" +IMAGE_INSTALL_append = " dropbear " ``` -* Run oe-selftest: +3. To be able to build an image for the grub tests, you will need to install https://github.com/tianocore/tianocore.github.io/wiki/OVMF[TianoCore's ovmf] package on your host system. On Debian-like systems, you can do so with this command: ++ +``` +sudo apt install ovmf +``` +4. Run oe-selftest: ++ ``` oe-selftest --run-tests updater ``` + +For more information about oe-selftest, including details about how to run individual test modules or classes, please refer to the https://wiki.yoctoproject.org/wiki/Oe-selftest[Yocto Project wiki]. -- cgit v1.2.3-54-g00ecf From 5c141641e143883e06b815371dd69551dbf3d52a Mon Sep 17 00:00:00 2001 From: Patrick Vacek Date: Mon, 19 Feb 2018 16:52:12 +0100 Subject: oe-selftest standardization and general improvement. --- lib/oeqa/selftest/updater.py | 72 ++++++++++++++++++++++++++------------------ 1 file changed, 42 insertions(+), 30 deletions(-) diff --git a/lib/oeqa/selftest/updater.py b/lib/oeqa/selftest/updater.py index c8ec711..0ef3e16 100644 --- a/lib/oeqa/selftest/updater.py +++ b/lib/oeqa/selftest/updater.py @@ -173,10 +173,11 @@ class QemuTests(oeSelfTest): def qemu_command(self, command): return qemu_send_command(self.qemu.ssh_port, command) - def test_hostname(self): - print('') + def test_qemu(self): print('Checking machine name (hostname) of device:') stdout, stderr, retcode = self.qemu_command('hostname') + self.assertEqual(retcode, 0, "Unable to check hostname. " + + "Is an ssh daemon (such as dropbear or openssh) installed on the device?") machine = get_bb_var('MACHINE', 'core-image-minimal') self.assertEqual(stderr, b'', 'Error: ' + stderr.decode()) # Strip off line ending. @@ -184,27 +185,14 @@ class QemuTests(oeSelfTest): self.assertEqual(value_str, machine, 'MACHINE does not match hostname: ' + machine + ', ' + value_str) print(value_str) - - def test_var_sota(self): - print('') - print('Checking contents of /var/sota:') - stdout, stderr, retcode = self.qemu_command('ls /var/sota') - self.assertEqual(stderr, b'', 'Error: ' + stderr.decode()) - self.assertEqual(retcode, 0) - print(stdout.decode()) - - def test_aktualizr_info(self): print('Checking output of aktualizr-info:') ran_ok = False for delay in [0, 1, 2, 5, 10, 15]: sleep(delay) - try: - stdout, stderr, retcode = self.qemu_command('aktualizr-info') - if retcode == 0 and stderr == b'': - ran_ok = True - break - except IOError as e: - print(e) + stdout, stderr, retcode = self.qemu_command('aktualizr-info') + if retcode == 0 and stderr == b'': + ran_ok = True + break self.assertTrue(ran_ok, 'aktualizr-info failed: ' + stderr.decode() + stdout.decode()) @@ -227,26 +215,39 @@ class GrubTests(oeSelfTest): runCmd('bitbake-layers remove-layer "%s"' % self.meta_intel, ignore_status=True) runCmd('bitbake-layers remove-layer "%s"' % self.meta_minnow, ignore_status=True) + def qemu_command(self, command): + return qemu_send_command(self.qemu.ssh_port, command) + def test_grub(self): print('') print('Checking machine name (hostname) of device:') - value, err, retcode = qemu_send_command(self.qemu.ssh_port, 'hostname') + stdout, stderr, retcode = self.qemu_command('hostname') + self.assertEqual(retcode, 0, "Unable to check hostname. " + + "Is an ssh daemon (such as dropbear or openssh) installed on the device?") machine = get_bb_var('MACHINE', 'core-image-minimal') - self.assertEqual(err, b'', 'Error: ' + err.decode()) - self.assertEqual(retcode, 0) + self.assertEqual(stderr, b'', 'Error: ' + stderr.decode()) # Strip off line ending. - value_str = value.decode()[:-1] - self.assertEqual(value_str, machine, - 'MACHINE does not match hostname: ' + machine + ', ' + value_str + - '\nIs tianocore ovmf installed?') - print(value_str) + value = stdout.decode()[:-1] + self.assertEqual(value, machine, + 'MACHINE does not match hostname: ' + machine + ', ' + value + + '\nIs TianoCore ovmf installed?') + print(value) + print('Checking output of aktualizr-info:') + ran_ok = False + for delay in [0, 1, 2, 5, 10, 15]: + sleep(delay) + stdout, stderr, retcode = self.qemu_command('aktualizr-info') + if retcode == 0 and stderr == b'': + ran_ok = True + break + self.assertTrue(ran_ok, 'aktualizr-info failed: ' + stderr.decode() + stdout.decode()) class HsmTests(oeSelfTest): def setUpLocal(self): - self.write_config('SOTA_CLIENT_PROV = " aktualizr-hsm-prov "') - self.write_config('SOTA_CLIENT_FEATURES="hsm"') + self.write_config('SOTA_CLIENT_PROV = "aktualizr-hsm-prov"') + self.write_config('SOTA_CLIENT_FEATURES = "hsm"') self.qemu, self.s = qemu_launch(machine='qemux86-64') def tearDownLocal(self): @@ -256,7 +257,18 @@ class HsmTests(oeSelfTest): return qemu_send_command(self.qemu.ssh_port, command) def test_provisioning(self): - print('') + print('Checking machine name (hostname) of device:') + stdout, stderr, retcode = self.qemu_command('hostname') + self.assertEqual(retcode, 0, "Unable to check hostname. " + + "Is an ssh daemon (such as dropbear or openssh) installed on the device?") + machine = get_bb_var('MACHINE', 'core-image-minimal') + self.assertEqual(stderr, b'', 'Error: ' + stderr.decode()) + # Strip off line ending. + value_str = stdout.decode()[:-1] + self.assertEqual(value_str, machine, + 'MACHINE does not match hostname: ' + machine + ', ' + value_str) + print(value_str) + print('Checking output of aktualizr-info:') ran_ok = False for delay in [0, 1, 2, 5, 10, 15]: stdout, stderr, retcode = self.qemu_command('aktualizr-info') -- cgit v1.2.3-54-g00ecf From e77c7c7b6121ed9ad207d7fd1603a32e59540f00 Mon Sep 17 00:00:00 2001 From: Patrick Vacek Date: Tue, 20 Feb 2018 11:56:55 +0100 Subject: Replace write_config with append_config. Also fix a minor provisioning check ordering problem. --- lib/oeqa/selftest/updater.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/oeqa/selftest/updater.py b/lib/oeqa/selftest/updater.py index 0ef3e16..703df91 100644 --- a/lib/oeqa/selftest/updater.py +++ b/lib/oeqa/selftest/updater.py @@ -57,7 +57,7 @@ class GeneralTests(oeSelfTest): def test_credentials(self): logger = logging.getLogger("selftest") logger.info('Running bitbake to build core-image-minimal') - self.write_config('SOTA_CLIENT_PROV = " aktualizr-auto-prov "') + self.append_config('SOTA_CLIENT_PROV = "aktualizr-auto-prov"') bitbake('core-image-minimal') credentials = get_bb_var('SOTA_PACKED_CREDENTIALS') # skip the test if the variable SOTA_PACKED_CREDENTIALS is not set @@ -74,7 +74,8 @@ class GeneralTests(oeSelfTest): def test_java(self): result = runCmd('which java', ignore_status=True) - self.assertEqual(result.status, 0, "Java not found.") + self.assertEqual(result.status, 0, + "Java not found. Do you have a JDK installed on your host machine?") def test_add_package(self): print('') @@ -84,7 +85,7 @@ class GeneralTests(oeSelfTest): logger = logging.getLogger("selftest") logger.info('Running bitbake with man in the image package list') - self.write_config('IMAGE_INSTALL_append = " man "') + self.append_config('IMAGE_INSTALL_append = " man "') bitbake('-c cleanall man') bitbake('core-image-minimal') result = runCmd('oe-pkgdata-util find-path /usr/bin/man') @@ -94,7 +95,7 @@ class GeneralTests(oeSelfTest): logger.info('First image %s has size %i' % (path1, size1)) logger.info('Running bitbake without man in the image package list') - self.write_config('IMAGE_INSTALL_remove = " man "') + self.append_config('IMAGE_INSTALL_remove = " man "') bitbake('-c cleanall man') bitbake('core-image-minimal') result = runCmd('oe-pkgdata-util find-path /usr/bin/man', ignore_status=True) @@ -230,7 +231,7 @@ class GrubTests(oeSelfTest): value = stdout.decode()[:-1] self.assertEqual(value, machine, 'MACHINE does not match hostname: ' + machine + ', ' + value + - '\nIs TianoCore ovmf installed?') + '\nIs TianoCore ovmf installed on your host machine?') print(value) print('Checking output of aktualizr-info:') ran_ok = False @@ -246,8 +247,8 @@ class GrubTests(oeSelfTest): class HsmTests(oeSelfTest): def setUpLocal(self): - self.write_config('SOTA_CLIENT_PROV = "aktualizr-hsm-prov"') - self.write_config('SOTA_CLIENT_FEATURES = "hsm"') + self.append_config('SOTA_CLIENT_PROV = "aktualizr-hsm-prov"') + self.append_config('SOTA_CLIENT_FEATURES = "hsm"') self.qemu, self.s = qemu_launch(machine='qemux86-64') def tearDownLocal(self): @@ -349,7 +350,7 @@ class HsmTests(oeSelfTest): for delay in [5, 5, 5, 5, 10]: sleep(delay) stdout, stderr, retcode = self.qemu_command('aktualizr-info') - if retcode == 0 and stderr == b'' and stdout.decode().find('Provisioned on server: yes') >= 0: + if retcode == 0 and stderr == b'' and stdout.decode().find('Fetched metadata: yes') >= 0: ran_ok = True break self.assertIn(b'Device ID: ', stdout, 'Provisioning failed: ' + stderr.decode() + stdout.decode()) -- cgit v1.2.3-54-g00ecf From b9922d6eeda2f0fffadb660f80f13e4ae92ae1cd Mon Sep 17 00:00:00 2001 From: Patrick Vacek Date: Tue, 20 Feb 2018 15:46:54 +0100 Subject: Bump aktualizr to fix a CMAKE_BUILD_TYPE bug. --- recipes-sota/aktualizr/aktualizr_git.bb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/recipes-sota/aktualizr/aktualizr_git.bb b/recipes-sota/aktualizr/aktualizr_git.bb index ab9a8dc..a2a952e 100644 --- a/recipes-sota/aktualizr/aktualizr_git.bb +++ b/recipes-sota/aktualizr/aktualizr_git.bb @@ -20,7 +20,7 @@ SRC_URI = " \ file://aktualizr.service \ file://aktualizr-serialcan.service \ " -SRCREV = "abd0db4e503cbe647fbe3a6e70d28456c2ad7ea4" +SRCREV = "17aeb9dfef7beb02d148b0a72e17ed0d8f3b4042" BRANCH ?= "master" S = "${WORKDIR}/git" -- cgit v1.2.3-54-g00ecf From fc84de73eb3f04f1e7600a1c86061af7f856e8d4 Mon Sep 17 00:00:00 2001 From: Laurent Bonnans Date: Tue, 20 Feb 2018 17:43:52 +0100 Subject: Refactor oe selftests Factorize the call of aktualizr-native commands in each testing class --- lib/oeqa/selftest/updater.py | 121 +++++++++++++++++++++++++------------------ 1 file 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): @classmethod def setUpClass(cls): logger = logging.getLogger("selftest") + bb_vars = get_bb_vars(['SYSROOT_DESTDIR', 'base_prefix', 'libdir', 'bindir'], + 'aktualizr-native') + cls.sysroot = bb_vars['SYSROOT_DESTDIR'] + bb_vars['base_prefix'] + cls.sysrootbin = bb_vars['SYSROOT_DESTDIR'] + bb_vars['bindir'] + cls.libdir = bb_vars['libdir'] + logger.info('Running bitbake to build aktualizr-native tools') bitbake('aktualizr-native') - def test_push_help(self): - bb_vars = get_bb_vars(['SYSROOT_DESTDIR', 'bindir', 'libdir'], 'aktualizr-native') - l = bb_vars['libdir'] - p = bb_vars['SYSROOT_DESTDIR'] + bb_vars['bindir'] + "/garage-push" - self.assertTrue(os.path.isfile(p), msg = "No garage-push found (%s)" % p) - result = runCmd('LD_LIBRARY_PATH=%s %s --help' % (l, p), ignore_status=True) + def runNativeCmd(self, cmd, **kwargs): + program, *_ = cmd.split(' ') + p = '{}/{}'.format(self.sysrootbin, program) + self.assertTrue(os.path.isfile(p), msg="No {} found ({})".format(program, p)) + env = dict(os.environ) + env['LD_LIBRARY_PATH'] = self.libdir + result = runCmd(cmd, env=env, native_sysroot=self.sysroot, ignore_status=True, **kwargs) self.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output) + def test_push_help(self): + self.runNativeCmd('garage-push --help') + def test_deploy_help(self): - bb_vars = get_bb_vars(['SYSROOT_DESTDIR', 'bindir', 'libdir'], 'aktualizr-native') - l = bb_vars['libdir'] - p = bb_vars['SYSROOT_DESTDIR'] + bb_vars['bindir'] + "/garage-deploy" - self.assertTrue(os.path.isfile(p), msg = "No garage-deploy found (%s)" % p) - result = runCmd('LD_LIBRARY_PATH=%s %s --help' % (l, p), ignore_status=True) - self.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output) + self.runNativeCmd('garage-deploy --help') def test_garagesign_help(self): - bb_vars = get_bb_vars(['SYSROOT_DESTDIR', 'bindir', 'libdir'], 'aktualizr-native') - l = bb_vars['libdir'] - p = bb_vars['SYSROOT_DESTDIR'] + bb_vars['bindir'] + "/garage-sign" - self.assertTrue(os.path.isfile(p), msg = "No garage-sign found (%s)" % p) - result = runCmd('LD_LIBRARY_PATH=%s %s --help' % (l, p), ignore_status=True) - self.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output) + self.runNativeCmd('garage-sign --help') class GeneralTests(oeSelfTest): @@ -113,24 +113,29 @@ class AktualizrToolsTests(oeSelfTest): @classmethod def setUpClass(cls): logger = logging.getLogger("selftest") + bb_vars = get_bb_vars(['SYSROOT_DESTDIR', 'base_prefix', 'libdir', 'bindir'], + 'aktualizr-native') + cls.sysroot = bb_vars['SYSROOT_DESTDIR'] + bb_vars['base_prefix'] + cls.sysrootbin = bb_vars['SYSROOT_DESTDIR'] + bb_vars['bindir'] + cls.libdir = bb_vars['libdir'] + logger.info('Running bitbake to build aktualizr-native tools') bitbake('aktualizr-native') - def test_implicit_writer_help(self): - bb_vars = get_bb_vars(['SYSROOT_DESTDIR', 'bindir', 'libdir'], 'aktualizr-native') - l = bb_vars['libdir'] - p = bb_vars['SYSROOT_DESTDIR'] + bb_vars['bindir'] + "/aktualizr_implicit_writer" - self.assertTrue(os.path.isfile(p), msg = "No aktualizr_implicit_writer found (%s)" % p) - result = runCmd('LD_LIBRARY_PATH=%s %s --help' % (l, p), ignore_status=True) + def runNativeCmd(self, cmd, **kwargs): + program, *_ = cmd.split(' ') + p = '{}/{}'.format(self.sysrootbin, program) + self.assertTrue(os.path.isfile(p), msg="No {} found ({})".format(program, p)) + env = dict(os.environ) + env['LD_LIBRARY_PATH'] = self.libdir + result = runCmd(cmd, env=env, native_sysroot=self.sysroot, ignore_status=True, **kwargs) self.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output) + def test_implicit_writer_help(self): + self.runNativeCmd('aktualizr_implicit_writer --help') + def test_cert_provider_help(self): - bb_vars = get_bb_vars(['SYSROOT_DESTDIR', 'bindir', 'libdir'], 'aktualizr-native') - l = bb_vars['libdir'] - p = bb_vars['SYSROOT_DESTDIR'] + bb_vars['bindir'] + "/aktualizr_cert_provider" - self.assertTrue(os.path.isfile(p), msg = "No aktualizr_cert_provider found (%s)" % p) - result = runCmd('LD_LIBRARY_PATH=%s %s --help' % (l, p), ignore_status=True) - self.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output) + self.runNativeCmd('aktualizr_cert_provider --help') def test_cert_provider_local_output(self): logger = logging.getLogger("selftest") @@ -138,17 +143,14 @@ class AktualizrToolsTests(oeSelfTest): bitbake('aktualizr-implicit-prov') bb_vars = get_bb_vars(['SYSROOT_DESTDIR', 'bindir', 'libdir', 'SOTA_PACKED_CREDENTIALS', 'T'], 'aktualizr-native') - l = bb_vars['libdir'] - p = bb_vars['SYSROOT_DESTDIR'] + bb_vars['bindir'] + "/aktualizr_cert_provider" creds = bb_vars['SOTA_PACKED_CREDENTIALS'] temp_dir = bb_vars['T'] bb_vars_prov = get_bb_vars(['STAGING_DIR_NATIVE', 'libdir'], 'aktualizr-implicit-prov') config = bb_vars_prov['STAGING_DIR_NATIVE'] + bb_vars_prov['libdir'] + '/sota/sota_implicit_prov.toml' - self.assertTrue(os.path.isfile(p), msg = "No aktualizr_cert_provider found (%s)" % p) - command = 'LD_LIBRARY_PATH=' + l + ' ' + p + ' -c ' + creds + ' -r -l ' + temp_dir + ' -g ' + config - # logger.info('Checking output of: ' + command) - result = runCmd(command, ignore_status=True) - self.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output) + + self.runNativeCmd('aktualizr_cert_provider -c {creds} -r -l {temp} -g {config}' + .format(creds=creds, temp=temp_dir, config=config)) + # Might be nice if these names weren't hardcoded. cert_path = temp_dir + '/client.pem' self.assertTrue(os.path.isfile(cert_path), "Client certificate not found at %s." % cert_path) @@ -178,7 +180,7 @@ class QemuTests(oeSelfTest): print('Checking machine name (hostname) of device:') stdout, stderr, retcode = self.qemu_command('hostname') self.assertEqual(retcode, 0, "Unable to check hostname. " + - "Is an ssh daemon (such as dropbear or openssh) installed on the device?") + "Is an ssh daemon (such as dropbear or openssh) installed on the device?") machine = get_bb_var('MACHINE', 'core-image-minimal') self.assertEqual(stderr, b'', 'Error: ' + stderr.decode()) # Strip off line ending. @@ -224,7 +226,7 @@ class GrubTests(oeSelfTest): print('Checking machine name (hostname) of device:') stdout, stderr, retcode = self.qemu_command('hostname') self.assertEqual(retcode, 0, "Unable to check hostname. " + - "Is an ssh daemon (such as dropbear or openssh) installed on the device?") + "Is an ssh daemon (such as dropbear or openssh) installed on the device?") machine = get_bb_var('MACHINE', 'core-image-minimal') self.assertEqual(stderr, b'', 'Error: ' + stderr.decode()) # Strip off line ending. @@ -246,6 +248,18 @@ class GrubTests(oeSelfTest): class HsmTests(oeSelfTest): + @classmethod + def setUpClass(cls): + logger = logging.getLogger("selftest") + bb_vars = get_bb_vars(['SYSROOT_DESTDIR', 'base_prefix', 'libdir', 'bindir'], + 'aktualizr-native') + cls.sysroot = bb_vars['SYSROOT_DESTDIR'] + bb_vars['base_prefix'] + cls.sysrootbin = bb_vars['SYSROOT_DESTDIR'] + bb_vars['bindir'] + cls.libdir = bb_vars['libdir'] + + logger.info('Running bitbake to build aktualizr-native tools') + bitbake('aktualizr-native') + def setUpLocal(self): self.append_config('SOTA_CLIENT_PROV = "aktualizr-hsm-prov"') self.append_config('SOTA_CLIENT_FEATURES = "hsm"') @@ -254,6 +268,15 @@ class HsmTests(oeSelfTest): def tearDownLocal(self): qemu_terminate(self.s) + def runNativeCmd(self, cmd, **kwargs): + program, *_ = cmd.split(' ') + p = '{}/{}'.format(self.sysrootbin, program) + self.assertTrue(os.path.isfile(p), msg="No {} found ({})".format(program, p)) + env = dict(os.environ) + env['LD_LIBRARY_PATH'] = self.libdir + result = runCmd(cmd, env=env, native_sysroot=self.sysroot, ignore_status=True, **kwargs) + self.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output) + def qemu_command(self, command): return qemu_send_command(self.qemu.ssh_port, command) @@ -261,7 +284,7 @@ class HsmTests(oeSelfTest): print('Checking machine name (hostname) of device:') stdout, stderr, retcode = self.qemu_command('hostname') self.assertEqual(retcode, 0, "Unable to check hostname. " + - "Is an ssh daemon (such as dropbear or openssh) installed on the device?") + "Is an ssh daemon (such as dropbear or openssh) installed on the device?") machine = get_bb_var('MACHINE', 'core-image-minimal') self.assertEqual(stderr, b'', 'Error: ' + stderr.decode()) # Strip off line ending. @@ -291,7 +314,7 @@ class HsmTests(oeSelfTest): pkcs11_command = 'pkcs11-tool --module=/usr/lib/softhsm/libsofthsm2.so -O' stdout, stderr, retcode = self.qemu_command(pkcs11_command) self.assertNotEqual(retcode, 0, 'pkcs11-tool succeeded before initialization: ' + - stdout.decode() + stderr.decode()) + stdout.decode() + stderr.decode()) softhsm2_command = 'softhsm2-util --show-slots' stdout, stderr, retcode = self.qemu_command(softhsm2_command) self.assertNotEqual(retcode, 0, 'softhsm2-tool succeeded before initialization: ' + @@ -300,18 +323,12 @@ class HsmTests(oeSelfTest): # Run cert_provider. bb_vars = get_bb_vars(['SYSROOT_DESTDIR', 'bindir', 'libdir', 'SOTA_PACKED_CREDENTIALS'], 'aktualizr-native') - l = bb_vars['libdir'] - p = bb_vars['SYSROOT_DESTDIR'] + bb_vars['bindir'] + "/aktualizr_cert_provider" creds = bb_vars['SOTA_PACKED_CREDENTIALS'] bb_vars_prov = get_bb_vars(['STAGING_DIR_NATIVE', 'libdir'], 'aktualizr-hsm-prov') config = bb_vars_prov['STAGING_DIR_NATIVE'] + bb_vars_prov['libdir'] + '/sota/sota_implicit_prov.toml' - self.assertTrue(os.path.isfile(p), msg = "No aktualizr_cert_provider found (%s)" % p) - command = ('LD_LIBRARY_PATH=' + l + ' ' + p + ' -c ' + creds + ' -t root@localhost -p ' + - str(self.qemu.ssh_port) + ' -r -s -g ' + config) - logger = logging.getLogger("selftest") - # logger.info('Checking output of: ' + command) - result = runCmd(command, ignore_status=True) - self.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output) + + self.runNativeCmd('aktualizr_cert_provider -c {creds} -t root@localhost -p {port} -r -s -g {config}' + .format(creds=creds, port=self.qemu.ssh_port, config=config)) # Verify that HSM is able to initialize. ran_ok = False @@ -361,7 +378,7 @@ class HsmTests(oeSelfTest): m = p.search(stdout.decode()) self.assertTrue(m, 'Device ID could not be read: ' + stderr.decode() + stdout.decode()) self.assertGreater(m.lastindex, 0, 'Device ID could not be read: ' + stderr.decode() + stdout.decode()) - logger.info('Device successfully provisioned with ID: ' + m.group(1)) + self.logger.info('Device successfully provisioned with ID: ' + m.group(1)) def qemu_launch(efi=False, machine=None): @@ -391,12 +408,14 @@ def qemu_launch(efi=False, machine=None): sleep(10) return qemu, s + def qemu_terminate(s): try: s.terminate() except KeyboardInterrupt: pass + def qemu_send_command(port, command): command = ['ssh -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@localhost -p ' + str(port) + ' "' + command + '"'] -- cgit v1.2.3-54-g00ecf From 2023bfbbe31d5bb2df6da2af66ff828b2321b1e4 Mon Sep 17 00:00:00 2001 From: Patrick Vacek Date: Wed, 21 Feb 2018 08:56:38 +0100 Subject: Fix minor logging issue. No need for the extra bitbake of aktualizr-native. --- lib/oeqa/selftest/updater.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/oeqa/selftest/updater.py b/lib/oeqa/selftest/updater.py index 8563e3b..1efbba9 100644 --- a/lib/oeqa/selftest/updater.py +++ b/lib/oeqa/selftest/updater.py @@ -250,16 +250,12 @@ class HsmTests(oeSelfTest): @classmethod def setUpClass(cls): - logger = logging.getLogger("selftest") bb_vars = get_bb_vars(['SYSROOT_DESTDIR', 'base_prefix', 'libdir', 'bindir'], 'aktualizr-native') cls.sysroot = bb_vars['SYSROOT_DESTDIR'] + bb_vars['base_prefix'] cls.sysrootbin = bb_vars['SYSROOT_DESTDIR'] + bb_vars['bindir'] cls.libdir = bb_vars['libdir'] - logger.info('Running bitbake to build aktualizr-native tools') - bitbake('aktualizr-native') - def setUpLocal(self): self.append_config('SOTA_CLIENT_PROV = "aktualizr-hsm-prov"') self.append_config('SOTA_CLIENT_FEATURES = "hsm"') @@ -378,7 +374,8 @@ class HsmTests(oeSelfTest): m = p.search(stdout.decode()) self.assertTrue(m, 'Device ID could not be read: ' + stderr.decode() + stdout.decode()) self.assertGreater(m.lastindex, 0, 'Device ID could not be read: ' + stderr.decode() + stdout.decode()) - self.logger.info('Device successfully provisioned with ID: ' + m.group(1)) + logger = logging.getLogger("selftest") + logger.info('Device successfully provisioned with ID: ' + m.group(1)) def qemu_launch(efi=False, machine=None): -- cgit v1.2.3-54-g00ecf