aboutsummaryrefslogtreecommitdiffstats
path: root/lib/oeqa/selftest/cases/anaconda_oe.py
blob: 2e775630ee11a800918d5800750f83f5ef915477 (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
from oeqa.selftest.case import OESelftestTestCase
from oeqa.core.decorator.depends import OETestDepends
from oeqa.utils.commands import runCmd, bitbake, get_bb_vars, get_bb_var, runqemu
from oeqa.utils.sshcontrol import SSHControl
import os
import time
import sys

class TestAnacondaOE(OESelftestTestCase):

    # We only want to print runqemu stdout/stderr if there is a test case failure
    buffer = True

    def setUpLocal(self):
        super(TestAnacondaOE, self).setUpLocal()
        self.machine =  'qemux86-64'
        features = 'MACHINE = "%s"\n' % self.machine
        features += 'PACKAGE_CLASSES = "package_rpm"\n'
        features += 'VIRTUAL-RUNTIME_init_manager = "systemd"\n'
        features += 'DISTRO_FEATURES_append = " systemd"\n'
        features += 'DISTRO_FEATURES_append = " pam"\n'
        features += 'DISTRO_FEATURES_BACKFILL_CONSIDERED_append = " sysvinit"\n'
        self.write_config(features)
        self.logger.info('local.conf:\n%s' % features)

        bbvars = get_bb_vars(['TOPDIR', 'DEPLOY_DIR_IMAGE', 'BBLAYERS', 'STAGING_BINDIR_NATIVE'], 'qemu-helper-native')

        self.anaconda_distro = "anaconda"
        self.target_recipe = "core-image-minimal"
        self.anaconda_recipe = "core-image-anaconda"
        self.topdir = bbvars['TOPDIR']
        self.vdisk = '%s/hd0.vdisk' % self.topdir
        self.cmd_common = "runqemu slirp qemuparams='-smp 8 -drive file=%s,if=virtio,format=qcow -m 1024 -vnc :4'" % self.vdisk
        self.install_timeout = 14400
        self.target_deploy_dir_image = bbvars['DEPLOY_DIR_IMAGE']
        for d in bbvars['BBLAYERS'].split():
            if d.endswith('/meta-anaconda'):
                self.layer_path = d
                break

    def __start_qemu_shutdown_check_if_shutdown_succeeded(self, qemu, timeout):
        # Stop thread will stop the LoggingThread instance used for logging
        # qemu through serial console, stop thread will prevent this code
        # from facing exception (Console connection closed unexpectedly)
        # when qemu was shutdown by the above shutdown command
        qemu.runner.stop_thread()
        time_track = 0
        while True:
            is_alive = qemu.check()
            if not is_alive:
                return True
            if time_track > timeout:
                return False
            time.sleep(1)
            time_track += 1

    def _start_runqemu(self):
        # Test runqemu machine iso
        self.logger.info("start runqemu")
        cmd = "%s %s iso" % (self.cmd_common, self.machine)
        with runqemu(self.anaconda_recipe, ssh=False, launch_cmd=cmd) as qemu:
            self.logger.info("runqemu as qemu")
            qemu_shutdown_succeeded = self.__start_qemu_shutdown_check_if_shutdown_succeeded(qemu, self.install_timeout)
            if not qemu_shutdown_succeeded:
                ssh = SSHControl(ip="127.0.0.1", logfile=qemu.sshlog, port="2222")
                for log in ['anaconda.log', 'program.log', 'packaging.log']:
                    self.logger.error("-----------%s----------" % log)
                    status, output = ssh.run("/bin/cat /tmp/%s" % log)
                    self.logger.error(output)

            self.assertTrue(qemu_shutdown_succeeded, 'Failed: %s does not shutdown within timeout(%s)' % (self.machine, self.install_timeout))

            with open(qemu.qemurunnerlog) as f:
                self.assertTrue('media=cdrom' in f.read(), "Failed: %s" % cmd)

    def test_testanaconda_create_target_disk(self):
        # Provide qemu-img
        try:
            bitbake("qemu-helper-native")
        except AssertionError as err:
            self.logger.error("Command failed: %s", str(err))
            sys.exit(1)

        bindir_native = get_bb_var('STAGING_BINDIR_NATIVE', 'qemu-helper-native')
        try:
            runCmd("%s/qemu-img create -f qcow %s 5000M" % (bindir_native, self.vdisk))
        except AssertionError as err:
            self.logger.error("Command failed: %s", str(err))
            runCmd("find %s" % bindir_native)
            sys.exit(1)
        self.logger.info("Create qemu image %s successfully" % self.vdisk)


    def test_testanaconda_build_target_image(self):
        features = 'DISTRO_FEATURES_append = " anaconda-support"\n'
        self.logger.info('extra local.conf:\n%s' % features)
        self.append_config(features)

        # The 1st target build
        try:
            bitbake(self.target_recipe)
        except AssertionError as err:
            self.logger.error("Command failed: %s", str(err))
            sys.exit(1)

        self.logger.info("Build %s successfully" % self.target_recipe)
        res = runCmd("ls %s -al" % self.target_deploy_dir_image, ignore_status=True)
        self.logger.info("ls %s -al\n%s" % (self.target_deploy_dir_image, res.output))

    @OETestDepends(['test_testanaconda_build_target_image'])
    def test_testanaconda_build_pkg_installer_image(self):
        # The 2nd host build with kickstart
        ks_file = os.path.join(self.layer_path, 'example/ks-pkg.cfg')
        features = 'TMPDIR .= "_host"\n'
        features += 'DISTRO = "%s"\n' % self.anaconda_distro
        features += 'INSTALLER_TARGET_BUILD = "%s"\n' % self.topdir
        features += 'INSTALLER_TARGET_IMAGE = "%s"\n' % self.target_recipe
        features += 'KICKSTART_FILE = "%s"\n' % ks_file
        features += 'SYSLINUX_TIMEOUT = "10"\n'
        self.logger.info('extra local.conf:\n%s' % features)
        self.append_config(features)

        try:
            bitbake(self.anaconda_recipe)
        except AssertionError as err:
            self.logger.error("Command failed: %s", str(err))
            sys.exit(1)

    @OETestDepends(['test_testanaconda_create_target_disk', 'test_testanaconda_build_pkg_installer_image'])
    def test_testanaconda_pkg_install(self):
        features = 'TMPDIR .= "_host"\n'
        features += 'DISTRO = "%s"\n' % self.anaconda_distro
        features += 'INSTALLER_TARGET_BUILD = "%s"\n' % self.topdir
        features += 'INSTALLER_TARGET_IMAGE = "%s"\n' % self.target_recipe
        self.logger.info('extra local.conf:\n%s' % features)
        self.append_config(features)

        self._start_runqemu()

    @OETestDepends(['test_testanaconda_pkg_install'])
    def test_testanaconda_build_imagecopy_installer_image(self):
        # The 2nd host build with kickstart
        ks_file = os.path.join(self.layer_path, 'example/ks-imagecopy.cfg')
        features = 'TMPDIR .= "_host"\n'
        features += 'DISTRO = "%s"\n' % self.anaconda_distro
        features += 'INSTALLER_TARGET_BUILD = "%s/%s-%s.ext4"\n' % (self.target_deploy_dir_image, self.target_recipe, self.machine)
        features += 'KICKSTART_FILE = "%s"\n' % ks_file
        features += 'SYSLINUX_TIMEOUT = "10"\n'
        features += 'APPEND_append = " textinst"\n'
        self.logger.info('extra local.conf:\n%s' % features)
        self.append_config(features)

        try:
            bitbake(self.anaconda_recipe)
        except AssertionError as err:
            self.logger.error("Command failed: %s", str(err))
            sys.exit(1)

    @OETestDepends(['test_testanaconda_build_imagecopy_installer_image'])
    def test_testanaconda_imagecopy_install(self):
        features = 'TMPDIR .= "_host"\n'
        features += 'DISTRO = "%s"\n' % self.anaconda_distro
        features += 'INSTALLER_TARGET_BUILD = "%s/%s-%s.ext4"\n' % (self.target_deploy_dir_image, self.target_recipe, self.machine)
        self.logger.info('extra local.conf:\n%s' % features)
        self.append_config(features)

        self._start_runqemu()