summaryrefslogtreecommitdiffstats
path: root/core/modules/qemu
diff options
context:
space:
mode:
authorManuel Bentele2021-11-30 09:09:43 +0100
committerManuel Bentele2021-11-30 09:09:43 +0100
commit0577e6e51877cdb1021e194588a5854457b312ee (patch)
tree66c7aaecaf5cb0eca36c4bc6bd7e0816167dcc29 /core/modules/qemu
parent[qemu] Create missing ACPI OpRegion for GVT-g instance on UEFI machines (diff)
downloadmltk-0577e6e51877cdb1021e194588a5854457b312ee.tar.gz
mltk-0577e6e51877cdb1021e194588a5854457b312ee.tar.xz
mltk-0577e6e51877cdb1021e194588a5854457b312ee.zip
[qemu] Move firmware loader lookup to master-sync-shared
Diffstat (limited to 'core/modules/qemu')
-rw-r--r--core/modules/qemu/runvirt-plugin-qemu/pom.xml14
-rw-r--r--core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/configuration/TransformationSpecificQemuFirmware.java229
-rw-r--r--core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/configuration/TransformationTestResources.java16
-rw-r--r--core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/configuration/TransformationTestUtils.java19
-rw-r--r--core/modules/qemu/runvirt-plugin-qemu/src/test/resources/qemu/firmware/50-edk2-i386-secure.json34
-rw-r--r--core/modules/qemu/runvirt-plugin-qemu/src/test/resources/qemu/firmware/50-edk2-x86_64-secure.json35
-rw-r--r--core/modules/qemu/runvirt-plugin-qemu/src/test/resources/qemu/firmware/60-edk2-aarch64.json31
-rw-r--r--core/modules/qemu/runvirt-plugin-qemu/src/test/resources/qemu/firmware/60-edk2-arm.json31
-rw-r--r--core/modules/qemu/runvirt-plugin-qemu/src/test/resources/qemu/firmware/60-edk2-i386.json33
-rw-r--r--core/modules/qemu/runvirt-plugin-qemu/src/test/resources/qemu/firmware/60-edk2-x86_64.json34
10 files changed, 16 insertions, 460 deletions
diff --git a/core/modules/qemu/runvirt-plugin-qemu/pom.xml b/core/modules/qemu/runvirt-plugin-qemu/pom.xml
index d2887cd2..71946b8b 100644
--- a/core/modules/qemu/runvirt-plugin-qemu/pom.xml
+++ b/core/modules/qemu/runvirt-plugin-qemu/pom.xml
@@ -90,11 +90,6 @@
<scope>compile</scope>
</dependency>
<dependency>
- <groupId>com.google.code.gson</groupId>
- <artifactId>gson</artifactId>
- <version>2.8.8</version>
- </dependency>
- <dependency>
<groupId>com.ginsberg</groupId>
<artifactId>junit5-system-exit</artifactId>
<version>1.0.0</version>
@@ -232,14 +227,5 @@
<version>3.0.0</version>
</plugin>
</plugins>
- <testResources>
- <testResource>
- <directory>${basedir}/src/test/resources</directory>
- <includes>
- <include>libvirt/xml/*</include>
- <include>qemu/firmware/*</include>
- </includes>
- </testResource>
- </testResources>
</build>
</project>
diff --git a/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/configuration/TransformationSpecificQemuFirmware.java b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/configuration/TransformationSpecificQemuFirmware.java
index 6be0368e..3967a0b4 100644
--- a/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/configuration/TransformationSpecificQemuFirmware.java
+++ b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/configuration/TransformationSpecificQemuFirmware.java
@@ -1,152 +1,13 @@
package org.openslx.runvirt.plugin.qemu.configuration;
-import java.io.File;
-import java.io.FileFilter;
-import java.io.FileNotFoundException;
-import java.io.FileReader;
-import java.io.Reader;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.ArrayList;
-import java.util.function.Predicate;
-
+import org.openslx.firmware.FirmwareException;
+import org.openslx.firmware.QemuFirmwareUtil;
import org.openslx.libvirt.domain.Domain;
import org.openslx.runvirt.plugin.qemu.cmdln.CommandLineArgs;
import org.openslx.runvirt.plugin.qemu.virtualization.LibvirtHypervisorQemu;
-import org.openslx.util.LevenshteinDistance;
import org.openslx.virtualization.configuration.transformation.TransformationException;
import org.openslx.virtualization.configuration.transformation.TransformationSpecific;
-import com.google.gson.Gson;
-import com.google.gson.JsonIOException;
-import com.google.gson.JsonSyntaxException;
-import com.google.gson.annotations.SerializedName;
-
-class QemuFirmware
-{
- @SerializedName( "description" )
- private String description;
- @SerializedName( "interface-types" )
- private ArrayList<String> interfaceTypes;
- @SerializedName( "mapping" )
- private QemuFirmwareMapping mapping;
- @SerializedName( "targets" )
- private ArrayList<QemuFirmwareTarget> targets;
- @SerializedName( "features" )
- private ArrayList<String> features;
- @SerializedName( "tags" )
- private ArrayList<String> tags;
-
- public String getDescription()
- {
- return description;
- }
-
- public ArrayList<String> getInterfaceTypes()
- {
- return interfaceTypes;
- }
-
- public QemuFirmwareMapping getMapping()
- {
- return mapping;
- }
-
- public ArrayList<QemuFirmwareTarget> getTargets()
- {
- return targets;
- }
-
- public ArrayList<String> getFeatures()
- {
- return features;
- }
-
- public ArrayList<String> getTags()
- {
- return tags;
- }
-}
-
-class QemuFirmwareMapping
-{
- @SerializedName( "device" )
- private String device;
- @SerializedName( "executable" )
- private QemuFirmwareMappingExecutable executable;
- @SerializedName( "nvram-template" )
- private QemuFirmwareMappingNvramTemplate nvramTemplate;
-
- public String getDevice()
- {
- return device;
- }
-
- public QemuFirmwareMappingExecutable getExecutable()
- {
- return executable;
- }
-
- public QemuFirmwareMappingNvramTemplate getNvramTemplate()
- {
- return nvramTemplate;
- }
-}
-
-class QemuFirmwareMappingExecutable
-{
- @SerializedName( "filename" )
- private String fileName;
- @SerializedName( "format" )
- private String format;
-
- public String getFileName()
- {
- return fileName;
- }
-
- public String getFormat()
- {
- return format;
- }
-}
-
-class QemuFirmwareMappingNvramTemplate
-{
- @SerializedName( "filename" )
- private String fileName;
- @SerializedName( "format" )
- private String format;
-
- public String getFileName()
- {
- return fileName;
- }
-
- public String getFormat()
- {
- return format;
- }
-}
-
-class QemuFirmwareTarget
-{
- @SerializedName( "architecture" )
- private String architecture;
- @SerializedName( "machines" )
- private ArrayList<String> machines;
-
- public String getArchitecture()
- {
- return architecture;
- }
-
- public ArrayList<String> getMachines()
- {
- return machines;
- }
-}
-
/**
* Specific firmware transformation for Libvirt/QEMU virtualization configurations.
*
@@ -187,80 +48,6 @@ public class TransformationSpecificQemuFirmware
}
}
- private String lookupTargetOsLoader( String firmwareSpecDirectory, String sourceOsLoader, String sourceOsArch,
- String sourceOsMachine )
- throws TransformationException
- {
- String lookupOsLoader = null;
-
- // parse and check firmware specification directory
- final File fwSpecDirectory = new File( firmwareSpecDirectory );
- if ( !fwSpecDirectory.exists() || !fwSpecDirectory.isDirectory() ) {
- throw new TransformationException( "Path to QEMU firmware specifications directory is invalid!" );
- }
-
- // get all firmware specification files
- final FileFilter fwSpecFilesFilter = file -> !file.isDirectory() && file.getName().endsWith( ".json" );
- final File[] fwSpecFiles = fwSpecDirectory.listFiles( fwSpecFilesFilter );
-
- // get paths to firmware files from firmware specification files
- if ( fwSpecFiles != null ) {
- final ArrayList<QemuFirmware> uefiFirmwares = new ArrayList<QemuFirmware>();
- final Gson gson = new Gson();
- for ( final File fwSpecFile : fwSpecFiles ) {
- QemuFirmware firmware = null;
-
- try {
- final Reader jsonContent = new FileReader( fwSpecFile );
- firmware = gson.fromJson( jsonContent, QemuFirmware.class );
- } catch ( FileNotFoundException | JsonSyntaxException | JsonIOException e ) {
- throw new TransformationException( e.getLocalizedMessage() );
- }
-
- final Predicate<String> byInterfaceType = s -> s.toLowerCase().equals( "uefi" );
- if ( firmware.getInterfaceTypes().stream().filter( byInterfaceType ).findAny().isPresent() ) {
- // found valid UEFI firmware
- // check if architecture and machine type of the VM is supported by the firmware
- final Predicate<QemuFirmwareTarget> byArchitecture = t -> sourceOsArch.equals( t.getArchitecture() );
- final Predicate<String> byMachineType = s -> sourceOsMachine.startsWith( s.replace( "*", "" ) );
- final Predicate<QemuFirmwareTarget> byMachines = t -> t.getMachines().stream().filter( byMachineType )
- .findAny().isPresent();
-
- if ( firmware.getTargets().stream().filter( byArchitecture ).filter( byMachines ).findAny()
- .isPresent() ) {
- // found UEFI firmware supporting suitable architecture and machine type from VM
- uefiFirmwares.add( firmware );
- }
- }
- }
-
- if ( uefiFirmwares.isEmpty() ) {
- throw new TransformationException( "There aren't any suitable UEFI firmwares locally available!" );
- } else {
- final LevenshteinDistance distance = new LevenshteinDistance( 1, 1, 1 );
- int minFileNameDistance = Integer.MAX_VALUE;
- Path suitablestUefiFirmwarePath = null;
-
- for ( final QemuFirmware uefiFirmware : uefiFirmwares ) {
- final Path uefiFirmwarePath = Paths.get( uefiFirmware.getMapping().getExecutable().getFileName() );
- final Path sourceOsLoaderPath = Paths.get( sourceOsLoader );
- final String uefiFirmwareFileName = uefiFirmwarePath.getFileName().toString().toLowerCase();
- final String sourceOsLoaderFileName = sourceOsLoaderPath.getFileName().toString().toLowerCase();
-
- final int fileNameDistance = distance.calculateDistance( uefiFirmwareFileName, sourceOsLoaderFileName );
- if ( fileNameDistance < minFileNameDistance ) {
- minFileNameDistance = fileNameDistance;
- suitablestUefiFirmwarePath = uefiFirmwarePath;
- }
- }
-
- lookupOsLoader = suitablestUefiFirmwarePath.toString();
- }
- }
-
- return lookupOsLoader;
- }
-
@Override
public void transform( Domain config, CommandLineArgs args ) throws TransformationException
{
@@ -279,8 +66,16 @@ public class TransformationSpecificQemuFirmware
// check if OS loader is specified
if ( sourceOsLoader != null && !sourceOsLoader.isEmpty() ) {
// OS loader is specified so transform path to specified firmware path
- final String targetOsLoader = this.lookupTargetOsLoader( args.getFirmware(), sourceOsLoader, sourceOsArch,
- sourceOsMachine );
+ // First, lookup QEMU firmware loader for target
+ String targetOsLoader = null;
+ try {
+ targetOsLoader = QemuFirmwareUtil.lookupTargetOsLoader( args.getFirmware(), sourceOsLoader, sourceOsArch,
+ sourceOsMachine );
+ } catch ( FirmwareException e ) {
+ throw new TransformationException( e.getLocalizedMessage() );
+ }
+
+ // Second, set target QEMU firmware loader if specified
if ( targetOsLoader != null && !targetOsLoader.isEmpty() ) {
config.setOsLoader( targetOsLoader );
}
diff --git a/core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/configuration/TransformationTestResources.java b/core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/configuration/TransformationTestResources.java
deleted file mode 100644
index 2c278f23..00000000
--- a/core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/configuration/TransformationTestResources.java
+++ /dev/null
@@ -1,16 +0,0 @@
-package org.openslx.runvirt.plugin.qemu.configuration;
-
-import java.io.File;
-import java.net.URL;
-
-public class TransformationTestResources
-{
- private static final String QEMU_PREFIX_PATH = File.separator + "qemu";
- private static final String QEMU_PREFIX_PATH_FW = QEMU_PREFIX_PATH + File.separator + "firmware";
-
- public static String getQemuFirmwareSpecPath()
- {
- final URL qemuFwSpecPath = TransformationTestResources.class.getResource( QEMU_PREFIX_PATH_FW );
- return qemuFwSpecPath.getFile();
- }
-}
diff --git a/core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/configuration/TransformationTestUtils.java b/core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/configuration/TransformationTestUtils.java
index 248df102..d5605402 100644
--- a/core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/configuration/TransformationTestUtils.java
+++ b/core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/configuration/TransformationTestUtils.java
@@ -2,11 +2,9 @@ package org.openslx.runvirt.plugin.qemu.configuration;
import static org.junit.jupiter.api.Assertions.fail;
+import org.openslx.firmware.QemuFirmwareTestResources;
import org.openslx.libvirt.domain.Domain;
-import org.openslx.libvirt.xml.LibvirtXmlDocumentException;
-import org.openslx.libvirt.xml.LibvirtXmlSerializationException;
-import org.openslx.libvirt.xml.LibvirtXmlTestResources;
-import org.openslx.libvirt.xml.LibvirtXmlValidationException;
+import org.openslx.libvirt.domain.DomainTest;
import org.openslx.runvirt.plugin.qemu.cmdln.CommandLineArgs;
import org.openslx.runvirt.plugin.qemu.cmdln.CommandLineArgs.CmdLnOption;
import org.openslx.runvirt.plugin.qemu.cmdln.CommandLineArgsException;
@@ -15,7 +13,7 @@ import org.openslx.runvirt.plugin.qemu.cmdln.CommandLineArgsTest;
public class TransformationTestUtils
{
// @formatter:off
- public static final String DEFAULT_FW_PATH = TransformationTestResources.getQemuFirmwareSpecPath();
+ public static final String DEFAULT_FW_PATH = QemuFirmwareTestResources.getQemuFirmwareSpecPath();
public static final String DEFAULT_VM_NAME = "archlinux";
public static final String DEFAULT_VM_UUID = "4ec504d5-5eac-482f-a344-dbf1dd4956c8";
public static final String DEFAULT_VM_DSPLNAME = "Archlinux";
@@ -110,16 +108,7 @@ public class TransformationTestUtils
public static Domain getDomain( String fileName )
{
- Domain domain = null;
-
- try {
- domain = new Domain( LibvirtXmlTestResources.getLibvirtXmlStream( fileName ) );
- } catch ( LibvirtXmlDocumentException | LibvirtXmlSerializationException | LibvirtXmlValidationException e ) {
- fail( "Cannot prepare requested Libvirt domain XML file from the resources folder: "
- + e.getLocalizedMessage() );
- }
-
- return domain;
+ return DomainTest.getDomain( fileName );
}
public static Domain getDefaultDomain()
diff --git a/core/modules/qemu/runvirt-plugin-qemu/src/test/resources/qemu/firmware/50-edk2-i386-secure.json b/core/modules/qemu/runvirt-plugin-qemu/src/test/resources/qemu/firmware/50-edk2-i386-secure.json
deleted file mode 100644
index 9838f16a..00000000
--- a/core/modules/qemu/runvirt-plugin-qemu/src/test/resources/qemu/firmware/50-edk2-i386-secure.json
+++ /dev/null
@@ -1,34 +0,0 @@
-{
- "description": "UEFI firmware for i386, with Secure Boot and SMM",
- "interface-types": [
- "uefi"
- ],
- "mapping": {
- "device": "flash",
- "executable": {
- "filename": "/usr/share/qemu/edk2-i386-secure-code.fd",
- "format": "raw"
- },
- "nvram-template": {
- "filename": "/usr/share/qemu/edk2-i386-vars.fd",
- "format": "raw"
- }
- },
- "targets": [
- {
- "architecture": "i386",
- "machines": [
- "pc-q35-*"
- ]
- }
- ],
- "features": [
- "acpi-s3",
- "requires-smm",
- "secure-boot",
- "verbose-dynamic"
- ],
- "tags": [
-
- ]
-}
diff --git a/core/modules/qemu/runvirt-plugin-qemu/src/test/resources/qemu/firmware/50-edk2-x86_64-secure.json b/core/modules/qemu/runvirt-plugin-qemu/src/test/resources/qemu/firmware/50-edk2-x86_64-secure.json
deleted file mode 100644
index 12fa688c..00000000
--- a/core/modules/qemu/runvirt-plugin-qemu/src/test/resources/qemu/firmware/50-edk2-x86_64-secure.json
+++ /dev/null
@@ -1,35 +0,0 @@
-{
- "description": "UEFI firmware for x86_64, with Secure Boot and SMM",
- "interface-types": [
- "uefi"
- ],
- "mapping": {
- "device": "flash",
- "executable": {
- "filename": "/usr/share/qemu/edk2-x86_64-secure-code.fd",
- "format": "raw"
- },
- "nvram-template": {
- "filename": "/usr/share/qemu/edk2-i386-vars.fd",
- "format": "raw"
- }
- },
- "targets": [
- {
- "architecture": "x86_64",
- "machines": [
- "pc-q35-*"
- ]
- }
- ],
- "features": [
- "acpi-s3",
- "amd-sev",
- "requires-smm",
- "secure-boot",
- "verbose-dynamic"
- ],
- "tags": [
-
- ]
-}
diff --git a/core/modules/qemu/runvirt-plugin-qemu/src/test/resources/qemu/firmware/60-edk2-aarch64.json b/core/modules/qemu/runvirt-plugin-qemu/src/test/resources/qemu/firmware/60-edk2-aarch64.json
deleted file mode 100644
index 52a65c73..00000000
--- a/core/modules/qemu/runvirt-plugin-qemu/src/test/resources/qemu/firmware/60-edk2-aarch64.json
+++ /dev/null
@@ -1,31 +0,0 @@
-{
- "description": "UEFI firmware for aarch64",
- "interface-types": [
- "uefi"
- ],
- "mapping": {
- "device": "flash",
- "executable": {
- "filename": "/usr/share/qemu/edk2-aarch64-code.fd",
- "format": "raw"
- },
- "nvram-template": {
- "filename": "/usr/share/qemu/edk2-arm-vars.fd",
- "format": "raw"
- }
- },
- "targets": [
- {
- "architecture": "aarch64",
- "machines": [
- "virt-*"
- ]
- }
- ],
- "features": [
- "verbose-static"
- ],
- "tags": [
-
- ]
-}
diff --git a/core/modules/qemu/runvirt-plugin-qemu/src/test/resources/qemu/firmware/60-edk2-arm.json b/core/modules/qemu/runvirt-plugin-qemu/src/test/resources/qemu/firmware/60-edk2-arm.json
deleted file mode 100644
index 8dc6e0f1..00000000
--- a/core/modules/qemu/runvirt-plugin-qemu/src/test/resources/qemu/firmware/60-edk2-arm.json
+++ /dev/null
@@ -1,31 +0,0 @@
-{
- "description": "UEFI firmware for arm",
- "interface-types": [
- "uefi"
- ],
- "mapping": {
- "device": "flash",
- "executable": {
- "filename": "/usr/share/qemu/edk2-arm-code.fd",
- "format": "raw"
- },
- "nvram-template": {
- "filename": "/usr/share/qemu/edk2-arm-vars.fd",
- "format": "raw"
- }
- },
- "targets": [
- {
- "architecture": "arm",
- "machines": [
- "virt-*"
- ]
- }
- ],
- "features": [
- "verbose-static"
- ],
- "tags": [
-
- ]
-}
diff --git a/core/modules/qemu/runvirt-plugin-qemu/src/test/resources/qemu/firmware/60-edk2-i386.json b/core/modules/qemu/runvirt-plugin-qemu/src/test/resources/qemu/firmware/60-edk2-i386.json
deleted file mode 100644
index f0929ed5..00000000
--- a/core/modules/qemu/runvirt-plugin-qemu/src/test/resources/qemu/firmware/60-edk2-i386.json
+++ /dev/null
@@ -1,33 +0,0 @@
-{
- "description": "UEFI firmware for i386",
- "interface-types": [
- "uefi"
- ],
- "mapping": {
- "device": "flash",
- "executable": {
- "filename": "/usr/share/qemu/edk2-i386-code.fd",
- "format": "raw"
- },
- "nvram-template": {
- "filename": "/usr/share/qemu/edk2-i386-vars.fd",
- "format": "raw"
- }
- },
- "targets": [
- {
- "architecture": "i386",
- "machines": [
- "pc-i440fx-*",
- "pc-q35-*"
- ]
- }
- ],
- "features": [
- "acpi-s3",
- "verbose-dynamic"
- ],
- "tags": [
-
- ]
-}
diff --git a/core/modules/qemu/runvirt-plugin-qemu/src/test/resources/qemu/firmware/60-edk2-x86_64.json b/core/modules/qemu/runvirt-plugin-qemu/src/test/resources/qemu/firmware/60-edk2-x86_64.json
deleted file mode 100644
index d0b6542c..00000000
--- a/core/modules/qemu/runvirt-plugin-qemu/src/test/resources/qemu/firmware/60-edk2-x86_64.json
+++ /dev/null
@@ -1,34 +0,0 @@
-{
- "description": "UEFI firmware for x86_64",
- "interface-types": [
- "uefi"
- ],
- "mapping": {
- "device": "flash",
- "executable": {
- "filename": "/usr/share/qemu/edk2-x86_64-code.fd",
- "format": "raw"
- },
- "nvram-template": {
- "filename": "/usr/share/qemu/edk2-i386-vars.fd",
- "format": "raw"
- }
- },
- "targets": [
- {
- "architecture": "x86_64",
- "machines": [
- "pc-i440fx-*",
- "pc-q35-*"
- ]
- }
- ],
- "features": [
- "acpi-s3",
- "amd-sev",
- "verbose-dynamic"
- ],
- "tags": [
-
- ]
-}