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