xref: /openbmc/qemu/tests/functional/test_s390x_pxelinux.py (revision 3adbf0bb8a78f17a1e9390b59e51eb1a47d8ac98)
1*c784de96SThomas Huth#!/usr/bin/env python3
2*c784de96SThomas Huth#
3*c784de96SThomas Huth# SPDX-License-Identifier: GPL-2.0-or-later
4*c784de96SThomas Huth#
5*c784de96SThomas Huth# Functional test that checks the pxelinux.cfg network booting of a s390x VM
6*c784de96SThomas Huth# (TFTP booting without config file is already tested by the pxe qtest, so
7*c784de96SThomas Huth#  we don't repeat that here).
8*c784de96SThomas Huth
9*c784de96SThomas Huthimport os
10*c784de96SThomas Huthimport shutil
11*c784de96SThomas Huth
12*c784de96SThomas Huthfrom qemu_test import QemuSystemTest, Asset, wait_for_console_pattern
13*c784de96SThomas Huth
14*c784de96SThomas Huth
15*c784de96SThomas Huthpxelinux_cfg_contents='''# pxelinux.cfg style config file
16*c784de96SThomas Huthdefault Debian
17*c784de96SThomas Huthlabel Nonexisting
18*c784de96SThomas Huthkernel kernel.notavailable
19*c784de96SThomas Huthinitrd initrd.notavailable
20*c784de96SThomas Huthlabel Debian
21*c784de96SThomas Huthkernel kernel.debian
22*c784de96SThomas Huthinitrd initrd.debian
23*c784de96SThomas Huthappend testoption=teststring
24*c784de96SThomas Huthlabel Fedora
25*c784de96SThomas Huthkernel kernel.fedora
26*c784de96SThomas Huth'''
27*c784de96SThomas Huth
28*c784de96SThomas Huthclass S390PxeLinux(QemuSystemTest):
29*c784de96SThomas Huth
30*c784de96SThomas Huth    ASSET_DEBIAN_KERNEL = Asset(
31*c784de96SThomas Huth        ('https://snapshot.debian.org/archive/debian/'
32*c784de96SThomas Huth         '20201126T092837Z/dists/buster/main/installer-s390x/'
33*c784de96SThomas Huth         '20190702+deb10u6/images/generic/kernel.debian'),
34*c784de96SThomas Huth        'd411d17c39ae7ad38d27534376cbe88b68b403c325739364122c2e6f1537e818')
35*c784de96SThomas Huth
36*c784de96SThomas Huth    ASSET_DEBIAN_INITRD = Asset(
37*c784de96SThomas Huth        ('https://snapshot.debian.org/archive/debian/'
38*c784de96SThomas Huth         '20201126T092837Z/dists/buster/main/installer-s390x/'
39*c784de96SThomas Huth         '20190702+deb10u6/images/generic/initrd.debian'),
40*c784de96SThomas Huth        '836bbd0fe6a5ca81274c28c2b063ea315ce1868660866e9b60180c575fef9fd5')
41*c784de96SThomas Huth
42*c784de96SThomas Huth    ASSET_FEDORA_KERNEL = Asset(
43*c784de96SThomas Huth        ('https://archives.fedoraproject.org/pub/archive'
44*c784de96SThomas Huth         '/fedora-secondary/releases/31/Server/s390x/os'
45*c784de96SThomas Huth         '/images/kernel.img'),
46*c784de96SThomas Huth        '480859574f3f44caa6cd35c62d70e1ac0609134e22ce2a954bbed9b110c06e0b')
47*c784de96SThomas Huth
48*c784de96SThomas Huth    def pxelinux_launch(self, pl_name='default', extra_opts=None):
49*c784de96SThomas Huth        self.require_netdev('user')
50*c784de96SThomas Huth        self.set_machine('s390-ccw-virtio')
51*c784de96SThomas Huth
52*c784de96SThomas Huth        debian_kernel = self.ASSET_DEBIAN_KERNEL.fetch()
53*c784de96SThomas Huth        debian_initrd = self.ASSET_DEBIAN_INITRD.fetch()
54*c784de96SThomas Huth        fedora_kernel = self.ASSET_FEDORA_KERNEL.fetch()
55*c784de96SThomas Huth
56*c784de96SThomas Huth        # Prepare a folder for the TFTP "server":
57*c784de96SThomas Huth        tftpdir = self.scratch_file('tftp')
58*c784de96SThomas Huth        shutil.rmtree(tftpdir, ignore_errors=True)   # Remove stale stuff
59*c784de96SThomas Huth        os.mkdir(tftpdir)
60*c784de96SThomas Huth        shutil.copy(debian_kernel, os.path.join(tftpdir, 'kernel.debian'))
61*c784de96SThomas Huth        shutil.copy(debian_initrd, os.path.join(tftpdir, 'initrd.debian'))
62*c784de96SThomas Huth        shutil.copy(fedora_kernel, os.path.join(tftpdir, 'kernel.fedora'))
63*c784de96SThomas Huth
64*c784de96SThomas Huth        pxelinuxdir = self.scratch_file('tftp', 'pxelinux.cfg')
65*c784de96SThomas Huth        os.mkdir(pxelinuxdir)
66*c784de96SThomas Huth
67*c784de96SThomas Huth        cfg_fname = self.scratch_file('tftp', 'pxelinux.cfg', pl_name)
68*c784de96SThomas Huth        with open(cfg_fname, 'w', encoding='utf-8') as f:
69*c784de96SThomas Huth            f.write(pxelinux_cfg_contents)
70*c784de96SThomas Huth
71*c784de96SThomas Huth        virtio_net_dev = 'virtio-net-ccw,netdev=n1,bootindex=1'
72*c784de96SThomas Huth        if extra_opts:
73*c784de96SThomas Huth                virtio_net_dev += ',' + extra_opts
74*c784de96SThomas Huth
75*c784de96SThomas Huth        self.vm.add_args('-m', '384',
76*c784de96SThomas Huth                         '-netdev', f'user,id=n1,tftp={tftpdir}',
77*c784de96SThomas Huth                         '-device', virtio_net_dev)
78*c784de96SThomas Huth        self.vm.set_console()
79*c784de96SThomas Huth        self.vm.launch()
80*c784de96SThomas Huth
81*c784de96SThomas Huth
82*c784de96SThomas Huth    def test_default(self):
83*c784de96SThomas Huth        self.pxelinux_launch()
84*c784de96SThomas Huth        # The kernel prints its arguments to the console, so we can use
85*c784de96SThomas Huth        # this to check whether the kernel parameters are correctly handled:
86*c784de96SThomas Huth        wait_for_console_pattern(self, 'testoption=teststring')
87*c784de96SThomas Huth        # Now also check that we've successfully loaded the initrd:
88*c784de96SThomas Huth        wait_for_console_pattern(self, 'Unpacking initramfs...')
89*c784de96SThomas Huth        wait_for_console_pattern(self, 'Run /init as init process')
90*c784de96SThomas Huth
91*c784de96SThomas Huth    def test_mac(self):
92*c784de96SThomas Huth        self.pxelinux_launch(pl_name='01-02-ca-fe-ba-be-42',
93*c784de96SThomas Huth                             extra_opts='mac=02:ca:fe:ba:be:42,loadparm=3')
94*c784de96SThomas Huth        wait_for_console_pattern(self, 'Linux version 5.3.7-301.fc31.s390x')
95*c784de96SThomas Huth
96*c784de96SThomas Huth    def test_uuid(self):
97*c784de96SThomas Huth        # Also add a non-bootable disk to check the fallback to network boot:
98*c784de96SThomas Huth        self.vm.add_args('-blockdev', 'null-co,size=65536,node-name=d1',
99*c784de96SThomas Huth                         '-device', 'virtio-blk,drive=d1,bootindex=0,loadparm=1',
100*c784de96SThomas Huth                         '-uuid', '550e8400-e29b-11d4-a716-446655441234')
101*c784de96SThomas Huth        self.pxelinux_launch(pl_name='550e8400-e29b-11d4-a716-446655441234')
102*c784de96SThomas Huth        wait_for_console_pattern(self, 'Debian 4.19.146-1 (2020-09-17)')
103*c784de96SThomas Huth
104*c784de96SThomas Huth    def test_ip(self):
105*c784de96SThomas Huth        self.vm.add_args('-M', 'loadparm=3')
106*c784de96SThomas Huth        self.pxelinux_launch(pl_name='0A00020F')
107*c784de96SThomas Huth        wait_for_console_pattern(self, 'Linux version 5.3.7-301.fc31.s390x')
108*c784de96SThomas Huth
109*c784de96SThomas Huth    def test_menu(self):
110*c784de96SThomas Huth        self.vm.add_args('-boot', 'menu=on,splash-time=10')
111*c784de96SThomas Huth        self.pxelinux_launch(pl_name='0A00')
112*c784de96SThomas Huth        wait_for_console_pattern(self, '[1] Nonexisting')
113*c784de96SThomas Huth        wait_for_console_pattern(self, '[2] Debian')
114*c784de96SThomas Huth        wait_for_console_pattern(self, '[3] Fedora')
115*c784de96SThomas Huth        wait_for_console_pattern(self, 'Debian 4.19.146-1 (2020-09-17)')
116*c784de96SThomas Huth
117*c784de96SThomas Huth
118*c784de96SThomas Huthif __name__ == '__main__':
119*c784de96SThomas Huth    QemuSystemTest.main()
120