Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | from oeqa.selftest.base import oeSelfTest |
| 2 | from oeqa.utils.commands import runCmd, bitbake, get_bb_var, runqemu |
| 3 | from oeqa.utils.decorators import testcase |
| 4 | from oeqa.utils.sshcontrol import SSHControl |
| 5 | import os |
| 6 | import sys |
| 7 | import logging |
| 8 | |
| 9 | class ImageFeatures(oeSelfTest): |
| 10 | |
| 11 | test_user = 'tester' |
| 12 | root_user = 'root' |
| 13 | |
| 14 | @testcase(1107) |
| 15 | def test_non_root_user_can_connect_via_ssh_without_password(self): |
| 16 | """ |
| 17 | Summary: Check if non root user can connect via ssh without password |
| 18 | Expected: 1. Connection to the image via ssh using root user without providing a password should be allowed. |
| 19 | 2. Connection to the image via ssh using tester user without providing a password should be allowed. |
| 20 | Product: oe-core |
| 21 | Author: Ionut Chisanovici <ionutx.chisanovici@intel.com> |
| 22 | AutomatedBy: Daniel Istrate <daniel.alexandrux.istrate@intel.com> |
| 23 | """ |
| 24 | |
| 25 | features = 'EXTRA_IMAGE_FEATURES = "ssh-server-openssh empty-root-password allow-empty-password"\n' |
| 26 | features += 'INHERIT += "extrausers"\n' |
| 27 | features += 'EXTRA_USERS_PARAMS = "useradd -p \'\' {}; usermod -s /bin/sh {};"'.format(self.test_user, self.test_user) |
| 28 | |
| 29 | # Append 'features' to local.conf |
| 30 | self.append_config(features) |
| 31 | |
| 32 | # Build a core-image-minimal |
| 33 | bitbake('core-image-minimal') |
| 34 | |
| 35 | with runqemu("core-image-minimal", self) as qemu: |
| 36 | # Attempt to ssh with each user into qemu with empty password |
| 37 | for user in [self.root_user, self.test_user]: |
| 38 | ssh = SSHControl(ip=qemu.ip, logfile=qemu.sshlog, user=user) |
| 39 | status, output = ssh.run("true") |
| 40 | self.assertEqual(status, 0, 'ssh to user %s failed with %s' % (user, output)) |
| 41 | |
| 42 | @testcase(1115) |
| 43 | def test_all_users_can_connect_via_ssh_without_password(self): |
| 44 | """ |
| 45 | Summary: Check if all users can connect via ssh without password |
| 46 | Expected: 1. Connection to the image via ssh using root user without providing a password should NOT be allowed. |
| 47 | 2. Connection to the image via ssh using tester user without providing a password should be allowed. |
| 48 | Product: oe-core |
| 49 | Author: Ionut Chisanovici <ionutx.chisanovici@intel.com> |
| 50 | AutomatedBy: Daniel Istrate <daniel.alexandrux.istrate@intel.com> |
| 51 | """ |
| 52 | |
| 53 | features = 'EXTRA_IMAGE_FEATURES = "ssh-server-openssh allow-empty-password"\n' |
| 54 | features += 'INHERIT += "extrausers"\n' |
| 55 | features += 'EXTRA_USERS_PARAMS = "useradd -p \'\' {}; usermod -s /bin/sh {};"'.format(self.test_user, self.test_user) |
| 56 | |
| 57 | # Append 'features' to local.conf |
| 58 | self.append_config(features) |
| 59 | |
| 60 | # Build a core-image-minimal |
| 61 | bitbake('core-image-minimal') |
| 62 | |
| 63 | with runqemu("core-image-minimal", self) as qemu: |
| 64 | # Attempt to ssh with each user into qemu with empty password |
| 65 | for user in [self.root_user, self.test_user]: |
| 66 | ssh = SSHControl(ip=qemu.ip, logfile=qemu.sshlog, user=user) |
| 67 | status, output = ssh.run("true") |
| 68 | if user == 'root': |
| 69 | self.assertNotEqual(status, 0, 'ssh to user root was allowed when it should not have been') |
| 70 | else: |
| 71 | self.assertEqual(status, 0, 'ssh to user tester failed with %s' % output) |
| 72 | |
| 73 | |
| 74 | @testcase(1114) |
| 75 | def test_rpm_version_4_support_on_image(self): |
| 76 | """ |
| 77 | Summary: Check rpm version 4 support on image |
| 78 | Expected: Rpm version must be 4.x |
| 79 | Product: oe-core |
| 80 | Author: Ionut Chisanovici <ionutx.chisanovici@intel.com> |
| 81 | AutomatedBy: Daniel Istrate <daniel.alexandrux.istrate@intel.com> |
| 82 | """ |
| 83 | |
| 84 | features = 'PREFERRED_VERSION_rpm = "4.%"\n' |
| 85 | features += 'PREFERRED_VERSION_rpm-native = "4.%"\n' |
| 86 | # Use openssh in IMAGE_INSTALL instead of ssh-server-openssh in EXTRA_IMAGE_FEATURES as a workaround for bug 8047 |
| 87 | features += 'IMAGE_INSTALL_append = " openssh"\n' |
| 88 | features += 'EXTRA_IMAGE_FEATURES = "empty-root-password allow-empty-password package-management"\n' |
| 89 | features += 'RPMROOTFSDEPENDS_remove = "rpmresolve-native:do_populate_sysroot"' |
| 90 | |
| 91 | # Append 'features' to local.conf |
| 92 | self.append_config(features) |
| 93 | |
| 94 | # Build a core-image-minimal |
| 95 | bitbake('core-image-minimal') |
| 96 | |
| 97 | # Check the native version of rpm is correct |
| 98 | native_bindir = get_bb_var('STAGING_BINDIR_NATIVE') |
| 99 | result = runCmd(os.path.join(native_bindir, 'rpm') + ' --version') |
| 100 | self.assertIn('version 4.', result.output) |
| 101 | |
| 102 | # Check manifest for the rpm package |
| 103 | deploydir = get_bb_var('DEPLOY_DIR_IMAGE') |
| 104 | imgname = get_bb_var('IMAGE_LINK_NAME', 'core-image-minimal') |
| 105 | with open(os.path.join(deploydir, imgname) + '.manifest', 'r') as f: |
| 106 | for line in f: |
| 107 | splitline = line.split() |
| 108 | if len(splitline) > 2: |
| 109 | rpm_version = splitline[2] |
| 110 | if splitline[0] == 'rpm': |
| 111 | if not rpm_version.startswith('4.'): |
| 112 | self.fail('rpm version %s found in image, expected 4.x' % rpm_version) |
| 113 | break |
| 114 | else: |
| 115 | self.fail('No rpm package found in image') |
| 116 | |
| 117 | # Now do a couple of runtime tests |
| 118 | with runqemu("core-image-minimal", self) as qemu: |
| 119 | command = "rpm --version" |
| 120 | status, output = qemu.run(command) |
| 121 | self.assertEqual(0, status, 'Failed to run command "%s": %s' % (command, output)) |
| 122 | found_rpm_version = output.strip() |
| 123 | |
| 124 | # Make sure the retrieved rpm version is the expected one |
| 125 | if rpm_version not in found_rpm_version: |
| 126 | self.fail('RPM version is not {}, found instead {}.'.format(rpm_version, found_rpm_version)) |
| 127 | |
| 128 | # Test that the rpm database is there and working |
| 129 | command = "rpm -qa" |
| 130 | status, output = qemu.run(command) |
| 131 | self.assertEqual(0, status, 'Failed to run command "%s": %s' % (command, output)) |
| 132 | self.assertIn('packagegroup-core-boot', output) |
| 133 | self.assertIn('busybox', output) |
| 134 | |
| 135 | |
| 136 | @testcase(1116) |
| 137 | def test_clutter_image_can_be_built(self): |
| 138 | """ |
| 139 | Summary: Check if clutter image can be built |
| 140 | Expected: 1. core-image-clutter can be built |
| 141 | Product: oe-core |
| 142 | Author: Ionut Chisanovici <ionutx.chisanovici@intel.com> |
| 143 | AutomatedBy: Daniel Istrate <daniel.alexandrux.istrate@intel.com> |
| 144 | """ |
| 145 | |
| 146 | # Build a core-image-clutter |
| 147 | bitbake('core-image-clutter') |
| 148 | |
| 149 | @testcase(1117) |
| 150 | def test_wayland_support_in_image(self): |
| 151 | """ |
| 152 | Summary: Check Wayland support in image |
| 153 | Expected: 1. Wayland image can be build |
| 154 | 2. Wayland feature can be installed |
| 155 | Product: oe-core |
| 156 | Author: Ionut Chisanovici <ionutx.chisanovici@intel.com> |
| 157 | AutomatedBy: Daniel Istrate <daniel.alexandrux.istrate@intel.com> |
| 158 | """ |
| 159 | |
| 160 | features = 'DISTRO_FEATURES_append = " wayland"\n' |
| 161 | features += 'CORE_IMAGE_EXTRA_INSTALL += "wayland weston"' |
| 162 | |
| 163 | # Append 'features' to local.conf |
| 164 | self.append_config(features) |
| 165 | |
| 166 | # Build a core-image-weston |
| 167 | bitbake('core-image-weston') |
| 168 | |