diff options
Diffstat (limited to 'lib/oeqa/selftest/cases')
| -rw-r--r-- | lib/oeqa/selftest/cases/testutils.py | 128 | ||||
| -rw-r--r-- | lib/oeqa/selftest/cases/updater_minnowboard.py | 60 | ||||
| -rw-r--r-- | lib/oeqa/selftest/cases/updater_native.py | 47 | ||||
| -rw-r--r-- | lib/oeqa/selftest/cases/updater_qemux86_64.py (renamed from lib/oeqa/selftest/cases/updater.py) | 374 | ||||
| -rw-r--r-- | lib/oeqa/selftest/cases/updater_raspberrypi.py | 78 |
5 files changed, 362 insertions, 325 deletions
diff --git a/lib/oeqa/selftest/cases/testutils.py b/lib/oeqa/selftest/cases/testutils.py new file mode 100644 index 0000000..90ba653 --- /dev/null +++ b/lib/oeqa/selftest/cases/testutils.py | |||
| @@ -0,0 +1,128 @@ | |||
| 1 | import os | ||
| 2 | import logging | ||
| 3 | import re | ||
| 4 | import subprocess | ||
| 5 | from time import sleep | ||
| 6 | |||
| 7 | from oeqa.utils.commands import runCmd, bitbake, get_bb_var, get_bb_vars | ||
| 8 | from qemucommand import QemuCommand | ||
| 9 | |||
| 10 | |||
| 11 | def qemu_launch(efi=False, machine=None, imagename=None): | ||
| 12 | logger = logging.getLogger("selftest") | ||
| 13 | if imagename is None: | ||
| 14 | imagename = 'core-image-minimal' | ||
| 15 | logger.info('Running bitbake to build {}'.format(imagename)) | ||
| 16 | bitbake(imagename) | ||
| 17 | # Create empty object. | ||
| 18 | args = type('', (), {})() | ||
| 19 | args.imagename = imagename | ||
| 20 | args.mac = None | ||
| 21 | # Could use DEPLOY_DIR_IMAGE here but it's already in the machine | ||
| 22 | # subdirectory. | ||
| 23 | args.dir = 'tmp/deploy/images' | ||
| 24 | args.efi = efi | ||
| 25 | args.machine = machine | ||
| 26 | qemu_use_kvm = get_bb_var("QEMU_USE_KVM") | ||
| 27 | if qemu_use_kvm and \ | ||
| 28 | (qemu_use_kvm == 'True' and 'x86' in machine or | ||
| 29 | get_bb_var('MACHINE') in qemu_use_kvm.split()): | ||
| 30 | args.kvm = True | ||
| 31 | else: | ||
| 32 | args.kvm = None # Autodetect | ||
| 33 | args.no_gui = True | ||
| 34 | args.gdb = False | ||
| 35 | args.pcap = None | ||
| 36 | args.overlay = None | ||
| 37 | args.dry_run = False | ||
| 38 | args.secondary_network = False | ||
| 39 | |||
| 40 | qemu = QemuCommand(args) | ||
| 41 | cmdline = qemu.command_line() | ||
| 42 | print('Booting image with run-qemu-ota...') | ||
| 43 | s = subprocess.Popen(cmdline) | ||
| 44 | sleep(10) | ||
| 45 | return qemu, s | ||
| 46 | |||
| 47 | |||
| 48 | def qemu_terminate(s): | ||
| 49 | try: | ||
| 50 | s.terminate() | ||
| 51 | except KeyboardInterrupt: | ||
| 52 | pass | ||
| 53 | |||
| 54 | |||
| 55 | def qemu_send_command(port, command): | ||
| 56 | command = ['ssh -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@localhost -p ' + | ||
| 57 | str(port) + ' "' + command + '"'] | ||
| 58 | s2 = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | ||
| 59 | stdout, stderr = s2.communicate(timeout=60) | ||
| 60 | return stdout, stderr, s2.returncode | ||
| 61 | |||
| 62 | |||
| 63 | def akt_native_run(testInst, cmd, **kwargs): | ||
| 64 | # run a command supplied by aktualizr-native and checks that: | ||
| 65 | # - the executable exists | ||
| 66 | # - the command runs without error | ||
| 67 | # NOTE: the base test class must have built aktualizr-native (in | ||
| 68 | # setUpClass, for example) | ||
| 69 | bb_vars = get_bb_vars(['SYSROOT_DESTDIR', 'base_prefix', 'libdir', 'bindir'], | ||
| 70 | 'aktualizr-native') | ||
| 71 | sysroot = bb_vars['SYSROOT_DESTDIR'] + bb_vars['base_prefix'] | ||
| 72 | sysrootbin = bb_vars['SYSROOT_DESTDIR'] + bb_vars['bindir'] | ||
| 73 | libdir = bb_vars['libdir'] | ||
| 74 | |||
| 75 | program, *_ = cmd.split(' ') | ||
| 76 | p = '{}/{}'.format(sysrootbin, program) | ||
| 77 | testInst.assertTrue(os.path.isfile(p), msg="No {} found ({})".format(program, p)) | ||
| 78 | env = dict(os.environ) | ||
| 79 | env['LD_LIBRARY_PATH'] = libdir | ||
| 80 | result = runCmd(cmd, env=env, native_sysroot=sysroot, ignore_status=True, **kwargs) | ||
| 81 | testInst.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output) | ||
| 82 | |||
| 83 | |||
| 84 | def verifyNotProvisioned(testInst, machine): | ||
| 85 | print('Checking output of aktualizr-info:') | ||
| 86 | ran_ok = False | ||
| 87 | for delay in [5, 5, 5, 5, 10, 10, 10, 10]: | ||
| 88 | stdout, stderr, retcode = testInst.qemu_command('aktualizr-info') | ||
| 89 | if retcode == 0 and stderr == b'': | ||
| 90 | ran_ok = True | ||
| 91 | break | ||
| 92 | sleep(delay) | ||
| 93 | testInst.assertTrue(ran_ok, 'aktualizr-info failed: ' + stderr.decode() + stdout.decode()) | ||
| 94 | |||
| 95 | # Verify that device has NOT yet provisioned. | ||
| 96 | testInst.assertIn(b'Couldn\'t load device ID', stdout, | ||
| 97 | 'Device already provisioned!? ' + stderr.decode() + stdout.decode()) | ||
| 98 | testInst.assertIn(b'Couldn\'t load ECU serials', stdout, | ||
| 99 | 'Device already provisioned!? ' + stderr.decode() + stdout.decode()) | ||
| 100 | testInst.assertIn(b'Provisioned on server: no', stdout, | ||
| 101 | 'Device already provisioned!? ' + stderr.decode() + stdout.decode()) | ||
| 102 | testInst.assertIn(b'Fetched metadata: no', stdout, | ||
| 103 | 'Device already provisioned!? ' + stderr.decode() + stdout.decode()) | ||
| 104 | |||
| 105 | |||
| 106 | def verifyProvisioned(testInst, machine): | ||
| 107 | # Verify that device HAS provisioned. | ||
| 108 | ran_ok = False | ||
| 109 | for delay in [5, 5, 5, 5, 10, 10, 10, 10]: | ||
| 110 | stdout, stderr, retcode = testInst.qemu_command('aktualizr-info') | ||
| 111 | if retcode == 0 and stderr == b'' and stdout.decode().find('Fetched metadata: yes') >= 0: | ||
| 112 | ran_ok = True | ||
| 113 | break | ||
| 114 | sleep(delay) | ||
| 115 | testInst.assertTrue(ran_ok, 'aktualizr-info failed: ' + stderr.decode() + stdout.decode()) | ||
| 116 | |||
| 117 | testInst.assertIn(b'Device ID: ', stdout, 'Provisioning failed: ' + stderr.decode() + stdout.decode()) | ||
| 118 | testInst.assertIn(b'Primary ecu hardware ID: ' + machine.encode(), stdout, | ||
| 119 | 'Provisioning failed: ' + stderr.decode() + stdout.decode()) | ||
| 120 | testInst.assertIn(b'Fetched metadata: yes', stdout, 'Provisioning failed: ' + stderr.decode() + stdout.decode()) | ||
| 121 | p = re.compile(r'Device ID: ([a-z0-9-]*)\n') | ||
| 122 | m = p.search(stdout.decode()) | ||
| 123 | testInst.assertTrue(m, 'Device ID could not be read: ' + stderr.decode() + stdout.decode()) | ||
| 124 | testInst.assertGreater(m.lastindex, 0, 'Device ID could not be read: ' + stderr.decode() + stdout.decode()) | ||
| 125 | logger = logging.getLogger("selftest") | ||
| 126 | logger.info('Device successfully provisioned with ID: ' + m.group(1)) | ||
| 127 | |||
| 128 | # vim:set ts=4 sw=4 sts=4 expandtab: | ||
diff --git a/lib/oeqa/selftest/cases/updater_minnowboard.py b/lib/oeqa/selftest/cases/updater_minnowboard.py new file mode 100644 index 0000000..f5df584 --- /dev/null +++ b/lib/oeqa/selftest/cases/updater_minnowboard.py | |||
| @@ -0,0 +1,60 @@ | |||
| 1 | import os | ||
| 2 | import re | ||
| 3 | |||
| 4 | from oeqa.selftest.case import OESelftestTestCase | ||
| 5 | from oeqa.utils.commands import runCmd, get_bb_var | ||
| 6 | from testutils import qemu_launch, qemu_send_command, qemu_terminate, verifyProvisioned | ||
| 7 | |||
| 8 | |||
| 9 | class MinnowTests(OESelftestTestCase): | ||
| 10 | |||
| 11 | def setUpLocal(self): | ||
| 12 | layer_intel = "meta-intel" | ||
| 13 | layer_minnow = "meta-updater-minnowboard" | ||
| 14 | result = runCmd('bitbake-layers show-layers') | ||
| 15 | # Assume the directory layout for finding other layers. We could also | ||
| 16 | # make assumptions by using 'show-layers', but either way, if the | ||
| 17 | # layers we need aren't where we expect them, we are out of luck. | ||
| 18 | path = os.path.abspath(os.path.dirname(__file__)) | ||
| 19 | metadir = path + "/../../../../../" | ||
| 20 | if re.search(layer_intel, result.output) is None: | ||
| 21 | self.meta_intel = metadir + layer_intel | ||
| 22 | runCmd('bitbake-layers add-layer "%s"' % self.meta_intel) | ||
| 23 | else: | ||
| 24 | self.meta_intel = None | ||
| 25 | if re.search(layer_minnow, result.output) is None: | ||
| 26 | self.meta_minnow = metadir + layer_minnow | ||
| 27 | runCmd('bitbake-layers add-layer "%s"' % self.meta_minnow) | ||
| 28 | else: | ||
| 29 | self.meta_minnow = None | ||
| 30 | self.append_config('MACHINE = "intel-corei7-64"') | ||
| 31 | self.append_config('OSTREE_BOOTLOADER = "grub"') | ||
| 32 | self.append_config('SOTA_CLIENT_PROV = " aktualizr-auto-prov "') | ||
| 33 | self.qemu, self.s = qemu_launch(efi=True, machine='intel-corei7-64') | ||
| 34 | |||
| 35 | def tearDownLocal(self): | ||
| 36 | qemu_terminate(self.s) | ||
| 37 | if self.meta_intel: | ||
| 38 | runCmd('bitbake-layers remove-layer "%s"' % self.meta_intel, ignore_status=True) | ||
| 39 | if self.meta_minnow: | ||
| 40 | runCmd('bitbake-layers remove-layer "%s"' % self.meta_minnow, ignore_status=True) | ||
| 41 | |||
| 42 | def qemu_command(self, command): | ||
| 43 | return qemu_send_command(self.qemu.ssh_port, command) | ||
| 44 | |||
| 45 | def test_provisioning(self): | ||
| 46 | print('Checking machine name (hostname) of device:') | ||
| 47 | stdout, stderr, retcode = self.qemu_command('hostname') | ||
| 48 | self.assertEqual(retcode, 0, "Unable to check hostname. " + | ||
| 49 | "Is an ssh daemon (such as dropbear or openssh) installed on the device?") | ||
| 50 | machine = get_bb_var('MACHINE', 'core-image-minimal') | ||
| 51 | self.assertEqual(stderr, b'', 'Error: ' + stderr.decode()) | ||
| 52 | # Strip off line ending. | ||
| 53 | value = stdout.decode()[:-1] | ||
| 54 | self.assertEqual(value, machine, | ||
| 55 | 'MACHINE does not match hostname: ' + machine + ', ' + value + | ||
| 56 | '\nIs TianoCore ovmf installed on your host machine?') | ||
| 57 | |||
| 58 | verifyProvisioned(self, machine) | ||
| 59 | |||
| 60 | # vim:set ts=4 sw=4 sts=4 expandtab: | ||
diff --git a/lib/oeqa/selftest/cases/updater_native.py b/lib/oeqa/selftest/cases/updater_native.py new file mode 100644 index 0000000..1fc9cb8 --- /dev/null +++ b/lib/oeqa/selftest/cases/updater_native.py | |||
| @@ -0,0 +1,47 @@ | |||
| 1 | # pylint: disable=C0111,C0325 | ||
| 2 | import logging | ||
| 3 | |||
| 4 | from oeqa.selftest.case import OESelftestTestCase | ||
| 5 | from oeqa.utils.commands import runCmd, bitbake, get_bb_var | ||
| 6 | from testutils import akt_native_run | ||
| 7 | |||
| 8 | |||
| 9 | class SotaToolsTests(OESelftestTestCase): | ||
| 10 | |||
| 11 | @classmethod | ||
| 12 | def setUpClass(cls): | ||
| 13 | super(SotaToolsTests, cls).setUpClass() | ||
| 14 | logger = logging.getLogger("selftest") | ||
| 15 | logger.info('Running bitbake to build aktualizr-native tools') | ||
| 16 | bitbake('aktualizr-native') | ||
| 17 | |||
| 18 | def test_push_help(self): | ||
| 19 | akt_native_run(self, 'garage-push --help') | ||
| 20 | |||
| 21 | def test_deploy_help(self): | ||
| 22 | akt_native_run(self, 'garage-deploy --help') | ||
| 23 | |||
| 24 | def test_garagesign_help(self): | ||
| 25 | akt_native_run(self, 'garage-sign --help') | ||
| 26 | |||
| 27 | |||
| 28 | class GeneralTests(OESelftestTestCase): | ||
| 29 | |||
| 30 | def test_feature_sota(self): | ||
| 31 | result = get_bb_var('DISTRO_FEATURES').find('sota') | ||
| 32 | self.assertNotEqual(result, -1, 'Feature "sota" not set at DISTRO_FEATURES') | ||
| 33 | |||
| 34 | def test_feature_usrmerge(self): | ||
| 35 | result = get_bb_var('DISTRO_FEATURES').find('usrmerge') | ||
| 36 | self.assertNotEqual(result, -1, 'Feature "sota" not set at DISTRO_FEATURES') | ||
| 37 | |||
| 38 | def test_feature_systemd(self): | ||
| 39 | result = get_bb_var('DISTRO_FEATURES').find('systemd') | ||
| 40 | self.assertNotEqual(result, -1, 'Feature "systemd" not set at DISTRO_FEATURES') | ||
| 41 | |||
| 42 | def test_java(self): | ||
| 43 | result = runCmd('which java', ignore_status=True) | ||
| 44 | self.assertEqual(result.status, 0, | ||
| 45 | "Java not found. Do you have a JDK installed on your host machine?") | ||
| 46 | |||
| 47 | # vim:set ts=4 sw=4 sts=4 expandtab: | ||
diff --git a/lib/oeqa/selftest/cases/updater.py b/lib/oeqa/selftest/cases/updater_qemux86_64.py index 473b2a8..bef6cdc 100644 --- a/lib/oeqa/selftest/cases/updater.py +++ b/lib/oeqa/selftest/cases/updater_qemux86_64.py | |||
| @@ -2,48 +2,16 @@ | |||
| 2 | import os | 2 | import os |
| 3 | import logging | 3 | import logging |
| 4 | import re | 4 | import re |
| 5 | import subprocess | ||
| 6 | import unittest | 5 | import unittest |
| 7 | from time import sleep | 6 | from time import sleep |
| 8 | 7 | ||
| 9 | from oeqa.selftest.case import OESelftestTestCase | 8 | from oeqa.selftest.case import OESelftestTestCase |
| 10 | from oeqa.utils.commands import runCmd, bitbake, get_bb_var, get_bb_vars | 9 | from oeqa.utils.commands import runCmd, bitbake, get_bb_var, get_bb_vars |
| 11 | from qemucommand import QemuCommand | 10 | from testutils import qemu_launch, qemu_send_command, qemu_terminate, \ |
| 12 | 11 | akt_native_run, verifyNotProvisioned, verifyProvisioned | |
| 13 | |||
| 14 | class SotaToolsTests(OESelftestTestCase): | ||
| 15 | |||
| 16 | @classmethod | ||
| 17 | def setUpClass(cls): | ||
| 18 | super(SotaToolsTests, cls).setUpClass() | ||
| 19 | logger = logging.getLogger("selftest") | ||
| 20 | logger.info('Running bitbake to build aktualizr-native tools') | ||
| 21 | bitbake('aktualizr-native') | ||
| 22 | |||
| 23 | def test_push_help(self): | ||
| 24 | akt_native_run(self, 'garage-push --help') | ||
| 25 | |||
| 26 | def test_deploy_help(self): | ||
| 27 | akt_native_run(self, 'garage-deploy --help') | ||
| 28 | |||
| 29 | def test_garagesign_help(self): | ||
| 30 | akt_native_run(self, 'garage-sign --help') | ||
| 31 | 12 | ||
| 32 | 13 | ||
| 33 | class GeneralTests(OESelftestTestCase): | 14 | class GeneralTests(OESelftestTestCase): |
| 34 | |||
| 35 | def test_feature_sota(self): | ||
| 36 | result = get_bb_var('DISTRO_FEATURES').find('sota') | ||
| 37 | self.assertNotEqual(result, -1, 'Feature "sota" not set at DISTRO_FEATURES') | ||
| 38 | |||
| 39 | def test_feature_usrmerge(self): | ||
| 40 | result = get_bb_var('DISTRO_FEATURES').find('usrmerge') | ||
| 41 | self.assertNotEqual(result, -1, 'Feature "sota" not set at DISTRO_FEATURES') | ||
| 42 | |||
| 43 | def test_feature_systemd(self): | ||
| 44 | result = get_bb_var('DISTRO_FEATURES').find('systemd') | ||
| 45 | self.assertNotEqual(result, -1, 'Feature "systemd" not set at DISTRO_FEATURES') | ||
| 46 | |||
| 47 | def test_credentials(self): | 15 | def test_credentials(self): |
| 48 | logger = logging.getLogger("selftest") | 16 | logger = logging.getLogger("selftest") |
| 49 | logger.info('Running bitbake to build core-image-minimal') | 17 | logger.info('Running bitbake to build core-image-minimal') |
| @@ -62,11 +30,6 @@ class GeneralTests(OESelftestTestCase): | |||
| 62 | (deploydir, imagename), ignore_status=True) | 30 | (deploydir, imagename), ignore_status=True) |
| 63 | self.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output) | 31 | self.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output) |
| 64 | 32 | ||
| 65 | def test_java(self): | ||
| 66 | result = runCmd('which java', ignore_status=True) | ||
| 67 | self.assertEqual(result.status, 0, | ||
| 68 | "Java not found. Do you have a JDK installed on your host machine?") | ||
| 69 | |||
| 70 | 33 | ||
| 71 | class AktualizrToolsTests(OESelftestTestCase): | 34 | class AktualizrToolsTests(OESelftestTestCase): |
| 72 | 35 | ||
| @@ -143,16 +106,6 @@ class AutoProvTests(OESelftestTestCase): | |||
| 143 | value = stdout.decode()[:-1] | 106 | value = stdout.decode()[:-1] |
| 144 | self.assertEqual(value, machine, | 107 | self.assertEqual(value, machine, |
| 145 | 'MACHINE does not match hostname: ' + machine + ', ' + value) | 108 | 'MACHINE does not match hostname: ' + machine + ', ' + value) |
| 146 | print(value) | ||
| 147 | print('Checking output of aktualizr-info:') | ||
| 148 | ran_ok = False | ||
| 149 | for delay in [1, 2, 5, 10, 15]: | ||
| 150 | stdout, stderr, retcode = self.qemu_command('aktualizr-info') | ||
| 151 | if retcode == 0 and stderr == b'': | ||
| 152 | ran_ok = True | ||
| 153 | break | ||
| 154 | sleep(delay) | ||
| 155 | self.assertTrue(ran_ok, 'aktualizr-info failed: ' + stderr.decode() + stdout.decode()) | ||
| 156 | 109 | ||
| 157 | verifyProvisioned(self, machine) | 110 | verifyProvisioned(self, machine) |
| 158 | 111 | ||
| @@ -201,136 +154,6 @@ class ManualControlTests(OESelftestTestCase): | |||
| 201 | 'Aktualizr should have run' + stderr.decode() + stdout.decode()) | 154 | 'Aktualizr should have run' + stderr.decode() + stdout.decode()) |
| 202 | 155 | ||
| 203 | 156 | ||
| 204 | class RpiTests(OESelftestTestCase): | ||
| 205 | |||
| 206 | def setUpLocal(self): | ||
| 207 | # Add layers before changing the machine type, otherwise the sanity | ||
| 208 | # checker complains loudly. | ||
| 209 | layer_rpi = "meta-raspberrypi" | ||
| 210 | layer_upd_rpi = "meta-updater-raspberrypi" | ||
| 211 | result = runCmd('bitbake-layers show-layers') | ||
| 212 | # Assume the directory layout for finding other layers. We could also | ||
| 213 | # make assumptions by using 'show-layers', but either way, if the | ||
| 214 | # layers we need aren't where we expect them, we are out of luck. | ||
| 215 | path = os.path.abspath(os.path.dirname(__file__)) | ||
| 216 | metadir = path + "/../../../../../" | ||
| 217 | if re.search(layer_rpi, result.output) is None: | ||
| 218 | self.meta_rpi = metadir + layer_rpi | ||
| 219 | runCmd('bitbake-layers add-layer "%s"' % self.meta_rpi) | ||
| 220 | else: | ||
| 221 | self.meta_rpi = None | ||
| 222 | if re.search(layer_upd_rpi, result.output) is None: | ||
| 223 | self.meta_upd_rpi = metadir + layer_upd_rpi | ||
| 224 | runCmd('bitbake-layers add-layer "%s"' % self.meta_upd_rpi) | ||
| 225 | else: | ||
| 226 | self.meta_upd_rpi = None | ||
| 227 | |||
| 228 | # This is trickier that I would've thought. The fundamental problem is | ||
| 229 | # that the qemu layer changes the u-boot file extension to .rom, but | ||
| 230 | # raspberrypi still expects .bin. To prevent this, the qemu layer must | ||
| 231 | # be temporarily removed if it is present. It has to be removed by name | ||
| 232 | # without the complete path, but to add it back when we are done, we | ||
| 233 | # need the full path. | ||
| 234 | p = re.compile(r'meta-updater-qemux86-64\s*(\S*meta-updater-qemux86-64)\s') | ||
| 235 | m = p.search(result.output) | ||
| 236 | if m and m.lastindex > 0: | ||
| 237 | self.meta_qemu = m.group(1) | ||
| 238 | runCmd('bitbake-layers remove-layer meta-updater-qemux86-64') | ||
| 239 | else: | ||
| 240 | self.meta_qemu = None | ||
| 241 | |||
| 242 | self.append_config('MACHINE = "raspberrypi3"') | ||
| 243 | self.append_config('SOTA_CLIENT_PROV = " aktualizr-auto-prov "') | ||
| 244 | |||
| 245 | def tearDownLocal(self): | ||
| 246 | if self.meta_qemu: | ||
| 247 | runCmd('bitbake-layers add-layer "%s"' % self.meta_qemu, ignore_status=True) | ||
| 248 | if self.meta_upd_rpi: | ||
| 249 | runCmd('bitbake-layers remove-layer "%s"' % self.meta_upd_rpi, ignore_status=True) | ||
| 250 | if self.meta_rpi: | ||
| 251 | runCmd('bitbake-layers remove-layer "%s"' % self.meta_rpi, ignore_status=True) | ||
| 252 | |||
| 253 | def test_rpi(self): | ||
| 254 | logger = logging.getLogger("selftest") | ||
| 255 | logger.info('Running bitbake to build core-image-minimal') | ||
| 256 | self.append_config('SOTA_CLIENT_PROV = "aktualizr-auto-prov"') | ||
| 257 | bitbake('core-image-minimal') | ||
| 258 | credentials = get_bb_var('SOTA_PACKED_CREDENTIALS') | ||
| 259 | # Skip the test if the variable SOTA_PACKED_CREDENTIALS is not set. | ||
| 260 | if credentials is None: | ||
| 261 | raise unittest.SkipTest("Variable 'SOTA_PACKED_CREDENTIALS' not set.") | ||
| 262 | # Check if the file exists. | ||
| 263 | self.assertTrue(os.path.isfile(credentials), "File %s does not exist" % credentials) | ||
| 264 | deploydir = get_bb_var('DEPLOY_DIR_IMAGE') | ||
| 265 | imagename = get_bb_var('IMAGE_LINK_NAME', 'core-image-minimal') | ||
| 266 | # Check if the credentials are included in the output image. | ||
| 267 | result = runCmd('tar -jtvf %s/%s.tar.bz2 | grep sota_provisioning_credentials.zip' % | ||
| 268 | (deploydir, imagename), ignore_status=True) | ||
| 269 | self.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output) | ||
| 270 | |||
| 271 | |||
| 272 | class GrubTests(OESelftestTestCase): | ||
| 273 | |||
| 274 | def setUpLocal(self): | ||
| 275 | layer_intel = "meta-intel" | ||
| 276 | layer_minnow = "meta-updater-minnowboard" | ||
| 277 | result = runCmd('bitbake-layers show-layers') | ||
| 278 | # Assume the directory layout for finding other layers. We could also | ||
| 279 | # make assumptions by using 'show-layers', but either way, if the | ||
| 280 | # layers we need aren't where we expect them, we are out of luck. | ||
| 281 | path = os.path.abspath(os.path.dirname(__file__)) | ||
| 282 | metadir = path + "/../../../../../" | ||
| 283 | if re.search(layer_intel, result.output) is None: | ||
| 284 | self.meta_intel = metadir + layer_intel | ||
| 285 | runCmd('bitbake-layers add-layer "%s"' % self.meta_intel) | ||
| 286 | else: | ||
| 287 | self.meta_intel = None | ||
| 288 | if re.search(layer_minnow, result.output) is None: | ||
| 289 | self.meta_minnow = metadir + layer_minnow | ||
| 290 | runCmd('bitbake-layers add-layer "%s"' % self.meta_minnow) | ||
| 291 | else: | ||
| 292 | self.meta_minnow = None | ||
| 293 | self.append_config('MACHINE = "intel-corei7-64"') | ||
| 294 | self.append_config('OSTREE_BOOTLOADER = "grub"') | ||
| 295 | self.append_config('SOTA_CLIENT_PROV = " aktualizr-auto-prov "') | ||
| 296 | self.qemu, self.s = qemu_launch(efi=True, machine='intel-corei7-64') | ||
| 297 | |||
| 298 | def tearDownLocal(self): | ||
| 299 | qemu_terminate(self.s) | ||
| 300 | if self.meta_intel: | ||
| 301 | runCmd('bitbake-layers remove-layer "%s"' % self.meta_intel, ignore_status=True) | ||
| 302 | if self.meta_minnow: | ||
| 303 | runCmd('bitbake-layers remove-layer "%s"' % self.meta_minnow, ignore_status=True) | ||
| 304 | |||
| 305 | def qemu_command(self, command): | ||
| 306 | return qemu_send_command(self.qemu.ssh_port, command) | ||
| 307 | |||
| 308 | def test_grub(self): | ||
| 309 | print('Checking machine name (hostname) of device:') | ||
| 310 | stdout, stderr, retcode = self.qemu_command('hostname') | ||
| 311 | self.assertEqual(retcode, 0, "Unable to check hostname. " + | ||
| 312 | "Is an ssh daemon (such as dropbear or openssh) installed on the device?") | ||
| 313 | machine = get_bb_var('MACHINE', 'core-image-minimal') | ||
| 314 | self.assertEqual(stderr, b'', 'Error: ' + stderr.decode()) | ||
| 315 | # Strip off line ending. | ||
| 316 | value = stdout.decode()[:-1] | ||
| 317 | self.assertEqual(value, machine, | ||
| 318 | 'MACHINE does not match hostname: ' + machine + ', ' + value + | ||
| 319 | '\nIs TianoCore ovmf installed on your host machine?') | ||
| 320 | print(value) | ||
| 321 | print('Checking output of aktualizr-info:') | ||
| 322 | ran_ok = False | ||
| 323 | for delay in [1, 2, 5, 10, 15]: | ||
| 324 | stdout, stderr, retcode = self.qemu_command('aktualizr-info') | ||
| 325 | if retcode == 0 and stderr == b'': | ||
| 326 | ran_ok = True | ||
| 327 | break | ||
| 328 | sleep(delay) | ||
| 329 | self.assertTrue(ran_ok, 'aktualizr-info failed: ' + stderr.decode() + stdout.decode()) | ||
| 330 | |||
| 331 | verifyProvisioned(self, machine) | ||
| 332 | |||
| 333 | |||
| 334 | class ImplProvTests(OESelftestTestCase): | 157 | class ImplProvTests(OESelftestTestCase): |
| 335 | 158 | ||
| 336 | def setUpLocal(self): | 159 | def setUpLocal(self): |
| @@ -371,25 +194,8 @@ class ImplProvTests(OESelftestTestCase): | |||
| 371 | value = stdout.decode()[:-1] | 194 | value = stdout.decode()[:-1] |
| 372 | self.assertEqual(value, machine, | 195 | self.assertEqual(value, machine, |
| 373 | 'MACHINE does not match hostname: ' + machine + ', ' + value) | 196 | 'MACHINE does not match hostname: ' + machine + ', ' + value) |
| 374 | print(value) | 197 | |
| 375 | print('Checking output of aktualizr-info:') | 198 | verifyNotProvisioned(self, machine) |
| 376 | ran_ok = False | ||
| 377 | for delay in [1, 2, 5, 10, 15]: | ||
| 378 | stdout, stderr, retcode = self.qemu_command('aktualizr-info') | ||
| 379 | if retcode == 0 and stderr == b'': | ||
| 380 | ran_ok = True | ||
| 381 | break | ||
| 382 | sleep(delay) | ||
| 383 | self.assertTrue(ran_ok, 'aktualizr-info failed: ' + stderr.decode() + stdout.decode()) | ||
| 384 | # Verify that device has NOT yet provisioned. | ||
| 385 | self.assertIn(b'Couldn\'t load device ID', stdout, | ||
| 386 | 'Device already provisioned!? ' + stderr.decode() + stdout.decode()) | ||
| 387 | self.assertIn(b'Couldn\'t load ECU serials', stdout, | ||
| 388 | 'Device already provisioned!? ' + stderr.decode() + stdout.decode()) | ||
| 389 | self.assertIn(b'Provisioned on server: no', stdout, | ||
| 390 | 'Device already provisioned!? ' + stderr.decode() + stdout.decode()) | ||
| 391 | self.assertIn(b'Fetched metadata: no', stdout, | ||
| 392 | 'Device already provisioned!? ' + stderr.decode() + stdout.decode()) | ||
| 393 | 199 | ||
| 394 | # Run aktualizr-cert-provider. | 200 | # Run aktualizr-cert-provider. |
| 395 | bb_vars = get_bb_vars(['SOTA_PACKED_CREDENTIALS'], 'aktualizr-native') | 201 | bb_vars = get_bb_vars(['SOTA_PACKED_CREDENTIALS'], 'aktualizr-native') |
| @@ -446,25 +252,8 @@ class HsmTests(OESelftestTestCase): | |||
| 446 | value = stdout.decode()[:-1] | 252 | value = stdout.decode()[:-1] |
| 447 | self.assertEqual(value, machine, | 253 | self.assertEqual(value, machine, |
| 448 | 'MACHINE does not match hostname: ' + machine + ', ' + value) | 254 | 'MACHINE does not match hostname: ' + machine + ', ' + value) |
| 449 | print(value) | 255 | |
| 450 | print('Checking output of aktualizr-info:') | 256 | verifyNotProvisioned(self, machine) |
| 451 | ran_ok = False | ||
| 452 | for delay in [1, 2, 5, 10, 15]: | ||
| 453 | stdout, stderr, retcode = self.qemu_command('aktualizr-info') | ||
| 454 | if retcode == 0 and stderr == b'': | ||
| 455 | ran_ok = True | ||
| 456 | break | ||
| 457 | sleep(delay) | ||
| 458 | self.assertTrue(ran_ok, 'aktualizr-info failed: ' + stderr.decode() + stdout.decode()) | ||
| 459 | # Verify that device has NOT yet provisioned. | ||
| 460 | self.assertIn(b'Couldn\'t load device ID', stdout, | ||
| 461 | 'Device already provisioned!? ' + stderr.decode() + stdout.decode()) | ||
| 462 | self.assertIn(b'Couldn\'t load ECU serials', stdout, | ||
| 463 | 'Device already provisioned!? ' + stderr.decode() + stdout.decode()) | ||
| 464 | self.assertIn(b'Provisioned on server: no', stdout, | ||
| 465 | 'Device already provisioned!? ' + stderr.decode() + stdout.decode()) | ||
| 466 | self.assertIn(b'Fetched metadata: no', stdout, | ||
| 467 | 'Device already provisioned!? ' + stderr.decode() + stdout.decode()) | ||
| 468 | 257 | ||
| 469 | # Verify that HSM is not yet initialized. | 258 | # Verify that HSM is not yet initialized. |
| 470 | pkcs11_command = 'pkcs11-tool --module=/usr/lib/softhsm/libsofthsm2.so -O' | 259 | pkcs11_command = 'pkcs11-tool --module=/usr/lib/softhsm/libsofthsm2.so -O' |
| @@ -474,7 +263,7 @@ class HsmTests(OESelftestTestCase): | |||
| 474 | softhsm2_command = 'softhsm2-util --show-slots' | 263 | softhsm2_command = 'softhsm2-util --show-slots' |
| 475 | stdout, stderr, retcode = self.qemu_command(softhsm2_command) | 264 | stdout, stderr, retcode = self.qemu_command(softhsm2_command) |
| 476 | self.assertNotEqual(retcode, 0, 'softhsm2-tool succeeded before initialization: ' + | 265 | self.assertNotEqual(retcode, 0, 'softhsm2-tool succeeded before initialization: ' + |
| 477 | stdout.decode() + stderr.decode()) | 266 | stdout.decode() + stderr.decode()) |
| 478 | 267 | ||
| 479 | # Run aktualizr-cert-provider. | 268 | # Run aktualizr-cert-provider. |
| 480 | bb_vars = get_bb_vars(['SOTA_PACKED_CREDENTIALS'], 'aktualizr-native') | 269 | bb_vars = get_bb_vars(['SOTA_PACKED_CREDENTIALS'], 'aktualizr-native') |
| @@ -521,13 +310,6 @@ class HsmTests(OESelftestTestCase): | |||
| 521 | 310 | ||
| 522 | 311 | ||
| 523 | class SecondaryTests(OESelftestTestCase): | 312 | class SecondaryTests(OESelftestTestCase): |
| 524 | @classmethod | ||
| 525 | def setUpClass(cls): | ||
| 526 | super(SecondaryTests, cls).setUpClass() | ||
| 527 | logger = logging.getLogger("selftest") | ||
| 528 | logger.info('Running bitbake to build secondary-image') | ||
| 529 | bitbake('secondary-image') | ||
| 530 | |||
| 531 | def setUpLocal(self): | 313 | def setUpLocal(self): |
| 532 | layer = "meta-updater-qemux86-64" | 314 | layer = "meta-updater-qemux86-64" |
| 533 | result = runCmd('bitbake-layers show-layers') | 315 | result = runCmd('bitbake-layers show-layers') |
| @@ -566,13 +348,6 @@ class SecondaryTests(OESelftestTestCase): | |||
| 566 | 348 | ||
| 567 | 349 | ||
| 568 | class PrimaryTests(OESelftestTestCase): | 350 | class PrimaryTests(OESelftestTestCase): |
| 569 | @classmethod | ||
| 570 | def setUpClass(cls): | ||
| 571 | super(PrimaryTests, cls).setUpClass() | ||
| 572 | logger = logging.getLogger("selftest") | ||
| 573 | logger.info('Running bitbake to build primary-image') | ||
| 574 | bitbake('primary-image') | ||
| 575 | |||
| 576 | def setUpLocal(self): | 351 | def setUpLocal(self): |
| 577 | layer = "meta-updater-qemux86-64" | 352 | layer = "meta-updater-qemux86-64" |
| 578 | result = runCmd('bitbake-layers show-layers') | 353 | result = runCmd('bitbake-layers show-layers') |
| @@ -606,99 +381,48 @@ class PrimaryTests(OESelftestTestCase): | |||
| 606 | self.assertEqual(stderr, b'', 'Error: ' + stderr.decode()) | 381 | self.assertEqual(stderr, b'', 'Error: ' + stderr.decode()) |
| 607 | 382 | ||
| 608 | 383 | ||
| 609 | def qemu_launch(efi=False, machine=None, imagename=None): | 384 | class ResourceControlTests(OESelftestTestCase): |
| 610 | logger = logging.getLogger("selftest") | 385 | def setUpLocal(self): |
| 611 | logger.info('Running bitbake to build core-image-minimal') | 386 | layer = "meta-updater-qemux86-64" |
| 612 | bitbake('core-image-minimal') | 387 | result = runCmd('bitbake-layers show-layers') |
| 613 | # Create empty object. | 388 | if re.search(layer, result.output) is None: |
| 614 | args = type('', (), {})() | 389 | # Assume the directory layout for finding other layers. We could also |
| 615 | if imagename: | 390 | # make assumptions by using 'show-layers', but either way, if the |
| 616 | args.imagename = imagename | 391 | # layers we need aren't where we expect them, we are out of luck. |
| 617 | else: | 392 | path = os.path.abspath(os.path.dirname(__file__)) |
| 618 | args.imagename = 'core-image-minimal' | 393 | metadir = path + "/../../../../../" |
| 619 | args.mac = None | 394 | self.meta_qemu = metadir + layer |
| 620 | # Could use DEPLOY_DIR_IMAGE here but it's already in the machine | 395 | runCmd('bitbake-layers add-layer "%s"' % self.meta_qemu) |
| 621 | # subdirectory. | 396 | else: |
| 622 | args.dir = 'tmp/deploy/images' | 397 | self.meta_qemu = None |
| 623 | args.efi = efi | 398 | self.append_config('MACHINE = "qemux86-64"') |
| 624 | args.machine = machine | 399 | self.append_config('SOTA_CLIENT_PROV = " aktualizr-auto-prov "') |
| 625 | qemu_use_kvm = get_bb_var("QEMU_USE_KVM") | 400 | self.append_config('IMAGE_INSTALL_append += " aktualizr-resource-control "') |
| 626 | if qemu_use_kvm and \ | 401 | self.append_config('RESOURCE_CPU_WEIGHT_pn-aktualizr = "1000"') |
| 627 | (qemu_use_kvm == 'True' and 'x86' in machine or \ | 402 | self.append_config('RESOURCE_MEMORY_HIGH_pn-aktualizr = "50M"') |
| 628 | get_bb_var('MACHINE') in qemu_use_kvm.split()): | 403 | self.append_config('RESOURCE_MEMORY_MAX_pn-aktualizr = "1M"') |
| 629 | args.kvm = True | 404 | self.qemu, self.s = qemu_launch(machine='qemux86-64') |
| 630 | else: | 405 | |
| 631 | args.kvm = None # Autodetect | 406 | def tearDownLocal(self): |
| 632 | args.no_gui = True | 407 | qemu_terminate(self.s) |
| 633 | args.gdb = False | 408 | if self.meta_qemu: |
| 634 | args.pcap = None | 409 | runCmd('bitbake-layers remove-layer "%s"' % self.meta_qemu, ignore_status=True) |
| 635 | args.overlay = None | 410 | |
| 636 | args.dry_run = False | 411 | def qemu_command(self, command): |
| 637 | args.secondary_network = False | 412 | return qemu_send_command(self.qemu.ssh_port, command) |
| 638 | 413 | ||
| 639 | qemu = QemuCommand(args) | 414 | def test_aktualizr_resource_control(self): |
| 640 | cmdline = qemu.command_line() | 415 | print('Checking aktualizr was killed') |
| 641 | print('Booting image with run-qemu-ota...') | 416 | stdout, stderr, retcode = self.qemu_command('systemctl --no-pager show aktualizr') |
| 642 | s = subprocess.Popen(cmdline) | 417 | self.assertIn(b'CPUWeight=1000', stdout, 'CPUWeight was not set correctly') |
| 643 | sleep(10) | 418 | self.assertIn(b'MemoryHigh=52428800', stdout, 'MemoryHigh was not set correctly') |
| 644 | return qemu, s | 419 | self.assertIn(b'MemoryMax=1048576', stdout, 'MemoryMax was not set correctly') |
| 645 | 420 | self.assertIn(b'ExecMainStatus=9', stdout, 'Aktualizr was not killed') | |
| 646 | 421 | ||
| 647 | def qemu_terminate(s): | 422 | self.qemu_command('systemctl --runtime set-property aktualizr MemoryMax=') |
| 648 | try: | 423 | self.qemu_command('systemctl restart aktualizr') |
| 649 | s.terminate() | ||
| 650 | except KeyboardInterrupt: | ||
| 651 | pass | ||
| 652 | |||
| 653 | |||
| 654 | def qemu_send_command(port, command): | ||
| 655 | command = ['ssh -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@localhost -p ' + | ||
| 656 | str(port) + ' "' + command + '"'] | ||
| 657 | s2 = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | ||
| 658 | stdout, stderr = s2.communicate(timeout=60) | ||
| 659 | return stdout, stderr, s2.returncode | ||
| 660 | |||
| 661 | |||
| 662 | def akt_native_run(testInst, cmd, **kwargs): | ||
| 663 | # run a command supplied by aktualizr-native and checks that: | ||
| 664 | # - the executable exists | ||
| 665 | # - the command runs without error | ||
| 666 | # NOTE: the base test class must have built aktualizr-native (in | ||
| 667 | # setUpClass, for example) | ||
| 668 | bb_vars = get_bb_vars(['SYSROOT_DESTDIR', 'base_prefix', 'libdir', 'bindir'], | ||
| 669 | 'aktualizr-native') | ||
| 670 | sysroot = bb_vars['SYSROOT_DESTDIR'] + bb_vars['base_prefix'] | ||
| 671 | sysrootbin = bb_vars['SYSROOT_DESTDIR'] + bb_vars['bindir'] | ||
| 672 | libdir = bb_vars['libdir'] | ||
| 673 | |||
| 674 | program, *_ = cmd.split(' ') | ||
| 675 | p = '{}/{}'.format(sysrootbin, program) | ||
| 676 | testInst.assertTrue(os.path.isfile(p), msg="No {} found ({})".format(program, p)) | ||
| 677 | env = dict(os.environ) | ||
| 678 | env['LD_LIBRARY_PATH'] = libdir | ||
| 679 | result = runCmd(cmd, env=env, native_sysroot=sysroot, ignore_status=True, **kwargs) | ||
| 680 | testInst.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output) | ||
| 681 | |||
| 682 | |||
| 683 | def verifyProvisioned(testInst, machine): | ||
| 684 | # Verify that device HAS provisioned. | ||
| 685 | ran_ok = False | ||
| 686 | for delay in [5, 5, 5, 5, 10, 10, 10, 10]: | ||
| 687 | stdout, stderr, retcode = testInst.qemu_command('aktualizr-info') | ||
| 688 | if retcode == 0 and stderr == b'' and stdout.decode().find('Fetched metadata: yes') >= 0: | ||
| 689 | ran_ok = True | ||
| 690 | break | ||
| 691 | sleep(delay) | ||
| 692 | testInst.assertIn(b'Device ID: ', stdout, 'Provisioning failed: ' + stderr.decode() + stdout.decode()) | ||
| 693 | testInst.assertIn(b'Primary ecu hardware ID: ' + machine.encode(), stdout, | ||
| 694 | 'Provisioning failed: ' + stderr.decode() + stdout.decode()) | ||
| 695 | testInst.assertIn(b'Fetched metadata: yes', stdout, 'Provisioning failed: ' + stderr.decode() + stdout.decode()) | ||
| 696 | p = re.compile(r'Device ID: ([a-z0-9-]*)\n') | ||
| 697 | m = p.search(stdout.decode()) | ||
| 698 | testInst.assertTrue(m, 'Device ID could not be read: ' + stderr.decode() + stdout.decode()) | ||
| 699 | testInst.assertGreater(m.lastindex, 0, 'Device ID could not be read: ' + stderr.decode() + stdout.decode()) | ||
| 700 | logger = logging.getLogger("selftest") | ||
| 701 | logger.info('Device successfully provisioned with ID: ' + m.group(1)) | ||
| 702 | 424 | ||
| 425 | stdout, stderr, retcode = self.qemu_command('systemctl --no-pager show --property=ExecMainStatus aktualizr') | ||
| 426 | self.assertIn(b'ExecMainStatus=0', stdout, 'Aktualizr did not restart') | ||
| 703 | 427 | ||
| 704 | # vim:set ts=4 sw=4 sts=4 expandtab: | 428 | # vim:set ts=4 sw=4 sts=4 expandtab: |
diff --git a/lib/oeqa/selftest/cases/updater_raspberrypi.py b/lib/oeqa/selftest/cases/updater_raspberrypi.py new file mode 100644 index 0000000..bb7cfa3 --- /dev/null +++ b/lib/oeqa/selftest/cases/updater_raspberrypi.py | |||
| @@ -0,0 +1,78 @@ | |||
| 1 | # pylint: disable=C0111,C0325 | ||
| 2 | import os | ||
| 3 | import logging | ||
| 4 | import re | ||
| 5 | import unittest | ||
| 6 | |||
| 7 | from oeqa.selftest.case import OESelftestTestCase | ||
| 8 | from oeqa.utils.commands import runCmd, bitbake, get_bb_var | ||
| 9 | |||
| 10 | |||
| 11 | class RpiTests(OESelftestTestCase): | ||
| 12 | |||
| 13 | def setUpLocal(self): | ||
| 14 | # Add layers before changing the machine type, otherwise the sanity | ||
| 15 | # checker complains loudly. | ||
| 16 | layer_rpi = "meta-raspberrypi" | ||
| 17 | layer_upd_rpi = "meta-updater-raspberrypi" | ||
| 18 | result = runCmd('bitbake-layers show-layers') | ||
| 19 | # Assume the directory layout for finding other layers. We could also | ||
| 20 | # make assumptions by using 'show-layers', but either way, if the | ||
| 21 | # layers we need aren't where we expect them, we are out of luck. | ||
| 22 | path = os.path.abspath(os.path.dirname(__file__)) | ||
| 23 | metadir = path + "/../../../../../" | ||
| 24 | if re.search(layer_rpi, result.output) is None: | ||
| 25 | self.meta_rpi = metadir + layer_rpi | ||
| 26 | runCmd('bitbake-layers add-layer "%s"' % self.meta_rpi) | ||
| 27 | else: | ||
| 28 | self.meta_rpi = None | ||
| 29 | if re.search(layer_upd_rpi, result.output) is None: | ||
| 30 | self.meta_upd_rpi = metadir + layer_upd_rpi | ||
| 31 | runCmd('bitbake-layers add-layer "%s"' % self.meta_upd_rpi) | ||
| 32 | else: | ||
| 33 | self.meta_upd_rpi = None | ||
| 34 | |||
| 35 | # This is trickier that I would've thought. The fundamental problem is | ||
| 36 | # that the qemu layer changes the u-boot file extension to .rom, but | ||
| 37 | # raspberrypi still expects .bin. To prevent this, the qemu layer must | ||
| 38 | # be temporarily removed if it is present. It has to be removed by name | ||
| 39 | # without the complete path, but to add it back when we are done, we | ||
| 40 | # need the full path. | ||
| 41 | p = re.compile(r'meta-updater-qemux86-64\s*(\S*meta-updater-qemux86-64)\s') | ||
| 42 | m = p.search(result.output) | ||
| 43 | if m and m.lastindex > 0: | ||
| 44 | self.meta_qemu = m.group(1) | ||
| 45 | runCmd('bitbake-layers remove-layer meta-updater-qemux86-64') | ||
| 46 | else: | ||
| 47 | self.meta_qemu = None | ||
| 48 | |||
| 49 | self.append_config('MACHINE = "raspberrypi3"') | ||
| 50 | self.append_config('SOTA_CLIENT_PROV = " aktualizr-auto-prov "') | ||
| 51 | |||
| 52 | def tearDownLocal(self): | ||
| 53 | if self.meta_qemu: | ||
| 54 | runCmd('bitbake-layers add-layer "%s"' % self.meta_qemu, ignore_status=True) | ||
| 55 | if self.meta_upd_rpi: | ||
| 56 | runCmd('bitbake-layers remove-layer "%s"' % self.meta_upd_rpi, ignore_status=True) | ||
| 57 | if self.meta_rpi: | ||
| 58 | runCmd('bitbake-layers remove-layer "%s"' % self.meta_rpi, ignore_status=True) | ||
| 59 | |||
| 60 | def test_build(self): | ||
| 61 | logger = logging.getLogger("selftest") | ||
| 62 | logger.info('Running bitbake to build core-image-minimal') | ||
| 63 | self.append_config('SOTA_CLIENT_PROV = "aktualizr-auto-prov"') | ||
| 64 | bitbake('core-image-minimal') | ||
| 65 | credentials = get_bb_var('SOTA_PACKED_CREDENTIALS') | ||
| 66 | # Skip the test if the variable SOTA_PACKED_CREDENTIALS is not set. | ||
| 67 | if credentials is None: | ||
| 68 | raise unittest.SkipTest("Variable 'SOTA_PACKED_CREDENTIALS' not set.") | ||
| 69 | # Check if the file exists. | ||
| 70 | self.assertTrue(os.path.isfile(credentials), "File %s does not exist" % credentials) | ||
| 71 | deploydir = get_bb_var('DEPLOY_DIR_IMAGE') | ||
| 72 | imagename = get_bb_var('IMAGE_LINK_NAME', 'core-image-minimal') | ||
| 73 | # Check if the credentials are included in the output image. | ||
| 74 | result = runCmd('tar -jtvf %s/%s.tar.bz2 | grep sota_provisioning_credentials.zip' % | ||
| 75 | (deploydir, imagename), ignore_status=True) | ||
| 76 | self.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output) | ||
| 77 | |||
| 78 | # vim:set ts=4 sw=4 sts=4 expandtab: | ||
