summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhil Wise <phil@advancedtelematic.com>2017-12-01 11:56:51 +0100
committerPatrick Vacek <patrickvacek@gmail.com>2018-02-13 15:56:31 +0100
commit3a4bdbcae17b1b2f2197c61a0d188336767e1c60 (patch)
treec886d8d9b9dc9522ecfba9260e3bd99e39398d87
parentc2e9fcc8744b6c1f1af5941fd7d4546273361a91 (diff)
downloadmeta-updater-3a4bdbcae17b1b2f2197c61a0d188336767e1c60.tar.gz
Add tests for aktualizr-info.
Cherry-pick of c64b399633975bc05856e5eded519c4f22adfe44 from rocko.
-rw-r--r--lib/oeqa/selftest/updater.py56
1 files changed, 40 insertions, 16 deletions
diff --git a/lib/oeqa/selftest/updater.py b/lib/oeqa/selftest/updater.py
index b435d1b..0962cb7 100644
--- a/lib/oeqa/selftest/updater.py
+++ b/lib/oeqa/selftest/updater.py
@@ -1,8 +1,9 @@
1import unittest 1# pylint: disable=C0111,C0325
2import os 2import os
3import logging 3import logging
4import subprocess 4import subprocess
5import time 5import unittest
6from time import sleep
6 7
7from oeqa.selftest.base import oeSelfTest 8from oeqa.selftest.base import oeSelfTest
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
@@ -49,11 +50,11 @@ class GeneralTests(oeSelfTest):
49 50
50 def test_feature_sota(self): 51 def test_feature_sota(self):
51 result = get_bb_var('DISTRO_FEATURES').find('sota') 52 result = get_bb_var('DISTRO_FEATURES').find('sota')
52 self.assertNotEqual(result, -1, 'Feature "sota" not set at DISTRO_FEATURES'); 53 self.assertNotEqual(result, -1, 'Feature "sota" not set at DISTRO_FEATURES')
53 54
54 def test_feature_systemd(self): 55 def test_feature_systemd(self):
55 result = get_bb_var('DISTRO_FEATURES').find('systemd') 56 result = get_bb_var('DISTRO_FEATURES').find('systemd')
56 self.assertNotEqual(result, -1, 'Feature "systemd" not set at DISTRO_FEATURES'); 57 self.assertNotEqual(result, -1, 'Feature "systemd" not set at DISTRO_FEATURES')
57 58
58 def test_credentials(self): 59 def test_credentials(self):
59 bitbake('core-image-minimal') 60 bitbake('core-image-minimal')
@@ -66,7 +67,8 @@ class GeneralTests(oeSelfTest):
66 deploydir = get_bb_var('DEPLOY_DIR_IMAGE') 67 deploydir = get_bb_var('DEPLOY_DIR_IMAGE')
67 imagename = get_bb_var('IMAGE_LINK_NAME', 'core-image-minimal') 68 imagename = get_bb_var('IMAGE_LINK_NAME', 'core-image-minimal')
68 # Check if the credentials are included in the output image 69 # Check if the credentials are included in the output image
69 result = runCmd('tar -jtvf %s/%s.tar.bz2 | grep sota_provisioning_credentials.zip' % (deploydir, imagename), ignore_status=True) 70 result = runCmd('tar -jtvf %s/%s.tar.bz2 | grep sota_provisioning_credentials.zip' %
71 (deploydir, imagename), ignore_status=True)
70 self.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output) 72 self.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output)
71 73
72 def test_java(self): 74 def test_java(self):
@@ -99,7 +101,7 @@ class GeneralTests(oeSelfTest):
99 self.assertEqual(result.output, 'ERROR: Unable to find any package producing path /usr/bin/man') 101 self.assertEqual(result.output, 'ERROR: Unable to find any package producing path /usr/bin/man')
100 path2 = os.path.realpath(image_path) 102 path2 = os.path.realpath(image_path)
101 size2 = os.path.getsize(path2) 103 size2 = os.path.getsize(path2)
102 logger.info('Second image %s has size %i' % (path2, size2)) 104 logger.info('Second image %s has size %i', path2, size2)
103 self.assertNotEqual(path1, path2, "Image paths are identical; image was not rebuilt.") 105 self.assertNotEqual(path1, path2, "Image paths are identical; image was not rebuilt.")
104 self.assertNotEqual(size1, size2, "Image sizes are identical; image was not rebuilt.") 106 self.assertNotEqual(size1, size2, "Image sizes are identical; image was not rebuilt.")
105 107
@@ -114,14 +116,17 @@ class QemuTests(oeSelfTest):
114 def tearDownClass(cls): 116 def tearDownClass(cls):
115 qemu_terminate(cls.s) 117 qemu_terminate(cls.s)
116 118
119 def run_command(self, command):
120 return qemu_send_command(self.qemu.ssh_port, command)
121
117 def test_hostname(self): 122 def test_hostname(self):
118 print('') 123 print('')
119 print('Checking machine name (hostname) of device:') 124 print('Checking machine name (hostname) of device:')
120 value, err = qemu_send_command(self.qemu.ssh_port, 'hostname') 125 stdout, stderr, retcode = self.run_command('hostname')
121 machine = get_bb_var('MACHINE', 'core-image-minimal') 126 machine = get_bb_var('MACHINE', 'core-image-minimal')
122 self.assertEqual(err, b'', 'Error: ' + err.decode()) 127 self.assertEqual(stderr, b'', 'Error: ' + stderr.decode())
123 # Strip off line ending. 128 # Strip off line ending.
124 value_str = value.decode()[:-1] 129 value_str = stdout.decode()[:-1]
125 self.assertEqual(value_str, machine, 130 self.assertEqual(value_str, machine,
126 'MACHINE does not match hostname: ' + machine + ', ' + value_str) 131 'MACHINE does not match hostname: ' + machine + ', ' + value_str)
127 print(value_str) 132 print(value_str)
@@ -129,9 +134,26 @@ class QemuTests(oeSelfTest):
129 def test_var_sota(self): 134 def test_var_sota(self):
130 print('') 135 print('')
131 print('Checking contents of /var/sota:') 136 print('Checking contents of /var/sota:')
132 value, err = qemu_send_command(self.qemu.ssh_port, 'ls /var/sota') 137 stdout, stderr, retcode = self.run_command('ls /var/sota')
133 self.assertEqual(err, b'', 'Error: ' + err.decode()) 138 self.assertEqual(stderr, b'', 'Error: ' + stderr.decode())
134 print(value.decode()) 139 self.assertEqual(retcode, 0)
140 print(stdout.decode())
141
142 def test_aktualizr_info(self):
143 print('Checking output of aktualizr-info:')
144 ran_ok = False
145 for delay in [0, 1, 2, 5, 10, 15]:
146 sleep(delay)
147 try:
148 stdout, stderr, retcode = self.run_command('aktualizr-info')
149 if retcode == 0 and stderr == b'':
150 ran_ok = True
151 break
152 except IOError as e:
153 print(e)
154 if not ran_ok:
155 print(stdout.decode())
156 print(stderr.decode())
135 157
136class GrubTests(oeSelfTest): 158class GrubTests(oeSelfTest):
137 159
@@ -155,9 +177,10 @@ class GrubTests(oeSelfTest):
155 def test_grub(self): 177 def test_grub(self):
156 print('') 178 print('')
157 print('Checking machine name (hostname) of device:') 179 print('Checking machine name (hostname) of device:')
158 value, err = qemu_send_command(self.qemu.ssh_port, 'hostname') 180 value, err, retcode = qemu_send_command(self.qemu.ssh_port, 'hostname')
159 machine = get_bb_var('MACHINE', 'core-image-minimal') 181 machine = get_bb_var('MACHINE', 'core-image-minimal')
160 self.assertEqual(err, b'', 'Error: ' + err.decode()) 182 self.assertEqual(err, b'', 'Error: ' + err.decode())
183 self.assertEqual(retcode, 0)
161 # Strip off line ending. 184 # Strip off line ending.
162 value_str = value.decode()[:-1] 185 value_str = value.decode()[:-1]
163 self.assertEqual(value_str, machine, 186 self.assertEqual(value_str, machine,
@@ -190,7 +213,7 @@ def qemu_launch(efi=False, machine=None):
190 cmdline = qemu.command_line() 213 cmdline = qemu.command_line()
191 print('Booting image with run-qemu-ota...') 214 print('Booting image with run-qemu-ota...')
192 s = subprocess.Popen(cmdline) 215 s = subprocess.Popen(cmdline)
193 time.sleep(10) 216 sleep(10)
194 return qemu, s 217 return qemu, s
195 218
196def qemu_terminate(s): 219def qemu_terminate(s):
@@ -203,6 +226,7 @@ def qemu_send_command(port, command):
203 command = ['ssh -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@localhost -p ' + 226 command = ['ssh -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@localhost -p ' +
204 str(port) + ' "' + command + '"'] 227 str(port) + ' "' + command + '"']
205 s2 = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) 228 s2 = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
206 value, err = s2.communicate() 229 stdout, stderr = s2.communicate()
207 return value, err 230 return stdout, stderr, s2.returncode
208 231
232# vim:set ts=4 sw=4 sts=4 expandtab: