summaryrefslogtreecommitdiffstats
path: root/lib/oeqa
diff options
context:
space:
mode:
authorLaurent Bonnans <laurent.bonnans@here.com>2019-03-19 16:45:34 +0100
committerPatrick Vacek <patrickvacek@gmail.com>2019-04-29 09:35:51 +0200
commitbe0725efaf8d9f9b22eb625cfd657ac720b9d690 (patch)
tree04464a4aa5eb309f14d8b062764838dbd4a8f4af /lib/oeqa
parentef25c1a1cb851a5dd8f7743a55c86a95087ed27a (diff)
downloadmeta-updater-be0725efaf8d9f9b22eb625cfd657ac720b9d690.tar.gz
Split oe-selftests by target machines
To allow for more targeted testing Signed-off-by: Laurent Bonnans <laurent.bonnans@here.com>
Diffstat (limited to 'lib/oeqa')
-rw-r--r--lib/oeqa/selftest/cases/testutils.py103
-rw-r--r--lib/oeqa/selftest/cases/updater_minnowboard.py71
-rw-r--r--lib/oeqa/selftest/cases/updater_native.py47
-rw-r--r--lib/oeqa/selftest/cases/updater_qemux86_64.py (renamed from lib/oeqa/selftest/cases/updater.py)277
-rw-r--r--lib/oeqa/selftest/cases/updater_raspberrypi.py86
5 files changed, 310 insertions, 274 deletions
diff --git a/lib/oeqa/selftest/cases/testutils.py b/lib/oeqa/selftest/cases/testutils.py
new file mode 100644
index 0000000..77bcad7
--- /dev/null
+++ b/lib/oeqa/selftest/cases/testutils.py
@@ -0,0 +1,103 @@
1import os
2import logging
3import re
4import subprocess
5from time import sleep
6
7from oeqa.utils.commands import runCmd, bitbake, get_bb_var, get_bb_vars
8from qemucommand import QemuCommand
9
10
11def qemu_launch(efi=False, machine=None, imagename=None):
12 logger = logging.getLogger("selftest")
13 logger.info('Running bitbake to build core-image-minimal')
14 bitbake('core-image-minimal')
15 # Create empty object.
16 args = type('', (), {})()
17 if imagename:
18 args.imagename = imagename
19 else:
20 args.imagename = 'core-image-minimal'
21 args.mac = None
22 # Could use DEPLOY_DIR_IMAGE here but it's already in the machine
23 # subdirectory.
24 args.dir = 'tmp/deploy/images'
25 args.efi = efi
26 args.machine = machine
27 qemu_use_kvm = get_bb_var("QEMU_USE_KVM")
28 if qemu_use_kvm and \
29 (qemu_use_kvm == 'True' and 'x86' in machine or
30 get_bb_var('MACHINE') in qemu_use_kvm.split()):
31 args.kvm = True
32 else:
33 args.kvm = None # Autodetect
34 args.no_gui = True
35 args.gdb = False
36 args.pcap = None
37 args.overlay = None
38 args.dry_run = False
39 args.secondary_network = False
40
41 qemu = QemuCommand(args)
42 cmdline = qemu.command_line()
43 print('Booting image with run-qemu-ota...')
44 s = subprocess.Popen(cmdline)
45 sleep(10)
46 return qemu, s
47
48
49def qemu_terminate(s):
50 try:
51 s.terminate()
52 except KeyboardInterrupt:
53 pass
54
55
56def qemu_send_command(port, command):
57 command = ['ssh -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@localhost -p ' +
58 str(port) + ' "' + command + '"']
59 s2 = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
60 stdout, stderr = s2.communicate(timeout=60)
61 return stdout, stderr, s2.returncode
62
63
64def akt_native_run(testInst, cmd, **kwargs):
65 # run a command supplied by aktualizr-native and checks that:
66 # - the executable exists
67 # - the command runs without error
68 # NOTE: the base test class must have built aktualizr-native (in
69 # setUpClass, for example)
70 bb_vars = get_bb_vars(['SYSROOT_DESTDIR', 'base_prefix', 'libdir', 'bindir'],
71 'aktualizr-native')
72 sysroot = bb_vars['SYSROOT_DESTDIR'] + bb_vars['base_prefix']
73 sysrootbin = bb_vars['SYSROOT_DESTDIR'] + bb_vars['bindir']
74 libdir = bb_vars['libdir']
75
76 program, *_ = cmd.split(' ')
77 p = '{}/{}'.format(sysrootbin, program)
78 testInst.assertTrue(os.path.isfile(p), msg="No {} found ({})".format(program, p))
79 env = dict(os.environ)
80 env['LD_LIBRARY_PATH'] = libdir
81 result = runCmd(cmd, env=env, native_sysroot=sysroot, ignore_status=True, **kwargs)
82 testInst.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output)
83
84
85def verifyProvisioned(testInst, machine):
86 # Verify that device HAS provisioned.
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'' and stdout.decode().find('Fetched metadata: yes') >= 0:
90 break
91 sleep(delay)
92 testInst.assertIn(b'Device ID: ', stdout, 'Provisioning failed: ' + stderr.decode() + stdout.decode())
93 testInst.assertIn(b'Primary ecu hardware ID: ' + machine.encode(), stdout,
94 'Provisioning failed: ' + stderr.decode() + stdout.decode())
95 testInst.assertIn(b'Fetched metadata: yes', stdout, 'Provisioning failed: ' + stderr.decode() + stdout.decode())
96 p = re.compile(r'Device ID: ([a-z0-9-]*)\n')
97 m = p.search(stdout.decode())
98 testInst.assertTrue(m, 'Device ID could not be read: ' + stderr.decode() + stdout.decode())
99 testInst.assertGreater(m.lastindex, 0, 'Device ID could not be read: ' + stderr.decode() + stdout.decode())
100 logger = logging.getLogger("selftest")
101 logger.info('Device successfully provisioned with ID: ' + m.group(1))
102
103# 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..97b2a86
--- /dev/null
+++ b/lib/oeqa/selftest/cases/updater_minnowboard.py
@@ -0,0 +1,71 @@
1import os
2import re
3from time import sleep
4
5from oeqa.selftest.case import OESelftestTestCase
6from oeqa.utils.commands import runCmd, bitbake, get_bb_var
7from testutils import qemu_launch, qemu_send_command, qemu_terminate, verifyProvisioned
8
9
10class MinnowTests(OESelftestTestCase):
11
12 def setUpLocal(self):
13 layer_intel = "meta-intel"
14 layer_minnow = "meta-updater-minnowboard"
15 result = runCmd('bitbake-layers show-layers')
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 luck.
19 path = os.path.abspath(os.path.dirname(__file__))
20 metadir = path + "/../../../../../"
21 if re.search(layer_intel, result.output) is None:
22 self.meta_intel = metadir + layer_intel
23 runCmd('bitbake-layers add-layer "%s"' % self.meta_intel)
24 else:
25 self.meta_intel = None
26 if re.search(layer_minnow, result.output) is None:
27 self.meta_minnow = metadir + layer_minnow
28 runCmd('bitbake-layers add-layer "%s"' % self.meta_minnow)
29 else:
30 self.meta_minnow = None
31 self.append_config('MACHINE = "intel-corei7-64"')
32 self.append_config('OSTREE_BOOTLOADER = "grub"')
33 self.append_config('SOTA_CLIENT_PROV = " aktualizr-auto-prov "')
34 self.qemu, self.s = qemu_launch(efi=True, machine='intel-corei7-64')
35
36 def tearDownLocal(self):
37 qemu_terminate(self.s)
38 if self.meta_intel:
39 runCmd('bitbake-layers remove-layer "%s"' % self.meta_intel, ignore_status=True)
40 if self.meta_minnow:
41 runCmd('bitbake-layers remove-layer "%s"' % self.meta_minnow, ignore_status=True)
42
43 def qemu_command(self, command):
44 return qemu_send_command(self.qemu.ssh_port, command)
45
46 def test_provisioning(self):
47 print('Checking machine name (hostname) of device:')
48 stdout, stderr, retcode = self.qemu_command('hostname')
49 self.assertEqual(retcode, 0, "Unable to check hostname. " +
50 "Is an ssh daemon (such as dropbear or openssh) installed on the device?")
51 machine = get_bb_var('MACHINE', 'core-image-minimal')
52 self.assertEqual(stderr, b'', 'Error: ' + stderr.decode())
53 # Strip off line ending.
54 value = stdout.decode()[:-1]
55 self.assertEqual(value, machine,
56 'MACHINE does not match hostname: ' + machine + ', ' + value +
57 '\nIs TianoCore ovmf installed on your host machine?')
58 print(value)
59 print('Checking output of aktualizr-info:')
60 ran_ok = False
61 for delay in [1, 2, 5, 10, 15]:
62 stdout, stderr, retcode = self.qemu_command('aktualizr-info')
63 if retcode == 0 and stderr == b'':
64 ran_ok = True
65 break
66 sleep(delay)
67 self.assertTrue(ran_ok, 'aktualizr-info failed: ' + stderr.decode() + stdout.decode())
68
69 verifyProvisioned(self, machine)
70
71# 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..1fc9cb8
--- /dev/null
+++ b/lib/oeqa/selftest/cases/updater_native.py
@@ -0,0 +1,47 @@
1# pylint: disable=C0111,C0325
2import logging
3
4from oeqa.selftest.case import OESelftestTestCase
5from oeqa.utils.commands import runCmd, bitbake, get_bb_var
6from testutils import akt_native_run
7
8
9class 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
28class 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_usrmerge(self):
35 result = get_bb_var('DISTRO_FEATURES').find('usrmerge')
36 self.assertNotEqual(result, -1, 'Feature "sota" not set at DISTRO_FEATURES')
37
38 def test_feature_systemd(self):
39 result = get_bb_var('DISTRO_FEATURES').find('systemd')
40 self.assertNotEqual(result, -1, 'Feature "systemd" not set at DISTRO_FEATURES')
41
42 def test_java(self):
43 result = runCmd('which java', ignore_status=True)
44 self.assertEqual(result.status, 0,
45 "Java not found. Do you have a JDK installed on your host machine?")
46
47# 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 a09a594..9310841 100644
--- a/lib/oeqa/selftest/cases/updater.py
+++ b/lib/oeqa/selftest/cases/updater_qemux86_64.py
@@ -2,48 +2,16 @@
2import os 2import os
3import logging 3import logging
4import re 4import re
5import subprocess
6import unittest 5import unittest
7from time import sleep 6from time import sleep
8 7
9from oeqa.selftest.case import OESelftestTestCase 8from oeqa.selftest.case import OESelftestTestCase
10from oeqa.utils.commands import runCmd, bitbake, get_bb_var, get_bb_vars 9from oeqa.utils.commands import runCmd, bitbake, get_bb_var, get_bb_vars
11from qemucommand import QemuCommand 10from testutils import qemu_launch, qemu_send_command, qemu_terminate, \
12 11 akt_native_run, verifyProvisioned
13
14class 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
33class GeneralTests(OESelftestTestCase): 14class 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_usrmerge(self):
40 result = get_bb_var('DISTRO_FEATURES').find('usrmerge')
41 self.assertNotEqual(result, -1, 'Feature "sota" not set at DISTRO_FEATURES')
42
43 def test_feature_systemd(self):
44 result = get_bb_var('DISTRO_FEATURES').find('systemd')
45 self.assertNotEqual(result, -1, 'Feature "systemd" not set at DISTRO_FEATURES')
46
47 def test_credentials(self): 15 def test_credentials(self):
48 logger = logging.getLogger("selftest") 16 logger = logging.getLogger("selftest")
49 logger.info('Running bitbake to build core-image-minimal') 17 logger.info('Running bitbake to build core-image-minimal')
@@ -62,11 +30,6 @@ class GeneralTests(OESelftestTestCase):
62 (deploydir, imagename), ignore_status=True) 30 (deploydir, imagename), ignore_status=True)
63 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)
64 32
65 def test_java(self):
66 result = runCmd('which java', ignore_status=True)
67 self.assertEqual(result.status, 0,
68 "Java not found. Do you have a JDK installed on your host machine?")
69
70 33
71class AktualizrToolsTests(OESelftestTestCase): 34class AktualizrToolsTests(OESelftestTestCase):
72 35
@@ -201,144 +164,6 @@ class ManualControlTests(OESelftestTestCase):
201 'Aktualizr should have run' + stderr.decode() + stdout.decode()) 164 'Aktualizr should have run' + stderr.decode() + stdout.decode())
202 165
203 166
204class RpiTests(OESelftestTestCase):
205
206 def setUpLocal(self):
207 # Add layers before changing the machine type, otherwise the sanity
208 # checker complains loudly.
209 layer_python = "meta-openembedded/meta-python"
210 layer_rpi = "meta-raspberrypi"
211 layer_upd_rpi = "meta-updater-raspberrypi"
212 result = runCmd('bitbake-layers show-layers')
213 # Assume the directory layout for finding other layers. We could also
214 # make assumptions by using 'show-layers', but either way, if the
215 # layers we need aren't where we expect them, we are out of luck.
216 path = os.path.abspath(os.path.dirname(__file__))
217 metadir = path + "/../../../../../"
218 if re.search(layer_python, result.output) is None:
219 self.meta_python = metadir + layer_python
220 runCmd('bitbake-layers add-layer "%s"' % self.meta_python)
221 else:
222 self.meta_python = None
223 if re.search(layer_rpi, result.output) is None:
224 self.meta_rpi = metadir + layer_rpi
225 runCmd('bitbake-layers add-layer "%s"' % self.meta_rpi)
226 else:
227 self.meta_rpi = None
228 if re.search(layer_upd_rpi, result.output) is None:
229 self.meta_upd_rpi = metadir + layer_upd_rpi
230 runCmd('bitbake-layers add-layer "%s"' % self.meta_upd_rpi)
231 else:
232 self.meta_upd_rpi = None
233
234 # This is trickier that I would've thought. The fundamental problem is
235 # that the qemu layer changes the u-boot file extension to .rom, but
236 # raspberrypi still expects .bin. To prevent this, the qemu layer must
237 # be temporarily removed if it is present. It has to be removed by name
238 # without the complete path, but to add it back when we are done, we
239 # need the full path.
240 p = re.compile(r'meta-updater-qemux86-64\s*(\S*meta-updater-qemux86-64)\s')
241 m = p.search(result.output)
242 if m and m.lastindex > 0:
243 self.meta_qemu = m.group(1)
244 runCmd('bitbake-layers remove-layer meta-updater-qemux86-64')
245 else:
246 self.meta_qemu = None
247
248 self.append_config('MACHINE = "raspberrypi3"')
249 self.append_config('SOTA_CLIENT_PROV = " aktualizr-auto-prov "')
250
251 def tearDownLocal(self):
252 if self.meta_qemu:
253 runCmd('bitbake-layers add-layer "%s"' % self.meta_qemu, ignore_status=True)
254 if self.meta_upd_rpi:
255 runCmd('bitbake-layers remove-layer "%s"' % self.meta_upd_rpi, ignore_status=True)
256 if self.meta_rpi:
257 runCmd('bitbake-layers remove-layer "%s"' % self.meta_rpi, ignore_status=True)
258 if self.meta_python:
259 runCmd('bitbake-layers remove-layer "%s"' % self.meta_python, ignore_status=True)
260
261 def test_rpi(self):
262 logger = logging.getLogger("selftest")
263 logger.info('Running bitbake to build core-image-minimal')
264 self.append_config('SOTA_CLIENT_PROV = "aktualizr-auto-prov"')
265 bitbake('core-image-minimal')
266 credentials = get_bb_var('SOTA_PACKED_CREDENTIALS')
267 # Skip the test if the variable SOTA_PACKED_CREDENTIALS is not set.
268 if credentials is None:
269 raise unittest.SkipTest("Variable 'SOTA_PACKED_CREDENTIALS' not set.")
270 # Check if the file exists.
271 self.assertTrue(os.path.isfile(credentials), "File %s does not exist" % credentials)
272 deploydir = get_bb_var('DEPLOY_DIR_IMAGE')
273 imagename = get_bb_var('IMAGE_LINK_NAME', 'core-image-minimal')
274 # Check if the credentials are included in the output image.
275 result = runCmd('tar -jtvf %s/%s.tar.bz2 | grep sota_provisioning_credentials.zip' %
276 (deploydir, imagename), ignore_status=True)
277 self.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output)
278
279
280class GrubTests(OESelftestTestCase):
281
282 def setUpLocal(self):
283 layer_intel = "meta-intel"
284 layer_minnow = "meta-updater-minnowboard"
285 result = runCmd('bitbake-layers show-layers')
286 # Assume the directory layout for finding other layers. We could also
287 # make assumptions by using 'show-layers', but either way, if the
288 # layers we need aren't where we expect them, we are out of luck.
289 path = os.path.abspath(os.path.dirname(__file__))
290 metadir = path + "/../../../../../"
291 if re.search(layer_intel, result.output) is None:
292 self.meta_intel = metadir + layer_intel
293 runCmd('bitbake-layers add-layer "%s"' % self.meta_intel)
294 else:
295 self.meta_intel = None
296 if re.search(layer_minnow, result.output) is None:
297 self.meta_minnow = metadir + layer_minnow
298 runCmd('bitbake-layers add-layer "%s"' % self.meta_minnow)
299 else:
300 self.meta_minnow = None
301 self.append_config('MACHINE = "intel-corei7-64"')
302 self.append_config('OSTREE_BOOTLOADER = "grub"')
303 self.append_config('SOTA_CLIENT_PROV = " aktualizr-auto-prov "')
304 self.qemu, self.s = qemu_launch(efi=True, machine='intel-corei7-64')
305
306 def tearDownLocal(self):
307 qemu_terminate(self.s)
308 if self.meta_intel:
309 runCmd('bitbake-layers remove-layer "%s"' % self.meta_intel, ignore_status=True)
310 if self.meta_minnow:
311 runCmd('bitbake-layers remove-layer "%s"' % self.meta_minnow, ignore_status=True)
312
313 def qemu_command(self, command):
314 return qemu_send_command(self.qemu.ssh_port, command)
315
316 def test_grub(self):
317 print('Checking machine name (hostname) of device:')
318 stdout, stderr, retcode = self.qemu_command('hostname')
319 self.assertEqual(retcode, 0, "Unable to check hostname. " +
320 "Is an ssh daemon (such as dropbear or openssh) installed on the device?")
321 machine = get_bb_var('MACHINE', 'core-image-minimal')
322 self.assertEqual(stderr, b'', 'Error: ' + stderr.decode())
323 # Strip off line ending.
324 value = stdout.decode()[:-1]
325 self.assertEqual(value, machine,
326 'MACHINE does not match hostname: ' + machine + ', ' + value +
327 '\nIs TianoCore ovmf installed on your host machine?')
328 print(value)
329 print('Checking output of aktualizr-info:')
330 ran_ok = False
331 for delay in [1, 2, 5, 10, 15]:
332 stdout, stderr, retcode = self.qemu_command('aktualizr-info')
333 if retcode == 0 and stderr == b'':
334 ran_ok = True
335 break
336 sleep(delay)
337 self.assertTrue(ran_ok, 'aktualizr-info failed: ' + stderr.decode() + stdout.decode())
338
339 verifyProvisioned(self, machine)
340
341
342class ImplProvTests(OESelftestTestCase): 167class ImplProvTests(OESelftestTestCase):
343 168
344 def setUpLocal(self): 169 def setUpLocal(self):
@@ -482,7 +307,7 @@ class HsmTests(OESelftestTestCase):
482 softhsm2_command = 'softhsm2-util --show-slots' 307 softhsm2_command = 'softhsm2-util --show-slots'
483 stdout, stderr, retcode = self.qemu_command(softhsm2_command) 308 stdout, stderr, retcode = self.qemu_command(softhsm2_command)
484 self.assertNotEqual(retcode, 0, 'softhsm2-tool succeeded before initialization: ' + 309 self.assertNotEqual(retcode, 0, 'softhsm2-tool succeeded before initialization: ' +
485 stdout.decode() + stderr.decode()) 310 stdout.decode() + stderr.decode())
486 311
487 # Run aktualizr-cert-provider. 312 # Run aktualizr-cert-provider.
488 bb_vars = get_bb_vars(['SOTA_PACKED_CREDENTIALS'], 'aktualizr-native') 313 bb_vars = get_bb_vars(['SOTA_PACKED_CREDENTIALS'], 'aktualizr-native')
@@ -613,100 +438,4 @@ class PrimaryTests(OESelftestTestCase):
613 self.assertEqual(retcode, 0, "Unable to run aktualizr --help") 438 self.assertEqual(retcode, 0, "Unable to run aktualizr --help")
614 self.assertEqual(stderr, b'', 'Error: ' + stderr.decode()) 439 self.assertEqual(stderr, b'', 'Error: ' + stderr.decode())
615 440
616
617def qemu_launch(efi=False, machine=None, imagename=None):
618 logger = logging.getLogger("selftest")
619 logger.info('Running bitbake to build core-image-minimal')
620 bitbake('core-image-minimal')
621 # Create empty object.
622 args = type('', (), {})()
623 if imagename:
624 args.imagename = imagename
625 else:
626 args.imagename = 'core-image-minimal'
627 args.mac = None
628 # Could use DEPLOY_DIR_IMAGE here but it's already in the machine
629 # subdirectory.
630 args.dir = 'tmp/deploy/images'
631 args.efi = efi
632 args.machine = machine
633 qemu_use_kvm = get_bb_var("QEMU_USE_KVM")
634 if qemu_use_kvm and \
635 (qemu_use_kvm == 'True' and 'x86' in machine or \
636 get_bb_var('MACHINE') in qemu_use_kvm.split()):
637 args.kvm = True
638 else:
639 args.kvm = None # Autodetect
640 args.no_gui = True
641 args.gdb = False
642 args.pcap = None
643 args.overlay = None
644 args.dry_run = False
645 args.secondary_network = False
646
647 qemu = QemuCommand(args)
648 cmdline = qemu.command_line()
649 print('Booting image with run-qemu-ota...')
650 s = subprocess.Popen(cmdline)
651 sleep(10)
652 return qemu, s
653
654
655def qemu_terminate(s):
656 try:
657 s.terminate()
658 except KeyboardInterrupt:
659 pass
660
661
662def qemu_send_command(port, command):
663 command = ['ssh -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@localhost -p ' +
664 str(port) + ' "' + command + '"']
665 s2 = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
666 stdout, stderr = s2.communicate(timeout=60)
667 return stdout, stderr, s2.returncode
668
669
670def akt_native_run(testInst, cmd, **kwargs):
671 # run a command supplied by aktualizr-native and checks that:
672 # - the executable exists
673 # - the command runs without error
674 # NOTE: the base test class must have built aktualizr-native (in
675 # setUpClass, for example)
676 bb_vars = get_bb_vars(['SYSROOT_DESTDIR', 'base_prefix', 'libdir', 'bindir'],
677 'aktualizr-native')
678 sysroot = bb_vars['SYSROOT_DESTDIR'] + bb_vars['base_prefix']
679 sysrootbin = bb_vars['SYSROOT_DESTDIR'] + bb_vars['bindir']
680 libdir = bb_vars['libdir']
681
682 program, *_ = cmd.split(' ')
683 p = '{}/{}'.format(sysrootbin, program)
684 testInst.assertTrue(os.path.isfile(p), msg="No {} found ({})".format(program, p))
685 env = dict(os.environ)
686 env['LD_LIBRARY_PATH'] = libdir
687 result = runCmd(cmd, env=env, native_sysroot=sysroot, ignore_status=True, **kwargs)
688 testInst.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output)
689
690
691def verifyProvisioned(testInst, machine):
692 # Verify that device HAS provisioned.
693 ran_ok = False
694 for delay in [5, 5, 5, 5, 10, 10, 10, 10]:
695 stdout, stderr, retcode = testInst.qemu_command('aktualizr-info')
696 if retcode == 0 and stderr == b'' and stdout.decode().find('Fetched metadata: yes') >= 0:
697 ran_ok = True
698 break
699 sleep(delay)
700 testInst.assertIn(b'Device ID: ', stdout, 'Provisioning failed: ' + stderr.decode() + stdout.decode())
701 testInst.assertIn(b'Primary ecu hardware ID: ' + machine.encode(), stdout,
702 'Provisioning failed: ' + stderr.decode() + stdout.decode())
703 testInst.assertIn(b'Fetched metadata: yes', stdout, 'Provisioning failed: ' + stderr.decode() + stdout.decode())
704 p = re.compile(r'Device ID: ([a-z0-9-]*)\n')
705 m = p.search(stdout.decode())
706 testInst.assertTrue(m, 'Device ID could not be read: ' + stderr.decode() + stdout.decode())
707 testInst.assertGreater(m.lastindex, 0, 'Device ID could not be read: ' + stderr.decode() + stdout.decode())
708 logger = logging.getLogger("selftest")
709 logger.info('Device successfully provisioned with ID: ' + m.group(1))
710
711
712# vim:set ts=4 sw=4 sts=4 expandtab: 441# vim:set ts=4 sw=4 sts=4 expandtab:
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
2import os
3import logging
4import re
5import unittest
6
7from oeqa.selftest.case import OESelftestTestCase
8from oeqa.utils.commands import runCmd, bitbake, get_bb_var
9
10
11class 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: