From 8da7de18c9b5a84bd594220121d9ab324427d057 Mon Sep 17 00:00:00 2001 From: Patrick Vacek Date: Fri, 17 Nov 2017 12:11:38 +0100 Subject: Refactor Qemu interaction into seperate functions. This should make it easy to make new test classes that launch independent qemu instances with different configurations. --- lib/oeqa/selftest/updater.py | 81 ++++++++++++++++++++++++-------------------- 1 file changed, 44 insertions(+), 37 deletions(-) (limited to 'lib') diff --git a/lib/oeqa/selftest/updater.py b/lib/oeqa/selftest/updater.py index ad99964..408f2c3 100644 --- a/lib/oeqa/selftest/updater.py +++ b/lib/oeqa/selftest/updater.py @@ -118,49 +118,16 @@ class QemuTests(oeSelfTest): @classmethod def setUpClass(cls): - logger = logging.getLogger("selftest") - logger.info('Running bitbake to build core-image-minimal') - bitbake('core-image-minimal') - # Create empty object. - args = type('', (), {})() - args.imagename = 'core-image-minimal' - args.mac = None - # Could use DEPLOY_DIR_IMAGE here but it's already in the machine - # subdirectory. - args.dir = 'tmp/deploy/images' - args.efi = False - args.machine = None - args.kvm = None # Autodetect - args.no_gui = True - args.gdb = False - args.pcap = None - args.overlay = None - args.dry_run = False - - cls.qemu = QemuCommand(args) - cmdline = cls.qemu.command_line() - print('Booting image with run-qemu-ota...') - cls.s = subprocess.Popen(cmdline) - time.sleep(10) + cls.qemu, cls.s = qemu_launch() @classmethod def tearDownClass(cls): - try: - cls.s.terminate() - except KeyboardInterrupt: - pass - - def run_test_qemu(self, command): - command = ['ssh -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@localhost -p ' + - str(self.qemu.ssh_port) + ' "' + command + '"'] - s2 = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - value, err = s2.communicate() - return value, err + qemu_terminate(cls.s) def test_hostname(self): print('') print('Checking machine name (hostname) of device:') - value, err = self.run_test_qemu('hostname') + value, err = qemu_send_command(self.qemu.ssh_port, 'hostname') machine = get_bb_var('MACHINE', 'core-image-minimal') self.assertEqual(err, b'', 'Error: ' + err.decode()) # Strip off line ending. @@ -172,8 +139,48 @@ class QemuTests(oeSelfTest): def test_var_sota(self): print('') print('Checking contents of /var/sota:') - value, err = self.run_test_qemu('ls /var/sota') + value, err = qemu_send_command(self.qemu.ssh_port, 'ls /var/sota') self.assertEqual(err, b'', 'Error: ' + err.decode()) print(value.decode()) +def qemu_launch(): + logger = logging.getLogger("selftest") + logger.info('Running bitbake to build core-image-minimal') + bitbake('core-image-minimal') + # Create empty object. + args = type('', (), {})() + args.imagename = 'core-image-minimal' + args.mac = None + # Could use DEPLOY_DIR_IMAGE here but it's already in the machine + # subdirectory. + args.dir = 'tmp/deploy/images' + args.efi = False + args.machine = None + args.kvm = None # Autodetect + args.no_gui = True + args.gdb = False + args.pcap = None + args.overlay = None + args.dry_run = False + + qemu = QemuCommand(args) + cmdline = qemu.command_line() + print('Booting image with run-qemu-ota...') + s = subprocess.Popen(cmdline) + time.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 + '"'] + s2 = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + value, err = s2.communicate() + return value, err + -- cgit v1.2.3-54-g00ecf From 495a4a4ec6d540e1045852bc92ef46aa6a6bd9d9 Mon Sep 17 00:00:00 2001 From: Patrick Vacek Date: Fri, 17 Nov 2017 14:11:10 +0100 Subject: Test booting with grub. --- lib/oeqa/selftest/updater.py | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/oeqa/selftest/updater.py b/lib/oeqa/selftest/updater.py index 408f2c3..e3d4fc3 100644 --- a/lib/oeqa/selftest/updater.py +++ b/lib/oeqa/selftest/updater.py @@ -118,7 +118,7 @@ class QemuTests(oeSelfTest): @classmethod def setUpClass(cls): - cls.qemu, cls.s = qemu_launch() + cls.qemu, cls.s = qemu_launch(machine='qemux86-64') @classmethod def tearDownClass(cls): @@ -143,8 +143,39 @@ class QemuTests(oeSelfTest): self.assertEqual(err, b'', 'Error: ' + err.decode()) print(value.decode()) +class GrubTests(oeSelfTest): + + def setUpLocal(self): + # This is a bit of a hack but I can't see a better option. + path = os.path.abspath(os.path.dirname(__file__)) + metadir = path + "/../../../../" + grub_config = 'OSTREE_BOOTLOADER = "grub"\nMACHINE = "intel-corei7-64"' + self.append_config(grub_config) + self.meta_intel = metadir + "meta-intel" + self.meta_minnow = metadir + "meta-updater-minnowboard" + runCmd('bitbake-layers add-layer "%s"' % self.meta_intel) + runCmd('bitbake-layers add-layer "%s"' % self.meta_minnow) + self.qemu, self.s = qemu_launch(efi=True, machine='intel-corei7-64') + + def tearDownLocal(self): + qemu_terminate(self.s) + 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 test_grub(self): + print('') + print('Checking machine name (hostname) of device:') + value, err = qemu_send_command(self.qemu.ssh_port, 'hostname') + machine = get_bb_var('MACHINE', 'core-image-minimal') + self.assertEqual(err, b'', 'Error: ' + err.decode()) + # Strip off line ending. + value_str = value.decode()[:-1] + self.assertEqual(value_str, machine, + 'MACHINE does not match hostname: ' + machine + ', ' + value_str) + print(value_str) + -def qemu_launch(): +def qemu_launch(efi=False, machine=None): logger = logging.getLogger("selftest") logger.info('Running bitbake to build core-image-minimal') bitbake('core-image-minimal') @@ -155,8 +186,8 @@ def qemu_launch(): # Could use DEPLOY_DIR_IMAGE here but it's already in the machine # subdirectory. args.dir = 'tmp/deploy/images' - args.efi = False - args.machine = None + args.efi = efi + args.machine = machine args.kvm = None # Autodetect args.no_gui = True args.gdb = False -- cgit v1.2.3-54-g00ecf From c99f5e78eaddc41904ebd6e2b15214b4fd4e5a91 Mon Sep 17 00:00:00 2001 From: Patrick Vacek Date: Wed, 6 Dec 2017 09:20:27 +0100 Subject: Minor fixes and cleanup. * hsm-test is no longer used. * Use Yocto variables where suitable. * Eliminate redundant directory slashes. --- lib/oeqa/selftest/updater.py | 2 +- recipes-sota/aktualizr/aktualizr-auto-prov.bb | 8 ++++---- recipes-sota/aktualizr/aktualizr-hsm-test-prov.bb | 6 +++--- recipes-sota/aktualizr/aktualizr-implicit-prov.bb | 6 +++--- recipes-sota/garage-sign/garage-sign.bb | 7 +++---- recipes-support/ca-certificates/ca-certificates_%.bbappend | 2 +- 6 files changed, 15 insertions(+), 16 deletions(-) (limited to 'lib') diff --git a/lib/oeqa/selftest/updater.py b/lib/oeqa/selftest/updater.py index e3d4fc3..c07b154 100644 --- a/lib/oeqa/selftest/updater.py +++ b/lib/oeqa/selftest/updater.py @@ -51,7 +51,7 @@ class GarageSignTests(oeSelfTest): class HsmTests(oeSelfTest): def test_hsm(self): - self.write_config('SOTA_CLIENT_FEATURES="hsm hsm-test"') + self.write_config('SOTA_CLIENT_FEATURES="hsm"') bitbake('core-image-minimal') diff --git a/recipes-sota/aktualizr/aktualizr-auto-prov.bb b/recipes-sota/aktualizr/aktualizr-auto-prov.bb index cee5039..f05bf75 100644 --- a/recipes-sota/aktualizr/aktualizr-auto-prov.bb +++ b/recipes-sota/aktualizr/aktualizr-auto-prov.bb @@ -43,13 +43,13 @@ do_install() { # deploy SOTA credentials if [ -e ${SOTA_PACKED_CREDENTIALS} ]; then - cp ${SOTA_PACKED_CREDENTIALS} ${D}/var/sota/sota_provisioning_credentials.zip + cp ${SOTA_PACKED_CREDENTIALS} ${D}${localstatedir}/sota/sota_provisioning_credentials.zip # Device should not be able to push data to treehub - zip -d ${D}/var/sota/sota_provisioning_credentials.zip treehub.json + zip -d ${D}${localstatedir}/sota/sota_provisioning_credentials.zip treehub.json fi fi - install -d ${D}/${systemd_unitdir}/system - install -m 0644 ${WORKDIR}/aktualizr.service ${D}/${systemd_unitdir}/system/aktualizr.service + install -d ${D}${systemd_unitdir}/system + install -m 0644 ${WORKDIR}/aktualizr.service ${D}${systemd_unitdir}/system/aktualizr.service } FILES_${PN} = " \ diff --git a/recipes-sota/aktualizr/aktualizr-hsm-test-prov.bb b/recipes-sota/aktualizr/aktualizr-hsm-test-prov.bb index ddc8dbf..e0a8efe 100644 --- a/recipes-sota/aktualizr/aktualizr-hsm-test-prov.bb +++ b/recipes-sota/aktualizr/aktualizr-hsm-test-prov.bb @@ -22,11 +22,11 @@ inherit systemd require environment.inc do_install() { - install -d ${D}/${systemd_unitdir}/system - install -m 0644 ${WORKDIR}/aktualizr.service ${D}/${systemd_unitdir}/system/aktualizr.service + install -d ${D}${systemd_unitdir}/system + install -m 0644 ${WORKDIR}/aktualizr.service ${D}${systemd_unitdir}/system/aktualizr.service install -d ${D}${libdir}/sota aktualizr_implicit_writer -c ${SOTA_PACKED_CREDENTIALS} --no-root-ca \ - -i ${STAGING_DIR_NATIVE}/${libdir}/sota/sota_hsm_test.toml -o ${D}${libdir}/sota/sota.toml -p ${D} + -i ${STAGING_DIR_NATIVE}${libdir}/sota/sota_hsm_test.toml -o ${D}${libdir}/sota/sota.toml -p ${D} } FILES_${PN} = " \ diff --git a/recipes-sota/aktualizr/aktualizr-implicit-prov.bb b/recipes-sota/aktualizr/aktualizr-implicit-prov.bb index 37d0e91..5ce55e0 100644 --- a/recipes-sota/aktualizr/aktualizr-implicit-prov.bb +++ b/recipes-sota/aktualizr/aktualizr-implicit-prov.bb @@ -21,11 +21,11 @@ inherit systemd require environment.inc do_install() { - install -d ${D}/${systemd_unitdir}/system - install -m 0644 ${WORKDIR}/aktualizr.service ${D}/${systemd_unitdir}/system/aktualizr.service + install -d ${D}${systemd_unitdir}/system + install -m 0644 ${WORKDIR}/aktualizr.service ${D}${systemd_unitdir}/system/aktualizr.service install -d ${D}${libdir}/sota aktualizr_implicit_writer -c ${SOTA_PACKED_CREDENTIALS} \ - -i ${STAGING_DIR_NATIVE}/${libdir}/sota/sota_implicit_prov.toml -o ${D}${libdir}/sota/sota.toml -p ${D} + -i ${STAGING_DIR_NATIVE}${libdir}/sota/sota_implicit_prov.toml -o ${D}${libdir}/sota/sota.toml -p ${D} } FILES_${PN} = " \ diff --git a/recipes-sota/garage-sign/garage-sign.bb b/recipes-sota/garage-sign/garage-sign.bb index 61c4b5a..7057a57 100644 --- a/recipes-sota/garage-sign/garage-sign.bb +++ b/recipes-sota/garage-sign/garage-sign.bb @@ -27,8 +27,7 @@ do_install() { } FILES_${PN} = " \ - /usr/bin \ - /usr/bin/garage-sign.bat \ - /usr/bin/garage-sign \ - /usr/lib/* \ + ${bindir}/garage-sign.bat \ + ${bindir}/garage-sign \ + ${libdir}/* \ " diff --git a/recipes-support/ca-certificates/ca-certificates_%.bbappend b/recipes-support/ca-certificates/ca-certificates_%.bbappend index afaadfd..cc95a68 100644 --- a/recipes-support/ca-certificates/ca-certificates_%.bbappend +++ b/recipes-support/ca-certificates/ca-certificates_%.bbappend @@ -1 +1 @@ -SYSROOT_DIRS += "/etc" +SYSROOT_DIRS += "${sysconfdir}" -- cgit v1.2.3-54-g00ecf From 6630a83d1292bb96a531208b7c52aa1744c54f79 Mon Sep 17 00:00:00 2001 From: Anton Gerasimov Date: Wed, 13 Dec 2017 15:30:03 +0100 Subject: Fixes for Spekulatius - New garage-sign interface - Remove garage-sign recipe (now installed with aktualizr-native) - Small but critical bugfixes in aktualizr --- classes/image_repo_manifest.bbclass | 4 +-- classes/image_types_ostree.bbclass | 13 ++++----- classes/sota.bbclass | 4 +-- lib/oeqa/selftest/updater.py | 14 ++-------- recipes-sota/aktualizr/aktualizr-implicit-prov.bb | 2 +- recipes-sota/aktualizr/aktualizr_git.bb | 2 +- recipes-sota/garage-sign/garage-sign.bb | 33 ----------------------- 7 files changed, 13 insertions(+), 59 deletions(-) delete mode 100644 recipes-sota/garage-sign/garage-sign.bb (limited to 'lib') diff --git a/classes/image_repo_manifest.bbclass b/classes/image_repo_manifest.bbclass index 2012363..467fd9a 100644 --- a/classes/image_repo_manifest.bbclass +++ b/classes/image_repo_manifest.bbclass @@ -14,9 +14,9 @@ HOSTTOOLS_NONFATAL += " repo " # Write build information to target filesystem buildinfo () { if [ $(which repo) ]; then - repo manifest --revision-as-HEAD -o ${IMAGE_ROOTFS}${sysconfdir}/manifest.xml || echo "Android repo tool failed to run; manifest not copied" + repo manifest --revision-as-HEAD -o ${IMAGE_ROOTFS}${sysconfdir}/manifest.xml || bbwarn "Android repo tool failed to run; manifest not copied" else - echo "Android repo tool not found; manifest not copied." + bbwarn "Android repo tool not found; manifest not copied." fi } diff --git a/classes/image_types_ostree.bbclass b/classes/image_types_ostree.bbclass index 56a9720..05db62a 100644 --- a/classes/image_types_ostree.bbclass +++ b/classes/image_types_ostree.bbclass @@ -179,7 +179,7 @@ IMAGE_CMD_ostreepush () { } IMAGE_TYPEDEP_garagesign = "ostreepush" -IMAGE_DEPENDS_garagesign = "garage-sign-native:do_populate_sysroot" +IMAGE_DEPENDS_garagesign = "aktualizr-native:do_populate_sysroot" IMAGE_CMD_garagesign () { if [ -n "${SOTA_PACKED_CREDENTIALS}" ]; then # if credentials are issued by a server that doesn't support offline signing, exit silently @@ -194,11 +194,8 @@ IMAGE_CMD_garagesign () { exit 1 fi - if [ ! -d "${GARAGE_SIGN_REPO}" ]; then - garage-sign init --repo ${GARAGE_SIGN_REPO} --home-dir ${GARAGE_SIGN_REPO} --credentials ${SOTA_PACKED_CREDENTIALS} - fi - - reposerver_args="--reposerver $( unzip -p ${SOTA_PACKED_CREDENTIALS} tufrepo.url )" + rm -rf ${GARAGE_SIGN_REPO} + garage-sign init --repo ${GARAGE_SIGN_REPO} --home-dir ${GARAGE_SIGN_REPO} --credentials ${SOTA_PACKED_CREDENTIALS} ostree_target_hash=$(cat ${OSTREE_REPO}/refs/heads/${OSTREE_BRANCHNAME}) @@ -206,11 +203,11 @@ IMAGE_CMD_garagesign () { # in which case targets.json should be pulled again and the whole procedure repeated push_success=0 for push_retries in $( seq 3 ); do - garage-sign targets pull --repo ${GARAGE_SIGN_REPO} --home-dir ${GARAGE_SIGN_REPO} ${reposerver_args} + garage-sign targets pull --repo ${GARAGE_SIGN_REPO} --home-dir ${GARAGE_SIGN_REPO} garage-sign targets add --repo ${GARAGE_SIGN_REPO} --home-dir ${GARAGE_SIGN_REPO} --name ${OSTREE_BRANCHNAME} --format OSTREE --version ${ostree_target_hash} --length 0 --url "https://example.com/" --sha256 ${ostree_target_hash} --hardwareids ${MACHINE} garage-sign targets sign --repo ${GARAGE_SIGN_REPO} --home-dir ${GARAGE_SIGN_REPO} --key-name=targets errcode=0 - garage-sign targets push --repo ${GARAGE_SIGN_REPO} --home-dir ${GARAGE_SIGN_REPO} ${reposerver_args} || errcode=$? + garage-sign targets push --repo ${GARAGE_SIGN_REPO} --home-dir ${GARAGE_SIGN_REPO} || errcode=$? if [ "$errcode" -eq "0" ]; then push_success=1 break diff --git a/classes/sota.bbclass b/classes/sota.bbclass index 0f42332..bbb9ac9 100644 --- a/classes/sota.bbclass +++ b/classes/sota.bbclass @@ -13,8 +13,8 @@ IMAGE_INSTALL_append_sota = " ostree os-release ${SOTA_CLIENT} ${SOTA_CLIENT_PRO IMAGE_CLASSES += " image_types_ostree image_types_ota" IMAGE_FSTYPES += "${@bb.utils.contains('DISTRO_FEATURES', 'sota', 'ostreepush garagesign garagecheck otaimg wic', ' ', d)}" -PACKAGECONFIG_append_pn-curl = "${@bb.utils.contains('SOTA_CLIENT_FEATURES', 'hsm', " ssl", " ", d)}" -PACKAGECONFIG_remove_pn-curl = "${@bb.utils.contains('SOTA_CLIENT_FEATURES', 'hsm', " gnutls", " ", d)}" +PACKAGECONFIG_append_pn-curl = " ssl" +PACKAGECONFIG_remove_pn-curl = "gnutls" WKS_FILE_sota ?= "sdimage-sota.wks" diff --git a/lib/oeqa/selftest/updater.py b/lib/oeqa/selftest/updater.py index c07b154..f28349f 100644 --- a/lib/oeqa/selftest/updater.py +++ b/lib/oeqa/selftest/updater.py @@ -31,23 +31,13 @@ class SotaToolsTests(oeSelfTest): result = runCmd('%s --help' % p, ignore_status=True) self.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output) - -class GarageSignTests(oeSelfTest): - - @classmethod - def setUpClass(cls): - logger = logging.getLogger("selftest") - logger.info('Running bitbake to build garage-sign-native') - bitbake('garage-sign-native') - - def test_help(self): - bb_vars = get_bb_vars(['SYSROOT_DESTDIR', 'bindir'], 'garage-sign-native') + 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" self.assertTrue(os.path.isfile(p), msg = "No garage-sign found (%s)" % p) result = runCmd('%s --help' % 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): diff --git a/recipes-sota/aktualizr/aktualizr-implicit-prov.bb b/recipes-sota/aktualizr/aktualizr-implicit-prov.bb index 67bd2c2..e5d9c9b 100644 --- a/recipes-sota/aktualizr/aktualizr-implicit-prov.bb +++ b/recipes-sota/aktualizr/aktualizr-implicit-prov.bb @@ -27,7 +27,7 @@ do_install() { install -d ${D}${libdir}/sota if [ -n "${SOTA_PACKED_CREDENTIALS}" ]; then aktualizr_implicit_writer -c ${SOTA_PACKED_CREDENTIALS} \ - -i ${STAGING_DIR_NATIVE}${libdir}/sota/sota_implicit_prov.toml -o ${D}${libdir}/sota/sota.toml -p ${D} + -i ${STAGING_DIR_NATIVE}${libdir}/sota/sota_implicit_prov.toml -o ${D}${libdir}/sota/sota.toml -p ${D} --no-root-ca fi } diff --git a/recipes-sota/aktualizr/aktualizr_git.bb b/recipes-sota/aktualizr/aktualizr_git.bb index e4ffc5a..08aa6c2 100644 --- a/recipes-sota/aktualizr/aktualizr_git.bb +++ b/recipes-sota/aktualizr/aktualizr_git.bb @@ -18,7 +18,7 @@ PR = "7" SRC_URI = " \ git://github.com/advancedtelematic/aktualizr;branch=${BRANCH} \ " -SRCREV = "5bf2975aee4af667a1af17381bf68c34a00f03a3" +SRCREV = "eb6c0b43c2b8b32f66f228c1c3f590b5c16ad448" BRANCH ?= "master" S = "${WORKDIR}/git" diff --git a/recipes-sota/garage-sign/garage-sign.bb b/recipes-sota/garage-sign/garage-sign.bb deleted file mode 100644 index 32dda47..0000000 --- a/recipes-sota/garage-sign/garage-sign.bb +++ /dev/null @@ -1,33 +0,0 @@ -SUMMARY = "garage-sign" -DESCRIPTION = "Metadata signing tool for ATS Garage" -HOMEPAGE = "https://ats-tuf-cli-releases.s3-eu-central-1.amazonaws.com/index.html" -SECTION = "base" -LICENSE = "CLOSED" -LIC_FILES_CHKSUM = "file://${S}/docs/LICENSE;md5=3025e77db7bd3f1d616b3ffd11d54c94" -DEPENDS = "" - -PV = "0.2.0-57-g3f86c67" - -SRC_URI = " \ - https://ats-tuf-cli-releases.s3-eu-central-1.amazonaws.com/cli-${PV}.tgz \ - " - -SRC_URI[md5sum] = "5bbe080c0c3a80928b8856d2076dd49a" -SRC_URI[sha256sum] = "f653d24172ed245a6256b2f341a9b77bddf624cd6bbda574c1a85430e3155394" - -S = "${WORKDIR}/${BPN}" - -BBCLASSEXTEND =+ "native" - -do_install() { - install -d ${D}${bindir} - install -m "0755" -t ${D}${bindir} ${S}/bin/* - install -d ${D}${libdir} - install -m "0644" -t ${D}${libdir} ${S}/lib/* -} - -FILES_${PN} = " \ - ${bindir}/garage-sign.bat \ - ${bindir}/garage-sign \ - ${libdir}/* \ - " -- cgit v1.2.3-54-g00ecf