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/updater.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 lib/oeqa/selftest/updater.py (limited to 'lib/oeqa/selftest/updater.py') 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/updater.py') 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/updater.py') 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/updater.py') 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/updater.py') 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/updater.py') 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/updater.py') 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