diff options
| author | cajun-rat <phil@advancedtelematic.com> | 2017-11-15 17:38:11 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-11-15 17:38:11 +0100 |
| commit | f64cbdb8deadacbece998636b7d3bc83e7ac2ec9 (patch) | |
| tree | 364c02213fe9d16bdadc24d0e531e137eff1165b /lib | |
| parent | 71410bd31ec76e55247807551e68a2061e277b08 (diff) | |
| parent | 9411b6039661f50832779d021f3d47b2d8516634 (diff) | |
| download | meta-updater-f64cbdb8deadacbece998636b7d3bc83e7ac2ec9.tar.gz | |
Merge pull request #174 from advancedtelematic/feat/PRO-4199/oe-selftest-sota-tools
Feat/pro 4199/oe selftest sota tools
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/oeqa/selftest/garage_push.py | 42 | ||||
| l--------- | lib/oeqa/selftest/qemucommand.py | 1 | ||||
| -rw-r--r-- | lib/oeqa/selftest/updater.py | 125 |
3 files changed, 126 insertions, 42 deletions
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') | ||
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 new file mode 100644 index 0000000..6339e6e --- /dev/null +++ b/lib/oeqa/selftest/updater.py | |||
| @@ -0,0 +1,125 @@ | |||
| 1 | import unittest | ||
| 2 | import os | ||
| 3 | import logging | ||
| 4 | import subprocess | ||
| 5 | import time | ||
| 6 | |||
| 7 | from oeqa.selftest.base import oeSelfTest | ||
| 8 | from oeqa.utils.commands import runCmd, bitbake, get_bb_var, get_bb_vars | ||
| 9 | from oeqa.selftest.qemucommand import QemuCommand | ||
| 10 | |||
| 11 | |||
| 12 | class SotaToolsTests(oeSelfTest): | ||
| 13 | |||
| 14 | @classmethod | ||
| 15 | def setUpClass(cls): | ||
| 16 | logger = logging.getLogger("selftest") | ||
| 17 | logger.info('Running bitbake to build aktualizr-native tools') | ||
| 18 | bitbake('aktualizr-native') | ||
| 19 | |||
| 20 | def test_push_help(self): | ||
| 21 | bb_vars = get_bb_vars(['SYSROOT_DESTDIR', 'bindir'], 'aktualizr-native') | ||
| 22 | p = bb_vars['SYSROOT_DESTDIR'] + bb_vars['bindir'] + "/" + "garage-push" | ||
| 23 | self.assertTrue(os.path.isfile(p), msg = "No garage-push found (%s)" % p) | ||
| 24 | result = runCmd('%s --help' % p, ignore_status=True) | ||
| 25 | self.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output) | ||
| 26 | |||
| 27 | def test_deploy_help(self): | ||
| 28 | bb_vars = get_bb_vars(['SYSROOT_DESTDIR', 'bindir'], 'aktualizr-native') | ||
| 29 | p = bb_vars['SYSROOT_DESTDIR'] + bb_vars['bindir'] + "/" + "garage-deploy" | ||
| 30 | self.assertTrue(os.path.isfile(p), msg = "No garage-deploy found (%s)" % p) | ||
| 31 | result = runCmd('%s --help' % p, ignore_status=True) | ||
| 32 | self.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output) | ||
| 33 | |||
| 34 | |||
| 35 | class GarageSignTests(oeSelfTest): | ||
| 36 | |||
| 37 | @classmethod | ||
| 38 | def setUpClass(cls): | ||
| 39 | logger = logging.getLogger("selftest") | ||
| 40 | logger.info('Running bitbake to build garage-sign-native') | ||
| 41 | bitbake('garage-sign-native') | ||
| 42 | |||
| 43 | def test_help(self): | ||
| 44 | bb_vars = get_bb_vars(['SYSROOT_DESTDIR', 'bindir'], 'garage-sign-native') | ||
| 45 | p = bb_vars['SYSROOT_DESTDIR'] + bb_vars['bindir'] + "/" + "garage-sign" | ||
| 46 | self.assertTrue(os.path.isfile(p), msg = "No garage-sign found (%s)" % p) | ||
| 47 | result = runCmd('%s --help' % p, ignore_status=True) | ||
| 48 | self.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output) | ||
| 49 | |||
| 50 | |||
| 51 | class HsmTests(oeSelfTest): | ||
| 52 | |||
| 53 | def test_hsm(self): | ||
| 54 | self.write_config('SOTA_CLIENT_FEATURES="hsm hsm-test"') | ||
| 55 | bitbake('core-image-minimal') | ||
| 56 | |||
| 57 | |||
| 58 | class GeneralTests(oeSelfTest): | ||
| 59 | |||
| 60 | def test_java(self): | ||
| 61 | result = runCmd('which java', ignore_status=True) | ||
| 62 | self.assertEqual(result.status, 0, "Java not found.") | ||
| 63 | |||
| 64 | def test_add_package(self): | ||
| 65 | print('') | ||
| 66 | deploydir = get_bb_var('DEPLOY_DIR_IMAGE') | ||
| 67 | imagename = get_bb_var('IMAGE_LINK_NAME', 'core-image-minimal') | ||
| 68 | image_path = deploydir + '/' + imagename + '.otaimg' | ||
| 69 | logger = logging.getLogger("selftest") | ||
| 70 | |||
| 71 | logger.info('Running bitbake with man in the image package list') | ||
| 72 | self.write_config('IMAGE_INSTALL_append = " man "') | ||
| 73 | bitbake('-c cleanall man') | ||
| 74 | bitbake('core-image-minimal') | ||
| 75 | result = runCmd('oe-pkgdata-util find-path /usr/bin/man') | ||
| 76 | self.assertEqual(result.output, 'man: /usr/bin/man') | ||
| 77 | path1 = os.path.realpath(image_path) | ||
| 78 | size1 = os.path.getsize(path1) | ||
| 79 | logger.info('First image %s has size %i' % (path1, size1)) | ||
| 80 | |||
| 81 | logger.info('Running bitbake without man in the image package list') | ||
| 82 | self.write_config('IMAGE_INSTALL_remove = " man "') | ||
| 83 | bitbake('-c cleanall man') | ||
| 84 | bitbake('core-image-minimal') | ||
| 85 | result = runCmd('oe-pkgdata-util find-path /usr/bin/man', ignore_status=True) | ||
| 86 | self.assertEqual(result.status, 1, "Status different than 1. output: %s" % result.output) | ||
| 87 | self.assertEqual(result.output, 'ERROR: Unable to find any package producing path /usr/bin/man') | ||
| 88 | path2 = os.path.realpath(image_path) | ||
| 89 | size2 = os.path.getsize(path2) | ||
| 90 | logger.info('Second image %s has size %i' % (path2, size2)) | ||
| 91 | self.assertNotEqual(path1, path2, "Image paths are identical; image was not rebuilt.") | ||
| 92 | self.assertNotEqual(size1, size2, "Image sizes are identical; image was not rebuilt.") | ||
| 93 | |||
| 94 | def test_qemu(self): | ||
| 95 | print('') | ||
| 96 | # Create empty object. | ||
| 97 | args = type('', (), {})() | ||
| 98 | args.imagename = 'core-image-minimal' | ||
| 99 | args.mac = None | ||
| 100 | # Could use DEPLOY_DIR_IMAGE her but it's already in the machine | ||
| 101 | # subdirectory. | ||
| 102 | args.dir = 'tmp/deploy/images' | ||
| 103 | args.efi = False | ||
| 104 | args.machine = None | ||
| 105 | args.no_kvm = False | ||
| 106 | args.no_gui = True | ||
| 107 | args.gdb = False | ||
| 108 | args.pcap = None | ||
| 109 | args.overlay = None | ||
| 110 | args.dry_run = False | ||
| 111 | |||
| 112 | qemu_command = QemuCommand(args) | ||
| 113 | cmdline = qemu_command.command_line() | ||
| 114 | print('Booting image with run-qemu-ota...') | ||
| 115 | s = subprocess.Popen(cmdline) | ||
| 116 | time.sleep(10) | ||
| 117 | print('Machine name (hostname) of device is:') | ||
| 118 | ssh_cmd = ['ssh', '-q', '-o', 'UserKnownHostsFile=/dev/null', '-o', 'StrictHostKeyChecking=no', 'root@localhost', '-p', str(qemu_command.ssh_port), 'hostname'] | ||
| 119 | s2 = subprocess.Popen(ssh_cmd) | ||
| 120 | time.sleep(5) | ||
| 121 | try: | ||
| 122 | s.terminate() | ||
| 123 | except KeyboardInterrupt: | ||
| 124 | pass | ||
| 125 | |||
