summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/oeqa/selftest/updater.py89
1 files changed, 89 insertions, 0 deletions
diff --git a/lib/oeqa/selftest/updater.py b/lib/oeqa/selftest/updater.py
index 1efbba9..cad5b2a 100644
--- a/lib/oeqa/selftest/updater.py
+++ b/lib/oeqa/selftest/updater.py
@@ -246,6 +246,95 @@ class GrubTests(oeSelfTest):
246 self.assertTrue(ran_ok, 'aktualizr-info failed: ' + stderr.decode() + stdout.decode()) 246 self.assertTrue(ran_ok, 'aktualizr-info failed: ' + stderr.decode() + stdout.decode())
247 247
248 248
249class ImplProvTests(oeSelfTest):
250
251 @classmethod
252 def setUpClass(cls):
253 bb_vars = get_bb_vars(['SYSROOT_DESTDIR', 'base_prefix', 'libdir', 'bindir'],
254 'aktualizr-native')
255 cls.sysroot = bb_vars['SYSROOT_DESTDIR'] + bb_vars['base_prefix']
256 cls.sysrootbin = bb_vars['SYSROOT_DESTDIR'] + bb_vars['bindir']
257 cls.libdir = bb_vars['libdir']
258
259 def setUpLocal(self):
260 self.append_config('SOTA_CLIENT_PROV = " aktualizr-implicit-prov "')
261 self.qemu, self.s = qemu_launch(machine='qemux86-64')
262
263 def tearDownLocal(self):
264 qemu_terminate(self.s)
265
266 def runNativeCmd(self, cmd, **kwargs):
267 program, *_ = cmd.split(' ')
268 p = '{}/{}'.format(self.sysrootbin, program)
269 self.assertTrue(os.path.isfile(p), msg="No {} found ({})".format(program, p))
270 env = dict(os.environ)
271 env['LD_LIBRARY_PATH'] = self.libdir
272 result = runCmd(cmd, env=env, native_sysroot=self.sysroot, ignore_status=True, **kwargs)
273 self.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output)
274
275 def qemu_command(self, command):
276 return qemu_send_command(self.qemu.ssh_port, command)
277
278 def test_provisioning(self):
279 print('Checking machine name (hostname) of device:')
280 stdout, stderr, retcode = self.qemu_command('hostname')
281 self.assertEqual(retcode, 0, "Unable to check hostname. " +
282 "Is an ssh daemon (such as dropbear or openssh) installed on the device?")
283 machine = get_bb_var('MACHINE', 'core-image-minimal')
284 self.assertEqual(stderr, b'', 'Error: ' + stderr.decode())
285 # Strip off line ending.
286 value_str = stdout.decode()[:-1]
287 self.assertEqual(value_str, machine,
288 'MACHINE does not match hostname: ' + machine + ', ' + value_str)
289 print(value_str)
290 print('Checking output of aktualizr-info:')
291 ran_ok = False
292 for delay in [0, 1, 2, 5, 10, 15]:
293 stdout, stderr, retcode = self.qemu_command('aktualizr-info')
294 if retcode == 0 and stderr == b'':
295 ran_ok = True
296 break
297 self.assertTrue(ran_ok, 'aktualizr-info failed: ' + stderr.decode() + stdout.decode())
298 # Verify that device has NOT yet provisioned.
299 self.assertIn(b'Couldn\'t load device ID', stdout,
300 'Device already provisioned!? ' + stderr.decode() + stdout.decode())
301 self.assertIn(b'Couldn\'t load ECU serials', stdout,
302 'Device already provisioned!? ' + stderr.decode() + stdout.decode())
303 self.assertIn(b'Provisioned on server: no', stdout,
304 'Device already provisioned!? ' + stderr.decode() + stdout.decode())
305 self.assertIn(b'Fetched metadata: no', stdout,
306 'Device already provisioned!? ' + stderr.decode() + stdout.decode())
307
308 # Run cert_provider.
309 bb_vars = get_bb_vars(['SYSROOT_DESTDIR', 'bindir', 'libdir',
310 'SOTA_PACKED_CREDENTIALS'], 'aktualizr-native')
311 creds = bb_vars['SOTA_PACKED_CREDENTIALS']
312 bb_vars_prov = get_bb_vars(['STAGING_DIR_NATIVE', 'libdir'], 'aktualizr-implicit-prov')
313 config = bb_vars_prov['STAGING_DIR_NATIVE'] + bb_vars_prov['libdir'] + '/sota/sota_implicit_prov.toml'
314
315 self.runNativeCmd('aktualizr_cert_provider -c {creds} -t root@localhost -p {port} -s -g {config}' \
316 .format(creds=creds, port=self.qemu.ssh_port, config=config))
317
318 # Verify that device HAS provisioned.
319 ran_ok = False
320 for delay in [5, 5, 5, 5, 10]:
321 sleep(delay)
322 stdout, stderr, retcode = self.qemu_command('aktualizr-info')
323 if retcode == 0 and stderr == b'' and stdout.decode().find('Fetched metadata: yes') >= 0:
324 ran_ok = True
325 break
326 self.assertIn(b'Device ID: ', stdout, 'Provisioning failed: ' + stderr.decode() + stdout.decode())
327 self.assertIn(b'Primary ecu hardware ID: qemux86-64', stdout,
328 'Provisioning failed: ' + stderr.decode() + stdout.decode())
329 self.assertIn(b'Fetched metadata: yes', stdout, 'Provisioning failed: ' + stderr.decode() + stdout.decode())
330 p = re.compile(r'Device ID: ([a-z0-9-]*)\n')
331 m = p.search(stdout.decode())
332 self.assertTrue(m, 'Device ID could not be read: ' + stderr.decode() + stdout.decode())
333 self.assertGreater(m.lastindex, 0, 'Device ID could not be read: ' + stderr.decode() + stdout.decode())
334 logger = logging.getLogger("selftest")
335 logger.info('Device successfully provisioned with ID: ' + m.group(1))
336
337
249class HsmTests(oeSelfTest): 338class HsmTests(oeSelfTest):
250 339
251 @classmethod 340 @classmethod