From 95e2f81a149142b67076a3132e1b00d9f64bd031 Mon Sep 17 00:00:00 2001 From: Patrick Vacek Date: Tue, 7 Nov 2017 15:25:21 +0100 Subject: Rename for accuracy. --- lib/oeqa/selftest/garage_push.py | 42 ---------------------------------------- lib/oeqa/selftest/updater.py | 41 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 42 deletions(-) delete mode 100644 lib/oeqa/selftest/garage_push.py create mode 100644 lib/oeqa/selftest/updater.py (limited to 'lib/oeqa/selftest') diff --git a/lib/oeqa/selftest/garage_push.py b/lib/oeqa/selftest/garage_push.py deleted file mode 100644 index 21bd1c1..0000000 --- a/lib/oeqa/selftest/garage_push.py +++ /dev/null @@ -1,42 +0,0 @@ -import unittest -import os -import logging - -from oeqa.selftest.base import oeSelfTest -from oeqa.utils.commands import runCmd, bitbake, get_bb_var - -class GaragePushTests(oeSelfTest): - - @classmethod - def setUpClass(cls): - # Ensure we have the right data in pkgdata - logger = logging.getLogger("selftest") - logger.info('Running bitbake to build aktualizr-native tools') - bitbake('aktualizr-native garage-sign-native') - - def test_help(self): - image_dir = get_bb_var("D", "aktualizr-native") - bin_dir = get_bb_var("bindir", "aktualizr-native") - gp_path = os.path.join(image_dir, bin_dir[1:], 'garage-push') - result = runCmd('%s --help' % gp_path, ignore_status=True) - self.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output) - - def test_java(self): - result = runCmd('which java', ignore_status=True) - self.assertEqual(result.status, 0, "Java not found.") - - def test_sign(self): - image_dir = get_bb_var("D", "garage-sign-native") - bin_dir = get_bb_var("bindir", "garage-sign-native") - gs_path = os.path.join(image_dir, bin_dir[1:], 'garage-sign') - result = runCmd('%s --help' % gs_path, ignore_status=True) - self.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output) - - def test_push(self): - bitbake('core-image-minimal') - self.write_config('IMAGE_INSTALL_append = " man "') - bitbake('core-image-minimal') - - def test_hsm(self): - self.write_config('SOTA_CLIENT_FEATURES="hsm hsm-test"') - bitbake('core-image-minimal') diff --git a/lib/oeqa/selftest/updater.py b/lib/oeqa/selftest/updater.py new file mode 100644 index 0000000..e9048fd --- /dev/null +++ b/lib/oeqa/selftest/updater.py @@ -0,0 +1,41 @@ +import unittest +import os +import logging + +from oeqa.selftest.base import oeSelfTest +from oeqa.utils.commands import runCmd, bitbake, get_bb_var + +class UpdaterTests(oeSelfTest): + + @classmethod + def setUpClass(cls): + logger = logging.getLogger("selftest") + logger.info('Running bitbake to build aktualizr-native tools and garage-sign-native') + bitbake('aktualizr-native garage-sign-native') + + def test_help(self): + image_dir = get_bb_var("D", "aktualizr-native") + bin_dir = get_bb_var("bindir", "aktualizr-native") + gp_path = os.path.join(image_dir, bin_dir[1:], 'garage-push') + result = runCmd('%s --help' % gp_path, ignore_status=True) + self.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output) + + def test_java(self): + result = runCmd('which java', ignore_status=True) + self.assertEqual(result.status, 0, "Java not found.") + + def test_sign(self): + image_dir = get_bb_var("D", "garage-sign-native") + bin_dir = get_bb_var("bindir", "garage-sign-native") + gs_path = os.path.join(image_dir, bin_dir[1:], 'garage-sign') + result = runCmd('%s --help' % gs_path, ignore_status=True) + self.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output) + + def test_push(self): + bitbake('core-image-minimal') + self.write_config('IMAGE_INSTALL_append = " man "') + bitbake('core-image-minimal') + + def test_hsm(self): + self.write_config('SOTA_CLIENT_FEATURES="hsm hsm-test"') + bitbake('core-image-minimal') -- cgit v1.2.3-54-g00ecf From 9d5ad230a7558ae9adea42ea69d633d489c6dec0 Mon Sep 17 00:00:00 2001 From: Patrick Vacek Date: Tue, 7 Nov 2017 17:34:13 +0100 Subject: Rough draft of a run-qemu-ota test. Not very useful yet. Could be made into a function for the purpose of running arbitrary commands via SSH, for example. However, I had plenty of trouble even getting this far. Note that I created a softlink to qemucommand to get around the Python path issues in oe-selftest. I'm not sure if there's a better way to handle that, since manipulating the path is seemingly impossible. --- .gitignore | 1 + lib/oeqa/selftest/qemucommand.py | 1 + lib/oeqa/selftest/updater.py | 33 +++++++++++++++++++++++++++++++++ scripts/qemucommand.py | 4 ++-- 4 files changed, 37 insertions(+), 2 deletions(-) create mode 120000 lib/oeqa/selftest/qemucommand.py (limited to 'lib/oeqa/selftest') diff --git a/.gitignore b/.gitignore index bee8a64..8d35cb3 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ __pycache__ +*.pyc diff --git a/lib/oeqa/selftest/qemucommand.py b/lib/oeqa/selftest/qemucommand.py new file mode 120000 index 0000000..bc06dde --- /dev/null +++ b/lib/oeqa/selftest/qemucommand.py @@ -0,0 +1 @@ +../../../scripts/qemucommand.py \ No newline at end of file diff --git a/lib/oeqa/selftest/updater.py b/lib/oeqa/selftest/updater.py index e9048fd..4cdd1a2 100644 --- a/lib/oeqa/selftest/updater.py +++ b/lib/oeqa/selftest/updater.py @@ -4,6 +4,9 @@ import logging from oeqa.selftest.base import oeSelfTest from oeqa.utils.commands import runCmd, bitbake, get_bb_var +import subprocess +from oeqa.selftest.qemucommand import QemuCommand +import time class UpdaterTests(oeSelfTest): @@ -39,3 +42,33 @@ class UpdaterTests(oeSelfTest): def test_hsm(self): self.write_config('SOTA_CLIENT_FEATURES="hsm hsm-test"') bitbake('core-image-minimal') + + def test_qemu(self): + print('') + # Create empty object. + args = type('', (), {})() + args.imagename = 'core-image-minimal' + args.mac = None + args.dir = 'tmp/deploy/images' + args.efi = False + args.machine = None + args.no_kvm = False + args.no_gui = True + args.gdb = False + args.pcap = None + args.overlay = None + args.dry_run = False + + qemu_command = QemuCommand(args) + cmdline = qemu_command.command_line() + print('Booting image with run-qemu-ota...') + s = subprocess.Popen(cmdline) + time.sleep(10) + print('Machine name (hostname) of device is:') + ssh_cmd = ['ssh', '-q', '-o', 'UserKnownHostsFile=/dev/null', '-o', 'StrictHostKeyChecking=no', 'root@localhost', '-p', str(qemu_command.ssh_port), 'hostname'] + s2 = subprocess.Popen(ssh_cmd) + time.sleep(5) + try: + s.terminate() + except KeyboardInterrupt: + pass diff --git a/scripts/qemucommand.py b/scripts/qemucommand.py index ed14d9b..a75ffb6 100644 --- a/scripts/qemucommand.py +++ b/scripts/qemucommand.py @@ -1,4 +1,4 @@ -from os.path import exists, join, realpath +from os.path import exists, join, realpath, abspath from os import listdir import random import socket @@ -49,7 +49,7 @@ class QemuCommand(object): if args.efi: self.bios = 'OVMF.fd' else: - uboot = join(args.dir, self.machine, 'u-boot-qemux86-64.rom') + uboot = abspath(join(args.dir, self.machine, 'u-boot-qemux86-64.rom')) if not exists(uboot): raise ValueError("U-Boot image %s does not exist" % uboot) self.bios = uboot -- cgit v1.2.3-54-g00ecf From d05ef2141f0f707c75e6cafa8f8c49076c141376 Mon Sep 17 00:00:00 2001 From: Patrick Vacek Date: Mon, 13 Nov 2017 13:39:38 +0100 Subject: Fix paths to be more reliable. --- lib/oeqa/selftest/updater.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'lib/oeqa/selftest') diff --git a/lib/oeqa/selftest/updater.py b/lib/oeqa/selftest/updater.py index 4cdd1a2..e3542be 100644 --- a/lib/oeqa/selftest/updater.py +++ b/lib/oeqa/selftest/updater.py @@ -3,7 +3,7 @@ import os import logging from oeqa.selftest.base import oeSelfTest -from oeqa.utils.commands import runCmd, bitbake, get_bb_var +from oeqa.utils.commands import runCmd, bitbake, get_bb_var, get_bb_vars import subprocess from oeqa.selftest.qemucommand import QemuCommand import time @@ -17,10 +17,10 @@ class UpdaterTests(oeSelfTest): bitbake('aktualizr-native garage-sign-native') def test_help(self): - image_dir = get_bb_var("D", "aktualizr-native") - bin_dir = get_bb_var("bindir", "aktualizr-native") - gp_path = os.path.join(image_dir, bin_dir[1:], 'garage-push') - result = runCmd('%s --help' % gp_path, ignore_status=True) + bb_vars = get_bb_vars(['SYSROOT_DESTDIR', 'bindir'], 'aktualizr-native') + 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) self.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output) def test_java(self): @@ -28,10 +28,10 @@ class UpdaterTests(oeSelfTest): self.assertEqual(result.status, 0, "Java not found.") def test_sign(self): - image_dir = get_bb_var("D", "garage-sign-native") - bin_dir = get_bb_var("bindir", "garage-sign-native") - gs_path = os.path.join(image_dir, bin_dir[1:], 'garage-sign') - result = runCmd('%s --help' % gs_path, ignore_status=True) + bb_vars = get_bb_vars(['SYSROOT_DESTDIR', 'bindir'], 'garage-sign-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) def test_push(self): -- cgit v1.2.3-54-g00ecf From 7e1b40307aa780102796638e06a1284b6e318087 Mon Sep 17 00:00:00 2001 From: Patrick Vacek Date: Mon, 13 Nov 2017 13:57:49 +0100 Subject: Split tests into independent classes. This reduces unnecessary time spent on setUpClass calls that may not be necessary for individual tests. It also organizes things a bit better. --- lib/oeqa/selftest/updater.py | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) (limited to 'lib/oeqa/selftest') diff --git a/lib/oeqa/selftest/updater.py b/lib/oeqa/selftest/updater.py index e3542be..ea57f9d 100644 --- a/lib/oeqa/selftest/updater.py +++ b/lib/oeqa/selftest/updater.py @@ -8,13 +8,13 @@ import subprocess from oeqa.selftest.qemucommand import QemuCommand import time -class UpdaterTests(oeSelfTest): +class SotaToolsTests(oeSelfTest): @classmethod def setUpClass(cls): logger = logging.getLogger("selftest") - logger.info('Running bitbake to build aktualizr-native tools and garage-sign-native') - bitbake('aktualizr-native garage-sign-native') + logger.info('Running bitbake to build aktualizr-native tools') + bitbake('aktualizr-native') def test_help(self): bb_vars = get_bb_vars(['SYSROOT_DESTDIR', 'bindir'], 'aktualizr-native') @@ -23,26 +23,41 @@ class UpdaterTests(oeSelfTest): result = runCmd('%s --help' % p, ignore_status=True) self.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output) - def test_java(self): - result = runCmd('which java', ignore_status=True) - self.assertEqual(result.status, 0, "Java not found.") + def test_push(self): + bitbake('core-image-minimal') + self.write_config('IMAGE_INSTALL_append = " man "') + bitbake('core-image-minimal') + + +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_sign(self): + def test_help(self): bb_vars = get_bb_vars(['SYSROOT_DESTDIR', 'bindir'], 'garage-sign-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) - def test_push(self): - bitbake('core-image-minimal') - self.write_config('IMAGE_INSTALL_append = " man "') - bitbake('core-image-minimal') + +class HsmTests(oeSelfTest): def test_hsm(self): self.write_config('SOTA_CLIENT_FEATURES="hsm hsm-test"') bitbake('core-image-minimal') + +class GeneralTests(oeSelfTest): + + def test_java(self): + result = runCmd('which java', ignore_status=True) + self.assertEqual(result.status, 0, "Java not found.") + def test_qemu(self): print('') # Create empty object. @@ -72,3 +87,4 @@ class UpdaterTests(oeSelfTest): s.terminate() except KeyboardInterrupt: pass + -- cgit v1.2.3-54-g00ecf From 9178f7116aad6722121d3170ed76cf47c4d22cc4 Mon Sep 17 00:00:00 2001 From: Patrick Vacek Date: Mon, 13 Nov 2017 15:12:14 +0100 Subject: Make double-bitbake test actually useful. * Make sure to remove man package before bitbaking. * Test that the package exists or not. * Check the image name and size to make sure it changes. * Move to appropriate class and rename. --- lib/oeqa/selftest/updater.py | 43 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 8 deletions(-) (limited to 'lib/oeqa/selftest') diff --git a/lib/oeqa/selftest/updater.py b/lib/oeqa/selftest/updater.py index ea57f9d..adae081 100644 --- a/lib/oeqa/selftest/updater.py +++ b/lib/oeqa/selftest/updater.py @@ -1,12 +1,15 @@ import unittest import os import logging +import subprocess +import time from oeqa.selftest.base import oeSelfTest from oeqa.utils.commands import runCmd, bitbake, get_bb_var, get_bb_vars -import subprocess from oeqa.selftest.qemucommand import QemuCommand -import time + +DEFAULT_DIR = 'tmp/deploy/images' + class SotaToolsTests(oeSelfTest): @@ -23,11 +26,6 @@ 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) - def test_push(self): - bitbake('core-image-minimal') - self.write_config('IMAGE_INSTALL_append = " man "') - bitbake('core-image-minimal') - class GarageSignTests(oeSelfTest): @@ -58,13 +56,42 @@ class GeneralTests(oeSelfTest): result = runCmd('which java', ignore_status=True) self.assertEqual(result.status, 0, "Java not found.") + def test_add_package(self): + print('') + machine = get_bb_var('MACHINE', 'core-image-minimal') + image_path = DEFAULT_DIR + '/' + machine + '/core-image-minimal-' + machine + '.otaimg' + logger = logging.getLogger("selftest") + + logger.info('Running bitbake with man in the image package list') + self.write_config('IMAGE_INSTALL_append = " man "') + bitbake('-c cleanall man') + bitbake('core-image-minimal') + result = runCmd('oe-pkgdata-util find-path /usr/bin/man') + self.assertEqual(result.output, 'man: /usr/bin/man') + path1 = os.path.realpath(image_path) + size1 = os.path.getsize(path1) + 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 "') + bitbake('-c cleanall man') + bitbake('core-image-minimal') + result = runCmd('oe-pkgdata-util find-path /usr/bin/man', ignore_status=True) + self.assertEqual(result.status, 1, "Status different than 1. output: %s" % result.output) + self.assertEqual(result.output, 'ERROR: Unable to find any package producing path /usr/bin/man') + path2 = os.path.realpath(image_path) + size2 = os.path.getsize(path2) + logger.info('Second image %s has size %i' % (path2, size2)) + self.assertNotEqual(path1, path2, "Image paths are identical; image was not rebuilt.") + self.assertNotEqual(size1, size2, "Image sizes are identical; image was not rebuilt.") + def test_qemu(self): print('') # Create empty object. args = type('', (), {})() args.imagename = 'core-image-minimal' args.mac = None - args.dir = 'tmp/deploy/images' + args.dir = DEFAULT_DIR args.efi = False args.machine = None args.no_kvm = False -- cgit v1.2.3-54-g00ecf From 714f33c1d057db2058aaeadb9dec123199edf41e Mon Sep 17 00:00:00 2001 From: Patrick Vacek Date: Mon, 13 Nov 2017 16:40:43 +0100 Subject: Basic garage-deploy test. --- lib/oeqa/selftest/updater.py | 9 ++++++++- recipes-sota/aktualizr/aktualizr_git.bb | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) (limited to 'lib/oeqa/selftest') diff --git a/lib/oeqa/selftest/updater.py b/lib/oeqa/selftest/updater.py index adae081..13e1c21 100644 --- a/lib/oeqa/selftest/updater.py +++ b/lib/oeqa/selftest/updater.py @@ -19,13 +19,20 @@ class SotaToolsTests(oeSelfTest): logger.info('Running bitbake to build aktualizr-native tools') bitbake('aktualizr-native') - def test_help(self): + 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" self.assertTrue(os.path.isfile(p), msg = "No garage-push 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) + 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" + self.assertTrue(os.path.isfile(p), msg = "No garage-deploy 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 GarageSignTests(oeSelfTest): diff --git a/recipes-sota/aktualizr/aktualizr_git.bb b/recipes-sota/aktualizr/aktualizr_git.bb index c98027d..7af7c60 100644 --- a/recipes-sota/aktualizr/aktualizr_git.bb +++ b/recipes-sota/aktualizr/aktualizr_git.bb @@ -47,5 +47,6 @@ FILES_${PN}_class-target = " \ " FILES_${PN}_class-native = " \ ${bindir}/aktualizr_implicit_writer \ + ${bindir}/garage-deploy \ ${bindir}/garage-push \ " -- cgit v1.2.3-54-g00ecf From 9411b6039661f50832779d021f3d47b2d8516634 Mon Sep 17 00:00:00 2001 From: Patrick Vacek Date: Wed, 15 Nov 2017 15:50:32 +0100 Subject: Fix some paths based on Leon's techniques. --- lib/oeqa/selftest/updater.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'lib/oeqa/selftest') diff --git a/lib/oeqa/selftest/updater.py b/lib/oeqa/selftest/updater.py index 13e1c21..6339e6e 100644 --- a/lib/oeqa/selftest/updater.py +++ b/lib/oeqa/selftest/updater.py @@ -8,8 +8,6 @@ from oeqa.selftest.base import oeSelfTest from oeqa.utils.commands import runCmd, bitbake, get_bb_var, get_bb_vars from oeqa.selftest.qemucommand import QemuCommand -DEFAULT_DIR = 'tmp/deploy/images' - class SotaToolsTests(oeSelfTest): @@ -65,8 +63,9 @@ class GeneralTests(oeSelfTest): def test_add_package(self): print('') - machine = get_bb_var('MACHINE', 'core-image-minimal') - image_path = DEFAULT_DIR + '/' + machine + '/core-image-minimal-' + machine + '.otaimg' + deploydir = get_bb_var('DEPLOY_DIR_IMAGE') + imagename = get_bb_var('IMAGE_LINK_NAME', 'core-image-minimal') + image_path = deploydir + '/' + imagename + '.otaimg' logger = logging.getLogger("selftest") logger.info('Running bitbake with man in the image package list') @@ -98,7 +97,9 @@ class GeneralTests(oeSelfTest): args = type('', (), {})() args.imagename = 'core-image-minimal' args.mac = None - args.dir = DEFAULT_DIR + # Could use DEPLOY_DIR_IMAGE her but it's already in the machine + # subdirectory. + args.dir = 'tmp/deploy/images' args.efi = False args.machine = None args.no_kvm = False -- cgit v1.2.3-54-g00ecf From de48c402e207cde0c723ebb8ff5c2992101cfc27 Mon Sep 17 00:00:00 2001 From: Leon Anavi Date: Mon, 13 Nov 2017 15:48:11 +0200 Subject: garage_push.py: Check distro features Ensure that systemd and sota are among the distro features. Signed-off-by: Leon Anavi --- lib/oeqa/selftest/updater.py | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'lib/oeqa/selftest') diff --git a/lib/oeqa/selftest/updater.py b/lib/oeqa/selftest/updater.py index 6339e6e..9945b40 100644 --- a/lib/oeqa/selftest/updater.py +++ b/lib/oeqa/selftest/updater.py @@ -57,6 +57,14 @@ class HsmTests(oeSelfTest): class GeneralTests(oeSelfTest): + def test_feature_sota(self): + result = get_bb_var('DISTRO_FEATURES').find('sota') + self.assertNotEqual(result, -1, 'Feature "sota" not set at DISTRO_FEATURES'); + + def test_feature_systemd(self): + result = get_bb_var('DISTRO_FEATURES').find('systemd') + self.assertNotEqual(result, -1, 'Feature "systemd" not set at DISTRO_FEATURES'); + def test_java(self): result = runCmd('which java', ignore_status=True) self.assertEqual(result.status, 0, "Java not found.") -- cgit v1.2.3-54-g00ecf From 50d8ea5e540f1d2f423db77e8a93b0f5bcc1d1ca Mon Sep 17 00:00:00 2001 From: Leon Anavi Date: Tue, 14 Nov 2017 19:11:32 +0200 Subject: garage_push.py: Test SOTA_PACKED_CREDENTIALS Add test to verify that the file specified at SOTA_PACKED_CREDENTIALS exists and is included in the image. If SOTA_PACKED_CREDENTIALS is not set this test case will be skipped. Signed-off-by: Leon Anavi --- lib/oeqa/selftest/updater.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'lib/oeqa/selftest') diff --git a/lib/oeqa/selftest/updater.py b/lib/oeqa/selftest/updater.py index 9945b40..b59eefc 100644 --- a/lib/oeqa/selftest/updater.py +++ b/lib/oeqa/selftest/updater.py @@ -65,6 +65,20 @@ class GeneralTests(oeSelfTest): result = get_bb_var('DISTRO_FEATURES').find('systemd') self.assertNotEqual(result, -1, 'Feature "systemd" not set at DISTRO_FEATURES'); + def test_credentials(self): + bitbake('core-image-minimal') + credentials = get_bb_var('SOTA_PACKED_CREDENTIALS') + # skip the test if the variable SOTA_PACKED_CREDENTIALS is not set + if credentials is None: + raise unittest.SkipTest("Variable 'SOTA_PACKED_CREDENTIALS' not set.") + # Check if the file exists + self.assertTrue(os.path.isfile(credentials), "File %s does not exist" % credentials) + deploydir = get_bb_var('DEPLOY_DIR_IMAGE') + imagename = get_bb_var('IMAGE_LINK_NAME', 'core-image-minimal') + # Check if the credentials are included in the output image + result = runCmd('tar -jtvf %s/%s.tar.bz2 | grep sota_provisioning_credentials.zip' % (deploydir, imagename), ignore_status=True) + self.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output) + def test_java(self): result = runCmd('which java', ignore_status=True) self.assertEqual(result.status, 0, "Java not found.") -- cgit v1.2.3-54-g00ecf From 24e5a6d45886365cecce74c2c9aa1cfd8c0da69a Mon Sep 17 00:00:00 2001 From: Phil Wise Date: Thu, 16 Nov 2017 11:01:25 +0100 Subject: Autodetect KVM Autodetect KVM by using the 'kvm-ok' command line tool. This has two benefits: Firstly, it improves the UX of run-qemu-ota when working on machines without KVM (e.g. AWS). Previously, people had to use the --no-kvm option in these cases. Secondary, it makes oe-selftest usable on machines without KVM. Our tests call run-qemu-ota, and we want to able to run them on machines without KVM. --- lib/oeqa/selftest/updater.py | 4 ++-- scripts/qemucommand.py | 11 ++++++++++- scripts/run-qemu-ota | 6 +++++- 3 files changed, 17 insertions(+), 4 deletions(-) (limited to 'lib/oeqa/selftest') diff --git a/lib/oeqa/selftest/updater.py b/lib/oeqa/selftest/updater.py index 6339e6e..eb09302 100644 --- a/lib/oeqa/selftest/updater.py +++ b/lib/oeqa/selftest/updater.py @@ -97,12 +97,12 @@ class GeneralTests(oeSelfTest): args = type('', (), {})() args.imagename = 'core-image-minimal' args.mac = None - # Could use DEPLOY_DIR_IMAGE her but it's already in the machine + # 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.no_kvm = False + args.kvm = None # Autodetect args.no_gui = True args.gdb = False args.pcap = None diff --git a/scripts/qemucommand.py b/scripts/qemucommand.py index a75ffb6..82a9540 100644 --- a/scripts/qemucommand.py +++ b/scripts/qemucommand.py @@ -2,6 +2,7 @@ from os.path import exists, join, realpath, abspath from os import listdir import random import socket +from subprocess import check_output, CalledProcessError EXTENSIONS = { 'intel-corei7-64': 'wic', @@ -67,7 +68,15 @@ class QemuCommand(object): self.mac_address = random_mac() self.serial_port = find_local_port(8990) self.ssh_port = find_local_port(2222) - self.kvm = not args.no_kvm + if args.kvm is None: + # Autodetect KVM using 'kvm-ok' + try: + check_output(['kvm-ok']) + self.kvm = True + except CalledProcessError: + self.kvm = False + else: + self.kvm = args.kvm self.gui = not args.no_gui self.gdb = args.gdb self.pcap = args.pcap diff --git a/scripts/run-qemu-ota b/scripts/run-qemu-ota index 8e25197..56e4fbc 100755 --- a/scripts/run-qemu-ota +++ b/scripts/run-qemu-ota @@ -21,7 +21,11 @@ def main(): 'OSTREE_BOOTLOADER = "grub" and OVMF.fd firmware to be installed (try "apt install ovmf")', action='store_true') parser.add_argument('--machine', default=None, help="Target MACHINE") - parser.add_argument('--no-kvm', help='Disable KVM in QEMU', action='store_true') + kvm_group = parser.add_argument_group() + kvm_group.add_argument('--force-kvm', help='Force use of KVM (default is to autodetect)', + dest='kvm', action='store_true', default=None) + kvm_group.add_argument('--no-kvm', help='Disable KVM in QEMU', + dest='kvm', action='store_false') parser.add_argument('--no-gui', help='Disable GUI', action='store_true') parser.add_argument('--gdb', help='Export gdbserver port 2159 from the image', action='store_true') parser.add_argument('--pcap', default=None, help='Dump all network traffic') -- cgit v1.2.3-54-g00ecf From 7a3258934b2c53f7c29c212c695805da1893ba3f Mon Sep 17 00:00:00 2001 From: Patrick Vacek Date: Thu, 16 Nov 2017 16:04:36 +0100 Subject: Move oe-selftest qemu logic to its own function. This means we can call it from any number of tests and run arbitrary commands. I finally figured out how to get commands with arguments working, too. --- lib/oeqa/selftest/updater.py | 91 +++++++++++++++++++++++++++++--------------- 1 file changed, 60 insertions(+), 31 deletions(-) (limited to 'lib/oeqa/selftest') diff --git a/lib/oeqa/selftest/updater.py b/lib/oeqa/selftest/updater.py index 2723b4a..8ee3c69 100644 --- a/lib/oeqa/selftest/updater.py +++ b/lib/oeqa/selftest/updater.py @@ -113,35 +113,64 @@ class GeneralTests(oeSelfTest): self.assertNotEqual(path1, path2, "Image paths are identical; image was not rebuilt.") self.assertNotEqual(size1, size2, "Image sizes are identical; image was not rebuilt.") - def test_qemu(self): - print('') - # 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_command = QemuCommand(args) - cmdline = qemu_command.command_line() - print('Booting image with run-qemu-ota...') - s = subprocess.Popen(cmdline) - time.sleep(10) - print('Machine name (hostname) of device is:') - ssh_cmd = ['ssh', '-q', '-o', 'UserKnownHostsFile=/dev/null', '-o', 'StrictHostKeyChecking=no', 'root@localhost', '-p', str(qemu_command.ssh_port), 'hostname'] - s2 = subprocess.Popen(ssh_cmd) - time.sleep(5) - try: - s.terminate() - except KeyboardInterrupt: - pass + +class QemuTests(oeSelfTest): + + @classmethod + def setUpClass(cls): + logger = logging.getLogger("selftest") + logger.info('Running bitbake to build core-image-minimal') + bitbake('core-image-minimal') + + def test_hostname(self): + value, err = run_test_qemu('hostname', False, 'Checking machine name (hostname) of device:') + 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('hostname: ' + value_str) + + def test_var_sota(self): + value, err = run_test_qemu('ls /var/sota', True, 'Checking contents of /var/sota:') + self.assertEqual(err, b'', 'Error: ' + err.decode()) + print(value.decode()) + + +def run_test_qemu(command, use_shell, message): + print('') + # 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_command = QemuCommand(args) + cmdline = qemu_command.command_line() + print('Booting image with run-qemu-ota...') + s = subprocess.Popen(cmdline) + time.sleep(10) + print(message) + if not use_shell: + command = ['ssh', '-q', '-o', 'UserKnownHostsFile=/dev/null', '-o', 'StrictHostKeyChecking=no', 'root@localhost', '-p', str(qemu_command.ssh_port), '"' + command + '"'] + else: + command = 'ssh -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@localhost -p ' + str(qemu_command.ssh_port) + ' "' + command + '"' + s2 = subprocess.Popen(command, shell=use_shell, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + value, err = s2.communicate() + time.sleep(5) + try: + s.terminate() + except KeyboardInterrupt: + pass + return value, err -- cgit v1.2.3-54-g00ecf From c687237422dc7f22b85d9718d112fe0b674007c3 Mon Sep 17 00:00:00 2001 From: Patrick Vacek Date: Thu, 16 Nov 2017 16:57:57 +0100 Subject: Make launching qemu part of setUpClass. And terminating part of tearDownClass. This cleans things up nicely and means we only have to boot once for multiple tests. If we do want to boot multiple times (e.g. with different configs), we can move most of the qemu code to non-class functions and use multiple classes that each call those functions in setUpClass and tearDownClass. --- lib/oeqa/selftest/updater.py | 85 +++++++++++++++++++++++--------------------- 1 file changed, 44 insertions(+), 41 deletions(-) (limited to 'lib/oeqa/selftest') diff --git a/lib/oeqa/selftest/updater.py b/lib/oeqa/selftest/updater.py index 8ee3c69..ad99964 100644 --- a/lib/oeqa/selftest/updater.py +++ b/lib/oeqa/selftest/updater.py @@ -121,56 +121,59 @@ class QemuTests(oeSelfTest): 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) + + @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 def test_hostname(self): - value, err = run_test_qemu('hostname', False, 'Checking machine name (hostname) of device:') + print('') + print('Checking machine name (hostname) of device:') + value, err = self.run_test_qemu('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('hostname: ' + value_str) + self.assertEqual(value_str, machine, + 'MACHINE does not match hostname: ' + machine + ', ' + value_str) + print(value_str) def test_var_sota(self): - value, err = run_test_qemu('ls /var/sota', True, 'Checking contents of /var/sota:') + print('') + print('Checking contents of /var/sota:') + value, err = self.run_test_qemu('ls /var/sota') self.assertEqual(err, b'', 'Error: ' + err.decode()) print(value.decode()) -def run_test_qemu(command, use_shell, message): - print('') - # 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_command = QemuCommand(args) - cmdline = qemu_command.command_line() - print('Booting image with run-qemu-ota...') - s = subprocess.Popen(cmdline) - time.sleep(10) - print(message) - if not use_shell: - command = ['ssh', '-q', '-o', 'UserKnownHostsFile=/dev/null', '-o', 'StrictHostKeyChecking=no', 'root@localhost', '-p', str(qemu_command.ssh_port), '"' + command + '"'] - else: - command = 'ssh -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@localhost -p ' + str(qemu_command.ssh_port) + ' "' + command + '"' - s2 = subprocess.Popen(command, shell=use_shell, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - value, err = s2.communicate() - time.sleep(5) - try: - s.terminate() - except KeyboardInterrupt: - pass - return value, err - -- cgit v1.2.3-54-g00ecf 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/oeqa/selftest') 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/oeqa/selftest') 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/oeqa/selftest') 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/oeqa/selftest') 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 From 20b8d55c760ff9021f32a57a12563b01ef039e4e Mon Sep 17 00:00:00 2001 From: Patrick Vacek Date: Thu, 18 Jan 2018 12:33:08 +0100 Subject: oe-selftest fixes for rocko. --- lib/oeqa/selftest/cases/qemucommand.py | 1 + lib/oeqa/selftest/cases/updater.py | 209 +++++++++++++++++++++++++++++++++ lib/oeqa/selftest/qemucommand.py | 1 - lib/oeqa/selftest/updater.py | 207 -------------------------------- 4 files changed, 210 insertions(+), 208 deletions(-) create mode 120000 lib/oeqa/selftest/cases/qemucommand.py create mode 100644 lib/oeqa/selftest/cases/updater.py delete mode 120000 lib/oeqa/selftest/qemucommand.py delete mode 100644 lib/oeqa/selftest/updater.py (limited to 'lib/oeqa/selftest') diff --git a/lib/oeqa/selftest/cases/qemucommand.py b/lib/oeqa/selftest/cases/qemucommand.py new file mode 120000 index 0000000..075cdb8 --- /dev/null +++ b/lib/oeqa/selftest/cases/qemucommand.py @@ -0,0 +1 @@ +../../../../scripts/qemucommand.py \ No newline at end of file diff --git a/lib/oeqa/selftest/cases/updater.py b/lib/oeqa/selftest/cases/updater.py new file mode 100644 index 0000000..7d7bde7 --- /dev/null +++ b/lib/oeqa/selftest/cases/updater.py @@ -0,0 +1,209 @@ +import os +import logging +import subprocess +import time +import unittest + +from oeqa.selftest.case import OESelftestTestCase +from oeqa.utils.commands import runCmd, bitbake, get_bb_var, get_bb_vars +from qemucommand import QemuCommand + + +class SotaToolsTests(OESelftestTestCase): + + @classmethod + def setUpClass(cls): + logger = logging.getLogger("selftest") + 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'], 'aktualizr-native') + 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) + 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" + self.assertTrue(os.path.isfile(p), msg = "No garage-deploy 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) + + 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(OESelftestTestCase): + + def test_hsm(self): + self.write_config('SOTA_CLIENT_FEATURES="hsm"') + bitbake('core-image-minimal') + + +class GeneralTests(OESelftestTestCase): + + def test_feature_sota(self): + result = get_bb_var('DISTRO_FEATURES').find('sota') + self.assertNotEqual(result, -1, 'Feature "sota" not set at DISTRO_FEATURES'); + + def test_feature_systemd(self): + result = get_bb_var('DISTRO_FEATURES').find('systemd') + self.assertNotEqual(result, -1, 'Feature "systemd" not set at DISTRO_FEATURES'); + + def test_credentials(self): + bitbake('core-image-minimal') + credentials = get_bb_var('SOTA_PACKED_CREDENTIALS') + # skip the test if the variable SOTA_PACKED_CREDENTIALS is not set + if credentials is None: + raise unittest.SkipTest("Variable 'SOTA_PACKED_CREDENTIALS' not set.") + # Check if the file exists + self.assertTrue(os.path.isfile(credentials), "File %s does not exist" % credentials) + deploydir = get_bb_var('DEPLOY_DIR_IMAGE') + imagename = get_bb_var('IMAGE_LINK_NAME', 'core-image-minimal') + # Check if the credentials are included in the output image + result = runCmd('tar -jtvf %s/%s.tar.bz2 | grep sota_provisioning_credentials.zip' % (deploydir, imagename), ignore_status=True) + self.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output) + + def test_java(self): + result = runCmd('which java', ignore_status=True) + self.assertEqual(result.status, 0, "Java not found.") + + def test_add_package(self): + print('') + deploydir = get_bb_var('DEPLOY_DIR_IMAGE') + imagename = get_bb_var('IMAGE_LINK_NAME', 'core-image-minimal') + image_path = deploydir + '/' + imagename + '.otaimg' + logger = logging.getLogger("selftest") + + logger.info('Running bitbake with man in the image package list') + self.write_config('IMAGE_INSTALL_append = " man "') + bitbake('-c cleanall man') + bitbake('core-image-minimal') + result = runCmd('oe-pkgdata-util find-path /usr/bin/man') + self.assertEqual(result.output, 'man: /usr/bin/man') + path1 = os.path.realpath(image_path) + size1 = os.path.getsize(path1) + 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 "') + bitbake('-c cleanall man') + bitbake('core-image-minimal') + result = runCmd('oe-pkgdata-util find-path /usr/bin/man', ignore_status=True) + self.assertEqual(result.status, 1, "Status different than 1. output: %s" % result.output) + self.assertEqual(result.output, 'ERROR: Unable to find any package producing path /usr/bin/man') + path2 = os.path.realpath(image_path) + size2 = os.path.getsize(path2) + logger.info('Second image %s has size %i' % (path2, size2)) + self.assertNotEqual(path1, path2, "Image paths are identical; image was not rebuilt.") + self.assertNotEqual(size1, size2, "Image sizes are identical; image was not rebuilt.") + + +class QemuTests(OESelftestTestCase): + + @classmethod + def setUpClass(cls): + cls.qemu, cls.s = qemu_launch(machine='qemux86-64') + + @classmethod + def tearDownClass(cls): + qemu_terminate(cls.s) + + def test_hostname(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 test_var_sota(self): + print('') + print('Checking contents of /var/sota:') + value, err = qemu_send_command(self.qemu.ssh_port, 'ls /var/sota') + self.assertEqual(err, b'', 'Error: ' + err.decode()) + print(value.decode()) + + +class GrubTests(OESelftestTestCase): + + 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(efi=False, machine=None): + 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 = efi + args.machine = machine + 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 + diff --git a/lib/oeqa/selftest/qemucommand.py b/lib/oeqa/selftest/qemucommand.py deleted file mode 120000 index bc06dde..0000000 --- a/lib/oeqa/selftest/qemucommand.py +++ /dev/null @@ -1 +0,0 @@ -../../../scripts/qemucommand.py \ No newline at end of file diff --git a/lib/oeqa/selftest/updater.py b/lib/oeqa/selftest/updater.py deleted file mode 100644 index f28349f..0000000 --- a/lib/oeqa/selftest/updater.py +++ /dev/null @@ -1,207 +0,0 @@ -import unittest -import os -import logging -import subprocess -import time - -from oeqa.selftest.base import oeSelfTest -from oeqa.utils.commands import runCmd, bitbake, get_bb_var, get_bb_vars -from oeqa.selftest.qemucommand import QemuCommand - - -class SotaToolsTests(oeSelfTest): - - @classmethod - def setUpClass(cls): - logger = logging.getLogger("selftest") - 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'], 'aktualizr-native') - 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) - 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" - self.assertTrue(os.path.isfile(p), msg = "No garage-deploy 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) - - 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): - self.write_config('SOTA_CLIENT_FEATURES="hsm"') - bitbake('core-image-minimal') - - -class GeneralTests(oeSelfTest): - - def test_feature_sota(self): - result = get_bb_var('DISTRO_FEATURES').find('sota') - self.assertNotEqual(result, -1, 'Feature "sota" not set at DISTRO_FEATURES'); - - def test_feature_systemd(self): - result = get_bb_var('DISTRO_FEATURES').find('systemd') - self.assertNotEqual(result, -1, 'Feature "systemd" not set at DISTRO_FEATURES'); - - def test_credentials(self): - bitbake('core-image-minimal') - credentials = get_bb_var('SOTA_PACKED_CREDENTIALS') - # skip the test if the variable SOTA_PACKED_CREDENTIALS is not set - if credentials is None: - raise unittest.SkipTest("Variable 'SOTA_PACKED_CREDENTIALS' not set.") - # Check if the file exists - self.assertTrue(os.path.isfile(credentials), "File %s does not exist" % credentials) - deploydir = get_bb_var('DEPLOY_DIR_IMAGE') - imagename = get_bb_var('IMAGE_LINK_NAME', 'core-image-minimal') - # Check if the credentials are included in the output image - result = runCmd('tar -jtvf %s/%s.tar.bz2 | grep sota_provisioning_credentials.zip' % (deploydir, imagename), ignore_status=True) - self.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output) - - def test_java(self): - result = runCmd('which java', ignore_status=True) - self.assertEqual(result.status, 0, "Java not found.") - - def test_add_package(self): - print('') - deploydir = get_bb_var('DEPLOY_DIR_IMAGE') - imagename = get_bb_var('IMAGE_LINK_NAME', 'core-image-minimal') - image_path = deploydir + '/' + imagename + '.otaimg' - logger = logging.getLogger("selftest") - - logger.info('Running bitbake with man in the image package list') - self.write_config('IMAGE_INSTALL_append = " man "') - bitbake('-c cleanall man') - bitbake('core-image-minimal') - result = runCmd('oe-pkgdata-util find-path /usr/bin/man') - self.assertEqual(result.output, 'man: /usr/bin/man') - path1 = os.path.realpath(image_path) - size1 = os.path.getsize(path1) - 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 "') - bitbake('-c cleanall man') - bitbake('core-image-minimal') - result = runCmd('oe-pkgdata-util find-path /usr/bin/man', ignore_status=True) - self.assertEqual(result.status, 1, "Status different than 1. output: %s" % result.output) - self.assertEqual(result.output, 'ERROR: Unable to find any package producing path /usr/bin/man') - path2 = os.path.realpath(image_path) - size2 = os.path.getsize(path2) - logger.info('Second image %s has size %i' % (path2, size2)) - self.assertNotEqual(path1, path2, "Image paths are identical; image was not rebuilt.") - self.assertNotEqual(size1, size2, "Image sizes are identical; image was not rebuilt.") - - -class QemuTests(oeSelfTest): - - @classmethod - def setUpClass(cls): - cls.qemu, cls.s = qemu_launch(machine='qemux86-64') - - @classmethod - def tearDownClass(cls): - qemu_terminate(cls.s) - - def test_hostname(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 test_var_sota(self): - print('') - print('Checking contents of /var/sota:') - value, err = qemu_send_command(self.qemu.ssh_port, 'ls /var/sota') - 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(efi=False, machine=None): - 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 = efi - args.machine = machine - 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 84baa1c3d8f996f7daf2d8aa3d26197378218f21 Mon Sep 17 00:00:00 2001 From: Patrick Vacek Date: Thu, 18 Jan 2018 18:36:33 +0100 Subject: Fix some basic oe-selftest errors. Grub, HSM, and qemu hostname tests still fail for reasons I haven't figured out yet. --- lib/oeqa/selftest/cases/updater.py | 4 +++- scripts/qemucommand.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'lib/oeqa/selftest') diff --git a/lib/oeqa/selftest/cases/updater.py b/lib/oeqa/selftest/cases/updater.py index 7d7bde7..253320d 100644 --- a/lib/oeqa/selftest/cases/updater.py +++ b/lib/oeqa/selftest/cases/updater.py @@ -13,6 +13,7 @@ class SotaToolsTests(OESelftestTestCase): @classmethod def setUpClass(cls): + super(SotaToolsTests, cls).setUpClass() logger = logging.getLogger("selftest") logger.info('Running bitbake to build aktualizr-native tools') bitbake('aktualizr-native') @@ -109,6 +110,7 @@ class QemuTests(OESelftestTestCase): @classmethod def setUpClass(cls): + super(QemuTests, cls).setUpClass() cls.qemu, cls.s = qemu_launch(machine='qemux86-64') @classmethod @@ -140,7 +142,7 @@ class GrubTests(OESelftestTestCase): 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 + "/../../../../" + metadir = path + "/../../../../../" grub_config = 'OSTREE_BOOTLOADER = "grub"\nMACHINE = "intel-corei7-64"' self.append_config(grub_config) self.meta_intel = metadir + "meta-intel" diff --git a/scripts/qemucommand.py b/scripts/qemucommand.py index 9a893d8..7ae9381 100644 --- a/scripts/qemucommand.py +++ b/scripts/qemucommand.py @@ -96,7 +96,7 @@ class QemuCommand(object): "-serial", "tcp:127.0.0.1:%d,server,nowait" % self.serial_port, "-m", "1G", "-usb", - "-usbdevice", "tablet", + "-device", "usb-tablet", "-show-cursor", "-vga", "std", "-net", netuser, -- cgit v1.2.3-54-g00ecf From b605cf215ff4cef35c3f62fee0ec14e3c8d5ba22 Mon Sep 17 00:00:00 2001 From: Patrick Vacek Date: Fri, 19 Jan 2018 14:12:22 +0100 Subject: Add a brief doc section for common build problems. Also add a helpful hint for the oe-selftest grub problem. --- README.adoc | 10 ++++++++++ lib/oeqa/selftest/cases/updater.py | 3 ++- 2 files changed, 12 insertions(+), 1 deletion(-) (limited to 'lib/oeqa/selftest') diff --git a/README.adoc b/README.adoc index 0917e45..a85be18 100644 --- a/README.adoc +++ b/README.adoc @@ -44,6 +44,16 @@ and get as a result an "ostree_repo" folder in your images directory (tmp/deploy Although aglsetup.sh hooks provide reasonable defaults for SOTA-related variables, you may want to tune some of them. +=== Build problems + +Multilib systems may require adding this line to `local.conf`: + +.... +HOSTTOOLS += "x86_64-linux-gnu-gcc" +.... + +Ubuntu users that encounter an error due to missing `Python.h` should install `libpython2.7-dev` on their host machine. + == Supported boards Currently supported platforms are diff --git a/lib/oeqa/selftest/cases/updater.py b/lib/oeqa/selftest/cases/updater.py index 253320d..9264616 100644 --- a/lib/oeqa/selftest/cases/updater.py +++ b/lib/oeqa/selftest/cases/updater.py @@ -165,7 +165,8 @@ class GrubTests(OESelftestTestCase): # Strip off line ending. value_str = value.decode()[:-1] self.assertEqual(value_str, machine, - 'MACHINE does not match hostname: ' + machine + ', ' + value_str) + 'MACHINE does not match hostname: ' + machine + ', ' + value_str + + '\nIs tianocore ovmf installed?') print(value_str) -- cgit v1.2.3-54-g00ecf From c64b399633975bc05856e5eded519c4f22adfe44 Mon Sep 17 00:00:00 2001 From: Phil Wise Date: Fri, 1 Dec 2017 11:56:51 +0100 Subject: Add tests for aktualizr-info --- lib/oeqa/selftest/cases/updater.py | 54 +++++++++++++++++++++++++++----------- 1 file changed, 39 insertions(+), 15 deletions(-) (limited to 'lib/oeqa/selftest') diff --git a/lib/oeqa/selftest/cases/updater.py b/lib/oeqa/selftest/cases/updater.py index 9264616..91ac9fc 100644 --- a/lib/oeqa/selftest/cases/updater.py +++ b/lib/oeqa/selftest/cases/updater.py @@ -1,8 +1,9 @@ +# pylint: disable=C0111,C0325 import os import logging import subprocess -import time import unittest +from time import sleep from oeqa.selftest.case import OESelftestTestCase from oeqa.utils.commands import runCmd, bitbake, get_bb_var, get_bb_vars @@ -51,11 +52,11 @@ class GeneralTests(OESelftestTestCase): def test_feature_sota(self): result = get_bb_var('DISTRO_FEATURES').find('sota') - self.assertNotEqual(result, -1, 'Feature "sota" not set at DISTRO_FEATURES'); + self.assertNotEqual(result, -1, 'Feature "sota" not set at DISTRO_FEATURES') def test_feature_systemd(self): result = get_bb_var('DISTRO_FEATURES').find('systemd') - self.assertNotEqual(result, -1, 'Feature "systemd" not set at DISTRO_FEATURES'); + self.assertNotEqual(result, -1, 'Feature "systemd" not set at DISTRO_FEATURES') def test_credentials(self): bitbake('core-image-minimal') @@ -68,7 +69,8 @@ class GeneralTests(OESelftestTestCase): deploydir = get_bb_var('DEPLOY_DIR_IMAGE') imagename = get_bb_var('IMAGE_LINK_NAME', 'core-image-minimal') # Check if the credentials are included in the output image - result = runCmd('tar -jtvf %s/%s.tar.bz2 | grep sota_provisioning_credentials.zip' % (deploydir, imagename), ignore_status=True) + result = runCmd('tar -jtvf %s/%s.tar.bz2 | grep sota_provisioning_credentials.zip' % + (deploydir, imagename), ignore_status=True) self.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output) def test_java(self): @@ -101,7 +103,7 @@ class GeneralTests(OESelftestTestCase): self.assertEqual(result.output, 'ERROR: Unable to find any package producing path /usr/bin/man') path2 = os.path.realpath(image_path) size2 = os.path.getsize(path2) - logger.info('Second image %s has size %i' % (path2, size2)) + logger.info('Second image %s has size %i', path2, size2) self.assertNotEqual(path1, path2, "Image paths are identical; image was not rebuilt.") self.assertNotEqual(size1, size2, "Image sizes are identical; image was not rebuilt.") @@ -117,14 +119,17 @@ class QemuTests(OESelftestTestCase): def tearDownClass(cls): qemu_terminate(cls.s) + def run_command(self, command): + return qemu_send_command(self.qemu.ssh_port, command) + def test_hostname(self): print('') print('Checking machine name (hostname) of device:') - value, err = qemu_send_command(self.qemu.ssh_port, 'hostname') + stdout, stderr, retcode = self.run_command('hostname') machine = get_bb_var('MACHINE', 'core-image-minimal') - self.assertEqual(err, b'', 'Error: ' + err.decode()) + self.assertEqual(stderr, b'', 'Error: ' + stderr.decode()) # Strip off line ending. - value_str = value.decode()[:-1] + value_str = stdout.decode()[:-1] self.assertEqual(value_str, machine, 'MACHINE does not match hostname: ' + machine + ', ' + value_str) print(value_str) @@ -132,9 +137,26 @@ class QemuTests(OESelftestTestCase): def test_var_sota(self): print('') print('Checking contents of /var/sota:') - value, err = qemu_send_command(self.qemu.ssh_port, 'ls /var/sota') - self.assertEqual(err, b'', 'Error: ' + err.decode()) - print(value.decode()) + stdout, stderr, retcode = self.run_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.run_command('aktualizr-info') + if retcode == 0 and stderr == b'': + ran_ok = True + break + except IOError as e: + print(e) + if not ran_ok: + print(stdout.decode()) + print(stderr.decode()) class GrubTests(OESelftestTestCase): @@ -159,9 +181,10 @@ class GrubTests(OESelftestTestCase): def test_grub(self): print('') print('Checking machine name (hostname) of device:') - value, err = qemu_send_command(self.qemu.ssh_port, 'hostname') + value, err, retcode = qemu_send_command(self.qemu.ssh_port, 'hostname') machine = get_bb_var('MACHINE', 'core-image-minimal') self.assertEqual(err, b'', 'Error: ' + err.decode()) + self.assertEqual(retcode, 0) # Strip off line ending. value_str = value.decode()[:-1] self.assertEqual(value_str, machine, @@ -194,7 +217,7 @@ def qemu_launch(efi=False, machine=None): cmdline = qemu.command_line() print('Booting image with run-qemu-ota...') s = subprocess.Popen(cmdline) - time.sleep(10) + sleep(10) return qemu, s def qemu_terminate(s): @@ -207,6 +230,7 @@ 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 + stdout, stderr = s2.communicate() + return stdout, stderr, s2.returncode +# vim:set ts=4 sw=4 sts=4 expandtab: -- cgit v1.2.3-54-g00ecf