summaryrefslogtreecommitdiffstats
path: root/meta/lib/oeqa/selftest/imagefeatures.py
blob: 1795b7bcf31825da29710f84b22e8a31cabc215f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
from oeqa.selftest.base import oeSelfTest
from oeqa.utils.commands import runCmd, bitbake, get_bb_var
from oeqa.utils.decorators import testcase
import pexpect
from os.path import isfile
from os import system, killpg
import glob
import signal


class ImageFeatures(oeSelfTest):

    test_user = 'tester'
    root_user = 'root'
    prompt = r'qemux86:\S+[$#]\s+'
    ssh_cmd = "ssh {} -l {} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
    get_ip_patt = r'\s+ip=(?P<qemu_ip>(\d+.){3}\d+)::'

    @testcase(1107)
    def test_non_root_user_can_connect_via_ssh_without_password(self):
        """
        Summary: Check if non root user can connect via ssh without password
        Expected: 1. Connection to the image via ssh using root user without providing a password should be allowed.
                  2. Connection to the image via ssh using tester user without providing a password should be allowed.
        Product: oe-core
        Author: Ionut Chisanovici <ionutx.chisanovici@intel.com>
        AutomatedBy: Daniel Istrate <daniel.alexandrux.istrate@intel.com>
        """

        features = 'EXTRA_IMAGE_FEATURES += "ssh-server-openssh empty-root-password"\n'
        features += 'INHERIT += "extrausers"\n'
        features += 'EXTRA_USERS_PARAMS = "useradd -p \'\' {}; usermod -s /bin/sh {};"'.format(self.test_user, self.test_user)

        # Append 'features' to local.conf
        self.append_config(features)

        # Build a core-image-minimal
        bitbake('core-image-minimal')

        # Boot qemu image
        proc_qemu = pexpect.spawn('runqemu qemux86 nographic')
        try:
            proc_qemu.expect(self.get_ip_patt, timeout=100)
            qemu_ip = proc_qemu.match.group('qemu_ip')
            proc_qemu.expect('qemux86 login:', timeout=100)
        except Exception as e:
            try:
                killpg(proc_qemu.pid, signal.SIGTERM)
            except:
                pass
            self.fail('Failed to start qemu: %s' % e)

        # Attempt to ssh with each user into qemu with empty password
        for user in [self.root_user, self.test_user]:
            proc_ssh = pexpect.spawn(self.ssh_cmd.format(qemu_ip, user))
            index = proc_ssh.expect([self.prompt, pexpect.TIMEOUT, pexpect.EOF])
            if index == 0:
                # user successfully logged in with empty password
                pass
            elif index == 1:
                killpg(proc_qemu.pid, signal.SIGTERM)
                proc_ssh.terminate()
                self.fail('Failed to ssh with {} user into qemu (timeout).'.format(user))
            else:
                killpg(proc_qemu.pid, signal.SIGTERM)
                proc_ssh.terminate()
                self.fail('Failed to ssh with {} user into qemu (eof).'.format(user))
            proc_ssh.terminate()

        # Cleanup
        try:
            killpg(proc_qemu.pid, signal.SIGTERM)
        except:
            pass

    @testcase(1115)
    def test_all_users_can_connect_via_ssh_without_password(self):
        """
        Summary:     Check if all users can connect via ssh without password
        Expected:    1. Connection to the image via ssh using root or tester user without providing a password should be allowed.
        Product:     oe-core
        Author:      Ionut Chisanovici <ionutx.chisanovici@intel.com>
        AutomatedBy: Daniel Istrate <daniel.alexandrux.istrate@intel.com>
        """

        features = 'EXTRA_IMAGE_FEATURES += "ssh-server-openssh allow-empty-password"\n'
        features += 'INHERIT += "extrausers"\n'
        features += 'EXTRA_USERS_PARAMS = "useradd -p \'\' {}; usermod -s /bin/sh {};"'.format(self.test_user, self.test_user)

        # Append 'features' to local.conf
        self.append_config(features)

        # Build a core-image-minimal
        bitbake('core-image-minimal')

        # Boot qemu image
        proc_qemu = pexpect.spawn('runqemu qemux86 nographic')
        try:
            proc_qemu.expect(self.get_ip_patt, timeout=100)
            qemu_ip = proc_qemu.match.group('qemu_ip')
            proc_qemu.expect('qemux86 login:', timeout=100)
        except Exception as e:
            try:
                killpg(proc_qemu.pid, signal.SIGTERM)
            except:
                pass
            self.fail('Failed to start qemu: %s' % e)

        # Attempt to ssh with each user into qemu with empty password
        for user in [self.root_user, self.test_user]:
            proc_ssh = pexpect.spawn(self.ssh_cmd.format(qemu_ip, user))
            index = proc_ssh.expect([self.prompt, pexpect.TIMEOUT, pexpect.EOF])
            if index == 0:
                # user successfully logged in with empty password
                pass
            elif index == 1:
                killpg(proc_qemu.pid, signal.SIGTERM)
                proc_ssh.terminate()
                self.fail('Failed to ssh with {} user into qemu (timeout).'.format(user))
            else:
                killpg(proc_qemu.pid, signal.SIGTERM)
                proc_ssh.terminate()
                self.fail('Failed to ssh with {} user into qemu (eof).'.format(user))
            proc_ssh.terminate()

        # Cleanup
        try:
            killpg(proc_qemu.pid, signal.SIGTERM)
        except:
            pass

    @testcase(1114)
    def test_rpm_version_4_support_on_image(self):
        """
        Summary:     Check rpm version 4 support on image
        Expected:    Rpm version must be 4.11.2
        Product:     oe-core
        Author:      Ionut Chisanovici <ionutx.chisanovici@intel.com>
        AutomatedBy: Daniel Istrate <daniel.alexandrux.istrate@intel.com>
        """

        rpm_version = '4.11.2'
        features = 'IMAGE_INSTALL_append = " rpm"\n'
        features += 'PREFERRED_VERSION_rpm = "{}"\n'.format(rpm_version)
        features += 'PREFERRED_VERSION_rpm-native = "{}"\n'.format(rpm_version)
        features += 'RPMROOTFSDEPENDS_remove = "rpmresolve-native:do_populate_sysroot"'

        # Append 'features' to local.conf
        self.append_config(features)

        # Build a core-image-minimal
        bitbake('core-image-minimal')

        # Boot qemu image & get rpm version
        proc_qemu = pexpect.spawn('runqemu qemux86 nographic')
        try:
            proc_qemu.expect('qemux86 login:', timeout=100)
            proc_qemu.sendline(self.root_user)
            proc_qemu.expect(self.prompt)
            proc_qemu.sendline('rpm --version')
            proc_qemu.expect(self.prompt)
        except Exception as e:
            try:
                killpg(proc_qemu.pid, signal.SIGTERM)
            except:
                pass
            self.fail('Failed to start qemu: %s' % e)

        found_rpm_version = proc_qemu.before

        # Make sure the retrieved rpm version is the expected one
        self.assertIn(rpm_version, found_rpm_version,
                      'RPM version is not {}, found instead {}.'.format(rpm_version, found_rpm_version))

        # Cleanup (close qemu)
        try:
            killpg(proc_qemu.pid, signal.SIGTERM)
        except:
            pass

    @testcase(1116)
    def test_clutter_image_can_be_built(self):
        """
        Summary:     Check if clutter image can be built
        Expected:    1. core-image-clutter can be built
        Product:     oe-core
        Author:      Ionut Chisanovici <ionutx.chisanovici@intel.com>
        AutomatedBy: Daniel Istrate <daniel.alexandrux.istrate@intel.com>
        """

        # Build a core-image-clutter
        bitbake('core-image-clutter')

    @testcase(1117)
    def test_wayland_support_in_image(self):
        """
        Summary:     Check Wayland support in image
        Expected:    1. Wayland image can be build
                     2. Wayland feature can be installed
        Product:     oe-core
        Author:      Ionut Chisanovici <ionutx.chisanovici@intel.com>
        AutomatedBy: Daniel Istrate <daniel.alexandrux.istrate@intel.com>
        """

        features = 'DISTRO_FEATURES_append = " wayland"\n'
        features += 'CORE_IMAGE_EXTRA_INSTALL += "wayland weston"'

        # Append 'features' to local.conf
        self.append_config(features)

        # Build a core-image-weston
        bitbake('core-image-weston')


class Gummiboot(oeSelfTest):

    meta_intel_dir = ''

    def setUpLocal(self):
        """
        Common setup for test cases: 1101, 1103
        """

        self.meta_intel_dir = get_bb_var('COREBASE') + '/meta-intel'
        meta_nuc_dir = self.meta_intel_dir + '/meta-nuc'
        meta_intel_repo = 'http://git.yoctoproject.org/git/meta-intel'

        # Delete meta_intel_dir
        system('rm -rf ' + self.meta_intel_dir)

        # Delete meta-intel dir even if the setUp fails
        self.add_command_to_tearDown('rm -rf ' + self.meta_intel_dir)

        # Clone meta-intel
        runCmd('git clone ' + meta_intel_repo + ' ' + self.meta_intel_dir)

        # Add meta-intel and meta-nuc layers in conf/bblayers.conf
        features = 'BBLAYERS += "' + self.meta_intel_dir + ' ' + meta_nuc_dir + '"'
        self.append_bblayers_config(features)

        # Set EFI_PROVIDER = "gummiboot" and MACHINE = "nuc" in conf/local.conf
        features = 'EFI_PROVIDER = "gummiboot"\n'
        features += 'MACHINE = "nuc"'
        self.append_config(features)

        # Run "bitbake syslinux syslinux-native parted-native dosfstools-native mtools-native core-image-minimal "
        # to build a nuc/efi gummiboot image

        bitbake('syslinux syslinux-native parted-native dosfstools-native mtools-native core-image-minimal')

    @testcase(1101)
    def test_efi_gummiboot_images_can_be_build(self):
        """
        Summary:     Check if efi/gummiboot images can be buit
        Expected:    1. File gummibootx64.efi should be available in build/tmp/deploy/images/nuc
                     2. Efi/gummiboot images can be built
        Product:     oe-core
        Author:      Ionut Chisanovici <ionutx.chisanovici@intel.com>
        AutomatedBy: Daniel Istrate <daniel.alexandrux.istrate@intel.com>
        """

        look_for_file = 'gummibootx64.efi'
        file_location = get_bb_var('COREBASE') + '/build/tmp/deploy/images/nuc/'

        found = isfile(file_location + look_for_file)
        self.assertTrue(found, 'File {} not found under {}.'.format(look_for_file, file_location))

    @testcase(1103)
    def test_wic_command_can_create_efi_gummiboot_installation_images(self):
        """
        Summary:     Check that wic command can create efi/gummiboot installation images
        Expected:    A .direct file in folder /var/tmp/wic/ must be created.
        Product:     oe-core
        Author:      Ionut Chisanovici <ionutx.chisanovici@intel.com>
        AutomatedBy: Daniel Istrate <daniel.alexandrux.istrate@intel.com>
        """

        # Create efi/gummiboot installation images
        wic_create_cmd = 'wic create mkgummidisk -e core-image-minimal'
        runCmd(wic_create_cmd)

        # Verify that a .direct file was created
        direct_file = '/var/tmp/wic/build/*.direct'
        ret = glob.glob(direct_file)
        self.assertEqual(1, len(ret), 'Failed to find the .direct file')