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