diff options
-rw-r--r-- | Makefile | 9 | ||||
-rw-r--r-- | domain/test-ipxe-ipv4-aarch64.xml | 26 | ||||
-rw-r--r-- | domain/test-ipxe-ipv6-aarch64.xml | 26 | ||||
-rw-r--r-- | ipxe/helloworld.ipxe | 5 | ||||
-rw-r--r-- | libvirt-cleanup.sh | 18 | ||||
-rw-r--r-- | libvirt-setup.sh | 7 | ||||
-rw-r--r-- | network/test-ipxe-ipv4-aarch64.xml | 19 | ||||
-rw-r--r-- | network/test-ipxe-ipv6-aarch64.xml | 20 | ||||
-rw-r--r-- | test-ipxe.py | 66 | ||||
-rw-r--r-- | test-ipxe.sh | 7 |
10 files changed, 203 insertions, 0 deletions
diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..0cd20d8 --- /dev/null +++ b/Makefile @@ -0,0 +1,9 @@ + +default: + @echo "targets: test clean" + +test: + sh test-ipxe.sh + +clean: + rm -f *~ */*~ diff --git a/domain/test-ipxe-ipv4-aarch64.xml b/domain/test-ipxe-ipv4-aarch64.xml new file mode 100644 index 0000000..4791bd2 --- /dev/null +++ b/domain/test-ipxe-ipv4-aarch64.xml @@ -0,0 +1,26 @@ +<domain type='kvm' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'> + <name>test-ipxe-ipv4-aarch64</name> + <memory unit='GiB'>1</memory> + <vcpu placement='static'>1</vcpu> + <os firmware='efi'> + <type arch='aarch64' machine='virt'>hvm</type> + <firmware> + <feature enabled='no' name='enrolled-keys'/> + <feature enabled='no' name='secure-boot'/> + </firmware> + </os> + <cpu mode='host-passthrough' check='none'/> + <devices> + <interface type='network'> + <source network='test-ipxe-ipv4-aarch64'/> + <model type='virtio'/> + <boot order='1'/> + </interface> + <console type='pty'/> + </devices> + <qemu:commandline> + <qemu:arg value='-fw_cfg'/> + <qemu:arg value='name=opt/org.tianocore/IPv6PXESupport,string=no'/> + </qemu:commandline> +</domain> + diff --git a/domain/test-ipxe-ipv6-aarch64.xml b/domain/test-ipxe-ipv6-aarch64.xml new file mode 100644 index 0000000..4676ea8 --- /dev/null +++ b/domain/test-ipxe-ipv6-aarch64.xml @@ -0,0 +1,26 @@ +<domain type='kvm' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'> + <name>test-ipxe-ipv6-aarch64</name> + <memory unit='GiB'>1</memory> + <vcpu placement='static'>1</vcpu> + <os firmware='efi'> + <type arch='aarch64' machine='virt'>hvm</type> + <firmware> + <feature enabled='no' name='enrolled-keys'/> + <feature enabled='no' name='secure-boot'/> + </firmware> + </os> + <cpu mode='host-passthrough' check='none'/> + <devices> + <interface type='network'> + <source network='test-ipxe-ipv6-aarch64'/> + <model type='virtio'/> + <boot order='1'/> + </interface> + <console type='pty'/> + </devices> + <qemu:commandline> + <qemu:arg value='-fw_cfg'/> + <qemu:arg value='name=opt/org.tianocore/IPv4PXESupport,string=no'/> + </qemu:commandline> +</domain> + diff --git a/ipxe/helloworld.ipxe b/ipxe/helloworld.ipxe new file mode 100644 index 0000000..36c1403 --- /dev/null +++ b/ipxe/helloworld.ipxe @@ -0,0 +1,5 @@ +#!ipxe +echo +echo hello world from ipxe script +echo +shell diff --git a/libvirt-cleanup.sh b/libvirt-cleanup.sh new file mode 100644 index 0000000..5166f2b --- /dev/null +++ b/libvirt-cleanup.sh @@ -0,0 +1,18 @@ +#!/bin/sh +arch="$(uname -m)" +domains="$(virsh list --all --name | grep test-ipxe-ipv.-${arch})" +networks="$(virsh net-list --all --name | grep test-ipxe-ipv.-${arch})" + +for domain in $domains; do + if virsh list --name | grep -q $domain; then + virsh destroy $domain + fi + virsh undefine --nvram $domain +done + +for network in $networks; do + if virsh net-list --name | grep -q $domain; then + virsh net-destroy $network + fi + virsh net-undefine $network +done diff --git a/libvirt-setup.sh b/libvirt-setup.sh new file mode 100644 index 0000000..a69b1c6 --- /dev/null +++ b/libvirt-setup.sh @@ -0,0 +1,7 @@ +#!/bin/sh +arch="$(uname -m)" +cd $(dirname $0) +virsh net-define network/test-ipxe-ipv4-${arch}.xml +virsh net-define network/test-ipxe-ipv6-${arch}.xml +virsh define domain/test-ipxe-ipv4-${arch}.xml +virsh define domain/test-ipxe-ipv6-${arch}.xml diff --git a/network/test-ipxe-ipv4-aarch64.xml b/network/test-ipxe-ipv4-aarch64.xml new file mode 100644 index 0000000..d0bf512 --- /dev/null +++ b/network/test-ipxe-ipv4-aarch64.xml @@ -0,0 +1,19 @@ +<network xmlns:dnsmasq='http://libvirt.org/schemas/network/dnsmasq/1.0'> + <name>test-ipxe-ipv4-aarch64</name> + <bridge name='testipxe4' stp='on' delay='0'/> + <ip address='192.168.44.1' netmask='255.255.255.0'> + <dhcp> + <range start='192.168.44.10' end='192.168.44.99'/> + <bootp file='unknown.arch.efi'/> + </dhcp> + </ip> + <dnsmasq:options> + <dnsmasq:option value='#'/> + <dnsmasq:option value='dhcp-match=set:aa64-pxe,option:client-arch,11'/> + <dnsmasq:option value='dhcp-boot=tag:aa64-pxe,arm64-efi/snponly.efi,,192.168.44.1'/> + <dnsmasq:option value='#'/> + <dnsmasq:option value='enable-tftp=testipxe4'/> + <dnsmasq:option value='tftp-root=/usr/share/ipxe'/> + </dnsmasq:options> +</network> + diff --git a/network/test-ipxe-ipv6-aarch64.xml b/network/test-ipxe-ipv6-aarch64.xml new file mode 100644 index 0000000..101363c --- /dev/null +++ b/network/test-ipxe-ipv6-aarch64.xml @@ -0,0 +1,20 @@ +<network xmlns:dnsmasq='http://libvirt.org/schemas/network/dnsmasq/1.0'> + <name>test-ipxe-ipv6-aarch64</name> + <bridge name='testipxe6' stp='on' delay='0'/> + <ip family='ipv6' address='fd00:2342::1' prefix='64'> + <dhcp> + <range start='fd00:2342::10' end='fd00:2342::ff'/> + </dhcp> + </ip> + <dnsmasq:options> + <dnsmasq:option value='#'/> + <dnsmasq:option value='dhcp-option=option6:bootfile-url,tftp://[fd00:2342::1]/arm64-efi/snponly.efi'/> + <dnsmasq:option value='#'/> + <dnsmasq:option value='dhcp-userclass=set:ipxe,iPXE'/> + <dnsmasq:option value='dhcp-option=tag:ipxe,option6:bootfile-url,tftp://[fd00:2342::1]/tests/helloworld.ipxe'/> + <dnsmasq:option value='#'/> + <dnsmasq:option value='enable-tftp=testipxe6'/> + <dnsmasq:option value='tftp-root=/usr/share/ipxe'/> + </dnsmasq:options> +</network> + diff --git a/test-ipxe.py b/test-ipxe.py new file mode 100644 index 0000000..1b3b9f1 --- /dev/null +++ b/test-ipxe.py @@ -0,0 +1,66 @@ +#!/usr/bin/python3 +import os +import sys +import time +import libvirt +import unittest + +class test_ipxe(unittest.TestCase): + + def setUp(self): + self.arch = os.uname()[4] + self.conn = libvirt.open(None) + self.network = {} + self.domain = {} + + def tearDown(self): + for (mode, domain) in self.domain.items(): + domain.destroy() + for (mode, network) in self.network.items(): + network.destroy() + self.conn.close() + + def do_wait(self, stream, substr, timeout, verbose = False): + start = time.time() + log = b'' + while time.time() - start < timeout: + data = stream.recv(128) + if type(data) is int and data == -2: + continue + if verbose: + print(data) + log += data + if substr in log: + secs = time.time() - start + print(f'{substr.decode()} ({secs:.1f}s) ... ', end = '', flush = True) + return + time.sleep(0.01) + self.fail(f'not found: {substr}') + + def do_ipxe(self, mode): + name = f'test-ipxe-{mode}-{self.arch}' + + network = self.conn.networkLookupByName(name) + if not network.isActive(): + network.create() + self.network[mode] = network + + domain = self.conn.lookupByName(name) + domain.create() + self.domain[mode] = domain + + stream = self.conn.newStream() + domain.openConsole(None, stream, 0) + + self.do_wait(stream, b'Start PXE', 20) + self.do_wait(stream, b'iPXE', 40) + self.do_wait(stream, b'hello world', 90) + + def test_ipv4(self): + self.do_ipxe('ipv4') + + def test_ipv6(self): + self.do_ipxe('ipv6') + +if __name__ == '__main__': + unittest.main() diff --git a/test-ipxe.sh b/test-ipxe.sh new file mode 100644 index 0000000..c1ca3e1 --- /dev/null +++ b/test-ipxe.sh @@ -0,0 +1,7 @@ +#!/bin/sh +cd $(dirname $0) +sh libvirt-setup.sh +python3 test-ipxe.py -v +rc="$?" +sh libvirt-cleanup.sh +exit $rc |