diff options
author | Daniel Istrate <daniel.alexandrux.istrate@intel.com> | 2015-07-21 15:54:40 +0300 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2015-07-21 23:56:17 +0100 |
commit | d6fa512d90c6baabda6fb3daa1f9ca3da2b08a79 (patch) | |
tree | 3eb2933978d4d139b91a1f77c63b58a03f2faed0 | |
parent | aa05be4882eed830c2fc91f93653223edfab2a0c (diff) | |
download | poky-d6fa512d90c6baabda6fb3daa1f9ca3da2b08a79.tar.gz |
oeqa/selftest: Fix imagefeature testcases not to interfere with testimage on AB
[YOCTO #8017] - selftest does not use pkill qemu
[YOCTO #7976] - tests do not touch .ssh/known_hosts
- don't hardcode qemu IP
[YOCTO #8027] - use qemu nographic
Extra: removed unnecessary assert for bitbake and runCmd status
(From OE-Core rev: f58df3a630b774083934171463b2b07add29dc0e)
Signed-off-by: Daniel Istrate <daniel.alexandrux.istrate@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r-- | meta/lib/oeqa/selftest/imagefeatures.py | 148 |
1 files changed, 48 insertions, 100 deletions
diff --git a/meta/lib/oeqa/selftest/imagefeatures.py b/meta/lib/oeqa/selftest/imagefeatures.py index e0e424dada..70ebbe4321 100644 --- a/meta/lib/oeqa/selftest/imagefeatures.py +++ b/meta/lib/oeqa/selftest/imagefeatures.py | |||
@@ -2,13 +2,20 @@ from oeqa.selftest.base import oeSelfTest | |||
2 | from oeqa.utils.commands import runCmd, bitbake, get_bb_var | 2 | from oeqa.utils.commands import runCmd, bitbake, get_bb_var |
3 | from oeqa.utils.decorators import testcase | 3 | from oeqa.utils.decorators import testcase |
4 | import pexpect | 4 | import pexpect |
5 | from os.path import expanduser, isfile | 5 | from os.path import isfile |
6 | from os import system | 6 | from os import system, killpg |
7 | import glob | 7 | import glob |
8 | import signal | ||
8 | 9 | ||
9 | 10 | ||
10 | class ImageFeatures(oeSelfTest): | 11 | class ImageFeatures(oeSelfTest): |
11 | 12 | ||
13 | test_user = 'tester' | ||
14 | root_user = 'root' | ||
15 | prompt = r'qemux86:\S+[$#]\s+' | ||
16 | ssh_cmd = "ssh {} -l {} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" | ||
17 | get_ip_patt = r'\s+ip=(?P<qemu_ip>(\d+.){3}\d+)::' | ||
18 | |||
12 | @testcase(1107) | 19 | @testcase(1107) |
13 | def test_non_root_user_can_connect_via_ssh_without_password(self): | 20 | def test_non_root_user_can_connect_via_ssh_without_password(self): |
14 | """ | 21 | """ |
@@ -20,69 +27,45 @@ class ImageFeatures(oeSelfTest): | |||
20 | AutomatedBy: Daniel Istrate <daniel.alexandrux.istrate@intel.com> | 27 | AutomatedBy: Daniel Istrate <daniel.alexandrux.istrate@intel.com> |
21 | """ | 28 | """ |
22 | 29 | ||
23 | test_user = 'tester' | ||
24 | root_user = 'root' | ||
25 | prompt = r'qemux86:\S+[$#]\s+' | ||
26 | tap_inf_ip = '192.168.7.2' | ||
27 | |||
28 | features = 'EXTRA_IMAGE_FEATURES += "ssh-server-openssh empty-root-password"\n' | 30 | features = 'EXTRA_IMAGE_FEATURES += "ssh-server-openssh empty-root-password"\n' |
29 | features += 'INHERIT += "extrausers"\n' | 31 | features += 'INHERIT += "extrausers"\n' |
30 | features += 'EXTRA_USERS_PARAMS = "useradd -p \'\' {}; usermod -s /bin/sh {};"'.format(test_user, test_user) | 32 | features += 'EXTRA_USERS_PARAMS = "useradd -p \'\' {}; usermod -s /bin/sh {};"'.format(self.test_user, self.test_user) |
31 | 33 | ||
32 | # Append 'features' to local.conf | 34 | # Append 'features' to local.conf |
33 | self.append_config(features) | 35 | self.append_config(features) |
34 | 36 | ||
35 | # Build a core-image-minimal | 37 | # Build a core-image-minimal |
36 | ret = bitbake('core-image-minimal') | 38 | bitbake('core-image-minimal') |
37 | self.assertEqual(0, ret.status, 'Failed to build a core-image-minimal') | ||
38 | |||
39 | rm_ssh_keys_cmd = 'ssh-keygen -f "{}/.ssh/known_hosts" -R {}'.format(expanduser('~'), tap_inf_ip) | ||
40 | # Delete the ssh keys for 192.168.7.2 (qemu) | ||
41 | ret = runCmd(rm_ssh_keys_cmd) | ||
42 | self.assertEqual(0, ret.status, 'Failed to delete ssh keys for qemu host.') | ||
43 | 39 | ||
44 | # Boot qemu image | 40 | # Boot qemu image |
45 | proc_qemu = pexpect.spawn('runqemu qemux86 nographic') | 41 | proc_qemu = pexpect.spawn('runqemu qemux86 nographic') |
46 | try: | 42 | try: |
43 | proc_qemu.expect(self.get_ip_patt, timeout=100) | ||
44 | qemu_ip = proc_qemu.match.group('qemu_ip') | ||
47 | proc_qemu.expect('qemux86 login:', timeout=100) | 45 | proc_qemu.expect('qemux86 login:', timeout=100) |
48 | except: | 46 | except: |
49 | system('pkill qemu') | 47 | killpg(proc_qemu.pid, signal.SIGTERM) |
50 | proc_qemu.close() | ||
51 | self.fail('Failed to start qemu.') | 48 | self.fail('Failed to start qemu.') |
52 | 49 | ||
53 | # Attempt to ssh with each user into qemu with empty password | 50 | # Attempt to ssh with each user into qemu with empty password |
54 | for user in [root_user, test_user]: | 51 | for user in [self.root_user, self.test_user]: |
55 | proc_ssh = pexpect.spawn('ssh {} -l {}'.format(tap_inf_ip, user)) | 52 | proc_ssh = pexpect.spawn(self.ssh_cmd.format(qemu_ip, user)) |
56 | index = proc_ssh.expect(['Are you sure you want to continue connecting', prompt, pexpect.TIMEOUT, pexpect.EOF]) | 53 | index = proc_ssh.expect([self.prompt, pexpect.TIMEOUT, pexpect.EOF]) |
57 | if index == 0: | 54 | if index == 0: |
58 | proc_ssh.sendline('yes') | ||
59 | try: | ||
60 | proc_ssh.expect(prompt) | ||
61 | except: | ||
62 | system('pkill qemu') | ||
63 | proc_qemu.close() | ||
64 | proc_ssh.terminate() | ||
65 | self.fail('Failed to ssh with {} user into qemu.'.format(user)) | ||
66 | elif index == 1: | ||
67 | # user successfully logged in with empty password | 55 | # user successfully logged in with empty password |
68 | pass | 56 | pass |
69 | elif index == 2: | 57 | elif index == 1: |
70 | system('pkill qemu') | 58 | killpg(proc_qemu.pid, signal.SIGTERM) |
71 | proc_qemu.close() | ||
72 | proc_ssh.terminate() | 59 | proc_ssh.terminate() |
73 | self.fail('Failed to ssh with {} user into qemu (timeout).'.format(user)) | 60 | self.fail('Failed to ssh with {} user into qemu (timeout).'.format(user)) |
74 | else: | 61 | else: |
75 | system('pkill qemu') | 62 | killpg(proc_qemu.pid, signal.SIGTERM) |
76 | proc_qemu.close() | ||
77 | proc_ssh.terminate() | 63 | proc_ssh.terminate() |
78 | self.fail('Failed to ssh with {} user into qemu (eof).'.format(user)) | 64 | self.fail('Failed to ssh with {} user into qemu (eof).'.format(user)) |
65 | proc_ssh.terminate() | ||
79 | 66 | ||
80 | # Cleanup | 67 | # Cleanup |
81 | system('pkill qemu') | 68 | killpg(proc_qemu.pid, signal.SIGTERM) |
82 | proc_qemu.close() | ||
83 | proc_ssh.terminate() | ||
84 | ret = runCmd(rm_ssh_keys_cmd) | ||
85 | self.assertEqual(0, ret.status, 'Failed to delete ssh keys for qemu host (at cleanup).') | ||
86 | 69 | ||
87 | @testcase(1115) | 70 | @testcase(1115) |
88 | def test_all_users_can_connect_via_ssh_without_password(self): | 71 | def test_all_users_can_connect_via_ssh_without_password(self): |
@@ -93,69 +76,46 @@ class ImageFeatures(oeSelfTest): | |||
93 | Author: Ionut Chisanovici <ionutx.chisanovici@intel.com> | 76 | Author: Ionut Chisanovici <ionutx.chisanovici@intel.com> |
94 | AutomatedBy: Daniel Istrate <daniel.alexandrux.istrate@intel.com> | 77 | AutomatedBy: Daniel Istrate <daniel.alexandrux.istrate@intel.com> |
95 | """ | 78 | """ |
96 | test_user = 'tester' | ||
97 | root_user = 'root' | ||
98 | prompt = r'qemux86:\S+[$#]\s+' | ||
99 | tap_inf_ip = '192.168.7.2' | ||
100 | 79 | ||
101 | features = 'EXTRA_IMAGE_FEATURES += "ssh-server-openssh allow-empty-password"\n' | 80 | features = 'EXTRA_IMAGE_FEATURES += "ssh-server-openssh allow-empty-password"\n' |
102 | features += 'INHERIT += "extrausers"\n' | 81 | features += 'INHERIT += "extrausers"\n' |
103 | features += 'EXTRA_USERS_PARAMS = "useradd -p \'\' {}; usermod -s /bin/sh {};"'.format(test_user, test_user) | 82 | features += 'EXTRA_USERS_PARAMS = "useradd -p \'\' {}; usermod -s /bin/sh {};"'.format(self.test_user, self.test_user) |
104 | 83 | ||
105 | # Append 'features' to local.conf | 84 | # Append 'features' to local.conf |
106 | self.append_config(features) | 85 | self.append_config(features) |
107 | 86 | ||
108 | # Build a core-image-minimal | 87 | # Build a core-image-minimal |
109 | ret = bitbake('core-image-minimal') | 88 | bitbake('core-image-minimal') |
110 | self.assertEqual(0, ret.status, 'Failed to build a core-image-minimal') | ||
111 | |||
112 | rm_ssh_keys_cmd = 'ssh-keygen -f "{}/.ssh/known_hosts" -R {}'.format(expanduser('~'), tap_inf_ip) | ||
113 | # Delete the ssh keys for 192.168.7.2 (qemu) | ||
114 | ret = runCmd(rm_ssh_keys_cmd) | ||
115 | self.assertEqual(0, ret.status, 'Failed to delete ssh keys for qemu host.') | ||
116 | 89 | ||
117 | # Boot qemu image | 90 | # Boot qemu image |
118 | proc_qemu = pexpect.spawn('runqemu qemux86 nographic') | 91 | proc_qemu = pexpect.spawn('runqemu qemux86 nographic') |
119 | try: | 92 | try: |
93 | proc_qemu.expect(self.get_ip_patt, timeout=100) | ||
94 | qemu_ip = proc_qemu.match.group('qemu_ip') | ||
120 | proc_qemu.expect('qemux86 login:', timeout=100) | 95 | proc_qemu.expect('qemux86 login:', timeout=100) |
121 | except: | 96 | except: |
122 | system('pkill qemu') | 97 | killpg(proc_qemu.pid, signal.SIGTERM) |
123 | proc_qemu.close() | ||
124 | self.fail('Failed to start qemu.') | 98 | self.fail('Failed to start qemu.') |
125 | 99 | ||
126 | # Attempt to ssh with each user into qemu with empty password | 100 | # Attempt to ssh with each user into qemu with empty password |
127 | for user in [root_user, test_user]: | 101 | for user in [self.root_user, self.test_user]: |
128 | proc_ssh = pexpect.spawn('ssh {} -l {}'.format(tap_inf_ip, user)) | 102 | proc_ssh = pexpect.spawn(self.ssh_cmd.format(qemu_ip, user)) |
129 | index = proc_ssh.expect(['Are you sure you want to continue connecting', prompt, pexpect.TIMEOUT, pexpect.EOF]) | 103 | index = proc_ssh.expect([self.prompt, pexpect.TIMEOUT, pexpect.EOF]) |
130 | if index == 0: | 104 | if index == 0: |
131 | proc_ssh.sendline('yes') | ||
132 | try: | ||
133 | proc_ssh.expect(prompt) | ||
134 | except: | ||
135 | system('pkill qemu') | ||
136 | proc_qemu.close() | ||
137 | proc_ssh.terminate() | ||
138 | self.fail('Failed to ssh with {} user into qemu.'.format(user)) | ||
139 | elif index == 1: | ||
140 | # user successfully logged in with empty password | 105 | # user successfully logged in with empty password |
141 | pass | 106 | pass |
142 | elif index == 2: | 107 | elif index == 1: |
143 | system('pkill qemu') | 108 | killpg(proc_qemu.pid, signal.SIGTERM) |
144 | proc_qemu.close() | ||
145 | proc_ssh.terminate() | 109 | proc_ssh.terminate() |
146 | self.fail('Failed to ssh with {} user into qemu (timeout).'.format(user)) | 110 | self.fail('Failed to ssh with {} user into qemu (timeout).'.format(user)) |
147 | else: | 111 | else: |
148 | system('pkill qemu') | 112 | killpg(proc_qemu.pid, signal.SIGTERM) |
149 | proc_qemu.close() | ||
150 | proc_ssh.terminate() | 113 | proc_ssh.terminate() |
151 | self.fail('Failed to ssh with {} user into qemu (eof).'.format(user)) | 114 | self.fail('Failed to ssh with {} user into qemu (eof).'.format(user)) |
115 | proc_ssh.terminate() | ||
152 | 116 | ||
153 | # Cleanup | 117 | # Cleanup |
154 | system('pkill qemu') | 118 | killpg(proc_qemu.pid, signal.SIGTERM) |
155 | proc_qemu.close() | ||
156 | proc_ssh.terminate() | ||
157 | ret = runCmd(rm_ssh_keys_cmd) | ||
158 | self.assertEqual(0, ret.status, 'Failed to delete ssh keys for qemu host (at cleanup).') | ||
159 | 119 | ||
160 | @testcase(1114) | 120 | @testcase(1114) |
161 | def test_rpm_version_4_support_on_image(self): | 121 | def test_rpm_version_4_support_on_image(self): |
@@ -167,8 +127,6 @@ class ImageFeatures(oeSelfTest): | |||
167 | AutomatedBy: Daniel Istrate <daniel.alexandrux.istrate@intel.com> | 127 | AutomatedBy: Daniel Istrate <daniel.alexandrux.istrate@intel.com> |
168 | """ | 128 | """ |
169 | 129 | ||
170 | root_user = 'root' | ||
171 | prompt = '{}@qemux86:~# '.format(root_user) | ||
172 | rpm_version = '4.11.2' | 130 | rpm_version = '4.11.2' |
173 | features = 'IMAGE_INSTALL_append = " rpm"\n' | 131 | features = 'IMAGE_INSTALL_append = " rpm"\n' |
174 | features += 'PREFERRED_VERSION_rpm = "{}"\n'.format(rpm_version) | 132 | features += 'PREFERRED_VERSION_rpm = "{}"\n'.format(rpm_version) |
@@ -179,33 +137,28 @@ class ImageFeatures(oeSelfTest): | |||
179 | self.append_config(features) | 137 | self.append_config(features) |
180 | 138 | ||
181 | # Build a core-image-minimal | 139 | # Build a core-image-minimal |
182 | ret = bitbake('core-image-minimal') | 140 | bitbake('core-image-minimal') |
183 | self.assertEqual(0, ret.status, 'Failed to build a core-image-minimal') | ||
184 | 141 | ||
185 | # Boot qemu image & get rpm version | 142 | # Boot qemu image & get rpm version |
186 | proc_qemu = pexpect.spawn('runqemu qemux86 nographic') | 143 | proc_qemu = pexpect.spawn('runqemu qemux86 nographic') |
187 | try: | 144 | try: |
188 | proc_qemu.expect('qemux86 login:', timeout=100) | 145 | proc_qemu.expect('qemux86 login:', timeout=100) |
189 | proc_qemu.sendline(root_user) | 146 | proc_qemu.sendline(self.root_user) |
190 | proc_qemu.expect(prompt) | 147 | proc_qemu.expect(self.prompt) |
191 | proc_qemu.sendline('rpm --version') | 148 | proc_qemu.sendline('rpm --version') |
192 | proc_qemu.expect(prompt) | 149 | proc_qemu.expect(self.prompt) |
193 | except: | 150 | except: |
194 | system('pkill qemu') | 151 | killpg(proc_qemu.pid, signal.SIGTERM) |
195 | proc_qemu.close() | ||
196 | self.fail('Failed to boot qemu.') | 152 | self.fail('Failed to boot qemu.') |
197 | 153 | ||
198 | found_rpm_version = proc_qemu.before | 154 | found_rpm_version = proc_qemu.before |
199 | 155 | ||
200 | # Make sure the retrieved rpm version is the expected one | 156 | # Make sure the retrieved rpm version is the expected one |
201 | if rpm_version not in found_rpm_version: | 157 | self.assertIn(rpm_version, found_rpm_version, |
202 | system('pkill qemu') | 158 | 'RPM version is not {}, found instead {}.'.format(rpm_version, found_rpm_version)) |
203 | proc_qemu.close() | ||
204 | self.fail('RPM version is not {}, found instead {}.'.format(rpm_version, found_rpm_version)) | ||
205 | 159 | ||
206 | # Cleanup (close qemu) | 160 | # Cleanup (close qemu) |
207 | system('pkill qemu') | 161 | killpg(proc_qemu.pid, signal.SIGTERM) |
208 | proc_qemu.close() | ||
209 | 162 | ||
210 | @testcase(1116) | 163 | @testcase(1116) |
211 | def test_clutter_image_can_be_built(self): | 164 | def test_clutter_image_can_be_built(self): |
@@ -218,8 +171,7 @@ class ImageFeatures(oeSelfTest): | |||
218 | """ | 171 | """ |
219 | 172 | ||
220 | # Build a core-image-clutter | 173 | # Build a core-image-clutter |
221 | ret = bitbake('core-image-clutter') | 174 | bitbake('core-image-clutter') |
222 | self.assertEqual(0, ret.status, 'Failed to build core-image-clutter') | ||
223 | 175 | ||
224 | @testcase(1117) | 176 | @testcase(1117) |
225 | def test_wayland_support_in_image(self): | 177 | def test_wayland_support_in_image(self): |
@@ -239,8 +191,7 @@ class ImageFeatures(oeSelfTest): | |||
239 | self.append_config(features) | 191 | self.append_config(features) |
240 | 192 | ||
241 | # Build a core-image-weston | 193 | # Build a core-image-weston |
242 | ret = bitbake('core-image-weston') | 194 | bitbake('core-image-weston') |
243 | self.assertEqual(0, ret.status, 'Failed to build a core-image-weston') | ||
244 | 195 | ||
245 | 196 | ||
246 | class Gummiboot(oeSelfTest): | 197 | class Gummiboot(oeSelfTest): |
@@ -263,8 +214,7 @@ class Gummiboot(oeSelfTest): | |||
263 | self.add_command_to_tearDown('rm -rf ' + self.meta_intel_dir) | 214 | self.add_command_to_tearDown('rm -rf ' + self.meta_intel_dir) |
264 | 215 | ||
265 | # Clone meta-intel | 216 | # Clone meta-intel |
266 | ret = runCmd('git clone ' + meta_intel_repo + ' ' + self.meta_intel_dir) | 217 | runCmd('git clone ' + meta_intel_repo + ' ' + self.meta_intel_dir) |
267 | self.assertEqual(0, ret.status, 'Failed to clone meta-intel.') | ||
268 | 218 | ||
269 | # Add meta-intel and meta-nuc layers in conf/bblayers.conf | 219 | # Add meta-intel and meta-nuc layers in conf/bblayers.conf |
270 | features = 'BBLAYERS += "' + self.meta_intel_dir + ' ' + meta_nuc_dir + '"' | 220 | features = 'BBLAYERS += "' + self.meta_intel_dir + ' ' + meta_nuc_dir + '"' |
@@ -278,8 +228,7 @@ class Gummiboot(oeSelfTest): | |||
278 | # Run "bitbake syslinux syslinux-native parted-native dosfstools-native mtools-native core-image-minimal " | 228 | # Run "bitbake syslinux syslinux-native parted-native dosfstools-native mtools-native core-image-minimal " |
279 | # to build a nuc/efi gummiboot image | 229 | # to build a nuc/efi gummiboot image |
280 | 230 | ||
281 | ret = bitbake('syslinux syslinux-native parted-native dosfstools-native mtools-native core-image-minimal') | 231 | bitbake('syslinux syslinux-native parted-native dosfstools-native mtools-native core-image-minimal') |
282 | self.assertEqual(0, ret.status, 'Failed to build a core-image-minimal') | ||
283 | 232 | ||
284 | @testcase(1101) | 233 | @testcase(1101) |
285 | def test_efi_gummiboot_images_can_be_build(self): | 234 | def test_efi_gummiboot_images_can_be_build(self): |
@@ -310,8 +259,7 @@ class Gummiboot(oeSelfTest): | |||
310 | 259 | ||
311 | # Create efi/gummiboot installation images | 260 | # Create efi/gummiboot installation images |
312 | wic_create_cmd = 'wic create mkgummidisk -e core-image-minimal' | 261 | wic_create_cmd = 'wic create mkgummidisk -e core-image-minimal' |
313 | ret = runCmd(wic_create_cmd) | 262 | runCmd(wic_create_cmd) |
314 | self.assertEqual(0, ret.status, 'Failed to create efi/gummiboot installation images.') | ||
315 | 263 | ||
316 | # Verify that a .direct file was created | 264 | # Verify that a .direct file was created |
317 | direct_file = '/var/tmp/wic/build/*.direct' | 265 | direct_file = '/var/tmp/wic/build/*.direct' |