summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBen Luck <ben+qa@advancedtelematic.com>2018-02-27 15:09:53 +0100
committerGitHub <noreply@github.com>2018-02-27 15:09:53 +0100
commit4b4fb87a79c7b6c6d787e9152758401ddf86485a (patch)
tree4a1de9f88a2bbcc00ed14b1df7ba4942c372cb68
parentc91742110b2344f869198534a326ddd69d039bd0 (diff)
parent0f55df2e10db67f33d5656c4569c8de40ca89fb5 (diff)
downloadmeta-updater-4b4fb87a79c7b6c6d787e9152758401ddf86485a.tar.gz
Merge pull request #261 from advancedtelematic/test/PRO-4853/impl-prov-selftest
oe-selftest for implicit provisioning
-rw-r--r--lib/oeqa/selftest/updater.py169
1 files changed, 108 insertions, 61 deletions
diff --git a/lib/oeqa/selftest/updater.py b/lib/oeqa/selftest/updater.py
index 1efbba9..8fbc857 100644
--- a/lib/oeqa/selftest/updater.py
+++ b/lib/oeqa/selftest/updater.py
@@ -16,32 +16,17 @@ class SotaToolsTests(oeSelfTest):
16 @classmethod 16 @classmethod
17 def setUpClass(cls): 17 def setUpClass(cls):
18 logger = logging.getLogger("selftest") 18 logger = logging.getLogger("selftest")
19 bb_vars = get_bb_vars(['SYSROOT_DESTDIR', 'base_prefix', 'libdir', 'bindir'],
20 'aktualizr-native')
21 cls.sysroot = bb_vars['SYSROOT_DESTDIR'] + bb_vars['base_prefix']
22 cls.sysrootbin = bb_vars['SYSROOT_DESTDIR'] + bb_vars['bindir']
23 cls.libdir = bb_vars['libdir']
24
25 logger.info('Running bitbake to build aktualizr-native tools') 19 logger.info('Running bitbake to build aktualizr-native tools')
26 bitbake('aktualizr-native') 20 bitbake('aktualizr-native')
27 21
28 def runNativeCmd(self, cmd, **kwargs):
29 program, *_ = cmd.split(' ')
30 p = '{}/{}'.format(self.sysrootbin, program)
31 self.assertTrue(os.path.isfile(p), msg="No {} found ({})".format(program, p))
32 env = dict(os.environ)
33 env['LD_LIBRARY_PATH'] = self.libdir
34 result = runCmd(cmd, env=env, native_sysroot=self.sysroot, ignore_status=True, **kwargs)
35 self.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output)
36
37 def test_push_help(self): 22 def test_push_help(self):
38 self.runNativeCmd('garage-push --help') 23 akt_native_run(self, 'garage-push --help')
39 24
40 def test_deploy_help(self): 25 def test_deploy_help(self):
41 self.runNativeCmd('garage-deploy --help') 26 akt_native_run(self, 'garage-deploy --help')
42 27
43 def test_garagesign_help(self): 28 def test_garagesign_help(self):
44 self.runNativeCmd('garage-sign --help') 29 akt_native_run(self, 'garage-sign --help')
45 30
46 31
47class GeneralTests(oeSelfTest): 32class GeneralTests(oeSelfTest):
@@ -113,43 +98,27 @@ class AktualizrToolsTests(oeSelfTest):
113 @classmethod 98 @classmethod
114 def setUpClass(cls): 99 def setUpClass(cls):
115 logger = logging.getLogger("selftest") 100 logger = logging.getLogger("selftest")
116 bb_vars = get_bb_vars(['SYSROOT_DESTDIR', 'base_prefix', 'libdir', 'bindir'],
117 'aktualizr-native')
118 cls.sysroot = bb_vars['SYSROOT_DESTDIR'] + bb_vars['base_prefix']
119 cls.sysrootbin = bb_vars['SYSROOT_DESTDIR'] + bb_vars['bindir']
120 cls.libdir = bb_vars['libdir']
121
122 logger.info('Running bitbake to build aktualizr-native tools') 101 logger.info('Running bitbake to build aktualizr-native tools')
123 bitbake('aktualizr-native') 102 bitbake('aktualizr-native')
124 103
125 def runNativeCmd(self, cmd, **kwargs):
126 program, *_ = cmd.split(' ')
127 p = '{}/{}'.format(self.sysrootbin, program)
128 self.assertTrue(os.path.isfile(p), msg="No {} found ({})".format(program, p))
129 env = dict(os.environ)
130 env['LD_LIBRARY_PATH'] = self.libdir
131 result = runCmd(cmd, env=env, native_sysroot=self.sysroot, ignore_status=True, **kwargs)
132 self.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output)
133
134 def test_implicit_writer_help(self): 104 def test_implicit_writer_help(self):
135 self.runNativeCmd('aktualizr_implicit_writer --help') 105 akt_native_run(self, 'aktualizr_implicit_writer --help')
136 106
137 def test_cert_provider_help(self): 107 def test_cert_provider_help(self):
138 self.runNativeCmd('aktualizr_cert_provider --help') 108 akt_native_run(self, 'aktualizr_cert_provider --help')
139 109
140 def test_cert_provider_local_output(self): 110 def test_cert_provider_local_output(self):
141 logger = logging.getLogger("selftest") 111 logger = logging.getLogger("selftest")
142 logger.info('Running bitbake to build aktualizr-implicit-prov') 112 logger.info('Running bitbake to build aktualizr-implicit-prov')
143 bitbake('aktualizr-implicit-prov') 113 bitbake('aktualizr-implicit-prov')
144 bb_vars = get_bb_vars(['SYSROOT_DESTDIR', 'bindir', 'libdir', 114 bb_vars = get_bb_vars(['SOTA_PACKED_CREDENTIALS', 'T'], 'aktualizr-native')
145 'SOTA_PACKED_CREDENTIALS', 'T'], 'aktualizr-native')
146 creds = bb_vars['SOTA_PACKED_CREDENTIALS'] 115 creds = bb_vars['SOTA_PACKED_CREDENTIALS']
147 temp_dir = bb_vars['T'] 116 temp_dir = bb_vars['T']
148 bb_vars_prov = get_bb_vars(['STAGING_DIR_NATIVE', 'libdir'], 'aktualizr-implicit-prov') 117 bb_vars_prov = get_bb_vars(['STAGING_DIR_NATIVE', 'libdir'], 'aktualizr-implicit-prov')
149 config = bb_vars_prov['STAGING_DIR_NATIVE'] + bb_vars_prov['libdir'] + '/sota/sota_implicit_prov.toml' 118 config = bb_vars_prov['STAGING_DIR_NATIVE'] + bb_vars_prov['libdir'] + '/sota/sota_implicit_prov.toml'
150 119
151 self.runNativeCmd('aktualizr_cert_provider -c {creds} -r -l {temp} -g {config}' 120 akt_native_run(self, 'aktualizr_cert_provider -c {creds} -r -l {temp} -g {config}'
152 .format(creds=creds, temp=temp_dir, config=config)) 121 .format(creds=creds, temp=temp_dir, config=config))
153 122
154 # Might be nice if these names weren't hardcoded. 123 # Might be nice if these names weren't hardcoded.
155 cert_path = temp_dir + '/client.pem' 124 cert_path = temp_dir + '/client.pem'
@@ -246,33 +215,89 @@ class GrubTests(oeSelfTest):
246 self.assertTrue(ran_ok, 'aktualizr-info failed: ' + stderr.decode() + stdout.decode()) 215 self.assertTrue(ran_ok, 'aktualizr-info failed: ' + stderr.decode() + stdout.decode())
247 216
248 217
249class HsmTests(oeSelfTest): 218class ImplProvTests(oeSelfTest):
250 219
251 @classmethod 220 def setUpLocal(self):
252 def setUpClass(cls): 221 self.append_config('SOTA_CLIENT_PROV = " aktualizr-implicit-prov "')
253 bb_vars = get_bb_vars(['SYSROOT_DESTDIR', 'base_prefix', 'libdir', 'bindir'], 222 # note: this will build aktualizr-native as a side-effect
254 'aktualizr-native') 223 self.qemu, self.s = qemu_launch(machine='qemux86-64')
255 cls.sysroot = bb_vars['SYSROOT_DESTDIR'] + bb_vars['base_prefix'] 224
256 cls.sysrootbin = bb_vars['SYSROOT_DESTDIR'] + bb_vars['bindir'] 225 def tearDownLocal(self):
257 cls.libdir = bb_vars['libdir'] 226 qemu_terminate(self.s)
227
228 def qemu_command(self, command):
229 return qemu_send_command(self.qemu.ssh_port, command)
230
231 def test_provisioning(self):
232 print('Checking machine name (hostname) of device:')
233 stdout, stderr, retcode = self.qemu_command('hostname')
234 self.assertEqual(retcode, 0, "Unable to check hostname. " +
235 "Is an ssh daemon (such as dropbear or openssh) installed on the device?")
236 machine = get_bb_var('MACHINE', 'core-image-minimal')
237 self.assertEqual(stderr, b'', 'Error: ' + stderr.decode())
238 # Strip off line ending.
239 value_str = stdout.decode()[:-1]
240 self.assertEqual(value_str, machine,
241 'MACHINE does not match hostname: ' + machine + ', ' + value_str)
242 print(value_str)
243 print('Checking output of aktualizr-info:')
244 ran_ok = False
245 for delay in [0, 1, 2, 5, 10, 15]:
246 stdout, stderr, retcode = self.qemu_command('aktualizr-info')
247 if retcode == 0 and stderr == b'':
248 ran_ok = True
249 break
250 self.assertTrue(ran_ok, 'aktualizr-info failed: ' + stderr.decode() + stdout.decode())
251 # Verify that device has NOT yet provisioned.
252 self.assertIn(b'Couldn\'t load device ID', stdout,
253 'Device already provisioned!? ' + stderr.decode() + stdout.decode())
254 self.assertIn(b'Couldn\'t load ECU serials', stdout,
255 'Device already provisioned!? ' + stderr.decode() + stdout.decode())
256 self.assertIn(b'Provisioned on server: no', stdout,
257 'Device already provisioned!? ' + stderr.decode() + stdout.decode())
258 self.assertIn(b'Fetched metadata: no', stdout,
259 'Device already provisioned!? ' + stderr.decode() + stdout.decode())
260
261 # Run cert_provider.
262 bb_vars = get_bb_vars(['SOTA_PACKED_CREDENTIALS'], 'aktualizr-native')
263 creds = bb_vars['SOTA_PACKED_CREDENTIALS']
264 bb_vars_prov = get_bb_vars(['STAGING_DIR_NATIVE', 'libdir'], 'aktualizr-implicit-prov')
265 config = bb_vars_prov['STAGING_DIR_NATIVE'] + bb_vars_prov['libdir'] + '/sota/sota_implicit_prov.toml'
266
267 akt_native_run(self, 'aktualizr_cert_provider -c {creds} -t root@localhost -p {port} -s -g {config}'
268 .format(creds=creds, port=self.qemu.ssh_port, config=config))
269
270 # Verify that device HAS provisioned.
271 ran_ok = False
272 for delay in [5, 5, 5, 5, 10]:
273 sleep(delay)
274 stdout, stderr, retcode = self.qemu_command('aktualizr-info')
275 if retcode == 0 and stderr == b'' and stdout.decode().find('Fetched metadata: yes') >= 0:
276 ran_ok = True
277 break
278 self.assertIn(b'Device ID: ', stdout, 'Provisioning failed: ' + stderr.decode() + stdout.decode())
279 self.assertIn(b'Primary ecu hardware ID: qemux86-64', stdout,
280 'Provisioning failed: ' + stderr.decode() + stdout.decode())
281 self.assertIn(b'Fetched metadata: yes', stdout, 'Provisioning failed: ' + stderr.decode() + stdout.decode())
282 p = re.compile(r'Device ID: ([a-z0-9-]*)\n')
283 m = p.search(stdout.decode())
284 self.assertTrue(m, 'Device ID could not be read: ' + stderr.decode() + stdout.decode())
285 self.assertGreater(m.lastindex, 0, 'Device ID could not be read: ' + stderr.decode() + stdout.decode())
286 logger = logging.getLogger("selftest")
287 logger.info('Device successfully provisioned with ID: ' + m.group(1))
288
289
290class HsmTests(oeSelfTest):
258 291
259 def setUpLocal(self): 292 def setUpLocal(self):
260 self.append_config('SOTA_CLIENT_PROV = "aktualizr-hsm-prov"') 293 self.append_config('SOTA_CLIENT_PROV = "aktualizr-hsm-prov"')
261 self.append_config('SOTA_CLIENT_FEATURES = "hsm"') 294 self.append_config('SOTA_CLIENT_FEATURES = "hsm"')
295 # note: this will build aktualizr-native as a side-effect
262 self.qemu, self.s = qemu_launch(machine='qemux86-64') 296 self.qemu, self.s = qemu_launch(machine='qemux86-64')
263 297
264 def tearDownLocal(self): 298 def tearDownLocal(self):
265 qemu_terminate(self.s) 299 qemu_terminate(self.s)
266 300
267 def runNativeCmd(self, cmd, **kwargs):
268 program, *_ = cmd.split(' ')
269 p = '{}/{}'.format(self.sysrootbin, program)
270 self.assertTrue(os.path.isfile(p), msg="No {} found ({})".format(program, p))
271 env = dict(os.environ)
272 env['LD_LIBRARY_PATH'] = self.libdir
273 result = runCmd(cmd, env=env, native_sysroot=self.sysroot, ignore_status=True, **kwargs)
274 self.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output)
275
276 def qemu_command(self, command): 301 def qemu_command(self, command):
277 return qemu_send_command(self.qemu.ssh_port, command) 302 return qemu_send_command(self.qemu.ssh_port, command)
278 303
@@ -317,14 +342,13 @@ class HsmTests(oeSelfTest):
317 stdout.decode() + stderr.decode()) 342 stdout.decode() + stderr.decode())
318 343
319 # Run cert_provider. 344 # Run cert_provider.
320 bb_vars = get_bb_vars(['SYSROOT_DESTDIR', 'bindir', 'libdir', 345 bb_vars = get_bb_vars(['SOTA_PACKED_CREDENTIALS'], 'aktualizr-native')
321 'SOTA_PACKED_CREDENTIALS'], 'aktualizr-native')
322 creds = bb_vars['SOTA_PACKED_CREDENTIALS'] 346 creds = bb_vars['SOTA_PACKED_CREDENTIALS']
323 bb_vars_prov = get_bb_vars(['STAGING_DIR_NATIVE', 'libdir'], 'aktualizr-hsm-prov') 347 bb_vars_prov = get_bb_vars(['STAGING_DIR_NATIVE', 'libdir'], 'aktualizr-hsm-prov')
324 config = bb_vars_prov['STAGING_DIR_NATIVE'] + bb_vars_prov['libdir'] + '/sota/sota_implicit_prov.toml' 348 config = bb_vars_prov['STAGING_DIR_NATIVE'] + bb_vars_prov['libdir'] + '/sota/sota_hsm_prov.toml'
325 349
326 self.runNativeCmd('aktualizr_cert_provider -c {creds} -t root@localhost -p {port} -r -s -g {config}' 350 akt_native_run(self, 'aktualizr_cert_provider -c {creds} -t root@localhost -p {port} -r -s -g {config}'
327 .format(creds=creds, port=self.qemu.ssh_port, config=config)) 351 .format(creds=creds, port=self.qemu.ssh_port, config=config))
328 352
329 # Verify that HSM is able to initialize. 353 # Verify that HSM is able to initialize.
330 ran_ok = False 354 ran_ok = False
@@ -420,4 +444,27 @@ def qemu_send_command(port, command):
420 stdout, stderr = s2.communicate() 444 stdout, stderr = s2.communicate()
421 return stdout, stderr, s2.returncode 445 return stdout, stderr, s2.returncode
422 446
447
448def akt_native_run(testInst, cmd, **kwargs):
449 # run a command supplied by aktualizr-native and checks that:
450 # - the executable exists
451 # - the command runs without error
452 # NOTE: the base test class must have built aktualizr-native (in
453 # setUpClass, for example)
454 bb_vars = get_bb_vars(['SYSROOT_DESTDIR', 'base_prefix', 'libdir', 'bindir'],
455 'aktualizr-native')
456 sysroot = bb_vars['SYSROOT_DESTDIR'] + bb_vars['base_prefix']
457 sysrootbin = bb_vars['SYSROOT_DESTDIR'] + bb_vars['bindir']
458 libdir = bb_vars['libdir']
459
460 program, *_ = cmd.split(' ')
461 p = '{}/{}'.format(sysrootbin, program)
462 testInst.assertTrue(os.path.isfile(p), msg="No {} found ({})".format(program, p))
463 env = dict(os.environ)
464 env['LD_LIBRARY_PATH'] = libdir
465 result = runCmd(cmd, env=env, native_sysroot=sysroot, ignore_status=True, **kwargs)
466 testInst.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output)
467
468
469
423# vim:set ts=4 sw=4 sts=4 expandtab: 470# vim:set ts=4 sw=4 sts=4 expandtab: