summaryrefslogtreecommitdiffstats
path: root/lib/oeqa/selftest/cases
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:47:06 +0200
commit15964bd366153a114b528411b7273d3876cbf896 (patch)
treeea386dd5d3f93bb05e6c00d9c25e7c768011bc7b /lib/oeqa/selftest/cases
parent810fcdb167fc77309cc24c0ffb7786368dad5a57 (diff)
downloadmeta-updater-15964bd366153a114b528411b7273d3876cbf896.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/selftest/cases')
-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.py43
-rw-r--r--lib/oeqa/selftest/cases/updater_qemux86_64.py (renamed from lib/oeqa/selftest/cases/updater.py)273
-rw-r--r--lib/oeqa/selftest/cases/updater_raspberrypi.py86
5 files changed, 306 insertions, 270 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..de98a09
--- /dev/null
+++ b/lib/oeqa/selftest/cases/updater_native.py
@@ -0,0 +1,43 @@
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_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 bf2a737..9310841 100644
--- a/lib/oeqa/selftest/cases/updater.py
+++ b/lib/oeqa/selftest/cases/updater_qemux86_64.py
@@ -2,44 +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_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
67class AktualizrToolsTests(OESelftestTestCase): 34class AktualizrToolsTests(OESelftestTestCase):
68 35
@@ -197,144 +164,6 @@ class ManualControlTests(OESelftestTestCase):
197 'Aktualizr should have run' + stderr.decode() + stdout.decode()) 164 'Aktualizr should have run' + stderr.decode() + stdout.decode())
198 165
199 166
200class 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
276class 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
338class ImplProvTests(OESelftestTestCase): 167class ImplProvTests(OESelftestTestCase):
339 168
340 def setUpLocal(self): 169 def setUpLocal(self):
@@ -478,7 +307,7 @@ class HsmTests(OESelftestTestCase):
478 softhsm2_command = 'softhsm2-util --show-slots' 307 softhsm2_command = 'softhsm2-util --show-slots'
479 stdout, stderr, retcode = self.qemu_command(softhsm2_command) 308 stdout, stderr, retcode = self.qemu_command(softhsm2_command)
480 self.assertNotEqual(retcode, 0, 'softhsm2-tool succeeded before initialization: ' + 309 self.assertNotEqual(retcode, 0, 'softhsm2-tool succeeded before initialization: ' +
481 stdout.decode() + stderr.decode()) 310 stdout.decode() + stderr.decode())
482 311
483 # Run aktualizr-cert-provider. 312 # Run aktualizr-cert-provider.
484 bb_vars = get_bb_vars(['SOTA_PACKED_CREDENTIALS'], 'aktualizr-native') 313 bb_vars = get_bb_vars(['SOTA_PACKED_CREDENTIALS'], 'aktualizr-native')
@@ -609,100 +438,4 @@ class PrimaryTests(OESelftestTestCase):
609 self.assertEqual(retcode, 0, "Unable to run aktualizr --help") 438 self.assertEqual(retcode, 0, "Unable to run aktualizr --help")
610 self.assertEqual(stderr, b'', 'Error: ' + stderr.decode()) 439 self.assertEqual(stderr, b'', 'Error: ' + stderr.decode())
611 440
612
613def qemu_launch(efi=False, machine=None, imagename=None):
614 logger = logging.getLogger("selftest")
615 logger.info('Running bitbake to build core-image-minimal')
616 bitbake('core-image-minimal')
617 # Create empty object.
618 args = type('', (), {})()
619 if imagename:
620 args.imagename = imagename
621 else:
622 args.imagename = 'core-image-minimal'
623 args.mac = None
624 # Could use DEPLOY_DIR_IMAGE here but it's already in the machine
625 # subdirectory.
626 args.dir = 'tmp/deploy/images'
627 args.efi = efi
628 args.machine = machine
629 qemu_use_kvm = get_bb_var("QEMU_USE_KVM")
630 if qemu_use_kvm and \
631 (qemu_use_kvm == 'True' and 'x86' in machine or \
632 get_bb_var('MACHINE') in qemu_use_kvm.split()):
633 args.kvm = True
634 else:
635 args.kvm = None # Autodetect
636 args.no_gui = True
637 args.gdb = False
638 args.pcap = None
639 args.overlay = None
640 args.dry_run = False
641 args.secondary_network = False
642
643 qemu = QemuCommand(args)
644 cmdline = qemu.command_line()
645 print('Booting image with run-qemu-ota...')
646 s = subprocess.Popen(cmdline)
647 sleep(10)
648 return qemu, s
649
650
651def qemu_terminate(s):
652 try:
653 s.terminate()
654 except KeyboardInterrupt:
655 pass
656
657
658def qemu_send_command(port, command):
659 command = ['ssh -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@localhost -p ' +
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
666def 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
687def 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
707
708# 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: