diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/oeqa/selftest/garage_push.py | 42 | ||||
l--------- | lib/oeqa/selftest/qemucommand.py | 1 | ||||
-rw-r--r-- | lib/oeqa/selftest/updater.py | 179 |
3 files changed, 180 insertions, 42 deletions
diff --git a/lib/oeqa/selftest/garage_push.py b/lib/oeqa/selftest/garage_push.py deleted file mode 100644 index 21bd1c1..0000000 --- a/lib/oeqa/selftest/garage_push.py +++ /dev/null | |||
@@ -1,42 +0,0 @@ | |||
1 | import unittest | ||
2 | import os | ||
3 | import logging | ||
4 | |||
5 | from oeqa.selftest.base import oeSelfTest | ||
6 | from oeqa.utils.commands import runCmd, bitbake, get_bb_var | ||
7 | |||
8 | class GaragePushTests(oeSelfTest): | ||
9 | |||
10 | @classmethod | ||
11 | def setUpClass(cls): | ||
12 | # Ensure we have the right data in pkgdata | ||
13 | logger = logging.getLogger("selftest") | ||
14 | logger.info('Running bitbake to build aktualizr-native tools') | ||
15 | bitbake('aktualizr-native garage-sign-native') | ||
16 | |||
17 | def test_help(self): | ||
18 | image_dir = get_bb_var("D", "aktualizr-native") | ||
19 | bin_dir = get_bb_var("bindir", "aktualizr-native") | ||
20 | gp_path = os.path.join(image_dir, bin_dir[1:], 'garage-push') | ||
21 | result = runCmd('%s --help' % gp_path, ignore_status=True) | ||
22 | self.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output) | ||
23 | |||
24 | def test_java(self): | ||
25 | result = runCmd('which java', ignore_status=True) | ||
26 | self.assertEqual(result.status, 0, "Java not found.") | ||
27 | |||
28 | def test_sign(self): | ||
29 | image_dir = get_bb_var("D", "garage-sign-native") | ||
30 | bin_dir = get_bb_var("bindir", "garage-sign-native") | ||
31 | gs_path = os.path.join(image_dir, bin_dir[1:], 'garage-sign') | ||
32 | result = runCmd('%s --help' % gs_path, ignore_status=True) | ||
33 | self.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output) | ||
34 | |||
35 | def test_push(self): | ||
36 | bitbake('core-image-minimal') | ||
37 | self.write_config('IMAGE_INSTALL_append = " man "') | ||
38 | bitbake('core-image-minimal') | ||
39 | |||
40 | def test_hsm(self): | ||
41 | self.write_config('SOTA_CLIENT_FEATURES="hsm hsm-test"') | ||
42 | bitbake('core-image-minimal') | ||
diff --git a/lib/oeqa/selftest/qemucommand.py b/lib/oeqa/selftest/qemucommand.py new file mode 120000 index 0000000..bc06dde --- /dev/null +++ b/lib/oeqa/selftest/qemucommand.py | |||
@@ -0,0 +1 @@ | |||
../../../scripts/qemucommand.py \ No newline at end of file | |||
diff --git a/lib/oeqa/selftest/updater.py b/lib/oeqa/selftest/updater.py new file mode 100644 index 0000000..ad99964 --- /dev/null +++ b/lib/oeqa/selftest/updater.py | |||
@@ -0,0 +1,179 @@ | |||
1 | import unittest | ||
2 | import os | ||
3 | import logging | ||
4 | import subprocess | ||
5 | import time | ||
6 | |||
7 | from oeqa.selftest.base import oeSelfTest | ||
8 | from oeqa.utils.commands import runCmd, bitbake, get_bb_var, get_bb_vars | ||
9 | from oeqa.selftest.qemucommand import QemuCommand | ||
10 | |||
11 | |||
12 | class SotaToolsTests(oeSelfTest): | ||
13 | |||
14 | @classmethod | ||
15 | def setUpClass(cls): | ||
16 | logger = logging.getLogger("selftest") | ||
17 | logger.info('Running bitbake to build aktualizr-native tools') | ||
18 | bitbake('aktualizr-native') | ||
19 | |||
20 | def test_push_help(self): | ||
21 | bb_vars = get_bb_vars(['SYSROOT_DESTDIR', 'bindir'], 'aktualizr-native') | ||
22 | p = bb_vars['SYSROOT_DESTDIR'] + bb_vars['bindir'] + "/" + "garage-push" | ||
23 | self.assertTrue(os.path.isfile(p), msg = "No garage-push found (%s)" % p) | ||
24 | result = runCmd('%s --help' % p, ignore_status=True) | ||
25 | self.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output) | ||
26 | |||
27 | def test_deploy_help(self): | ||
28 | bb_vars = get_bb_vars(['SYSROOT_DESTDIR', 'bindir'], 'aktualizr-native') | ||
29 | p = bb_vars['SYSROOT_DESTDIR'] + bb_vars['bindir'] + "/" + "garage-deploy" | ||
30 | self.assertTrue(os.path.isfile(p), msg = "No garage-deploy found (%s)" % p) | ||
31 | result = runCmd('%s --help' % p, ignore_status=True) | ||
32 | self.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output) | ||
33 | |||
34 | |||
35 | class GarageSignTests(oeSelfTest): | ||
36 | |||
37 | @classmethod | ||
38 | def setUpClass(cls): | ||
39 | logger = logging.getLogger("selftest") | ||
40 | logger.info('Running bitbake to build garage-sign-native') | ||
41 | bitbake('garage-sign-native') | ||
42 | |||
43 | def test_help(self): | ||
44 | bb_vars = get_bb_vars(['SYSROOT_DESTDIR', 'bindir'], 'garage-sign-native') | ||
45 | p = bb_vars['SYSROOT_DESTDIR'] + bb_vars['bindir'] + "/" + "garage-sign" | ||
46 | self.assertTrue(os.path.isfile(p), msg = "No garage-sign found (%s)" % p) | ||
47 | result = runCmd('%s --help' % p, ignore_status=True) | ||
48 | self.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output) | ||
49 | |||
50 | |||
51 | class HsmTests(oeSelfTest): | ||
52 | |||
53 | def test_hsm(self): | ||
54 | self.write_config('SOTA_CLIENT_FEATURES="hsm hsm-test"') | ||
55 | bitbake('core-image-minimal') | ||
56 | |||
57 | |||
58 | class GeneralTests(oeSelfTest): | ||
59 | |||
60 | def test_feature_sota(self): | ||
61 | result = get_bb_var('DISTRO_FEATURES').find('sota') | ||
62 | self.assertNotEqual(result, -1, 'Feature "sota" not set at DISTRO_FEATURES'); | ||
63 | |||
64 | def test_feature_systemd(self): | ||
65 | result = get_bb_var('DISTRO_FEATURES').find('systemd') | ||
66 | self.assertNotEqual(result, -1, 'Feature "systemd" not set at DISTRO_FEATURES'); | ||
67 | |||
68 | def test_credentials(self): | ||
69 | bitbake('core-image-minimal') | ||
70 | credentials = get_bb_var('SOTA_PACKED_CREDENTIALS') | ||
71 | # skip the test if the variable SOTA_PACKED_CREDENTIALS is not set | ||
72 | if credentials is None: | ||
73 | raise unittest.SkipTest("Variable 'SOTA_PACKED_CREDENTIALS' not set.") | ||
74 | # Check if the file exists | ||
75 | self.assertTrue(os.path.isfile(credentials), "File %s does not exist" % credentials) | ||
76 | deploydir = get_bb_var('DEPLOY_DIR_IMAGE') | ||
77 | imagename = get_bb_var('IMAGE_LINK_NAME', 'core-image-minimal') | ||
78 | # Check if the credentials are included in the output image | ||
79 | result = runCmd('tar -jtvf %s/%s.tar.bz2 | grep sota_provisioning_credentials.zip' % (deploydir, imagename), ignore_status=True) | ||
80 | self.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output) | ||
81 | |||
82 | def test_java(self): | ||
83 | result = runCmd('which java', ignore_status=True) | ||
84 | self.assertEqual(result.status, 0, "Java not found.") | ||
85 | |||
86 | def test_add_package(self): | ||
87 | print('') | ||
88 | deploydir = get_bb_var('DEPLOY_DIR_IMAGE') | ||
89 | imagename = get_bb_var('IMAGE_LINK_NAME', 'core-image-minimal') | ||
90 | image_path = deploydir + '/' + imagename + '.otaimg' | ||
91 | logger = logging.getLogger("selftest") | ||
92 | |||
93 | logger.info('Running bitbake with man in the image package list') | ||
94 | self.write_config('IMAGE_INSTALL_append = " man "') | ||
95 | bitbake('-c cleanall man') | ||
96 | bitbake('core-image-minimal') | ||
97 | result = runCmd('oe-pkgdata-util find-path /usr/bin/man') | ||
98 | self.assertEqual(result.output, 'man: /usr/bin/man') | ||
99 | path1 = os.path.realpath(image_path) | ||
100 | size1 = os.path.getsize(path1) | ||
101 | logger.info('First image %s has size %i' % (path1, size1)) | ||
102 | |||
103 | logger.info('Running bitbake without man in the image package list') | ||
104 | self.write_config('IMAGE_INSTALL_remove = " man "') | ||
105 | bitbake('-c cleanall man') | ||
106 | bitbake('core-image-minimal') | ||
107 | result = runCmd('oe-pkgdata-util find-path /usr/bin/man', ignore_status=True) | ||
108 | self.assertEqual(result.status, 1, "Status different than 1. output: %s" % result.output) | ||
109 | self.assertEqual(result.output, 'ERROR: Unable to find any package producing path /usr/bin/man') | ||
110 | path2 = os.path.realpath(image_path) | ||
111 | size2 = os.path.getsize(path2) | ||
112 | logger.info('Second image %s has size %i' % (path2, size2)) | ||
113 | self.assertNotEqual(path1, path2, "Image paths are identical; image was not rebuilt.") | ||
114 | self.assertNotEqual(size1, size2, "Image sizes are identical; image was not rebuilt.") | ||
115 | |||
116 | |||
117 | class QemuTests(oeSelfTest): | ||
118 | |||
119 | @classmethod | ||
120 | def setUpClass(cls): | ||
121 | logger = logging.getLogger("selftest") | ||
122 | logger.info('Running bitbake to build core-image-minimal') | ||
123 | bitbake('core-image-minimal') | ||
124 | # Create empty object. | ||
125 | args = type('', (), {})() | ||
126 | args.imagename = 'core-image-minimal' | ||
127 | args.mac = None | ||
128 | # Could use DEPLOY_DIR_IMAGE here but it's already in the machine | ||
129 | # subdirectory. | ||
130 | args.dir = 'tmp/deploy/images' | ||
131 | args.efi = False | ||
132 | args.machine = None | ||
133 | args.kvm = None # Autodetect | ||
134 | args.no_gui = True | ||
135 | args.gdb = False | ||
136 | args.pcap = None | ||
137 | args.overlay = None | ||
138 | args.dry_run = False | ||
139 | |||
140 | cls.qemu = QemuCommand(args) | ||
141 | cmdline = cls.qemu.command_line() | ||
142 | print('Booting image with run-qemu-ota...') | ||
143 | cls.s = subprocess.Popen(cmdline) | ||
144 | time.sleep(10) | ||
145 | |||
146 | @classmethod | ||
147 | def tearDownClass(cls): | ||
148 | try: | ||
149 | cls.s.terminate() | ||
150 | except KeyboardInterrupt: | ||
151 | pass | ||
152 | |||
153 | def run_test_qemu(self, command): | ||
154 | command = ['ssh -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@localhost -p ' + | ||
155 | str(self.qemu.ssh_port) + ' "' + command + '"'] | ||
156 | s2 = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | ||
157 | value, err = s2.communicate() | ||
158 | return value, err | ||
159 | |||
160 | def test_hostname(self): | ||
161 | print('') | ||
162 | print('Checking machine name (hostname) of device:') | ||
163 | value, err = self.run_test_qemu('hostname') | ||
164 | machine = get_bb_var('MACHINE', 'core-image-minimal') | ||
165 | self.assertEqual(err, b'', 'Error: ' + err.decode()) | ||
166 | # Strip off line ending. | ||
167 | value_str = value.decode()[:-1] | ||
168 | self.assertEqual(value_str, machine, | ||
169 | 'MACHINE does not match hostname: ' + machine + ', ' + value_str) | ||
170 | print(value_str) | ||
171 | |||
172 | def test_var_sota(self): | ||
173 | print('') | ||
174 | print('Checking contents of /var/sota:') | ||
175 | value, err = self.run_test_qemu('ls /var/sota') | ||
176 | self.assertEqual(err, b'', 'Error: ' + err.decode()) | ||
177 | print(value.decode()) | ||
178 | |||
179 | |||