diff options
Diffstat (limited to 'lib/oeqa/selftest/cases/updater.py')
| -rw-r--r-- | lib/oeqa/selftest/cases/updater.py | 212 |
1 files changed, 212 insertions, 0 deletions
diff --git a/lib/oeqa/selftest/cases/updater.py b/lib/oeqa/selftest/cases/updater.py new file mode 100644 index 0000000..9264616 --- /dev/null +++ b/lib/oeqa/selftest/cases/updater.py | |||
| @@ -0,0 +1,212 @@ | |||
| 1 | import os | ||
| 2 | import logging | ||
| 3 | import subprocess | ||
| 4 | import time | ||
| 5 | import unittest | ||
| 6 | |||
| 7 | from oeqa.selftest.case import OESelftestTestCase | ||
| 8 | from oeqa.utils.commands import runCmd, bitbake, get_bb_var, get_bb_vars | ||
| 9 | from qemucommand import QemuCommand | ||
| 10 | |||
| 11 | |||
| 12 | class SotaToolsTests(OESelftestTestCase): | ||
| 13 | |||
| 14 | @classmethod | ||
| 15 | def setUpClass(cls): | ||
| 16 | super(SotaToolsTests, cls).setUpClass() | ||
| 17 | logger = logging.getLogger("selftest") | ||
| 18 | logger.info('Running bitbake to build aktualizr-native tools') | ||
| 19 | bitbake('aktualizr-native') | ||
| 20 | |||
| 21 | def test_push_help(self): | ||
| 22 | bb_vars = get_bb_vars(['SYSROOT_DESTDIR', 'bindir'], 'aktualizr-native') | ||
| 23 | p = bb_vars['SYSROOT_DESTDIR'] + bb_vars['bindir'] + "/" + "garage-push" | ||
| 24 | self.assertTrue(os.path.isfile(p), msg = "No garage-push found (%s)" % p) | ||
| 25 | result = runCmd('%s --help' % p, ignore_status=True) | ||
| 26 | self.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output) | ||
| 27 | |||
| 28 | def test_deploy_help(self): | ||
| 29 | bb_vars = get_bb_vars(['SYSROOT_DESTDIR', 'bindir'], 'aktualizr-native') | ||
| 30 | p = bb_vars['SYSROOT_DESTDIR'] + bb_vars['bindir'] + "/" + "garage-deploy" | ||
| 31 | self.assertTrue(os.path.isfile(p), msg = "No garage-deploy found (%s)" % p) | ||
| 32 | result = runCmd('%s --help' % p, ignore_status=True) | ||
| 33 | self.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output) | ||
| 34 | |||
| 35 | def test_garagesign_help(self): | ||
| 36 | bb_vars = get_bb_vars(['SYSROOT_DESTDIR', 'bindir'], 'aktualizr-native') | ||
| 37 | p = bb_vars['SYSROOT_DESTDIR'] + bb_vars['bindir'] + "/" + "garage-sign" | ||
| 38 | self.assertTrue(os.path.isfile(p), msg = "No garage-sign found (%s)" % p) | ||
| 39 | result = runCmd('%s --help' % p, ignore_status=True) | ||
| 40 | self.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output) | ||
| 41 | |||
| 42 | |||
| 43 | class HsmTests(OESelftestTestCase): | ||
| 44 | |||
| 45 | def test_hsm(self): | ||
| 46 | self.write_config('SOTA_CLIENT_FEATURES="hsm"') | ||
| 47 | bitbake('core-image-minimal') | ||
| 48 | |||
| 49 | |||
| 50 | class GeneralTests(OESelftestTestCase): | ||
| 51 | |||
| 52 | def test_feature_sota(self): | ||
| 53 | result = get_bb_var('DISTRO_FEATURES').find('sota') | ||
| 54 | self.assertNotEqual(result, -1, 'Feature "sota" not set at DISTRO_FEATURES'); | ||
| 55 | |||
| 56 | def test_feature_systemd(self): | ||
| 57 | result = get_bb_var('DISTRO_FEATURES').find('systemd') | ||
| 58 | self.assertNotEqual(result, -1, 'Feature "systemd" not set at DISTRO_FEATURES'); | ||
| 59 | |||
| 60 | def test_credentials(self): | ||
| 61 | bitbake('core-image-minimal') | ||
| 62 | credentials = get_bb_var('SOTA_PACKED_CREDENTIALS') | ||
| 63 | # skip the test if the variable SOTA_PACKED_CREDENTIALS is not set | ||
| 64 | if credentials is None: | ||
| 65 | raise unittest.SkipTest("Variable 'SOTA_PACKED_CREDENTIALS' not set.") | ||
| 66 | # Check if the file exists | ||
| 67 | self.assertTrue(os.path.isfile(credentials), "File %s does not exist" % credentials) | ||
| 68 | deploydir = get_bb_var('DEPLOY_DIR_IMAGE') | ||
| 69 | imagename = get_bb_var('IMAGE_LINK_NAME', 'core-image-minimal') | ||
| 70 | # Check if the credentials are included in the output image | ||
| 71 | result = runCmd('tar -jtvf %s/%s.tar.bz2 | grep sota_provisioning_credentials.zip' % (deploydir, imagename), ignore_status=True) | ||
| 72 | self.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output) | ||
| 73 | |||
| 74 | def test_java(self): | ||
| 75 | result = runCmd('which java', ignore_status=True) | ||
| 76 | self.assertEqual(result.status, 0, "Java not found.") | ||
| 77 | |||
| 78 | def test_add_package(self): | ||
| 79 | print('') | ||
| 80 | deploydir = get_bb_var('DEPLOY_DIR_IMAGE') | ||
| 81 | imagename = get_bb_var('IMAGE_LINK_NAME', 'core-image-minimal') | ||
| 82 | image_path = deploydir + '/' + imagename + '.otaimg' | ||
| 83 | logger = logging.getLogger("selftest") | ||
| 84 | |||
| 85 | logger.info('Running bitbake with man in the image package list') | ||
| 86 | self.write_config('IMAGE_INSTALL_append = " man "') | ||
| 87 | bitbake('-c cleanall man') | ||
| 88 | bitbake('core-image-minimal') | ||
| 89 | result = runCmd('oe-pkgdata-util find-path /usr/bin/man') | ||
| 90 | self.assertEqual(result.output, 'man: /usr/bin/man') | ||
| 91 | path1 = os.path.realpath(image_path) | ||
| 92 | size1 = os.path.getsize(path1) | ||
| 93 | logger.info('First image %s has size %i' % (path1, size1)) | ||
| 94 | |||
| 95 | logger.info('Running bitbake without man in the image package list') | ||
| 96 | self.write_config('IMAGE_INSTALL_remove = " man "') | ||
| 97 | bitbake('-c cleanall man') | ||
| 98 | bitbake('core-image-minimal') | ||
| 99 | result = runCmd('oe-pkgdata-util find-path /usr/bin/man', ignore_status=True) | ||
| 100 | self.assertEqual(result.status, 1, "Status different than 1. output: %s" % result.output) | ||
| 101 | self.assertEqual(result.output, 'ERROR: Unable to find any package producing path /usr/bin/man') | ||
| 102 | path2 = os.path.realpath(image_path) | ||
| 103 | size2 = os.path.getsize(path2) | ||
| 104 | logger.info('Second image %s has size %i' % (path2, size2)) | ||
| 105 | self.assertNotEqual(path1, path2, "Image paths are identical; image was not rebuilt.") | ||
| 106 | self.assertNotEqual(size1, size2, "Image sizes are identical; image was not rebuilt.") | ||
| 107 | |||
| 108 | |||
| 109 | class QemuTests(OESelftestTestCase): | ||
| 110 | |||
| 111 | @classmethod | ||
| 112 | def setUpClass(cls): | ||
| 113 | super(QemuTests, cls).setUpClass() | ||
| 114 | cls.qemu, cls.s = qemu_launch(machine='qemux86-64') | ||
| 115 | |||
| 116 | @classmethod | ||
| 117 | def tearDownClass(cls): | ||
| 118 | qemu_terminate(cls.s) | ||
| 119 | |||
| 120 | def test_hostname(self): | ||
| 121 | print('') | ||
| 122 | print('Checking machine name (hostname) of device:') | ||
| 123 | value, err = qemu_send_command(self.qemu.ssh_port, 'hostname') | ||
| 124 | machine = get_bb_var('MACHINE', 'core-image-minimal') | ||
| 125 | self.assertEqual(err, b'', 'Error: ' + err.decode()) | ||
| 126 | # Strip off line ending. | ||
| 127 | value_str = value.decode()[:-1] | ||
| 128 | self.assertEqual(value_str, machine, | ||
| 129 | 'MACHINE does not match hostname: ' + machine + ', ' + value_str) | ||
| 130 | print(value_str) | ||
| 131 | |||
| 132 | def test_var_sota(self): | ||
| 133 | print('') | ||
| 134 | print('Checking contents of /var/sota:') | ||
| 135 | value, err = qemu_send_command(self.qemu.ssh_port, 'ls /var/sota') | ||
| 136 | self.assertEqual(err, b'', 'Error: ' + err.decode()) | ||
| 137 | print(value.decode()) | ||
| 138 | |||
| 139 | |||
| 140 | class GrubTests(OESelftestTestCase): | ||
| 141 | |||
| 142 | def setUpLocal(self): | ||
| 143 | # This is a bit of a hack but I can't see a better option. | ||
| 144 | path = os.path.abspath(os.path.dirname(__file__)) | ||
| 145 | metadir = path + "/../../../../../" | ||
| 146 | grub_config = 'OSTREE_BOOTLOADER = "grub"\nMACHINE = "intel-corei7-64"' | ||
| 147 | self.append_config(grub_config) | ||
| 148 | self.meta_intel = metadir + "meta-intel" | ||
| 149 | self.meta_minnow = metadir + "meta-updater-minnowboard" | ||
| 150 | runCmd('bitbake-layers add-layer "%s"' % self.meta_intel) | ||
| 151 | runCmd('bitbake-layers add-layer "%s"' % self.meta_minnow) | ||
| 152 | self.qemu, self.s = qemu_launch(efi=True, machine='intel-corei7-64') | ||
| 153 | |||
| 154 | def tearDownLocal(self): | ||
| 155 | qemu_terminate(self.s) | ||
| 156 | runCmd('bitbake-layers remove-layer "%s"' % self.meta_intel, ignore_status=True) | ||
| 157 | runCmd('bitbake-layers remove-layer "%s"' % self.meta_minnow, ignore_status=True) | ||
| 158 | |||
| 159 | def test_grub(self): | ||
| 160 | print('') | ||
| 161 | print('Checking machine name (hostname) of device:') | ||
| 162 | value, err = qemu_send_command(self.qemu.ssh_port, 'hostname') | ||
| 163 | machine = get_bb_var('MACHINE', 'core-image-minimal') | ||
| 164 | self.assertEqual(err, b'', 'Error: ' + err.decode()) | ||
| 165 | # Strip off line ending. | ||
| 166 | value_str = value.decode()[:-1] | ||
| 167 | self.assertEqual(value_str, machine, | ||
| 168 | 'MACHINE does not match hostname: ' + machine + ', ' + value_str + | ||
| 169 | '\nIs tianocore ovmf installed?') | ||
| 170 | print(value_str) | ||
| 171 | |||
| 172 | |||
| 173 | def qemu_launch(efi=False, machine=None): | ||
| 174 | logger = logging.getLogger("selftest") | ||
| 175 | logger.info('Running bitbake to build core-image-minimal') | ||
| 176 | bitbake('core-image-minimal') | ||
| 177 | # Create empty object. | ||
| 178 | args = type('', (), {})() | ||
| 179 | args.imagename = 'core-image-minimal' | ||
| 180 | args.mac = None | ||
| 181 | # Could use DEPLOY_DIR_IMAGE here but it's already in the machine | ||
| 182 | # subdirectory. | ||
| 183 | args.dir = 'tmp/deploy/images' | ||
| 184 | args.efi = efi | ||
| 185 | args.machine = machine | ||
| 186 | args.kvm = None # Autodetect | ||
| 187 | args.no_gui = True | ||
| 188 | args.gdb = False | ||
| 189 | args.pcap = None | ||
| 190 | args.overlay = None | ||
| 191 | args.dry_run = False | ||
| 192 | |||
| 193 | qemu = QemuCommand(args) | ||
| 194 | cmdline = qemu.command_line() | ||
| 195 | print('Booting image with run-qemu-ota...') | ||
| 196 | s = subprocess.Popen(cmdline) | ||
| 197 | time.sleep(10) | ||
| 198 | return qemu, s | ||
| 199 | |||
| 200 | def qemu_terminate(s): | ||
| 201 | try: | ||
| 202 | s.terminate() | ||
| 203 | except KeyboardInterrupt: | ||
| 204 | pass | ||
| 205 | |||
| 206 | def qemu_send_command(port, command): | ||
| 207 | command = ['ssh -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@localhost -p ' + | ||
| 208 | str(port) + ' "' + command + '"'] | ||
| 209 | s2 = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | ||
| 210 | value, err = s2.communicate() | ||
| 211 | return value, err | ||
| 212 | |||
