summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick Vacek <patrickvacek@gmail.com>2018-02-28 10:27:01 +0100
committerPatrick Vacek <patrickvacek@gmail.com>2018-04-12 12:11:04 +0200
commitfc4939673066b28c0a856538028109fc4ffbc96f (patch)
tree1f9abc45df9841b0f325d443a97b0efe893d69a7
parentdd7f7d88ce253fce6a8c2675f58ee214586f3f08 (diff)
downloadmeta-updater-fc4939673066b28c0a856538028109fc4ffbc96f.tar.gz
oe-selftest improvements.
* Check successful provisioning with autoprov and grub. * Refactor provisioning check into an independent function. * Rename QemuTests to AutoProvTests since that's what it is now. * Be more explicit about MACHINE. Cherry-pick of c0d6f4c7949ddfc01977096b985c46c28aa8ed4f from rocko.
-rw-r--r--lib/oeqa/selftest/updater.py110
1 files changed, 52 insertions, 58 deletions
diff --git a/lib/oeqa/selftest/updater.py b/lib/oeqa/selftest/updater.py
index 8fbc857..1b51c1a 100644
--- a/lib/oeqa/selftest/updater.py
+++ b/lib/oeqa/selftest/updater.py
@@ -132,20 +132,20 @@ class AktualizrToolsTests(oeSelfTest):
132 self.assertTrue(os.path.getsize(ca_path) > 0, "Client certificate at %s is empty." % ca_path) 132 self.assertTrue(os.path.getsize(ca_path) > 0, "Client certificate at %s is empty." % ca_path)
133 133
134 134
135class QemuTests(oeSelfTest): 135class AutoProvTests(oeSelfTest):
136 136
137 @classmethod 137 def setUpLocal(self):
138 def setUpClass(cls): 138 self.append_config('MACHINE = "qemux86-64"')
139 cls.qemu, cls.s = qemu_launch(machine='qemux86-64') 139 self.append_config('SOTA_CLIENT_PROV = " aktualizr-auto-prov "')
140 self.qemu, self.s = qemu_launch(machine='qemux86-64')
140 141
141 @classmethod 142 def tearDownLocal(self):
142 def tearDownClass(cls): 143 qemu_terminate(self.s)
143 qemu_terminate(cls.s)
144 144
145 def qemu_command(self, command): 145 def qemu_command(self, command):
146 return qemu_send_command(self.qemu.ssh_port, command) 146 return qemu_send_command(self.qemu.ssh_port, command)
147 147
148 def test_qemu(self): 148 def test_provisioning(self):
149 print('Checking machine name (hostname) of device:') 149 print('Checking machine name (hostname) of device:')
150 stdout, stderr, retcode = self.qemu_command('hostname') 150 stdout, stderr, retcode = self.qemu_command('hostname')
151 self.assertEqual(retcode, 0, "Unable to check hostname. " + 151 self.assertEqual(retcode, 0, "Unable to check hostname. " +
@@ -153,10 +153,10 @@ class QemuTests(oeSelfTest):
153 machine = get_bb_var('MACHINE', 'core-image-minimal') 153 machine = get_bb_var('MACHINE', 'core-image-minimal')
154 self.assertEqual(stderr, b'', 'Error: ' + stderr.decode()) 154 self.assertEqual(stderr, b'', 'Error: ' + stderr.decode())
155 # Strip off line ending. 155 # Strip off line ending.
156 value_str = stdout.decode()[:-1] 156 value = stdout.decode()[:-1]
157 self.assertEqual(value_str, machine, 157 self.assertEqual(value, machine,
158 'MACHINE does not match hostname: ' + machine + ', ' + value_str) 158 'MACHINE does not match hostname: ' + machine + ', ' + value)
159 print(value_str) 159 print(value)
160 print('Checking output of aktualizr-info:') 160 print('Checking output of aktualizr-info:')
161 ran_ok = False 161 ran_ok = False
162 for delay in [0, 1, 2, 5, 10, 15]: 162 for delay in [0, 1, 2, 5, 10, 15]:
@@ -167,15 +167,18 @@ class QemuTests(oeSelfTest):
167 break 167 break
168 self.assertTrue(ran_ok, 'aktualizr-info failed: ' + stderr.decode() + stdout.decode()) 168 self.assertTrue(ran_ok, 'aktualizr-info failed: ' + stderr.decode() + stdout.decode())
169 169
170 verifyProvisioned(self, machine)
171
170 172
171class GrubTests(oeSelfTest): 173class GrubTests(oeSelfTest):
172 174
173 def setUpLocal(self): 175 def setUpLocal(self):
176 self.append_config('MACHINE = "intel-corei7-64"')
177 self.append_config('OSTREE_BOOTLOADER = "grub"')
178 self.append_config('SOTA_CLIENT_PROV = " aktualizr-auto-prov "')
174 # This is a bit of a hack but I can't see a better option. 179 # This is a bit of a hack but I can't see a better option.
175 path = os.path.abspath(os.path.dirname(__file__)) 180 path = os.path.abspath(os.path.dirname(__file__))
176 metadir = path + "/../../../../" 181 metadir = path + "/../../../../"
177 grub_config = 'OSTREE_BOOTLOADER = "grub"\nMACHINE = "intel-corei7-64"'
178 self.append_config(grub_config)
179 self.meta_intel = metadir + "meta-intel" 182 self.meta_intel = metadir + "meta-intel"
180 self.meta_minnow = metadir + "meta-updater-minnowboard" 183 self.meta_minnow = metadir + "meta-updater-minnowboard"
181 runCmd('bitbake-layers add-layer "%s"' % self.meta_intel) 184 runCmd('bitbake-layers add-layer "%s"' % self.meta_intel)
@@ -214,10 +217,13 @@ class GrubTests(oeSelfTest):
214 break 217 break
215 self.assertTrue(ran_ok, 'aktualizr-info failed: ' + stderr.decode() + stdout.decode()) 218 self.assertTrue(ran_ok, 'aktualizr-info failed: ' + stderr.decode() + stdout.decode())
216 219
220 verifyProvisioned(self, machine)
221
217 222
218class ImplProvTests(oeSelfTest): 223class ImplProvTests(oeSelfTest):
219 224
220 def setUpLocal(self): 225 def setUpLocal(self):
226 self.append_config('MACHINE = "qemux86-64"')
221 self.append_config('SOTA_CLIENT_PROV = " aktualizr-implicit-prov "') 227 self.append_config('SOTA_CLIENT_PROV = " aktualizr-implicit-prov "')
222 # note: this will build aktualizr-native as a side-effect 228 # note: this will build aktualizr-native as a side-effect
223 self.qemu, self.s = qemu_launch(machine='qemux86-64') 229 self.qemu, self.s = qemu_launch(machine='qemux86-64')
@@ -236,10 +242,10 @@ class ImplProvTests(oeSelfTest):
236 machine = get_bb_var('MACHINE', 'core-image-minimal') 242 machine = get_bb_var('MACHINE', 'core-image-minimal')
237 self.assertEqual(stderr, b'', 'Error: ' + stderr.decode()) 243 self.assertEqual(stderr, b'', 'Error: ' + stderr.decode())
238 # Strip off line ending. 244 # Strip off line ending.
239 value_str = stdout.decode()[:-1] 245 value = stdout.decode()[:-1]
240 self.assertEqual(value_str, machine, 246 self.assertEqual(value, machine,
241 'MACHINE does not match hostname: ' + machine + ', ' + value_str) 247 'MACHINE does not match hostname: ' + machine + ', ' + value)
242 print(value_str) 248 print(value)
243 print('Checking output of aktualizr-info:') 249 print('Checking output of aktualizr-info:')
244 ran_ok = False 250 ran_ok = False
245 for delay in [0, 1, 2, 5, 10, 15]: 251 for delay in [0, 1, 2, 5, 10, 15]:
@@ -267,29 +273,13 @@ class ImplProvTests(oeSelfTest):
267 akt_native_run(self, 'aktualizr_cert_provider -c {creds} -t root@localhost -p {port} -s -g {config}' 273 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)) 274 .format(creds=creds, port=self.qemu.ssh_port, config=config))
269 275
270 # Verify that device HAS provisioned. 276 verifyProvisioned(self, machine)
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 277
289 278
290class HsmTests(oeSelfTest): 279class HsmTests(oeSelfTest):
291 280
292 def setUpLocal(self): 281 def setUpLocal(self):
282 self.append_config('MACHINE = "qemux86-64"')
293 self.append_config('SOTA_CLIENT_PROV = "aktualizr-hsm-prov"') 283 self.append_config('SOTA_CLIENT_PROV = "aktualizr-hsm-prov"')
294 self.append_config('SOTA_CLIENT_FEATURES = "hsm"') 284 self.append_config('SOTA_CLIENT_FEATURES = "hsm"')
295 # note: this will build aktualizr-native as a side-effect 285 # note: this will build aktualizr-native as a side-effect
@@ -309,10 +299,11 @@ class HsmTests(oeSelfTest):
309 machine = get_bb_var('MACHINE', 'core-image-minimal') 299 machine = get_bb_var('MACHINE', 'core-image-minimal')
310 self.assertEqual(stderr, b'', 'Error: ' + stderr.decode()) 300 self.assertEqual(stderr, b'', 'Error: ' + stderr.decode())
311 # Strip off line ending. 301 # Strip off line ending.
312 value_str = stdout.decode()[:-1] 302 value = stdout.decode()[:-1]
313 self.assertEqual(value_str, machine, 303 self.assertEqual(value, machine,
314 'MACHINE does not match hostname: ' + machine + ', ' + value_str) 304 'MACHINE does not match hostname: ' + machine + ', ' + value +
315 print(value_str) 305 '\nIs tianocore ovmf installed?')
306 print(value)
316 print('Checking output of aktualizr-info:') 307 print('Checking output of aktualizr-info:')
317 ran_ok = False 308 ran_ok = False
318 for delay in [0, 1, 2, 5, 10, 15]: 309 for delay in [0, 1, 2, 5, 10, 15]:
@@ -382,24 +373,7 @@ class HsmTests(oeSelfTest):
382 self.assertEqual(p11_m.group(1), hsm_m.group(1), 'Slot number does not match: ' + 373 self.assertEqual(p11_m.group(1), hsm_m.group(1), 'Slot number does not match: ' +
383 p11_err.decode() + p11_out.decode() + hsm_err.decode() + hsm_out.decode()) 374 p11_err.decode() + p11_out.decode() + hsm_err.decode() + hsm_out.decode())
384 375
385 # Verify that device HAS provisioned. 376 verifyProvisioned(self, machine)
386 ran_ok = False
387 for delay in [5, 5, 5, 5, 10]:
388 sleep(delay)
389 stdout, stderr, retcode = self.qemu_command('aktualizr-info')
390 if retcode == 0 and stderr == b'' and stdout.decode().find('Fetched metadata: yes') >= 0:
391 ran_ok = True
392 break
393 self.assertIn(b'Device ID: ', stdout, 'Provisioning failed: ' + stderr.decode() + stdout.decode())
394 self.assertIn(b'Primary ecu hardware ID: qemux86-64', stdout,
395 'Provisioning failed: ' + stderr.decode() + stdout.decode())
396 self.assertIn(b'Fetched metadata: yes', stdout, 'Provisioning failed: ' + stderr.decode() + stdout.decode())
397 p = re.compile(r'Device ID: ([a-z0-9-]*)\n')
398 m = p.search(stdout.decode())
399 self.assertTrue(m, 'Device ID could not be read: ' + stderr.decode() + stdout.decode())
400 self.assertGreater(m.lastindex, 0, 'Device ID could not be read: ' + stderr.decode() + stdout.decode())
401 logger = logging.getLogger("selftest")
402 logger.info('Device successfully provisioned with ID: ' + m.group(1))
403 377
404 378
405def qemu_launch(efi=False, machine=None): 379def qemu_launch(efi=False, machine=None):
@@ -466,5 +440,25 @@ def akt_native_run(testInst, cmd, **kwargs):
466 testInst.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output) 440 testInst.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output)
467 441
468 442
443def verifyProvisioned(testInst, machine):
444 # Verify that device HAS provisioned.
445 ran_ok = False
446 for delay in [5, 5, 5, 5, 10]:
447 sleep(delay)
448 stdout, stderr, retcode = testInst.qemu_command('aktualizr-info')
449 if retcode == 0 and stderr == b'' and stdout.decode().find('Fetched metadata: yes') >= 0:
450 ran_ok = True
451 break
452 testInst.assertIn(b'Device ID: ', stdout, 'Provisioning failed: ' + stderr.decode() + stdout.decode())
453 testInst.assertIn(b'Primary ecu hardware ID: ' + machine.encode(), stdout,
454 'Provisioning failed: ' + stderr.decode() + stdout.decode())
455 testInst.assertIn(b'Fetched metadata: yes', stdout, 'Provisioning failed: ' + stderr.decode() + stdout.decode())
456 p = re.compile(r'Device ID: ([a-z0-9-]*)\n')
457 m = p.search(stdout.decode())
458 testInst.assertTrue(m, 'Device ID could not be read: ' + stderr.decode() + stdout.decode())
459 testInst.assertGreater(m.lastindex, 0, 'Device ID could not be read: ' + stderr.decode() + stdout.decode())
460 logger = logging.getLogger("selftest")
461 logger.info('Device successfully provisioned with ID: ' + m.group(1))
462
469 463
470# vim:set ts=4 sw=4 sts=4 expandtab: 464# vim:set ts=4 sw=4 sts=4 expandtab: