summaryrefslogtreecommitdiffstats
path: root/lib/oeqa/selftest
diff options
context:
space:
mode:
authorPatrick Vacek <patrickvacek@gmail.com>2018-02-28 10:27:01 +0100
committerPatrick Vacek <patrickvacek@gmail.com>2018-02-28 11:03:51 +0100
commitc0d6f4c7949ddfc01977096b985c46c28aa8ed4f (patch)
tree0465cd998c107e4d830333d86ca97950fb41a814 /lib/oeqa/selftest
parent91ad494544866512f7cfff0c67cdc02536f4242f (diff)
downloadmeta-updater-c0d6f4c7949ddfc01977096b985c46c28aa8ed4f.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.
Diffstat (limited to 'lib/oeqa/selftest')
-rw-r--r--lib/oeqa/selftest/cases/updater.py111
1 files changed, 51 insertions, 60 deletions
diff --git a/lib/oeqa/selftest/cases/updater.py b/lib/oeqa/selftest/cases/updater.py
index b544762..fe18981 100644
--- a/lib/oeqa/selftest/cases/updater.py
+++ b/lib/oeqa/selftest/cases/updater.py
@@ -134,22 +134,20 @@ class AktualizrToolsTests(OESelftestTestCase):
134 self.assertTrue(os.path.getsize(ca_path) > 0, "Client certificate at %s is empty." % ca_path) 134 self.assertTrue(os.path.getsize(ca_path) > 0, "Client certificate at %s is empty." % ca_path)
135 135
136 136
137class QemuTests(OESelftestTestCase): 137class AutoProvTests(OESelftestTestCase):
138 138
139 @classmethod 139 def setUpLocal(self):
140 def setUpClass(cls): 140 self.append_config('MACHINE = "qemux86-64"')
141 super(QemuTests, cls).setUpClass() 141 self.append_config('SOTA_CLIENT_PROV = " aktualizr-auto-prov "')
142 cls.qemu, cls.s = qemu_launch(machine='qemux86-64') 142 self.qemu, self.s = qemu_launch(machine='qemux86-64')
143 143
144 @classmethod 144 def tearDownLocal(self):
145 def tearDownClass(cls): 145 qemu_terminate(self.s)
146 qemu_terminate(cls.s)
147 super(QemuTests, cls).tearDownClass()
148 146
149 def qemu_command(self, command): 147 def qemu_command(self, command):
150 return qemu_send_command(self.qemu.ssh_port, command) 148 return qemu_send_command(self.qemu.ssh_port, command)
151 149
152 def test_qemu(self): 150 def test_provisioning(self):
153 print('Checking machine name (hostname) of device:') 151 print('Checking machine name (hostname) of device:')
154 stdout, stderr, retcode = self.qemu_command('hostname') 152 stdout, stderr, retcode = self.qemu_command('hostname')
155 self.assertEqual(retcode, 0, "Unable to check hostname. " + 153 self.assertEqual(retcode, 0, "Unable to check hostname. " +
@@ -157,10 +155,10 @@ class QemuTests(OESelftestTestCase):
157 machine = get_bb_var('MACHINE', 'core-image-minimal') 155 machine = get_bb_var('MACHINE', 'core-image-minimal')
158 self.assertEqual(stderr, b'', 'Error: ' + stderr.decode()) 156 self.assertEqual(stderr, b'', 'Error: ' + stderr.decode())
159 # Strip off line ending. 157 # Strip off line ending.
160 value_str = stdout.decode()[:-1] 158 value = stdout.decode()[:-1]
161 self.assertEqual(value_str, machine, 159 self.assertEqual(value, machine,
162 'MACHINE does not match hostname: ' + machine + ', ' + value_str) 160 'MACHINE does not match hostname: ' + machine + ', ' + value)
163 print(value_str) 161 print(value)
164 print('Checking output of aktualizr-info:') 162 print('Checking output of aktualizr-info:')
165 ran_ok = False 163 ran_ok = False
166 for delay in [0, 1, 2, 5, 10, 15]: 164 for delay in [0, 1, 2, 5, 10, 15]:
@@ -171,15 +169,18 @@ class QemuTests(OESelftestTestCase):
171 break 169 break
172 self.assertTrue(ran_ok, 'aktualizr-info failed: ' + stderr.decode() + stdout.decode()) 170 self.assertTrue(ran_ok, 'aktualizr-info failed: ' + stderr.decode() + stdout.decode())
173 171
172 verifyProvisioned(self, machine)
173
174 174
175class GrubTests(OESelftestTestCase): 175class GrubTests(OESelftestTestCase):
176 176
177 def setUpLocal(self): 177 def setUpLocal(self):
178 self.append_config('MACHINE = "intel-corei7-64"')
179 self.append_config('OSTREE_BOOTLOADER = "grub"')
180 self.append_config('SOTA_CLIENT_PROV = " aktualizr-auto-prov "')
178 # This is a bit of a hack but I can't see a better option. 181 # This is a bit of a hack but I can't see a better option.
179 path = os.path.abspath(os.path.dirname(__file__)) 182 path = os.path.abspath(os.path.dirname(__file__))
180 metadir = path + "/../../../../../" 183 metadir = path + "/../../../../../"
181 grub_config = 'OSTREE_BOOTLOADER = "grub"\nMACHINE = "intel-corei7-64"'
182 self.append_config(grub_config)
183 self.meta_intel = metadir + "meta-intel" 184 self.meta_intel = metadir + "meta-intel"
184 self.meta_minnow = metadir + "meta-updater-minnowboard" 185 self.meta_minnow = metadir + "meta-updater-minnowboard"
185 runCmd('bitbake-layers add-layer "%s"' % self.meta_intel) 186 runCmd('bitbake-layers add-layer "%s"' % self.meta_intel)
@@ -218,10 +219,13 @@ class GrubTests(OESelftestTestCase):
218 break 219 break
219 self.assertTrue(ran_ok, 'aktualizr-info failed: ' + stderr.decode() + stdout.decode()) 220 self.assertTrue(ran_ok, 'aktualizr-info failed: ' + stderr.decode() + stdout.decode())
220 221
222 verifyProvisioned(self, machine)
223
221 224
222class ImplProvTests(OESelftestTestCase): 225class ImplProvTests(OESelftestTestCase):
223 226
224 def setUpLocal(self): 227 def setUpLocal(self):
228 self.append_config('MACHINE = "qemux86-64"')
225 self.append_config('SOTA_CLIENT_PROV = " aktualizr-implicit-prov "') 229 self.append_config('SOTA_CLIENT_PROV = " aktualizr-implicit-prov "')
226 # note: this will build aktualizr-native as a side-effect 230 # note: this will build aktualizr-native as a side-effect
227 self.qemu, self.s = qemu_launch(machine='qemux86-64') 231 self.qemu, self.s = qemu_launch(machine='qemux86-64')
@@ -240,10 +244,10 @@ class ImplProvTests(OESelftestTestCase):
240 machine = get_bb_var('MACHINE', 'core-image-minimal') 244 machine = get_bb_var('MACHINE', 'core-image-minimal')
241 self.assertEqual(stderr, b'', 'Error: ' + stderr.decode()) 245 self.assertEqual(stderr, b'', 'Error: ' + stderr.decode())
242 # Strip off line ending. 246 # Strip off line ending.
243 value_str = stdout.decode()[:-1] 247 value = stdout.decode()[:-1]
244 self.assertEqual(value_str, machine, 248 self.assertEqual(value, machine,
245 'MACHINE does not match hostname: ' + machine + ', ' + value_str) 249 'MACHINE does not match hostname: ' + machine + ', ' + value)
246 print(value_str) 250 print(value)
247 print('Checking output of aktualizr-info:') 251 print('Checking output of aktualizr-info:')
248 ran_ok = False 252 ran_ok = False
249 for delay in [0, 1, 2, 5, 10, 15]: 253 for delay in [0, 1, 2, 5, 10, 15]:
@@ -271,29 +275,13 @@ class ImplProvTests(OESelftestTestCase):
271 akt_native_run(self, 'aktualizr_cert_provider -c {creds} -t root@localhost -p {port} -s -g {config}' 275 akt_native_run(self, 'aktualizr_cert_provider -c {creds} -t root@localhost -p {port} -s -g {config}'
272 .format(creds=creds, port=self.qemu.ssh_port, config=config)) 276 .format(creds=creds, port=self.qemu.ssh_port, config=config))
273 277
274 # Verify that device HAS provisioned. 278 verifyProvisioned(self, machine)
275 ran_ok = False
276 for delay in [5, 5, 5, 5, 10]:
277 sleep(delay)
278 stdout, stderr, retcode = self.qemu_command('aktualizr-info')
279 if retcode == 0 and stderr == b'' and stdout.decode().find('Fetched metadata: yes') >= 0:
280 ran_ok = True
281 break
282 self.assertIn(b'Device ID: ', stdout, 'Provisioning failed: ' + stderr.decode() + stdout.decode())
283 self.assertIn(b'Primary ecu hardware ID: qemux86-64', stdout,
284 'Provisioning failed: ' + stderr.decode() + stdout.decode())
285 self.assertIn(b'Fetched metadata: yes', stdout, 'Provisioning failed: ' + stderr.decode() + stdout.decode())
286 p = re.compile(r'Device ID: ([a-z0-9-]*)\n')
287 m = p.search(stdout.decode())
288 self.assertTrue(m, 'Device ID could not be read: ' + stderr.decode() + stdout.decode())
289 self.assertGreater(m.lastindex, 0, 'Device ID could not be read: ' + stderr.decode() + stdout.decode())
290 logger = logging.getLogger("selftest")
291 logger.info('Device successfully provisioned with ID: ' + m.group(1))
292 279
293 280
294class HsmTests(OESelftestTestCase): 281class HsmTests(OESelftestTestCase):
295 282
296 def setUpLocal(self): 283 def setUpLocal(self):
284 self.append_config('MACHINE = "qemux86-64"')
297 self.append_config('SOTA_CLIENT_PROV = "aktualizr-hsm-prov"') 285 self.append_config('SOTA_CLIENT_PROV = "aktualizr-hsm-prov"')
298 self.append_config('SOTA_CLIENT_FEATURES = "hsm"') 286 self.append_config('SOTA_CLIENT_FEATURES = "hsm"')
299 # note: this will build aktualizr-native as a side-effect 287 # note: this will build aktualizr-native as a side-effect
@@ -313,11 +301,11 @@ class HsmTests(OESelftestTestCase):
313 machine = get_bb_var('MACHINE', 'core-image-minimal') 301 machine = get_bb_var('MACHINE', 'core-image-minimal')
314 self.assertEqual(stderr, b'', 'Error: ' + stderr.decode()) 302 self.assertEqual(stderr, b'', 'Error: ' + stderr.decode())
315 # Strip off line ending. 303 # Strip off line ending.
316 value_str = stdout.decode()[:-1] 304 value = stdout.decode()[:-1]
317 self.assertEqual(value_str, machine, 305 self.assertEqual(value, machine,
318 'MACHINE does not match hostname: ' + machine + ', ' + value_str + 306 'MACHINE does not match hostname: ' + machine + ', ' + value +
319 '\nIs tianocore ovmf installed?') 307 '\nIs tianocore ovmf installed?')
320 print(value_str) 308 print(value)
321 print('Checking output of aktualizr-info:') 309 print('Checking output of aktualizr-info:')
322 ran_ok = False 310 ran_ok = False
323 for delay in [0, 1, 2, 5, 10, 15]: 311 for delay in [0, 1, 2, 5, 10, 15]:
@@ -387,24 +375,7 @@ class HsmTests(OESelftestTestCase):
387 self.assertEqual(p11_m.group(1), hsm_m.group(1), 'Slot number does not match: ' + 375 self.assertEqual(p11_m.group(1), hsm_m.group(1), 'Slot number does not match: ' +
388 p11_err.decode() + p11_out.decode() + hsm_err.decode() + hsm_out.decode()) 376 p11_err.decode() + p11_out.decode() + hsm_err.decode() + hsm_out.decode())
389 377
390 # Verify that device HAS provisioned. 378 verifyProvisioned(self, machine)
391 ran_ok = False
392 for delay in [5, 5, 5, 5, 10]:
393 sleep(delay)
394 stdout, stderr, retcode = self.qemu_command('aktualizr-info')
395 if retcode == 0 and stderr == b'' and stdout.decode().find('Fetched metadata: yes') >= 0:
396 ran_ok = True
397 break
398 self.assertIn(b'Device ID: ', stdout, 'Provisioning failed: ' + stderr.decode() + stdout.decode())
399 self.assertIn(b'Primary ecu hardware ID: qemux86-64', stdout,
400 'Provisioning failed: ' + stderr.decode() + stdout.decode())
401 self.assertIn(b'Fetched metadata: yes', stdout, 'Provisioning failed: ' + stderr.decode() + stdout.decode())
402 p = re.compile(r'Device ID: ([a-z0-9-]*)\n')
403 m = p.search(stdout.decode())
404 self.assertTrue(m, 'Device ID could not be read: ' + stderr.decode() + stdout.decode())
405 self.assertGreater(m.lastindex, 0, 'Device ID could not be read: ' + stderr.decode() + stdout.decode())
406 logger = logging.getLogger("selftest")
407 logger.info('Device successfully provisioned with ID: ' + m.group(1))
408 379
409 380
410def qemu_launch(efi=False, machine=None): 381def qemu_launch(efi=False, machine=None):
@@ -471,5 +442,25 @@ def akt_native_run(testInst, cmd, **kwargs):
471 testInst.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output) 442 testInst.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output)
472 443
473 444
445def verifyProvisioned(testInst, machine):
446 # Verify that device HAS provisioned.
447 ran_ok = False
448 for delay in [5, 5, 5, 5, 10]:
449 sleep(delay)
450 stdout, stderr, retcode = testInst.qemu_command('aktualizr-info')
451 if retcode == 0 and stderr == b'' and stdout.decode().find('Fetched metadata: yes') >= 0:
452 ran_ok = True
453 break
454 testInst.assertIn(b'Device ID: ', stdout, 'Provisioning failed: ' + stderr.decode() + stdout.decode())
455 testInst.assertIn(b'Primary ecu hardware ID: ' + machine.encode(), stdout,
456 'Provisioning failed: ' + stderr.decode() + stdout.decode())
457 testInst.assertIn(b'Fetched metadata: yes', stdout, 'Provisioning failed: ' + stderr.decode() + stdout.decode())
458 p = re.compile(r'Device ID: ([a-z0-9-]*)\n')
459 m = p.search(stdout.decode())
460 testInst.assertTrue(m, 'Device ID could not be read: ' + stderr.decode() + stdout.decode())
461 testInst.assertGreater(m.lastindex, 0, 'Device ID could not be read: ' + stderr.decode() + stdout.decode())
462 logger = logging.getLogger("selftest")
463 logger.info('Device successfully provisioned with ID: ' + m.group(1))
464
474 465
475# vim:set ts=4 sw=4 sts=4 expandtab: 466# vim:set ts=4 sw=4 sts=4 expandtab: