From 1fe26886490f0b66c2611db7d45a80288b141d1d Mon Sep 17 00:00:00 2001 From: Gerd Hoffmann Date: Fri, 28 Jun 2024 14:40:20 +0200 Subject: initial commit --- Makefile | 9 ++++++ domain/test-ipxe-ipv4-aarch64.xml | 26 +++++++++++++++ domain/test-ipxe-ipv6-aarch64.xml | 26 +++++++++++++++ ipxe/helloworld.ipxe | 5 +++ libvirt-cleanup.sh | 18 +++++++++++ libvirt-setup.sh | 7 ++++ network/test-ipxe-ipv4-aarch64.xml | 19 +++++++++++ network/test-ipxe-ipv6-aarch64.xml | 20 ++++++++++++ test-ipxe.py | 66 ++++++++++++++++++++++++++++++++++++++ test-ipxe.sh | 7 ++++ 10 files changed, 203 insertions(+) create mode 100644 Makefile create mode 100644 domain/test-ipxe-ipv4-aarch64.xml create mode 100644 domain/test-ipxe-ipv6-aarch64.xml create mode 100644 ipxe/helloworld.ipxe create mode 100644 libvirt-cleanup.sh create mode 100644 libvirt-setup.sh create mode 100644 network/test-ipxe-ipv4-aarch64.xml create mode 100644 network/test-ipxe-ipv6-aarch64.xml create mode 100644 test-ipxe.py create mode 100644 test-ipxe.sh 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 @@ + + test-ipxe-ipv4-aarch64 + 1 + 1 + + hvm + + + + + + + + + + + + + + + + + + + + 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 @@ + + test-ipxe-ipv6-aarch64 + 1 + 1 + + hvm + + + + + + + + + + + + + + + + + + + + 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 @@ + + test-ipxe-ipv4-aarch64 + + + + + + + + + + + + + + + + + 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 @@ + + test-ipxe-ipv6-aarch64 + + + + + + + + + + + + + + + + + + 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 -- cgit