blob: 8c95432e00b3cb58bb4efe6a341c273b24896f96 [file] [log] [blame]
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001from oeqa.selftest.case import OESelftestTestCase
2from oeqa.utils.commands import runCmd, bitbake, get_bb_var, runqemu
3from oeqa.core.decorator.oeid import OETestID
4from oeqa.utils.sshcontrol import SSHControl
5import os
6import json
7
8class ImageFeatures(OESelftestTestCase):
9
10 test_user = 'tester'
11 root_user = 'root'
12
Brad Bishopd7bf8c12018-02-25 22:55:05 -050013 @OETestID(1107)
14 def test_non_root_user_can_connect_via_ssh_without_password(self):
15 """
16 Summary: Check if non root user can connect via ssh without password
17 Expected: 1. Connection to the image via ssh using root user without providing a password should be allowed.
18 2. Connection to the image via ssh using tester user without providing a password should be allowed.
19 Product: oe-core
20 Author: Ionut Chisanovici <ionutx.chisanovici@intel.com>
21 AutomatedBy: Daniel Istrate <daniel.alexandrux.istrate@intel.com>
22 """
23
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080024 features = 'EXTRA_IMAGE_FEATURES = "ssh-server-openssh empty-root-password allow-empty-password allow-root-login"\n'
Brad Bishopd7bf8c12018-02-25 22:55:05 -050025 features += 'INHERIT += "extrausers"\n'
26 features += 'EXTRA_USERS_PARAMS = "useradd -p \'\' {}; usermod -s /bin/sh {};"'.format(self.test_user, self.test_user)
27 self.write_config(features)
28
29 # Build a core-image-minimal
30 bitbake('core-image-minimal')
31
32 with runqemu("core-image-minimal") as qemu:
33 # Attempt to ssh with each user into qemu with empty password
34 for user in [self.root_user, self.test_user]:
35 ssh = SSHControl(ip=qemu.ip, logfile=qemu.sshlog, user=user)
36 status, output = ssh.run("true")
37 self.assertEqual(status, 0, 'ssh to user %s failed with %s' % (user, output))
38
39 @OETestID(1115)
40 def test_all_users_can_connect_via_ssh_without_password(self):
41 """
42 Summary: Check if all users can connect via ssh without password
43 Expected: 1. Connection to the image via ssh using root user without providing a password should NOT be allowed.
44 2. Connection to the image via ssh using tester user without providing a password should be allowed.
45 Product: oe-core
46 Author: Ionut Chisanovici <ionutx.chisanovici@intel.com>
47 AutomatedBy: Daniel Istrate <daniel.alexandrux.istrate@intel.com>
48 """
49
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080050 features = 'EXTRA_IMAGE_FEATURES = "ssh-server-openssh allow-empty-password allow-root-login"\n'
Brad Bishopd7bf8c12018-02-25 22:55:05 -050051 features += 'INHERIT += "extrausers"\n'
52 features += 'EXTRA_USERS_PARAMS = "useradd -p \'\' {}; usermod -s /bin/sh {};"'.format(self.test_user, self.test_user)
53 self.write_config(features)
54
55 # Build a core-image-minimal
56 bitbake('core-image-minimal')
57
58 with runqemu("core-image-minimal") as qemu:
59 # Attempt to ssh with each user into qemu with empty password
60 for user in [self.root_user, self.test_user]:
61 ssh = SSHControl(ip=qemu.ip, logfile=qemu.sshlog, user=user)
62 status, output = ssh.run("true")
63 if user == 'root':
64 self.assertNotEqual(status, 0, 'ssh to user root was allowed when it should not have been')
65 else:
66 self.assertEqual(status, 0, 'ssh to user tester failed with %s' % output)
67
68
69 @OETestID(1116)
70 def test_clutter_image_can_be_built(self):
71 """
72 Summary: Check if clutter image can be built
73 Expected: 1. core-image-clutter can be built
74 Product: oe-core
75 Author: Ionut Chisanovici <ionutx.chisanovici@intel.com>
76 AutomatedBy: Daniel Istrate <daniel.alexandrux.istrate@intel.com>
77 """
78
79 # Build a core-image-clutter
80 bitbake('core-image-clutter')
81
82 @OETestID(1117)
83 def test_wayland_support_in_image(self):
84 """
85 Summary: Check Wayland support in image
86 Expected: 1. Wayland image can be build
87 2. Wayland feature can be installed
88 Product: oe-core
89 Author: Ionut Chisanovici <ionutx.chisanovici@intel.com>
90 AutomatedBy: Daniel Istrate <daniel.alexandrux.istrate@intel.com>
91 """
92
93 distro_features = get_bb_var('DISTRO_FEATURES')
94 if not ('opengl' in distro_features and 'wayland' in distro_features):
95 self.skipTest('neither opengl nor wayland present on DISTRO_FEATURES so core-image-weston cannot be built')
96
97 # Build a core-image-weston
98 bitbake('core-image-weston')
99
100 @OETestID(1497)
101 def test_bmap(self):
102 """
103 Summary: Check bmap support
104 Expected: 1. core-image-minimal can be build with bmap support
105 2. core-image-minimal is sparse
106 Product: oe-core
107 Author: Ed Bartosh <ed.bartosh@linux.intel.com>
108 """
109
110 features = 'IMAGE_FSTYPES += " ext4 ext4.bmap ext4.bmap.gz"'
111 self.write_config(features)
112
113 image_name = 'core-image-minimal'
114 bitbake(image_name)
115
116 deploy_dir_image = get_bb_var('DEPLOY_DIR_IMAGE')
117 link_name = get_bb_var('IMAGE_LINK_NAME', image_name)
118 image_path = os.path.join(deploy_dir_image, "%s.ext4" % link_name)
119 bmap_path = "%s.bmap" % image_path
120 gzip_path = "%s.gz" % bmap_path
121
122 # check if result image, bmap and bmap.gz files are in deploy directory
123 self.assertTrue(os.path.exists(image_path))
124 self.assertTrue(os.path.exists(bmap_path))
125 self.assertTrue(os.path.exists(gzip_path))
126
127 # check if result image is sparse
128 image_stat = os.stat(image_path)
129 self.assertTrue(image_stat.st_size > image_stat.st_blocks * 512)
130
131 # check if the resulting gzip is valid
132 self.assertTrue(runCmd('gzip -t %s' % gzip_path))
133
134 @OETestID(1903)
135 def test_hypervisor_fmts(self):
136 """
137 Summary: Check various hypervisor formats
138 Expected: 1. core-image-minimal can be built with vmdk, vdi and
139 qcow2 support.
140 2. qemu-img says each image has the expected format
141 Product: oe-core
142 Author: Tom Rini <trini@konsulko.com>
143 """
144
145 img_types = [ 'vmdk', 'vdi', 'qcow2' ]
146 features = ""
147 for itype in img_types:
148 features += 'IMAGE_FSTYPES += "wic.%s"\n' % itype
149 self.write_config(features)
150
151 image_name = 'core-image-minimal'
152 bitbake(image_name)
153
154 deploy_dir_image = get_bb_var('DEPLOY_DIR_IMAGE')
155 link_name = get_bb_var('IMAGE_LINK_NAME', image_name)
156 for itype in img_types:
157 image_path = os.path.join(deploy_dir_image, "%s.wic.%s" %
158 (link_name, itype))
159
160 # check if result image file is in deploy directory
161 self.assertTrue(os.path.exists(image_path))
162
163 # check if result image is vmdk
164 sysroot = get_bb_var('STAGING_DIR_NATIVE', 'core-image-minimal')
165 result = runCmd('qemu-img info --output json %s' % image_path,
166 native_sysroot=sysroot)
167 self.assertTrue(json.loads(result.output).get('format') == itype)
168
169 @OETestID(1905)
170 def test_long_chain_conversion(self):
171 """
172 Summary: Check for chaining many CONVERSION_CMDs together
173 Expected: 1. core-image-minimal can be built with
174 ext4.bmap.gz.bz2.lzo.xz.u-boot and also create a
175 sha256sum
176 2. The above image has a valid sha256sum
177 Product: oe-core
178 Author: Tom Rini <trini@konsulko.com>
179 """
180
181 conv = "ext4.bmap.gz.bz2.lzo.xz.u-boot"
182 features = 'IMAGE_FSTYPES += "%s %s.sha256sum"' % (conv, conv)
183 self.write_config(features)
184
185 image_name = 'core-image-minimal'
186 bitbake(image_name)
187
188 deploy_dir_image = get_bb_var('DEPLOY_DIR_IMAGE')
189 link_name = get_bb_var('IMAGE_LINK_NAME', image_name)
190 image_path = os.path.join(deploy_dir_image, "%s.%s" %
191 (link_name, conv))
192
193 # check if resulting image is in the deploy directory
194 self.assertTrue(os.path.exists(image_path))
195 self.assertTrue(os.path.exists(image_path + ".sha256sum"))
196
197 # check if the resulting sha256sum agrees
198 self.assertTrue(runCmd('cd %s;sha256sum -c %s.%s.sha256sum' %
199 (deploy_dir_image, link_name, conv)))
200
201 @OETestID(1904)
202 def test_image_fstypes(self):
203 """
204 Summary: Check if image of supported image fstypes can be built
205 Expected: core-image-minimal can be built for various image types
206 Product: oe-core
207 Author: Ed Bartosh <ed.bartosh@linux.intel.com>
208 """
209 image_name = 'core-image-minimal'
210
211 img_types = [itype for itype in get_bb_var("IMAGE_TYPES", image_name).split() \
Brad Bishop316dfdd2018-06-25 12:45:53 -0400212 if itype not in ('container', 'elf', 'f2fs', 'multiubi')]
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500213
214 config = 'IMAGE_FSTYPES += "%s"\n'\
215 'MKUBIFS_ARGS ?= "-m 2048 -e 129024 -c 2047"\n'\
216 'UBINIZE_ARGS ?= "-m 2048 -p 128KiB -s 512"' % ' '.join(img_types)
217
218 self.write_config(config)
219
220 bitbake(image_name)
221
222 deploy_dir_image = get_bb_var('DEPLOY_DIR_IMAGE')
223 link_name = get_bb_var('IMAGE_LINK_NAME', image_name)
224 for itype in img_types:
225 image_path = os.path.join(deploy_dir_image, "%s.%s" % (link_name, itype))
226 # check if result image is in deploy directory
227 self.assertTrue(os.path.exists(image_path),
228 "%s image %s doesn't exist" % (itype, image_path))
229
230 def test_useradd_static(self):
231 config = """
232USERADDEXTENSION = "useradd-staticids"
233USERADD_ERROR_DYNAMIC = "skip"
234USERADD_UID_TABLES += "files/static-passwd"
235USERADD_GID_TABLES += "files/static-group"
236"""
237 self.write_config(config)
238 bitbake("core-image-base")