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