summaryrefslogtreecommitdiffstats
path: root/lib/oeqa/selftest/updater.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/oeqa/selftest/updater.py')
-rw-r--r--lib/oeqa/selftest/updater.py147
1 files changed, 147 insertions, 0 deletions
diff --git a/lib/oeqa/selftest/updater.py b/lib/oeqa/selftest/updater.py
new file mode 100644
index 0000000..2723b4a
--- /dev/null
+++ b/lib/oeqa/selftest/updater.py
@@ -0,0 +1,147 @@
1import unittest
2import os
3import logging
4import subprocess
5import time
6
7from oeqa.selftest.base import oeSelfTest
8from oeqa.utils.commands import runCmd, bitbake, get_bb_var, get_bb_vars
9from oeqa.selftest.qemucommand import QemuCommand
10
11
12class 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
35class 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
51class 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
58class GeneralTests(oeSelfTest):
59
60 def test_feature_sota(self):
61 result = get_bb_var('DISTRO_FEATURES').find('sota')
62 self.assertNotEqual(result, -1, 'Feature "sota" not set at DISTRO_FEATURES');
63
64 def test_feature_systemd(self):
65 result = get_bb_var('DISTRO_FEATURES').find('systemd')
66 self.assertNotEqual(result, -1, 'Feature "systemd" not set at DISTRO_FEATURES');
67
68 def test_credentials(self):
69 bitbake('core-image-minimal')
70 credentials = get_bb_var('SOTA_PACKED_CREDENTIALS')
71 # skip the test if the variable SOTA_PACKED_CREDENTIALS is not set
72 if credentials is None:
73 raise unittest.SkipTest("Variable 'SOTA_PACKED_CREDENTIALS' not set.")
74 # Check if the file exists
75 self.assertTrue(os.path.isfile(credentials), "File %s does not exist" % credentials)
76 deploydir = get_bb_var('DEPLOY_DIR_IMAGE')
77 imagename = get_bb_var('IMAGE_LINK_NAME', 'core-image-minimal')
78 # Check if the credentials are included in the output image
79 result = runCmd('tar -jtvf %s/%s.tar.bz2 | grep sota_provisioning_credentials.zip' % (deploydir, imagename), ignore_status=True)
80 self.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output)
81
82 def test_java(self):
83 result = runCmd('which java', ignore_status=True)
84 self.assertEqual(result.status, 0, "Java not found.")
85
86 def test_add_package(self):
87 print('')
88 deploydir = get_bb_var('DEPLOY_DIR_IMAGE')
89 imagename = get_bb_var('IMAGE_LINK_NAME', 'core-image-minimal')
90 image_path = deploydir + '/' + imagename + '.otaimg'
91 logger = logging.getLogger("selftest")
92
93 logger.info('Running bitbake with man in the image package list')
94 self.write_config('IMAGE_INSTALL_append = " man "')
95 bitbake('-c cleanall man')
96 bitbake('core-image-minimal')
97 result = runCmd('oe-pkgdata-util find-path /usr/bin/man')
98 self.assertEqual(result.output, 'man: /usr/bin/man')
99 path1 = os.path.realpath(image_path)
100 size1 = os.path.getsize(path1)
101 logger.info('First image %s has size %i' % (path1, size1))
102
103 logger.info('Running bitbake without man in the image package list')
104 self.write_config('IMAGE_INSTALL_remove = " man "')
105 bitbake('-c cleanall man')
106 bitbake('core-image-minimal')
107 result = runCmd('oe-pkgdata-util find-path /usr/bin/man', ignore_status=True)
108 self.assertEqual(result.status, 1, "Status different than 1. output: %s" % result.output)
109 self.assertEqual(result.output, 'ERROR: Unable to find any package producing path /usr/bin/man')
110 path2 = os.path.realpath(image_path)
111 size2 = os.path.getsize(path2)
112 logger.info('Second image %s has size %i' % (path2, size2))
113 self.assertNotEqual(path1, path2, "Image paths are identical; image was not rebuilt.")
114 self.assertNotEqual(size1, size2, "Image sizes are identical; image was not rebuilt.")
115
116 def test_qemu(self):
117 print('')
118 # Create empty object.
119 args = type('', (), {})()
120 args.imagename = 'core-image-minimal'
121 args.mac = None
122 # Could use DEPLOY_DIR_IMAGE here but it's already in the machine
123 # subdirectory.
124 args.dir = 'tmp/deploy/images'
125 args.efi = False
126 args.machine = None
127 args.kvm = None # Autodetect
128 args.no_gui = True
129 args.gdb = False
130 args.pcap = None
131 args.overlay = None
132 args.dry_run = False
133
134 qemu_command = QemuCommand(args)
135 cmdline = qemu_command.command_line()
136 print('Booting image with run-qemu-ota...')
137 s = subprocess.Popen(cmdline)
138 time.sleep(10)
139 print('Machine name (hostname) of device is:')
140 ssh_cmd = ['ssh', '-q', '-o', 'UserKnownHostsFile=/dev/null', '-o', 'StrictHostKeyChecking=no', 'root@localhost', '-p', str(qemu_command.ssh_port), 'hostname']
141 s2 = subprocess.Popen(ssh_cmd)
142 time.sleep(5)
143 try:
144 s.terminate()
145 except KeyboardInterrupt:
146 pass
147