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') 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') 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') 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') 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') 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') 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') 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') 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') 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') 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') 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') 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