summaryrefslogtreecommitdiffstats
path: root/lib/oeqa/selftest
diff options
context:
space:
mode:
authorPhil Wise <phil@advancedtelematic.com>2017-12-01 11:56:51 +0100
committerPhil Wise <phil@advancedtelematic.com>2018-01-25 13:41:13 +0100
commitc64b399633975bc05856e5eded519c4f22adfe44 (patch)
treece453e69c0ba320a90f6b1692db1aefbc91679b3 /lib/oeqa/selftest
parent74283ba882d0460922156010f2ce95018d4a8205 (diff)
downloadmeta-updater-c64b399633975bc05856e5eded519c4f22adfe44.tar.gz
Add tests for aktualizr-info
Diffstat (limited to 'lib/oeqa/selftest')
-rw-r--r--lib/oeqa/selftest/cases/updater.py54
1 files changed, 39 insertions, 15 deletions
diff --git a/lib/oeqa/selftest/cases/updater.py b/lib/oeqa/selftest/cases/updater.py
index 9264616..91ac9fc 100644
--- a/lib/oeqa/selftest/cases/updater.py
+++ b/lib/oeqa/selftest/cases/updater.py
@@ -1,8 +1,9 @@
1# pylint: disable=C0111,C0325
1import os 2import os
2import logging 3import logging
3import subprocess 4import subprocess
4import time
5import unittest 5import unittest
6from time import sleep
6 7
7from oeqa.selftest.case import OESelftestTestCase 8from oeqa.selftest.case import OESelftestTestCase
8from 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
@@ -51,11 +52,11 @@ class GeneralTests(OESelftestTestCase):
51 52
52 def test_feature_sota(self): 53 def test_feature_sota(self):
53 result = get_bb_var('DISTRO_FEATURES').find('sota') 54 result = get_bb_var('DISTRO_FEATURES').find('sota')
54 self.assertNotEqual(result, -1, 'Feature "sota" not set at DISTRO_FEATURES'); 55 self.assertNotEqual(result, -1, 'Feature "sota" not set at DISTRO_FEATURES')
55 56
56 def test_feature_systemd(self): 57 def test_feature_systemd(self):
57 result = get_bb_var('DISTRO_FEATURES').find('systemd') 58 result = get_bb_var('DISTRO_FEATURES').find('systemd')
58 self.assertNotEqual(result, -1, 'Feature "systemd" not set at DISTRO_FEATURES'); 59 self.assertNotEqual(result, -1, 'Feature "systemd" not set at DISTRO_FEATURES')
59 60
60 def test_credentials(self): 61 def test_credentials(self):
61 bitbake('core-image-minimal') 62 bitbake('core-image-minimal')
@@ -68,7 +69,8 @@ class GeneralTests(OESelftestTestCase):
68 deploydir = get_bb_var('DEPLOY_DIR_IMAGE') 69 deploydir = get_bb_var('DEPLOY_DIR_IMAGE')
69 imagename = get_bb_var('IMAGE_LINK_NAME', 'core-image-minimal') 70 imagename = get_bb_var('IMAGE_LINK_NAME', 'core-image-minimal')
70 # Check if the credentials are included in the output image 71 # Check if the credentials are included in the output image
71 result = runCmd('tar -jtvf %s/%s.tar.bz2 | grep sota_provisioning_credentials.zip' % (deploydir, imagename), ignore_status=True) 72 result = runCmd('tar -jtvf %s/%s.tar.bz2 | grep sota_provisioning_credentials.zip' %
73 (deploydir, imagename), ignore_status=True)
72 self.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output) 74 self.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output)
73 75
74 def test_java(self): 76 def test_java(self):
@@ -101,7 +103,7 @@ class GeneralTests(OESelftestTestCase):
101 self.assertEqual(result.output, 'ERROR: Unable to find any package producing path /usr/bin/man') 103 self.assertEqual(result.output, 'ERROR: Unable to find any package producing path /usr/bin/man')
102 path2 = os.path.realpath(image_path) 104 path2 = os.path.realpath(image_path)
103 size2 = os.path.getsize(path2) 105 size2 = os.path.getsize(path2)
104 logger.info('Second image %s has size %i' % (path2, size2)) 106 logger.info('Second image %s has size %i', path2, size2)
105 self.assertNotEqual(path1, path2, "Image paths are identical; image was not rebuilt.") 107 self.assertNotEqual(path1, path2, "Image paths are identical; image was not rebuilt.")
106 self.assertNotEqual(size1, size2, "Image sizes are identical; image was not rebuilt.") 108 self.assertNotEqual(size1, size2, "Image sizes are identical; image was not rebuilt.")
107 109
@@ -117,14 +119,17 @@ class QemuTests(OESelftestTestCase):
117 def tearDownClass(cls): 119 def tearDownClass(cls):
118 qemu_terminate(cls.s) 120 qemu_terminate(cls.s)
119 121
122 def run_command(self, command):
123 return qemu_send_command(self.qemu.ssh_port, command)
124
120 def test_hostname(self): 125 def test_hostname(self):
121 print('') 126 print('')
122 print('Checking machine name (hostname) of device:') 127 print('Checking machine name (hostname) of device:')
123 value, err = qemu_send_command(self.qemu.ssh_port, 'hostname') 128 stdout, stderr, retcode = self.run_command('hostname')
124 machine = get_bb_var('MACHINE', 'core-image-minimal') 129 machine = get_bb_var('MACHINE', 'core-image-minimal')
125 self.assertEqual(err, b'', 'Error: ' + err.decode()) 130 self.assertEqual(stderr, b'', 'Error: ' + stderr.decode())
126 # Strip off line ending. 131 # Strip off line ending.
127 value_str = value.decode()[:-1] 132 value_str = stdout.decode()[:-1]
128 self.assertEqual(value_str, machine, 133 self.assertEqual(value_str, machine,
129 'MACHINE does not match hostname: ' + machine + ', ' + value_str) 134 'MACHINE does not match hostname: ' + machine + ', ' + value_str)
130 print(value_str) 135 print(value_str)
@@ -132,9 +137,26 @@ class QemuTests(OESelftestTestCase):
132 def test_var_sota(self): 137 def test_var_sota(self):
133 print('') 138 print('')
134 print('Checking contents of /var/sota:') 139 print('Checking contents of /var/sota:')
135 value, err = qemu_send_command(self.qemu.ssh_port, 'ls /var/sota') 140 stdout, stderr, retcode = self.run_command('ls /var/sota')
136 self.assertEqual(err, b'', 'Error: ' + err.decode()) 141 self.assertEqual(stderr, b'', 'Error: ' + stderr.decode())
137 print(value.decode()) 142 self.assertEqual(retcode, 0)
143 print(stdout.decode())
144
145 def test_aktualizr_info(self):
146 print('Checking output of aktualizr-info:')
147 ran_ok = False
148 for delay in [0, 1, 2, 5, 10, 15]:
149 sleep(delay)
150 try:
151 stdout, stderr, retcode = self.run_command('aktualizr-info')
152 if retcode == 0 and stderr == b'':
153 ran_ok = True
154 break
155 except IOError as e:
156 print(e)
157 if not ran_ok:
158 print(stdout.decode())
159 print(stderr.decode())
138 160
139 161
140class GrubTests(OESelftestTestCase): 162class GrubTests(OESelftestTestCase):
@@ -159,9 +181,10 @@ class GrubTests(OESelftestTestCase):
159 def test_grub(self): 181 def test_grub(self):
160 print('') 182 print('')
161 print('Checking machine name (hostname) of device:') 183 print('Checking machine name (hostname) of device:')
162 value, err = qemu_send_command(self.qemu.ssh_port, 'hostname') 184 value, err, retcode = qemu_send_command(self.qemu.ssh_port, 'hostname')
163 machine = get_bb_var('MACHINE', 'core-image-minimal') 185 machine = get_bb_var('MACHINE', 'core-image-minimal')
164 self.assertEqual(err, b'', 'Error: ' + err.decode()) 186 self.assertEqual(err, b'', 'Error: ' + err.decode())
187 self.assertEqual(retcode, 0)
165 # Strip off line ending. 188 # Strip off line ending.
166 value_str = value.decode()[:-1] 189 value_str = value.decode()[:-1]
167 self.assertEqual(value_str, machine, 190 self.assertEqual(value_str, machine,
@@ -194,7 +217,7 @@ def qemu_launch(efi=False, machine=None):
194 cmdline = qemu.command_line() 217 cmdline = qemu.command_line()
195 print('Booting image with run-qemu-ota...') 218 print('Booting image with run-qemu-ota...')
196 s = subprocess.Popen(cmdline) 219 s = subprocess.Popen(cmdline)
197 time.sleep(10) 220 sleep(10)
198 return qemu, s 221 return qemu, s
199 222
200def qemu_terminate(s): 223def qemu_terminate(s):
@@ -207,6 +230,7 @@ def qemu_send_command(port, command):
207 command = ['ssh -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@localhost -p ' + 230 command = ['ssh -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@localhost -p ' +
208 str(port) + ' "' + command + '"'] 231 str(port) + ' "' + command + '"']
209 s2 = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) 232 s2 = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
210 value, err = s2.communicate() 233 stdout, stderr = s2.communicate()
211 return value, err 234 return stdout, stderr, s2.returncode
212 235
236# vim:set ts=4 sw=4 sts=4 expandtab: