From 8d42bb08b26724e14afc2a9e86facfaf40f24794 Mon Sep 17 00:00:00 2001 From: karmab Date: Thu, 28 Nov 2024 19:55:50 +0100 Subject: [PATCH] kvm: handle uefi_firmware --- .github/container.sh | 2 +- .github/container_snapshot.sh | 10 ++++++++-- kvirt/extra_keywords/kvm.yaml | 1 + kvirt/providers/kvm/__init__.py | 33 ++++++++++++++++++--------------- 4 files changed, 28 insertions(+), 18 deletions(-) diff --git a/.github/container.sh b/.github/container.sh index b2188711c..43d2f964b 100755 --- a/.github/container.sh +++ b/.github/container.sh @@ -6,8 +6,8 @@ echo $GIT_VERSION > kvirt/version/git curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" -podman build -t quay.io/karmab/kcli:latest -f extras/debian . podman login -u $QUAY_USERNAME -p $QUAY_PASSWORD quay.io +podman build -t quay.io/karmab/kcli:latest -f extras/debian . podman push quay.io/karmab/kcli:latest # podman build --arch=amd64 -t quay.io/karmab/kcli:amd64 -f extras/debian . diff --git a/.github/container_snapshot.sh b/.github/container_snapshot.sh index ba7ac999b..3d9a1dff3 100755 --- a/.github/container_snapshot.sh +++ b/.github/container_snapshot.sh @@ -11,8 +11,14 @@ if [ -n "${EGG}" ] ; then TAG="${EGG}-${TAG}" fi -curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" +if [ "$TAG" == "arm64" ] ; then +curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/arm64/kubectl" +sed -i 's/bookworm/bookworm-arm64/' extras/debian +sed -i 's/\[all\]//' extras/debian +else + curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" +fi -podman build -t quay.io/karmab/kcli:$TAG -f extras/debian . podman login -u $QUAY_USERNAME -p $QUAY_PASSWORD quay.io +podman build -t quay.io/karmab/kcli:$TAG -f extras/debian . podman push quay.io/karmab/kcli:$TAG diff --git a/kvirt/extra_keywords/kvm.yaml b/kvirt/extra_keywords/kvm.yaml index 35399bf62..11d3064a6 100644 --- a/kvirt/extra_keywords/kvm.yaml +++ b/kvirt/extra_keywords/kvm.yaml @@ -10,6 +10,7 @@ machine: Custom machine type qemuextra: Extra cmdline for qemu secureboot: Enable secureboot uefi: Enable uefi +uefi_firmware: Path to specific UEFI firmware uefi_legacy: Enable uefi for rhel8 hypervisors uuid: Uuid boot_order: Set boot order on all disks to allow to boot from any of them diff --git a/kvirt/providers/kvm/__init__.py b/kvirt/providers/kvm/__init__.py index 7ee3bb044..0643aeab5 100644 --- a/kvirt/providers/kvm/__init__.py +++ b/kvirt/providers/kvm/__init__.py @@ -238,11 +238,11 @@ def create(self, name, virttype=None, profile='kvirt', flavor=None, plan='kvirt' default_disksize = disksize default_pool = pool conn = self.conn - capabilities = self.get_capabilities(overrides.get('arch')) - if 'arch' not in overrides: - overrides['arch'] = capabilities['arch'] - iommu_model = 'intel' if overrides.get('arch', 'x86_64') == 'x86_64' else 'smmuv3' custom_emulator = overrides.get('emulator') + default_arch = overrides.get('arch') + arch = 'aarch64' if custom_emulator is not None and custom_emulator.endswith('aarch64') else default_arch + capabilities = self.get_capabilities(arch) + arch = arch or capabilities['arch'] if custom_emulator is not None: if os.path.exists(custom_emulator): emulator = custom_emulator @@ -251,17 +251,20 @@ def create(self, name, virttype=None, profile='kvirt', flavor=None, plan='kvirt' else: emulator = which(custom_emulator) elif 'emulator' not in capabilities: - return {'result': 'failure', 'reason': "No valid emulator found for target arch"} + return {'result': 'failure', 'reason': f"No valid emulator found for target arch {arch}"} else: emulator = capabilities['emulator'] - if 'machine' in overrides and overrides['machine'] not in capabilities['machines']: - machines = ','.join(sorted(capabilities['machines'])) - return {'result': 'failure', 'reason': f"Incorrect machine. Choose between {machines}"} - aarch64 = capabilities['arch'] == 'aarch64' + if 'machine' in overrides and overrides['machine'] not in capabilities['machines']: + machines = ','.join(sorted(capabilities['machines'])) + return {'result': 'failure', 'reason': f"Incorrect machine. Choose between {machines}"} + iommu_model = 'smmuv3' if arch == 'aarch64' else 'intel' + aarch64 = arch == 'aarch64' aarch64_full = aarch64 and capabilities['kvm'] - as390x = capabilities['arch'] == 's390x' + as390x = arch == 's390x' if aarch64: - if 'machine' not in overrides: + if custom_emulator is not None: + warning("Not checking whether a valid machine is provided") + elif 'machine' not in overrides: virtmachines = [m for m in sorted(capabilities['machines']) if m.startswith('virt-')] if not virtmachines: return {'result': 'failure', 'reason': "Couldn't find a valid machine"} @@ -1206,11 +1209,11 @@ def create(self, name, virttype=None, profile='kvirt', flavor=None, plan='kvirt' ramxml = "" smmxml = "" osfirmware = "" - if uefi or uefi_legacy or secureboot or aarch64: + uefi_firmware = '/usr/share/OVMF/OVMF_CODE.secboot.fd' if uefi_legacy else overrides.get('uefi_firmware') + if uefi or uefi_firmware is not None or secureboot or aarch64: secure = 'yes' if secureboot else 'no' - if uefi_legacy: - firmware = '/usr/share/OVMF/OVMF_CODE.secboot.fd' - ramxml = f"{firmware}" + if uefi_firmware is not None: + ramxml = f"{uefi_firmware}" if secureboot: smmxml = "" sectemplate = '/usr/share/OVMF/OVMF_VARS.secboot.fd'