diff options
Diffstat (limited to 'lib/oeqa/selftest')
-rw-r--r-- | lib/oeqa/selftest/cases/testutils.py | 128 | ||||
-rw-r--r-- | lib/oeqa/selftest/cases/updater_minnowboard.py | 60 | ||||
-rw-r--r-- | lib/oeqa/selftest/cases/updater_native.py | 43 | ||||
-rw-r--r-- | lib/oeqa/selftest/cases/updater_qemux86_64.py (renamed from lib/oeqa/selftest/cases/updater.py) | 392 | ||||
-rw-r--r-- | lib/oeqa/selftest/cases/updater_qemux86_64_ptest.py | 52 | ||||
-rw-r--r-- | lib/oeqa/selftest/cases/updater_raspberrypi.py | 86 |
6 files changed, 426 insertions, 335 deletions
diff --git a/lib/oeqa/selftest/cases/testutils.py b/lib/oeqa/selftest/cases/testutils.py new file mode 100644 index 0000000..2ad99ad --- /dev/null +++ b/lib/oeqa/selftest/cases/testutils.py | |||
@@ -0,0 +1,128 @@ | |||
1 | import os | ||
2 | import logging | ||
3 | import re | ||
4 | import subprocess | ||
5 | from time import sleep | ||
6 | |||
7 | from oeqa.utils.commands import runCmd, bitbake, get_bb_var, get_bb_vars | ||
8 | from qemucommand import QemuCommand | ||
9 | |||
10 | |||
11 | def qemu_launch(efi=False, machine=None, imagename=None): | ||
12 | logger = logging.getLogger("selftest") | ||
13 | if imagename is None: | ||
14 | imagename = 'core-image-minimal' | ||
15 | logger.info('Running bitbake to build {}'.format(imagename)) | ||
16 | bitbake(imagename) | ||
17 | # Create empty object. | ||
18 | args = type('', (), {})() | ||
19 | args.imagename = imagename | ||
20 | args.mac = None | ||
21 | # Could use DEPLOY_DIR_IMAGE here but it's already in the machine | ||
22 | # subdirectory. | ||
23 | args.dir = 'tmp/deploy/images' | ||
24 | args.efi = efi | ||
25 | args.machine = machine | ||
26 | qemu_use_kvm = get_bb_var("QEMU_USE_KVM") | ||
27 | if qemu_use_kvm and \ | ||
28 | (qemu_use_kvm == 'True' and 'x86' in machine or | ||
29 | get_bb_var('MACHINE') in qemu_use_kvm.split()): | ||
30 | args.kvm = True | ||
31 | else: | ||
32 | args.kvm = None # Autodetect | ||
33 | args.no_gui = True | ||
34 | args.gdb = False | ||
35 | args.pcap = None | ||
36 | args.overlay = None | ||
37 | args.dry_run = False | ||
38 | args.secondary_network = False | ||
39 | |||
40 | qemu = QemuCommand(args) | ||
41 | cmdline = qemu.command_line() | ||
42 | print('Booting image with run-qemu-ota...') | ||
43 | s = subprocess.Popen(cmdline) | ||
44 | sleep(10) | ||
45 | return qemu, s | ||
46 | |||
47 | |||
48 | def qemu_terminate(s): | ||
49 | try: | ||
50 | s.terminate() | ||
51 | except KeyboardInterrupt: | ||
52 | pass | ||
53 | |||
54 | |||
55 | def qemu_send_command(port, command, timeout=60): | ||
56 | command = ['ssh -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@localhost -p ' + | ||
57 | str(port) + ' "' + command + '"'] | ||
58 | s2 = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | ||
59 | stdout, stderr = s2.communicate(timeout=timeout) | ||
60 | return stdout, stderr, s2.returncode | ||
61 | |||
62 | |||
63 | def akt_native_run(testInst, cmd, **kwargs): | ||
64 | # run a command supplied by aktualizr-native and checks that: | ||
65 | # - the executable exists | ||
66 | # - the command runs without error | ||
67 | # NOTE: the base test class must have built aktualizr-native (in | ||
68 | # setUpClass, for example) | ||
69 | bb_vars = get_bb_vars(['SYSROOT_DESTDIR', 'base_prefix', 'libdir', 'bindir'], | ||
70 | 'aktualizr-native') | ||
71 | sysroot = bb_vars['SYSROOT_DESTDIR'] + bb_vars['base_prefix'] | ||
72 | sysrootbin = bb_vars['SYSROOT_DESTDIR'] + bb_vars['bindir'] | ||
73 | libdir = bb_vars['libdir'] | ||
74 | |||
75 | program, *_ = cmd.split(' ') | ||
76 | p = '{}/{}'.format(sysrootbin, program) | ||
77 | testInst.assertTrue(os.path.isfile(p), msg="No {} found ({})".format(program, p)) | ||
78 | env = dict(os.environ) | ||
79 | env['LD_LIBRARY_PATH'] = libdir | ||
80 | result = runCmd(cmd, env=env, native_sysroot=sysroot, ignore_status=True, **kwargs) | ||
81 | testInst.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output) | ||
82 | |||
83 | |||
84 | def verifyNotProvisioned(testInst, machine): | ||
85 | print('Checking output of aktualizr-info:') | ||
86 | ran_ok = False | ||
87 | for delay in [5, 5, 5, 5, 10, 10, 10, 10]: | ||
88 | stdout, stderr, retcode = testInst.qemu_command('aktualizr-info') | ||
89 | if retcode == 0 and stderr == b'': | ||
90 | ran_ok = True | ||
91 | break | ||
92 | sleep(delay) | ||
93 | testInst.assertTrue(ran_ok, 'aktualizr-info failed: ' + stderr.decode() + stdout.decode()) | ||
94 | |||
95 | # Verify that device has NOT yet provisioned. | ||
96 | testInst.assertIn(b'Couldn\'t load device ID', stdout, | ||
97 | 'Device already provisioned!? ' + stderr.decode() + stdout.decode()) | ||
98 | testInst.assertIn(b'Couldn\'t load ECU serials', stdout, | ||
99 | 'Device already provisioned!? ' + stderr.decode() + stdout.decode()) | ||
100 | testInst.assertIn(b'Provisioned on server: no', stdout, | ||
101 | 'Device already provisioned!? ' + stderr.decode() + stdout.decode()) | ||
102 | testInst.assertIn(b'Fetched metadata: no', stdout, | ||
103 | 'Device already provisioned!? ' + stderr.decode() + stdout.decode()) | ||
104 | |||
105 | |||
106 | def verifyProvisioned(testInst, machine): | ||
107 | # Verify that device HAS provisioned. | ||
108 | ran_ok = False | ||
109 | for delay in [5, 5, 5, 5, 10, 10, 10, 10]: | ||
110 | stdout, stderr, retcode = testInst.qemu_command('aktualizr-info') | ||
111 | if retcode == 0 and stderr == b'' and stdout.decode().find('Fetched metadata: yes') >= 0: | ||
112 | ran_ok = True | ||
113 | break | ||
114 | sleep(delay) | ||
115 | testInst.assertTrue(ran_ok, 'aktualizr-info failed: ' + stderr.decode() + stdout.decode()) | ||
116 | |||
117 | testInst.assertIn(b'Device ID: ', stdout, 'Provisioning failed: ' + stderr.decode() + stdout.decode()) | ||
118 | testInst.assertIn(b'Primary ecu hardware ID: ' + machine.encode(), stdout, | ||
119 | 'Provisioning failed: ' + stderr.decode() + stdout.decode()) | ||
120 | testInst.assertIn(b'Fetched metadata: yes', stdout, 'Provisioning failed: ' + stderr.decode() + stdout.decode()) | ||
121 | p = re.compile(r'Device ID: ([a-z0-9-]*)\n') | ||
122 | m = p.search(stdout.decode()) | ||
123 | testInst.assertTrue(m, 'Device ID could not be read: ' + stderr.decode() + stdout.decode()) | ||
124 | testInst.assertGreater(m.lastindex, 0, 'Device ID could not be read: ' + stderr.decode() + stdout.decode()) | ||
125 | logger = logging.getLogger("selftest") | ||
126 | logger.info('Device successfully provisioned with ID: ' + m.group(1)) | ||
127 | |||
128 | # vim:set ts=4 sw=4 sts=4 expandtab: | ||
diff --git a/lib/oeqa/selftest/cases/updater_minnowboard.py b/lib/oeqa/selftest/cases/updater_minnowboard.py new file mode 100644 index 0000000..f5df584 --- /dev/null +++ b/lib/oeqa/selftest/cases/updater_minnowboard.py | |||
@@ -0,0 +1,60 @@ | |||
1 | import os | ||
2 | import re | ||
3 | |||
4 | from oeqa.selftest.case import OESelftestTestCase | ||
5 | from oeqa.utils.commands import runCmd, get_bb_var | ||
6 | from testutils import qemu_launch, qemu_send_command, qemu_terminate, verifyProvisioned | ||
7 | |||
8 | |||
9 | class MinnowTests(OESelftestTestCase): | ||
10 | |||
11 | def setUpLocal(self): | ||
12 | layer_intel = "meta-intel" | ||
13 | layer_minnow = "meta-updater-minnowboard" | ||
14 | result = runCmd('bitbake-layers show-layers') | ||
15 | # Assume the directory layout for finding other layers. We could also | ||
16 | # make assumptions by using 'show-layers', but either way, if the | ||
17 | # layers we need aren't where we expect them, we are out of luck. | ||
18 | path = os.path.abspath(os.path.dirname(__file__)) | ||
19 | metadir = path + "/../../../../../" | ||
20 | if re.search(layer_intel, result.output) is None: | ||
21 | self.meta_intel = metadir + layer_intel | ||
22 | runCmd('bitbake-layers add-layer "%s"' % self.meta_intel) | ||
23 | else: | ||
24 | self.meta_intel = None | ||
25 | if re.search(layer_minnow, result.output) is None: | ||
26 | self.meta_minnow = metadir + layer_minnow | ||
27 | runCmd('bitbake-layers add-layer "%s"' % self.meta_minnow) | ||
28 | else: | ||
29 | self.meta_minnow = None | ||
30 | self.append_config('MACHINE = "intel-corei7-64"') | ||
31 | self.append_config('OSTREE_BOOTLOADER = "grub"') | ||
32 | self.append_config('SOTA_CLIENT_PROV = " aktualizr-auto-prov "') | ||
33 | self.qemu, self.s = qemu_launch(efi=True, machine='intel-corei7-64') | ||
34 | |||
35 | def tearDownLocal(self): | ||
36 | qemu_terminate(self.s) | ||
37 | if self.meta_intel: | ||
38 | runCmd('bitbake-layers remove-layer "%s"' % self.meta_intel, ignore_status=True) | ||
39 | if self.meta_minnow: | ||
40 | runCmd('bitbake-layers remove-layer "%s"' % self.meta_minnow, ignore_status=True) | ||
41 | |||
42 | def qemu_command(self, command): | ||
43 | return qemu_send_command(self.qemu.ssh_port, command) | ||
44 | |||
45 | def test_provisioning(self): | ||
46 | print('Checking machine name (hostname) of device:') | ||
47 | stdout, stderr, retcode = self.qemu_command('hostname') | ||
48 | self.assertEqual(retcode, 0, "Unable to check hostname. " + | ||
49 | "Is an ssh daemon (such as dropbear or openssh) installed on the device?") | ||
50 | machine = get_bb_var('MACHINE', 'core-image-minimal') | ||
51 | self.assertEqual(stderr, b'', 'Error: ' + stderr.decode()) | ||
52 | # Strip off line ending. | ||
53 | value = stdout.decode()[:-1] | ||
54 | self.assertEqual(value, machine, | ||
55 | 'MACHINE does not match hostname: ' + machine + ', ' + value + | ||
56 | '\nIs TianoCore ovmf installed on your host machine?') | ||
57 | |||
58 | verifyProvisioned(self, machine) | ||
59 | |||
60 | # vim:set ts=4 sw=4 sts=4 expandtab: | ||
diff --git a/lib/oeqa/selftest/cases/updater_native.py b/lib/oeqa/selftest/cases/updater_native.py new file mode 100644 index 0000000..de98a09 --- /dev/null +++ b/lib/oeqa/selftest/cases/updater_native.py | |||
@@ -0,0 +1,43 @@ | |||
1 | # pylint: disable=C0111,C0325 | ||
2 | import logging | ||
3 | |||
4 | from oeqa.selftest.case import OESelftestTestCase | ||
5 | from oeqa.utils.commands import runCmd, bitbake, get_bb_var | ||
6 | from testutils import akt_native_run | ||
7 | |||
8 | |||
9 | class SotaToolsTests(OESelftestTestCase): | ||
10 | |||
11 | @classmethod | ||
12 | def setUpClass(cls): | ||
13 | super(SotaToolsTests, cls).setUpClass() | ||
14 | logger = logging.getLogger("selftest") | ||
15 | logger.info('Running bitbake to build aktualizr-native tools') | ||
16 | bitbake('aktualizr-native') | ||
17 | |||
18 | def test_push_help(self): | ||
19 | akt_native_run(self, 'garage-push --help') | ||
20 | |||
21 | def test_deploy_help(self): | ||
22 | akt_native_run(self, 'garage-deploy --help') | ||
23 | |||
24 | def test_garagesign_help(self): | ||
25 | akt_native_run(self, 'garage-sign --help') | ||
26 | |||
27 | |||
28 | class GeneralTests(OESelftestTestCase): | ||
29 | |||
30 | def test_feature_sota(self): | ||
31 | result = get_bb_var('DISTRO_FEATURES').find('sota') | ||
32 | self.assertNotEqual(result, -1, 'Feature "sota" not set at DISTRO_FEATURES') | ||
33 | |||
34 | def test_feature_systemd(self): | ||
35 | result = get_bb_var('DISTRO_FEATURES').find('systemd') | ||
36 | self.assertNotEqual(result, -1, 'Feature "systemd" not set at DISTRO_FEATURES') | ||
37 | |||
38 | def test_java(self): | ||
39 | result = runCmd('which java', ignore_status=True) | ||
40 | self.assertEqual(result.status, 0, | ||
41 | "Java not found. Do you have a JDK installed on your host machine?") | ||
42 | |||
43 | # vim:set ts=4 sw=4 sts=4 expandtab: | ||
diff --git a/lib/oeqa/selftest/cases/updater.py b/lib/oeqa/selftest/cases/updater_qemux86_64.py index 008ba4b..9f32bcf 100644 --- a/lib/oeqa/selftest/cases/updater.py +++ b/lib/oeqa/selftest/cases/updater_qemux86_64.py | |||
@@ -2,44 +2,16 @@ | |||
2 | import os | 2 | import os |
3 | import logging | 3 | import logging |
4 | import re | 4 | import re |
5 | import subprocess | ||
6 | import unittest | 5 | import unittest |
7 | from time import sleep | 6 | from time import sleep |
8 | 7 | ||
9 | from oeqa.selftest.case import OESelftestTestCase | 8 | from oeqa.selftest.case import OESelftestTestCase |
10 | from oeqa.utils.commands import runCmd, bitbake, get_bb_var, get_bb_vars | 9 | from oeqa.utils.commands import runCmd, bitbake, get_bb_var, get_bb_vars |
11 | from qemucommand import QemuCommand | 10 | from testutils import qemu_launch, qemu_send_command, qemu_terminate, \ |
12 | 11 | akt_native_run, verifyNotProvisioned, verifyProvisioned | |
13 | |||
14 | class SotaToolsTests(OESelftestTestCase): | ||
15 | |||
16 | @classmethod | ||
17 | def setUpClass(cls): | ||
18 | super(SotaToolsTests, cls).setUpClass() | ||
19 | logger = logging.getLogger("selftest") | ||
20 | logger.info('Running bitbake to build aktualizr-native tools') | ||
21 | bitbake('aktualizr-native') | ||
22 | |||
23 | def test_push_help(self): | ||
24 | akt_native_run(self, 'garage-push --help') | ||
25 | |||
26 | def test_deploy_help(self): | ||
27 | akt_native_run(self, 'garage-deploy --help') | ||
28 | |||
29 | def test_garagesign_help(self): | ||
30 | akt_native_run(self, 'garage-sign --help') | ||
31 | 12 | ||
32 | 13 | ||
33 | class GeneralTests(OESelftestTestCase): | 14 | class GeneralTests(OESelftestTestCase): |
34 | |||
35 | def test_feature_sota(self): | ||
36 | result = get_bb_var('DISTRO_FEATURES').find('sota') | ||
37 | self.assertNotEqual(result, -1, 'Feature "sota" not set at DISTRO_FEATURES') | ||
38 | |||
39 | def test_feature_systemd(self): | ||
40 | result = get_bb_var('DISTRO_FEATURES').find('systemd') | ||
41 | self.assertNotEqual(result, -1, 'Feature "systemd" not set at DISTRO_FEATURES') | ||
42 | |||
43 | def test_credentials(self): | 15 | def test_credentials(self): |
44 | logger = logging.getLogger("selftest") | 16 | logger = logging.getLogger("selftest") |
45 | logger.info('Running bitbake to build core-image-minimal') | 17 | logger.info('Running bitbake to build core-image-minimal') |
@@ -58,11 +30,6 @@ class GeneralTests(OESelftestTestCase): | |||
58 | (deploydir, imagename), ignore_status=True) | 30 | (deploydir, imagename), ignore_status=True) |
59 | self.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output) | 31 | self.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output) |
60 | 32 | ||
61 | def test_java(self): | ||
62 | result = runCmd('which java', ignore_status=True) | ||
63 | self.assertEqual(result.status, 0, | ||
64 | "Java not found. Do you have a JDK installed on your host machine?") | ||
65 | |||
66 | 33 | ||
67 | class AktualizrToolsTests(OESelftestTestCase): | 34 | class AktualizrToolsTests(OESelftestTestCase): |
68 | 35 | ||
@@ -139,16 +106,6 @@ class AutoProvTests(OESelftestTestCase): | |||
139 | value = stdout.decode()[:-1] | 106 | value = stdout.decode()[:-1] |
140 | self.assertEqual(value, machine, | 107 | self.assertEqual(value, machine, |
141 | 'MACHINE does not match hostname: ' + machine + ', ' + value) | 108 | 'MACHINE does not match hostname: ' + machine + ', ' + value) |
142 | print(value) | ||
143 | print('Checking output of aktualizr-info:') | ||
144 | ran_ok = False | ||
145 | for delay in [1, 2, 5, 10, 15]: | ||
146 | stdout, stderr, retcode = self.qemu_command('aktualizr-info') | ||
147 | if retcode == 0 and stderr == b'': | ||
148 | ran_ok = True | ||
149 | break | ||
150 | sleep(delay) | ||
151 | self.assertTrue(ran_ok, 'aktualizr-info failed: ' + stderr.decode() + stdout.decode()) | ||
152 | 109 | ||
153 | verifyProvisioned(self, machine) | 110 | verifyProvisioned(self, machine) |
154 | 111 | ||
@@ -187,7 +144,7 @@ class ManualControlTests(OESelftestTestCase): | |||
187 | """ | 144 | """ |
188 | sleep(20) | 145 | sleep(20) |
189 | stdout, stderr, retcode = self.qemu_command('aktualizr-info') | 146 | stdout, stderr, retcode = self.qemu_command('aktualizr-info') |
190 | self.assertIn(b'Can\'t open database', stdout, | 147 | self.assertIn(b'Can\'t open database', stderr, |
191 | 'Aktualizr should not have run yet' + stderr.decode() + stdout.decode()) | 148 | 'Aktualizr should not have run yet' + stderr.decode() + stdout.decode()) |
192 | 149 | ||
193 | stdout, stderr, retcode = self.qemu_command('aktualizr once') | 150 | stdout, stderr, retcode = self.qemu_command('aktualizr once') |
@@ -197,144 +154,6 @@ class ManualControlTests(OESelftestTestCase): | |||
197 | 'Aktualizr should have run' + stderr.decode() + stdout.decode()) | 154 | 'Aktualizr should have run' + stderr.decode() + stdout.decode()) |
198 | 155 | ||
199 | 156 | ||
200 | class RpiTests(OESelftestTestCase): | ||
201 | |||
202 | def setUpLocal(self): | ||
203 | # Add layers before changing the machine type, otherwise the sanity | ||
204 | # checker complains loudly. | ||
205 | layer_python = "meta-openembedded/meta-python" | ||
206 | layer_rpi = "meta-raspberrypi" | ||
207 | layer_upd_rpi = "meta-updater-raspberrypi" | ||
208 | result = runCmd('bitbake-layers show-layers') | ||
209 | # Assume the directory layout for finding other layers. We could also | ||
210 | # make assumptions by using 'show-layers', but either way, if the | ||
211 | # layers we need aren't where we expect them, we are out of luck. | ||
212 | path = os.path.abspath(os.path.dirname(__file__)) | ||
213 | metadir = path + "/../../../../../" | ||
214 | if re.search(layer_python, result.output) is None: | ||
215 | self.meta_python = metadir + layer_python | ||
216 | runCmd('bitbake-layers add-layer "%s"' % self.meta_python) | ||
217 | else: | ||
218 | self.meta_python = None | ||
219 | if re.search(layer_rpi, result.output) is None: | ||
220 | self.meta_rpi = metadir + layer_rpi | ||
221 | runCmd('bitbake-layers add-layer "%s"' % self.meta_rpi) | ||
222 | else: | ||
223 | self.meta_rpi = None | ||
224 | if re.search(layer_upd_rpi, result.output) is None: | ||
225 | self.meta_upd_rpi = metadir + layer_upd_rpi | ||
226 | runCmd('bitbake-layers add-layer "%s"' % self.meta_upd_rpi) | ||
227 | else: | ||
228 | self.meta_upd_rpi = None | ||
229 | |||
230 | # This is trickier that I would've thought. The fundamental problem is | ||
231 | # that the qemu layer changes the u-boot file extension to .rom, but | ||
232 | # raspberrypi still expects .bin. To prevent this, the qemu layer must | ||
233 | # be temporarily removed if it is present. It has to be removed by name | ||
234 | # without the complete path, but to add it back when we are done, we | ||
235 | # need the full path. | ||
236 | p = re.compile(r'meta-updater-qemux86-64\s*(\S*meta-updater-qemux86-64)\s') | ||
237 | m = p.search(result.output) | ||
238 | if m and m.lastindex > 0: | ||
239 | self.meta_qemu = m.group(1) | ||
240 | runCmd('bitbake-layers remove-layer meta-updater-qemux86-64') | ||
241 | else: | ||
242 | self.meta_qemu = None | ||
243 | |||
244 | self.append_config('MACHINE = "raspberrypi3"') | ||
245 | self.append_config('SOTA_CLIENT_PROV = " aktualizr-auto-prov "') | ||
246 | |||
247 | def tearDownLocal(self): | ||
248 | if self.meta_qemu: | ||
249 | runCmd('bitbake-layers add-layer "%s"' % self.meta_qemu, ignore_status=True) | ||
250 | if self.meta_upd_rpi: | ||
251 | runCmd('bitbake-layers remove-layer "%s"' % self.meta_upd_rpi, ignore_status=True) | ||
252 | if self.meta_rpi: | ||
253 | runCmd('bitbake-layers remove-layer "%s"' % self.meta_rpi, ignore_status=True) | ||
254 | if self.meta_python: | ||
255 | runCmd('bitbake-layers remove-layer "%s"' % self.meta_python, ignore_status=True) | ||
256 | |||
257 | def test_rpi(self): | ||
258 | logger = logging.getLogger("selftest") | ||
259 | logger.info('Running bitbake to build core-image-minimal') | ||
260 | self.append_config('SOTA_CLIENT_PROV = "aktualizr-auto-prov"') | ||
261 | bitbake('core-image-minimal') | ||
262 | credentials = get_bb_var('SOTA_PACKED_CREDENTIALS') | ||
263 | # Skip the test if the variable SOTA_PACKED_CREDENTIALS is not set. | ||
264 | if credentials is None: | ||
265 | raise unittest.SkipTest("Variable 'SOTA_PACKED_CREDENTIALS' not set.") | ||
266 | # Check if the file exists. | ||
267 | self.assertTrue(os.path.isfile(credentials), "File %s does not exist" % credentials) | ||
268 | deploydir = get_bb_var('DEPLOY_DIR_IMAGE') | ||
269 | imagename = get_bb_var('IMAGE_LINK_NAME', 'core-image-minimal') | ||
270 | # Check if the credentials are included in the output image. | ||
271 | result = runCmd('tar -jtvf %s/%s.tar.bz2 | grep sota_provisioning_credentials.zip' % | ||
272 | (deploydir, imagename), ignore_status=True) | ||
273 | self.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output) | ||
274 | |||
275 | |||
276 | class GrubTests(OESelftestTestCase): | ||
277 | |||
278 | def setUpLocal(self): | ||
279 | layer_intel = "meta-intel" | ||
280 | layer_minnow = "meta-updater-minnowboard" | ||
281 | result = runCmd('bitbake-layers show-layers') | ||
282 | # Assume the directory layout for finding other layers. We could also | ||
283 | # make assumptions by using 'show-layers', but either way, if the | ||
284 | # layers we need aren't where we expect them, we are out of luck. | ||
285 | path = os.path.abspath(os.path.dirname(__file__)) | ||
286 | metadir = path + "/../../../../../" | ||
287 | if re.search(layer_intel, result.output) is None: | ||
288 | self.meta_intel = metadir + layer_intel | ||
289 | runCmd('bitbake-layers add-layer "%s"' % self.meta_intel) | ||
290 | else: | ||
291 | self.meta_intel = None | ||
292 | if re.search(layer_minnow, result.output) is None: | ||
293 | self.meta_minnow = metadir + layer_minnow | ||
294 | runCmd('bitbake-layers add-layer "%s"' % self.meta_minnow) | ||
295 | else: | ||
296 | self.meta_minnow = None | ||
297 | self.append_config('MACHINE = "intel-corei7-64"') | ||
298 | self.append_config('OSTREE_BOOTLOADER = "grub"') | ||
299 | self.append_config('SOTA_CLIENT_PROV = " aktualizr-auto-prov "') | ||
300 | self.qemu, self.s = qemu_launch(efi=True, machine='intel-corei7-64') | ||
301 | |||
302 | def tearDownLocal(self): | ||
303 | qemu_terminate(self.s) | ||
304 | if self.meta_intel: | ||
305 | runCmd('bitbake-layers remove-layer "%s"' % self.meta_intel, ignore_status=True) | ||
306 | if self.meta_minnow: | ||
307 | runCmd('bitbake-layers remove-layer "%s"' % self.meta_minnow, ignore_status=True) | ||
308 | |||
309 | def qemu_command(self, command): | ||
310 | return qemu_send_command(self.qemu.ssh_port, command) | ||
311 | |||
312 | def test_grub(self): | ||
313 | print('Checking machine name (hostname) of device:') | ||
314 | stdout, stderr, retcode = self.qemu_command('hostname') | ||
315 | self.assertEqual(retcode, 0, "Unable to check hostname. " + | ||
316 | "Is an ssh daemon (such as dropbear or openssh) installed on the device?") | ||
317 | machine = get_bb_var('MACHINE', 'core-image-minimal') | ||
318 | self.assertEqual(stderr, b'', 'Error: ' + stderr.decode()) | ||
319 | # Strip off line ending. | ||
320 | value = stdout.decode()[:-1] | ||
321 | self.assertEqual(value, machine, | ||
322 | 'MACHINE does not match hostname: ' + machine + ', ' + value + | ||
323 | '\nIs TianoCore ovmf installed on your host machine?') | ||
324 | print(value) | ||
325 | print('Checking output of aktualizr-info:') | ||
326 | ran_ok = False | ||
327 | for delay in [1, 2, 5, 10, 15]: | ||
328 | stdout, stderr, retcode = self.qemu_command('aktualizr-info') | ||
329 | if retcode == 0 and stderr == b'': | ||
330 | ran_ok = True | ||
331 | break | ||
332 | sleep(delay) | ||
333 | self.assertTrue(ran_ok, 'aktualizr-info failed: ' + stderr.decode() + stdout.decode()) | ||
334 | |||
335 | verifyProvisioned(self, machine) | ||
336 | |||
337 | |||
338 | class ImplProvTests(OESelftestTestCase): | 157 | class ImplProvTests(OESelftestTestCase): |
339 | 158 | ||
340 | def setUpLocal(self): | 159 | def setUpLocal(self): |
@@ -375,25 +194,8 @@ class ImplProvTests(OESelftestTestCase): | |||
375 | value = stdout.decode()[:-1] | 194 | value = stdout.decode()[:-1] |
376 | self.assertEqual(value, machine, | 195 | self.assertEqual(value, machine, |
377 | 'MACHINE does not match hostname: ' + machine + ', ' + value) | 196 | 'MACHINE does not match hostname: ' + machine + ', ' + value) |
378 | print(value) | 197 | |
379 | print('Checking output of aktualizr-info:') | 198 | verifyNotProvisioned(self, machine) |
380 | ran_ok = False | ||
381 | for delay in [1, 2, 5, 10, 15]: | ||
382 | stdout, stderr, retcode = self.qemu_command('aktualizr-info') | ||
383 | if retcode == 0 and stderr == b'': | ||
384 | ran_ok = True | ||
385 | break | ||
386 | sleep(delay) | ||
387 | self.assertTrue(ran_ok, 'aktualizr-info failed: ' + stderr.decode() + stdout.decode()) | ||
388 | # Verify that device has NOT yet provisioned. | ||
389 | self.assertIn(b'Couldn\'t load device ID', stdout, | ||
390 | 'Device already provisioned!? ' + stderr.decode() + stdout.decode()) | ||
391 | self.assertIn(b'Couldn\'t load ECU serials', stdout, | ||
392 | 'Device already provisioned!? ' + stderr.decode() + stdout.decode()) | ||
393 | self.assertIn(b'Provisioned on server: no', stdout, | ||
394 | 'Device already provisioned!? ' + stderr.decode() + stdout.decode()) | ||
395 | self.assertIn(b'Fetched metadata: no', stdout, | ||
396 | 'Device already provisioned!? ' + stderr.decode() + stdout.decode()) | ||
397 | 199 | ||
398 | # Run aktualizr-cert-provider. | 200 | # Run aktualizr-cert-provider. |
399 | bb_vars = get_bb_vars(['SOTA_PACKED_CREDENTIALS'], 'aktualizr-native') | 201 | bb_vars = get_bb_vars(['SOTA_PACKED_CREDENTIALS'], 'aktualizr-native') |
@@ -450,25 +252,8 @@ class HsmTests(OESelftestTestCase): | |||
450 | value = stdout.decode()[:-1] | 252 | value = stdout.decode()[:-1] |
451 | self.assertEqual(value, machine, | 253 | self.assertEqual(value, machine, |
452 | 'MACHINE does not match hostname: ' + machine + ', ' + value) | 254 | 'MACHINE does not match hostname: ' + machine + ', ' + value) |
453 | print(value) | 255 | |
454 | print('Checking output of aktualizr-info:') | 256 | verifyNotProvisioned(self, machine) |
455 | ran_ok = False | ||
456 | for delay in [1, 2, 5, 10, 15]: | ||
457 | stdout, stderr, retcode = self.qemu_command('aktualizr-info') | ||
458 | if retcode == 0 and stderr == b'': | ||
459 | ran_ok = True | ||
460 | break | ||
461 | sleep(delay) | ||
462 | self.assertTrue(ran_ok, 'aktualizr-info failed: ' + stderr.decode() + stdout.decode()) | ||
463 | # Verify that device has NOT yet provisioned. | ||
464 | self.assertIn(b'Couldn\'t load device ID', stdout, | ||
465 | 'Device already provisioned!? ' + stderr.decode() + stdout.decode()) | ||
466 | self.assertIn(b'Couldn\'t load ECU serials', stdout, | ||
467 | 'Device already provisioned!? ' + stderr.decode() + stdout.decode()) | ||
468 | self.assertIn(b'Provisioned on server: no', stdout, | ||
469 | 'Device already provisioned!? ' + stderr.decode() + stdout.decode()) | ||
470 | self.assertIn(b'Fetched metadata: no', stdout, | ||
471 | 'Device already provisioned!? ' + stderr.decode() + stdout.decode()) | ||
472 | 257 | ||
473 | # Verify that HSM is not yet initialized. | 258 | # Verify that HSM is not yet initialized. |
474 | pkcs11_command = 'pkcs11-tool --module=/usr/lib/softhsm/libsofthsm2.so -O' | 259 | pkcs11_command = 'pkcs11-tool --module=/usr/lib/softhsm/libsofthsm2.so -O' |
@@ -478,7 +263,7 @@ class HsmTests(OESelftestTestCase): | |||
478 | softhsm2_command = 'softhsm2-util --show-slots' | 263 | softhsm2_command = 'softhsm2-util --show-slots' |
479 | stdout, stderr, retcode = self.qemu_command(softhsm2_command) | 264 | stdout, stderr, retcode = self.qemu_command(softhsm2_command) |
480 | self.assertNotEqual(retcode, 0, 'softhsm2-tool succeeded before initialization: ' + | 265 | self.assertNotEqual(retcode, 0, 'softhsm2-tool succeeded before initialization: ' + |
481 | stdout.decode() + stderr.decode()) | 266 | stdout.decode() + stderr.decode()) |
482 | 267 | ||
483 | # Run aktualizr-cert-provider. | 268 | # Run aktualizr-cert-provider. |
484 | bb_vars = get_bb_vars(['SOTA_PACKED_CREDENTIALS'], 'aktualizr-native') | 269 | bb_vars = get_bb_vars(['SOTA_PACKED_CREDENTIALS'], 'aktualizr-native') |
@@ -525,13 +310,6 @@ class HsmTests(OESelftestTestCase): | |||
525 | 310 | ||
526 | 311 | ||
527 | class SecondaryTests(OESelftestTestCase): | 312 | class SecondaryTests(OESelftestTestCase): |
528 | @classmethod | ||
529 | def setUpClass(cls): | ||
530 | super(SecondaryTests, cls).setUpClass() | ||
531 | logger = logging.getLogger("selftest") | ||
532 | logger.info('Running bitbake to build secondary-image') | ||
533 | bitbake('secondary-image') | ||
534 | |||
535 | def setUpLocal(self): | 313 | def setUpLocal(self): |
536 | layer = "meta-updater-qemux86-64" | 314 | layer = "meta-updater-qemux86-64" |
537 | result = runCmd('bitbake-layers show-layers') | 315 | result = runCmd('bitbake-layers show-layers') |
@@ -563,20 +341,8 @@ class SecondaryTests(OESelftestTestCase): | |||
563 | self.assertEqual(retcode, 0, "Unable to run aktualizr-secondary --help") | 341 | self.assertEqual(retcode, 0, "Unable to run aktualizr-secondary --help") |
564 | self.assertEqual(stderr, b'', 'Error: ' + stderr.decode()) | 342 | self.assertEqual(stderr, b'', 'Error: ' + stderr.decode()) |
565 | 343 | ||
566 | def test_secondary_listening(self): | ||
567 | print('Checking aktualizr-secondary service is listening') | ||
568 | stdout, stderr, retcode = self.qemu_command('aktualizr-check-discovery') | ||
569 | self.assertEqual(retcode, 0, "Unable to connect to secondary") | ||
570 | |||
571 | 344 | ||
572 | class PrimaryTests(OESelftestTestCase): | 345 | class PrimaryTests(OESelftestTestCase): |
573 | @classmethod | ||
574 | def setUpClass(cls): | ||
575 | super(PrimaryTests, cls).setUpClass() | ||
576 | logger = logging.getLogger("selftest") | ||
577 | logger.info('Running bitbake to build primary-image') | ||
578 | bitbake('primary-image') | ||
579 | |||
580 | def setUpLocal(self): | 346 | def setUpLocal(self): |
581 | layer = "meta-updater-qemux86-64" | 347 | layer = "meta-updater-qemux86-64" |
582 | result = runCmd('bitbake-layers show-layers') | 348 | result = runCmd('bitbake-layers show-layers') |
@@ -610,99 +376,55 @@ class PrimaryTests(OESelftestTestCase): | |||
610 | self.assertEqual(stderr, b'', 'Error: ' + stderr.decode()) | 376 | self.assertEqual(stderr, b'', 'Error: ' + stderr.decode()) |
611 | 377 | ||
612 | 378 | ||
613 | def qemu_launch(efi=False, machine=None, imagename=None): | 379 | class ResourceControlTests(OESelftestTestCase): |
614 | logger = logging.getLogger("selftest") | 380 | def setUpLocal(self): |
615 | logger.info('Running bitbake to build core-image-minimal') | 381 | layer = "meta-updater-qemux86-64" |
616 | bitbake('core-image-minimal') | 382 | result = runCmd('bitbake-layers show-layers') |
617 | # Create empty object. | 383 | if re.search(layer, result.output) is None: |
618 | args = type('', (), {})() | 384 | # Assume the directory layout for finding other layers. We could also |
619 | if imagename: | 385 | # make assumptions by using 'show-layers', but either way, if the |
620 | args.imagename = imagename | 386 | # layers we need aren't where we expect them, we are out of luck. |
621 | else: | 387 | path = os.path.abspath(os.path.dirname(__file__)) |
622 | args.imagename = 'core-image-minimal' | 388 | metadir = path + "/../../../../../" |
623 | args.mac = None | 389 | self.meta_qemu = metadir + layer |
624 | # Could use DEPLOY_DIR_IMAGE here but it's already in the machine | 390 | runCmd('bitbake-layers add-layer "%s"' % self.meta_qemu) |
625 | # subdirectory. | 391 | else: |
626 | args.dir = 'tmp/deploy/images' | 392 | self.meta_qemu = None |
627 | args.efi = efi | 393 | self.append_config('MACHINE = "qemux86-64"') |
628 | args.machine = machine | 394 | self.append_config('SOTA_CLIENT_PROV = " aktualizr-auto-prov "') |
629 | qemu_use_kvm = get_bb_var("QEMU_USE_KVM") | 395 | self.append_config('IMAGE_INSTALL_append += " aktualizr-resource-control "') |
630 | if qemu_use_kvm and \ | 396 | self.append_config('RESOURCE_CPU_WEIGHT_pn-aktualizr = "1000"') |
631 | (qemu_use_kvm == 'True' and 'x86' in machine or \ | 397 | self.append_config('RESOURCE_MEMORY_HIGH_pn-aktualizr = "50M"') |
632 | get_bb_var('MACHINE') in qemu_use_kvm.split()): | 398 | self.append_config('RESOURCE_MEMORY_MAX_pn-aktualizr = "1M"') |
633 | args.kvm = True | 399 | self.qemu, self.s = qemu_launch(machine='qemux86-64') |
634 | else: | 400 | |
635 | args.kvm = None # Autodetect | 401 | def tearDownLocal(self): |
636 | args.no_gui = True | 402 | qemu_terminate(self.s) |
637 | args.gdb = False | 403 | if self.meta_qemu: |
638 | args.pcap = None | 404 | runCmd('bitbake-layers remove-layer "%s"' % self.meta_qemu, ignore_status=True) |
639 | args.overlay = None | 405 | |
640 | args.dry_run = False | 406 | def qemu_command(self, command): |
641 | args.secondary_network = False | 407 | return qemu_send_command(self.qemu.ssh_port, command) |
642 | 408 | ||
643 | qemu = QemuCommand(args) | 409 | def test_aktualizr_resource_control(self): |
644 | cmdline = qemu.command_line() | 410 | print('Checking aktualizr was killed') |
645 | print('Booting image with run-qemu-ota...') | 411 | ran_ok = False |
646 | s = subprocess.Popen(cmdline) | 412 | for delay in [5, 5, 5, 5]: |
647 | sleep(10) | 413 | sleep(delay) |
648 | return qemu, s | 414 | stdout, stderr, retcode = self.qemu_command('systemctl --no-pager show aktualizr') |
649 | 415 | if retcode == 0 and b'ExecMainStatus=9' in stdout: | |
650 | 416 | ran_ok = True | |
651 | def qemu_terminate(s): | 417 | break |
652 | try: | 418 | self.assertTrue(ran_ok, 'Aktualizr was not killed') |
653 | s.terminate() | 419 | |
654 | except KeyboardInterrupt: | 420 | self.assertIn(b'CPUWeight=1000', stdout, 'CPUWeight was not set correctly') |
655 | pass | 421 | self.assertIn(b'MemoryHigh=52428800', stdout, 'MemoryHigh was not set correctly') |
656 | 422 | self.assertIn(b'MemoryMax=1048576', stdout, 'MemoryMax was not set correctly') | |
657 | 423 | ||
658 | def qemu_send_command(port, command): | 424 | self.qemu_command('systemctl --runtime set-property aktualizr MemoryMax=') |
659 | command = ['ssh -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@localhost -p ' + | 425 | self.qemu_command('systemctl restart aktualizr') |
660 | str(port) + ' "' + command + '"'] | ||
661 | s2 = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | ||
662 | stdout, stderr = s2.communicate(timeout=60) | ||
663 | return stdout, stderr, s2.returncode | ||
664 | |||
665 | |||
666 | def akt_native_run(testInst, cmd, **kwargs): | ||
667 | # run a command supplied by aktualizr-native and checks that: | ||
668 | # - the executable exists | ||
669 | # - the command runs without error | ||
670 | # NOTE: the base test class must have built aktualizr-native (in | ||
671 | # setUpClass, for example) | ||
672 | bb_vars = get_bb_vars(['SYSROOT_DESTDIR', 'base_prefix', 'libdir', 'bindir'], | ||
673 | 'aktualizr-native') | ||
674 | sysroot = bb_vars['SYSROOT_DESTDIR'] + bb_vars['base_prefix'] | ||
675 | sysrootbin = bb_vars['SYSROOT_DESTDIR'] + bb_vars['bindir'] | ||
676 | libdir = bb_vars['libdir'] | ||
677 | |||
678 | program, *_ = cmd.split(' ') | ||
679 | p = '{}/{}'.format(sysrootbin, program) | ||
680 | testInst.assertTrue(os.path.isfile(p), msg="No {} found ({})".format(program, p)) | ||
681 | env = dict(os.environ) | ||
682 | env['LD_LIBRARY_PATH'] = libdir | ||
683 | result = runCmd(cmd, env=env, native_sysroot=sysroot, ignore_status=True, **kwargs) | ||
684 | testInst.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output) | ||
685 | |||
686 | |||
687 | def verifyProvisioned(testInst, machine): | ||
688 | # Verify that device HAS provisioned. | ||
689 | ran_ok = False | ||
690 | for delay in [5, 5, 5, 5, 10, 10, 10, 10]: | ||
691 | stdout, stderr, retcode = testInst.qemu_command('aktualizr-info') | ||
692 | if retcode == 0 and stderr == b'' and stdout.decode().find('Fetched metadata: yes') >= 0: | ||
693 | ran_ok = True | ||
694 | break | ||
695 | sleep(delay) | ||
696 | testInst.assertIn(b'Device ID: ', stdout, 'Provisioning failed: ' + stderr.decode() + stdout.decode()) | ||
697 | testInst.assertIn(b'Primary ecu hardware ID: ' + machine.encode(), stdout, | ||
698 | 'Provisioning failed: ' + stderr.decode() + stdout.decode()) | ||
699 | testInst.assertIn(b'Fetched metadata: yes', stdout, 'Provisioning failed: ' + stderr.decode() + stdout.decode()) | ||
700 | p = re.compile(r'Device ID: ([a-z0-9-]*)\n') | ||
701 | m = p.search(stdout.decode()) | ||
702 | testInst.assertTrue(m, 'Device ID could not be read: ' + stderr.decode() + stdout.decode()) | ||
703 | testInst.assertGreater(m.lastindex, 0, 'Device ID could not be read: ' + stderr.decode() + stdout.decode()) | ||
704 | logger = logging.getLogger("selftest") | ||
705 | logger.info('Device successfully provisioned with ID: ' + m.group(1)) | ||
706 | 426 | ||
427 | stdout, stderr, retcode = self.qemu_command('systemctl --no-pager show --property=ExecMainStatus aktualizr') | ||
428 | self.assertIn(b'ExecMainStatus=0', stdout, 'Aktualizr did not restart') | ||
707 | 429 | ||
708 | # vim:set ts=4 sw=4 sts=4 expandtab: | 430 | # vim:set ts=4 sw=4 sts=4 expandtab: |
diff --git a/lib/oeqa/selftest/cases/updater_qemux86_64_ptest.py b/lib/oeqa/selftest/cases/updater_qemux86_64_ptest.py new file mode 100644 index 0000000..0f0f491 --- /dev/null +++ b/lib/oeqa/selftest/cases/updater_qemux86_64_ptest.py | |||
@@ -0,0 +1,52 @@ | |||
1 | # pylint: disable=C0111,C0325 | ||
2 | import os | ||
3 | import re | ||
4 | |||
5 | from oeqa.selftest.case import OESelftestTestCase | ||
6 | from oeqa.utils.commands import runCmd | ||
7 | from testutils import qemu_launch, qemu_send_command, qemu_terminate | ||
8 | |||
9 | |||
10 | class PtestTests(OESelftestTestCase): | ||
11 | |||
12 | def setUpLocal(self): | ||
13 | layer = "meta-updater-qemux86-64" | ||
14 | result = runCmd('bitbake-layers show-layers') | ||
15 | if re.search(layer, result.output) is None: | ||
16 | # Assume the directory layout for finding other layers. We could also | ||
17 | # make assumptions by using 'show-layers', but either way, if the | ||
18 | # layers we need aren't where we expect them, we are out of like. | ||
19 | path = os.path.abspath(os.path.dirname(__file__)) | ||
20 | metadir = path + "/../../../../../" | ||
21 | self.meta_qemu = metadir + layer | ||
22 | runCmd('bitbake-layers add-layer "%s"' % self.meta_qemu) | ||
23 | else: | ||
24 | self.meta_qemu = None | ||
25 | self.append_config('MACHINE = "qemux86-64"') | ||
26 | self.append_config('SYSTEMD_AUTO_ENABLE_aktualizr = "disable"') | ||
27 | self.append_config('PTEST_ENABLED_pn-aktualizr = "1"') | ||
28 | self.append_config('IMAGE_INSTALL_append += "aktualizr-ptest ptest-runner "') | ||
29 | self.qemu, self.s = qemu_launch(machine='qemux86-64') | ||
30 | |||
31 | def tearDownLocal(self): | ||
32 | qemu_terminate(self.s) | ||
33 | if self.meta_qemu: | ||
34 | runCmd('bitbake-layers remove-layer "%s"' % self.meta_qemu, ignore_status=True) | ||
35 | |||
36 | def qemu_command(self, command, timeout=60): | ||
37 | return qemu_send_command(self.qemu.ssh_port, command, timeout=timeout) | ||
38 | |||
39 | def test_run_ptests(self): | ||
40 | # simulate a login shell, so that /usr/sbin is in $PATH (from /etc/profile) | ||
41 | stdout, stderr, retcode = self.qemu_command('sh -l -c ptest-runner', timeout=None) | ||
42 | output = stdout.decode() | ||
43 | print(output) | ||
44 | |||
45 | has_failure = re.search('^FAIL', output, flags=re.MULTILINE) is not None | ||
46 | if has_failure: | ||
47 | print("Full test suite log:") | ||
48 | stdout, _, _ = self.qemu_command('cat /tmp/aktualizr-ptest.log || cat /tmp/aktualizr-ptest.log.tmp', timeout=None) | ||
49 | print(stdout.decode()) | ||
50 | |||
51 | self.assertEqual(retcode, 0) | ||
52 | self.assertFalse(has_failure) | ||
diff --git a/lib/oeqa/selftest/cases/updater_raspberrypi.py b/lib/oeqa/selftest/cases/updater_raspberrypi.py new file mode 100644 index 0000000..785d703 --- /dev/null +++ b/lib/oeqa/selftest/cases/updater_raspberrypi.py | |||
@@ -0,0 +1,86 @@ | |||
1 | # pylint: disable=C0111,C0325 | ||
2 | import os | ||
3 | import logging | ||
4 | import re | ||
5 | import unittest | ||
6 | |||
7 | from oeqa.selftest.case import OESelftestTestCase | ||
8 | from oeqa.utils.commands import runCmd, bitbake, get_bb_var | ||
9 | |||
10 | |||
11 | class RpiTests(OESelftestTestCase): | ||
12 | |||
13 | def setUpLocal(self): | ||
14 | # Add layers before changing the machine type, otherwise the sanity | ||
15 | # checker complains loudly. | ||
16 | layer_python = "meta-openembedded/meta-python" | ||
17 | layer_rpi = "meta-raspberrypi" | ||
18 | layer_upd_rpi = "meta-updater-raspberrypi" | ||
19 | result = runCmd('bitbake-layers show-layers') | ||
20 | # Assume the directory layout for finding other layers. We could also | ||
21 | # make assumptions by using 'show-layers', but either way, if the | ||
22 | # layers we need aren't where we expect them, we are out of luck. | ||
23 | path = os.path.abspath(os.path.dirname(__file__)) | ||
24 | metadir = path + "/../../../../../" | ||
25 | if re.search(layer_python, result.output) is None: | ||
26 | self.meta_python = metadir + layer_python | ||
27 | runCmd('bitbake-layers add-layer "%s"' % self.meta_python) | ||
28 | else: | ||
29 | self.meta_python = None | ||
30 | if re.search(layer_rpi, result.output) is None: | ||
31 | self.meta_rpi = metadir + layer_rpi | ||
32 | runCmd('bitbake-layers add-layer "%s"' % self.meta_rpi) | ||
33 | else: | ||
34 | self.meta_rpi = None | ||
35 | if re.search(layer_upd_rpi, result.output) is None: | ||
36 | self.meta_upd_rpi = metadir + layer_upd_rpi | ||
37 | runCmd('bitbake-layers add-layer "%s"' % self.meta_upd_rpi) | ||
38 | else: | ||
39 | self.meta_upd_rpi = None | ||
40 | |||
41 | # This is trickier that I would've thought. The fundamental problem is | ||
42 | # that the qemu layer changes the u-boot file extension to .rom, but | ||
43 | # raspberrypi still expects .bin. To prevent this, the qemu layer must | ||
44 | # be temporarily removed if it is present. It has to be removed by name | ||
45 | # without the complete path, but to add it back when we are done, we | ||
46 | # need the full path. | ||
47 | p = re.compile(r'meta-updater-qemux86-64\s*(\S*meta-updater-qemux86-64)\s') | ||
48 | m = p.search(result.output) | ||
49 | if m and m.lastindex > 0: | ||
50 | self.meta_qemu = m.group(1) | ||
51 | runCmd('bitbake-layers remove-layer meta-updater-qemux86-64') | ||
52 | else: | ||
53 | self.meta_qemu = None | ||
54 | |||
55 | self.append_config('MACHINE = "raspberrypi3"') | ||
56 | self.append_config('SOTA_CLIENT_PROV = " aktualizr-auto-prov "') | ||
57 | |||
58 | def tearDownLocal(self): | ||
59 | if self.meta_qemu: | ||
60 | runCmd('bitbake-layers add-layer "%s"' % self.meta_qemu, ignore_status=True) | ||
61 | if self.meta_upd_rpi: | ||
62 | runCmd('bitbake-layers remove-layer "%s"' % self.meta_upd_rpi, ignore_status=True) | ||
63 | if self.meta_rpi: | ||
64 | runCmd('bitbake-layers remove-layer "%s"' % self.meta_rpi, ignore_status=True) | ||
65 | if self.meta_python: | ||
66 | runCmd('bitbake-layers remove-layer "%s"' % self.meta_python, ignore_status=True) | ||
67 | |||
68 | def test_build(self): | ||
69 | logger = logging.getLogger("selftest") | ||
70 | logger.info('Running bitbake to build core-image-minimal') | ||
71 | self.append_config('SOTA_CLIENT_PROV = "aktualizr-auto-prov"') | ||
72 | bitbake('core-image-minimal') | ||
73 | credentials = get_bb_var('SOTA_PACKED_CREDENTIALS') | ||
74 | # Skip the test if the variable SOTA_PACKED_CREDENTIALS is not set. | ||
75 | if credentials is None: | ||
76 | raise unittest.SkipTest("Variable 'SOTA_PACKED_CREDENTIALS' not set.") | ||
77 | # Check if the file exists. | ||
78 | self.assertTrue(os.path.isfile(credentials), "File %s does not exist" % credentials) | ||
79 | deploydir = get_bb_var('DEPLOY_DIR_IMAGE') | ||
80 | imagename = get_bb_var('IMAGE_LINK_NAME', 'core-image-minimal') | ||
81 | # Check if the credentials are included in the output image. | ||
82 | result = runCmd('tar -jtvf %s/%s.tar.bz2 | grep sota_provisioning_credentials.zip' % | ||
83 | (deploydir, imagename), ignore_status=True) | ||
84 | self.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output) | ||
85 | |||
86 | # vim:set ts=4 sw=4 sts=4 expandtab: | ||