aboutsummaryrefslogtreecommitdiff
path: root/tests/vm/fedora
blob: 7fec1479fb74b27682ac6de7de87e498c08669a6 (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
#!/usr/bin/env python
#
# Fedora VM image
#
# Copyright 2019 Red Hat Inc.
#
# Authors:
#  Gerd Hoffmann <kraxel@redhat.com>
#
# This code is licensed under the GPL version 2 or later.  See
# the COPYING file in the top-level directory.
#

import os
import re
import sys
import time
import socket
import subprocess
import basevm

class FedoraVM(basevm.BaseVM):
    name = "fedora"
    arch = "x86_64"

    base = "https://archives.fedoraproject.org/pub/archive/fedora/linux/releases/30/"
    link = base + "Server/x86_64/iso/Fedora-Server-netinst-x86_64-30-1.2.iso"
    repo = base + "Server/x86_64/os/"
    full = base + "Everything/x86_64/os/"
    csum = "5e4eac4566d8c572bfb3bcf54b7d6c82006ec3c6c882a2c9235c6d3494d7b100"
    size = "20G"
    pkgs = [
        # tools
        'git-core',
        'flex', 'bison',
        'gcc', 'binutils', 'make',

        # perl
        'perl-Test-Harness',

        # libs: usb
        '"pkgconfig(libusb-1.0)"',
        '"pkgconfig(libusbredirparser-0.5)"',

        # libs: crypto
        '"pkgconfig(gnutls)"',

        # libs: ui
        '"pkgconfig(sdl2)"',
        '"pkgconfig(gtk+-3.0)"',
        '"pkgconfig(ncursesw)"',

        # libs: audio
        '"pkgconfig(libpulse)"',
        '"pkgconfig(alsa)"',
    ]

    BUILD_SCRIPT = """
        set -e;
        rm -rf /home/qemu/qemu-test.*
        cd $(mktemp -d /home/qemu/qemu-test.XXXXXX);
        mkdir src build; cd src;
        tar -xf /dev/vdb;
        cd ../build
        ../src/configure --python=python3 {configure_opts};
        gmake --output-sync -j{jobs} {target} {verbose};
    """

    def build_image(self, img):
        self.print_step("Downloading install iso")
        cimg = self._download_with_cache(self.link, sha256sum=self.csum)
        img_tmp = img + ".tmp"
        iso = img + ".install.iso"

        self.print_step("Preparing iso and disk image")
        subprocess.check_call(["cp", "-f", cimg, iso])
        subprocess.check_call(["qemu-img", "create", "-f", "qcow2",
                               img_tmp, self.size])

        self.print_step("Booting installer")
        self.boot(img_tmp, extra_args = [
            "-bios", "pc-bios/bios-256k.bin",
            "-machine", "graphics=off",
            "-cdrom", iso
        ])
        self.console_init(300)
        self.console_wait("installation process.")
        time.sleep(0.3)
        self.console_send("\t")
        time.sleep(0.3)
        self.console_send(" console=ttyS0")
        proxy = os.environ.get("http_proxy")
        if not proxy is None:
            self.console_send(" proxy=%s" % proxy)
            self.console_send(" inst.proxy=%s" % proxy)
        self.console_send(" inst.repo=%s" % self.repo)
        self.console_send("\n")

        self.console_wait_send("2) Use text mode",         "2\n")

        self.console_wait_send("5) [!] Installation Dest", "5\n")
        self.console_wait_send("1) [x]",                   "c\n")
        self.console_wait_send("2) [ ] Use All Space",     "2\n")
        self.console_wait_send("2) [x] Use All Space",     "c\n")
        self.console_wait_send("1) [ ] Standard Part",     "1\n")
        self.console_wait_send("1) [x] Standard Part",     "c\n")

        self.console_wait_send("7) [!] Root password",     "7\n")
        self.console_wait("Password:")
        self.console_send("%s\n" % self.ROOT_PASS)
        self.console_wait("Password (confirm):")
        self.console_send("%s\n" % self.ROOT_PASS)

        self.console_wait_send("8) [ ] User creation",     "8\n")
        self.console_wait_send("1) [ ] Create user",       "1\n")
        self.console_wait_send("3) User name",             "3\n")
        self.console_wait_send("ENTER:", "%s\n" % self.GUEST_USER)
        self.console_wait_send("4) [ ] Use password",      "4\n")
        self.console_wait_send("5) Password",              "5\n")
        self.console_wait("Password:")
        self.console_send("%s\n" % self.GUEST_PASS)
        self.console_wait("Password (confirm):")
        self.console_send("%s\n" % self.GUEST_PASS)
        self.console_wait_send("7) Groups",                "c\n")

        while True:
            good = self.console_wait("3) [x] Installation",
                                     "3) [!] Installation")
            self.console_send("r\n")
            if good:
                break
            time.sleep(10)

        while True:
            good = self.console_wait("4) [x] Software",
                                     "4) [!] Software")
            self.console_send("r\n")
            if good:
                break
            time.sleep(10)
            self.console_send("r\n" % self.GUEST_PASS)

        self.console_wait_send("'b' to begin install",     "b\n")

        self.print_step("Installation started now, this will take a while")

        self.console_wait_send("Installation complete",    "\n")
        self.print_step("Installation finished, rebooting")

        # setup qemu user
        prompt = " ~]$"
        self.console_ssh_init(prompt, self.GUEST_USER, self.GUEST_PASS)
        self.console_wait_send(prompt, "exit\n")

        # setup root user
        prompt = " ~]#"
        self.console_ssh_init(prompt, "root", self.ROOT_PASS)
        self.console_sshd_config(prompt)

        # setup virtio-blk #1 (tarfile)
        self.console_wait(prompt)
        self.console_send("echo 'KERNEL==\"vdb\" MODE=\"666\"' >> %s\n" %
                          "/etc/udev/rules.d/99-qemu.rules")

        self.print_step("Configuration finished, rebooting")
        self.console_wait_send(prompt, "reboot\n")
        self.console_wait("login:")
        self.wait_ssh()

        self.print_step("Installing packages")
        self.ssh_root_check("rm -vf /etc/yum.repos.d/fedora*.repo\n")
        self.ssh_root_check("echo '[fedora]' >> /etc/yum.repos.d/qemu.repo\n")
        self.ssh_root_check("echo 'baseurl=%s' >> /etc/yum.repos.d/qemu.repo\n" % self.full)
        self.ssh_root_check("echo 'gpgcheck=0' >> /etc/yum.repos.d/qemu.repo\n")
        self.ssh_root_check("dnf install -y %s\n" % " ".join(self.pkgs))

        # shutdown
        self.ssh_root(self.poweroff)
        self.console_wait("sleep state S5")
        self.wait()

        if os.path.exists(img):
            os.remove(img)
        os.rename(img_tmp, img)
        os.remove(iso)
        self.print_step("All done")

if __name__ == "__main__":
    sys.exit(basevm.main(FedoraVM))