diff options
Diffstat (limited to 'lib/oeqa/selftest/updater.py')
-rw-r--r-- | lib/oeqa/selftest/updater.py | 128 |
1 files changed, 78 insertions, 50 deletions
diff --git a/lib/oeqa/selftest/updater.py b/lib/oeqa/selftest/updater.py index ad99964..f28349f 100644 --- a/lib/oeqa/selftest/updater.py +++ b/lib/oeqa/selftest/updater.py | |||
@@ -31,27 +31,17 @@ class SotaToolsTests(oeSelfTest): | |||
31 | result = runCmd('%s --help' % p, ignore_status=True) | 31 | result = runCmd('%s --help' % p, ignore_status=True) |
32 | self.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output) | 32 | self.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output) |
33 | 33 | ||
34 | 34 | def test_garagesign_help(self): | |
35 | class GarageSignTests(oeSelfTest): | 35 | bb_vars = get_bb_vars(['SYSROOT_DESTDIR', 'bindir'], 'aktualizr-native') |
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" | 36 | p = bb_vars['SYSROOT_DESTDIR'] + bb_vars['bindir'] + "/" + "garage-sign" |
46 | self.assertTrue(os.path.isfile(p), msg = "No garage-sign found (%s)" % p) | 37 | self.assertTrue(os.path.isfile(p), msg = "No garage-sign found (%s)" % p) |
47 | result = runCmd('%s --help' % p, ignore_status=True) | 38 | result = runCmd('%s --help' % p, ignore_status=True) |
48 | self.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output) | 39 | self.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output) |
49 | 40 | ||
50 | |||
51 | class HsmTests(oeSelfTest): | 41 | class HsmTests(oeSelfTest): |
52 | 42 | ||
53 | def test_hsm(self): | 43 | def test_hsm(self): |
54 | self.write_config('SOTA_CLIENT_FEATURES="hsm hsm-test"') | 44 | self.write_config('SOTA_CLIENT_FEATURES="hsm"') |
55 | bitbake('core-image-minimal') | 45 | bitbake('core-image-minimal') |
56 | 46 | ||
57 | 47 | ||
@@ -118,49 +108,16 @@ class QemuTests(oeSelfTest): | |||
118 | 108 | ||
119 | @classmethod | 109 | @classmethod |
120 | def setUpClass(cls): | 110 | def setUpClass(cls): |
121 | logger = logging.getLogger("selftest") | 111 | cls.qemu, cls.s = qemu_launch(machine='qemux86-64') |
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 | 112 | ||
146 | @classmethod | 113 | @classmethod |
147 | def tearDownClass(cls): | 114 | def tearDownClass(cls): |
148 | try: | 115 | qemu_terminate(cls.s) |
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 | 116 | ||
160 | def test_hostname(self): | 117 | def test_hostname(self): |
161 | print('') | 118 | print('') |
162 | print('Checking machine name (hostname) of device:') | 119 | print('Checking machine name (hostname) of device:') |
163 | value, err = self.run_test_qemu('hostname') | 120 | value, err = qemu_send_command(self.qemu.ssh_port, 'hostname') |
164 | machine = get_bb_var('MACHINE', 'core-image-minimal') | 121 | machine = get_bb_var('MACHINE', 'core-image-minimal') |
165 | self.assertEqual(err, b'', 'Error: ' + err.decode()) | 122 | self.assertEqual(err, b'', 'Error: ' + err.decode()) |
166 | # Strip off line ending. | 123 | # Strip off line ending. |
@@ -172,8 +129,79 @@ class QemuTests(oeSelfTest): | |||
172 | def test_var_sota(self): | 129 | def test_var_sota(self): |
173 | print('') | 130 | print('') |
174 | print('Checking contents of /var/sota:') | 131 | print('Checking contents of /var/sota:') |
175 | value, err = self.run_test_qemu('ls /var/sota') | 132 | value, err = qemu_send_command(self.qemu.ssh_port, 'ls /var/sota') |
176 | self.assertEqual(err, b'', 'Error: ' + err.decode()) | 133 | self.assertEqual(err, b'', 'Error: ' + err.decode()) |
177 | print(value.decode()) | 134 | print(value.decode()) |
178 | 135 | ||
136 | class GrubTests(oeSelfTest): | ||
137 | |||
138 | def setUpLocal(self): | ||
139 | # This is a bit of a hack but I can't see a better option. | ||
140 | path = os.path.abspath(os.path.dirname(__file__)) | ||
141 | metadir = path + "/../../../../" | ||
142 | grub_config = 'OSTREE_BOOTLOADER = "grub"\nMACHINE = "intel-corei7-64"' | ||
143 | self.append_config(grub_config) | ||
144 | self.meta_intel = metadir + "meta-intel" | ||
145 | self.meta_minnow = metadir + "meta-updater-minnowboard" | ||
146 | runCmd('bitbake-layers add-layer "%s"' % self.meta_intel) | ||
147 | runCmd('bitbake-layers add-layer "%s"' % self.meta_minnow) | ||
148 | self.qemu, self.s = qemu_launch(efi=True, machine='intel-corei7-64') | ||
149 | |||
150 | def tearDownLocal(self): | ||
151 | qemu_terminate(self.s) | ||
152 | runCmd('bitbake-layers remove-layer "%s"' % self.meta_intel, ignore_status=True) | ||
153 | runCmd('bitbake-layers remove-layer "%s"' % self.meta_minnow, ignore_status=True) | ||
154 | |||
155 | def test_grub(self): | ||
156 | print('') | ||
157 | print('Checking machine name (hostname) of device:') | ||
158 | value, err = qemu_send_command(self.qemu.ssh_port, 'hostname') | ||
159 | machine = get_bb_var('MACHINE', 'core-image-minimal') | ||
160 | self.assertEqual(err, b'', 'Error: ' + err.decode()) | ||
161 | # Strip off line ending. | ||
162 | value_str = value.decode()[:-1] | ||
163 | self.assertEqual(value_str, machine, | ||
164 | 'MACHINE does not match hostname: ' + machine + ', ' + value_str) | ||
165 | print(value_str) | ||
166 | |||
167 | |||
168 | def qemu_launch(efi=False, machine=None): | ||
169 | logger = logging.getLogger("selftest") | ||
170 | logger.info('Running bitbake to build core-image-minimal') | ||
171 | bitbake('core-image-minimal') | ||
172 | # Create empty object. | ||
173 | args = type('', (), {})() | ||
174 | args.imagename = 'core-image-minimal' | ||
175 | args.mac = None | ||
176 | # Could use DEPLOY_DIR_IMAGE here but it's already in the machine | ||
177 | # subdirectory. | ||
178 | args.dir = 'tmp/deploy/images' | ||
179 | args.efi = efi | ||
180 | args.machine = machine | ||
181 | args.kvm = None # Autodetect | ||
182 | args.no_gui = True | ||
183 | args.gdb = False | ||
184 | args.pcap = None | ||
185 | args.overlay = None | ||
186 | args.dry_run = False | ||
187 | |||
188 | qemu = QemuCommand(args) | ||
189 | cmdline = qemu.command_line() | ||
190 | print('Booting image with run-qemu-ota...') | ||
191 | s = subprocess.Popen(cmdline) | ||
192 | time.sleep(10) | ||
193 | return qemu, s | ||
194 | |||
195 | def qemu_terminate(s): | ||
196 | try: | ||
197 | s.terminate() | ||
198 | except KeyboardInterrupt: | ||
199 | pass | ||
200 | |||
201 | def qemu_send_command(port, command): | ||
202 | command = ['ssh -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@localhost -p ' + | ||
203 | str(port) + ' "' + command + '"'] | ||
204 | s2 = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | ||
205 | value, err = s2.communicate() | ||
206 | return value, err | ||
179 | 207 | ||