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