diff options
author | Manuel Bentele | 2021-11-30 09:08:03 +0100 |
---|---|---|
committer | Manuel Bentele | 2021-11-30 09:08:03 +0100 |
commit | 8f1c0f8dacf3a5216276f0981d3f5753c75ed750 (patch) | |
tree | 7bc00214f63d0cac2638a55837a8029bf7692027 | |
parent | Add CPU topology functionality for Libvirt domain XML configs (diff) | |
download | master-sync-shared-8f1c0f8dacf3a5216276f0981d3f5753c75ed750.tar.gz master-sync-shared-8f1c0f8dacf3a5216276f0981d3f5753c75ed750.tar.xz master-sync-shared-8f1c0f8dacf3a5216276f0981d3f5753c75ed750.zip |
Add firmware loader lookup algorithm for Libvirt/QEMU machines
15 files changed, 843 insertions, 58 deletions
@@ -101,6 +101,7 @@ <includes> <include>disk/*</include> <include>libvirt/xml/*</include> + <include>qemu/firmware/*</include> <include>virtualbox/xml/*</include> <include>vmware/vmx/*</include> </includes> diff --git a/src/main/java/org/openslx/firmware/FirmwareException.java b/src/main/java/org/openslx/firmware/FirmwareException.java new file mode 100644 index 0000000..494d653 --- /dev/null +++ b/src/main/java/org/openslx/firmware/FirmwareException.java @@ -0,0 +1,25 @@ +package org.openslx.firmware; + +/** + * An exception of a firmware-related error. + * + * @author Manuel Bentele + * @version 1.0 + */ +public class FirmwareException extends Exception +{ + /** + * Version for serialization. + */ + private static final long serialVersionUID = -5932122856822258867L; + + /** + * Creates a firmware exception including an error message. + * + * @param errorMsg message to describe the exception. + */ + public FirmwareException( String errorMsg ) + { + super( errorMsg ); + } +} diff --git a/src/main/java/org/openslx/firmware/QemuFirmware.java b/src/main/java/org/openslx/firmware/QemuFirmware.java new file mode 100644 index 0000000..7a81217 --- /dev/null +++ b/src/main/java/org/openslx/firmware/QemuFirmware.java @@ -0,0 +1,169 @@ +package org.openslx.firmware; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.Reader; +import java.util.ArrayList; + +import com.google.gson.Gson; +import com.google.gson.JsonIOException; +import com.google.gson.JsonSyntaxException; +import com.google.gson.annotations.SerializedName; + +/** + * Data representation of QEMU firmware specification files (*.json). + * + * @author Manuel Bentele + * @version 1.0 + */ +public class QemuFirmware +{ + /** + * Default QEMU firmware specification directory under Linux-based systems. + */ + public final static String DEFAULT_SPEC_DIR = "/usr/share/qemu/firmware"; + + @SerializedName( "description" ) + private String description; + @SerializedName( "interface-types" ) + private ArrayList<String> interfaceTypes; + @SerializedName( "mapping" ) + private FirmwareMapping mapping; + @SerializedName( "targets" ) + private ArrayList<FirmwareTarget> 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 FirmwareMapping getMapping() + { + return mapping; + } + + public ArrayList<FirmwareTarget> getTargets() + { + return targets; + } + + public ArrayList<String> getFeatures() + { + return features; + } + + public ArrayList<String> getTags() + { + return tags; + } + + /** + * Parse QEMU firmware specification from firmware specification Json file. + * + * @param fwSpecFile firmware specification Json file. + * @return QEMU firmware specification. + */ + public static QemuFirmware fromFwSpec( File fwSpecFile ) + { + final Gson gson = new Gson(); + QemuFirmware firmware = null; + + try { + final Reader jsonContent = new FileReader( fwSpecFile ); + firmware = gson.fromJson( jsonContent, QemuFirmware.class ); + } catch ( FileNotFoundException | NullPointerException | JsonSyntaxException | JsonIOException e ) { + firmware = null; + } + + return firmware; + } +} + +class FirmwareMapping +{ + @SerializedName( "device" ) + private String device; + @SerializedName( "executable" ) + private FirmwareMappingExecutable executable; + @SerializedName( "nvram-template" ) + private FirmwareMappingNvramTemplate nvramTemplate; + + public String getDevice() + { + return device; + } + + public FirmwareMappingExecutable getExecutable() + { + return executable; + } + + public FirmwareMappingNvramTemplate getNvramTemplate() + { + return nvramTemplate; + } +} + +class FirmwareMappingExecutable +{ + @SerializedName( "filename" ) + private String fileName; + @SerializedName( "format" ) + private String format; + + public String getFileName() + { + return fileName; + } + + public String getFormat() + { + return format; + } +} + +class FirmwareMappingNvramTemplate +{ + @SerializedName( "filename" ) + private String fileName; + @SerializedName( "format" ) + private String format; + + public String getFileName() + { + return fileName; + } + + public String getFormat() + { + return format; + } +} + +class FirmwareTarget +{ + @SerializedName( "architecture" ) + private String architecture; + @SerializedName( "machines" ) + private ArrayList<String> machines; + + public String getArchitecture() + { + return architecture; + } + + public ArrayList<String> getMachines() + { + return machines; + } +} diff --git a/src/main/java/org/openslx/firmware/QemuFirmwareUtil.java b/src/main/java/org/openslx/firmware/QemuFirmwareUtil.java new file mode 100644 index 0000000..987a0c0 --- /dev/null +++ b/src/main/java/org/openslx/firmware/QemuFirmwareUtil.java @@ -0,0 +1,121 @@ +package org.openslx.firmware; + +import java.io.File; +import java.io.FileFilter; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.function.Predicate; + +import org.openslx.util.LevenshteinDistance; +import org.openslx.virtualization.configuration.transformation.TransformationException; + +/** + * Utilities to process QEMU firmware specification files. + * + * @author Manuel Bentele + * @version 1.0 + */ +public class QemuFirmwareUtil +{ + /** + * Lookup a virtual machine's target OS loader based on QEMU firmware specification files. + * + * @param fwSpecDir QEMU firmware specification directory of the target host. + * @param sourceOsLoader OS loader of the virtual machine. + * @param sourceOsArch OS architecture of the virtual machine. + * @param sourceOsMachine OS machine type of the virtual machine. + * @return Path to the new target OS loader file for the virtual machine. + * + * @throws TransformationException Failed to lookup target OS loader for virtual machine. + */ + public static String lookupTargetOsLoader( String fwSpecDir, String sourceOsLoader, String sourceOsArch, + String sourceOsMachine ) + throws FirmwareException + { + String lookupOsLoader = null; + + // parse and check firmware specification directory + final File fwSpecDirFile = new File( fwSpecDir ); + if ( !fwSpecDirFile.exists() || !fwSpecDirFile.isDirectory() ) { + throw new FirmwareException( "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 = fwSpecDirFile.listFiles( fwSpecFilesFilter ); + + // get paths to firmware files from firmware specification files + if ( fwSpecFiles != null ) { + final ArrayList<QemuFirmware> uefiFirmwares = new ArrayList<QemuFirmware>(); + + for ( final File fwSpecFile : fwSpecFiles ) { + // parse the firmware file + final QemuFirmware firmware = QemuFirmware.fromFwSpec( fwSpecFile ); + if ( firmware == null ) { + throw new FirmwareException( "Firmware '" + fwSpecFile.toString() + "' can not be parsed correctly!" ); + } else { + 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<FirmwareTarget> byArchitecture = t -> sourceOsArch.equals( t.getArchitecture() ); + final Predicate<String> byMachineType = s -> sourceOsMachine.startsWith( s.replace( "*", "" ) ); + final Predicate<FirmwareTarget> 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 FirmwareException( "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; + } + + /** + * Lookup a virtual machine's target OS loader based on QEMU firmware specification files under + * the default path. + * + * @param sourceOsLoader OS loader of the virtual machine. + * @param sourceOsArch OS architecture of the virtual machine. + * @param sourceOsMachine OS machine type of the virtual machine. + * @return Path to the new target OS loader file for the virtual machine. + * + * @throws TransformationException Failed to lookup target OS loader for virtual machine. + */ + public static String lookupTargetOsLoaderDefaultFwSpecDir( String sourceOsLoader, String sourceOsArch, + String sourceOsMachine ) + throws FirmwareException + { + return QemuFirmwareUtil.lookupTargetOsLoader( QemuFirmware.DEFAULT_SPEC_DIR, sourceOsLoader, sourceOsArch, + sourceOsMachine ); + } +} diff --git a/src/main/java/org/openslx/virtualization/configuration/VirtualizationConfigurationQemu.java b/src/main/java/org/openslx/virtualization/configuration/VirtualizationConfigurationQemu.java index 706a083..ced9160 100644 --- a/src/main/java/org/openslx/virtualization/configuration/VirtualizationConfigurationQemu.java +++ b/src/main/java/org/openslx/virtualization/configuration/VirtualizationConfigurationQemu.java @@ -7,6 +7,8 @@ import java.util.ArrayList; import java.util.List; import org.openslx.bwlp.thrift.iface.OperatingSystem; +import org.openslx.firmware.FirmwareException; +import org.openslx.firmware.QemuFirmwareUtil; import org.openslx.libvirt.domain.Domain; import org.openslx.libvirt.domain.DomainUtils; import org.openslx.libvirt.domain.device.ControllerUsb; @@ -208,6 +210,32 @@ public class VirtualizationConfigurationQemu extends VirtualizationConfiguration { } + public void transformOsLoader() throws VirtualizationConfigurationException + { + final String sourceOsLoader = this.vmConfig.getOsLoader(); + final String sourceOsArch = this.vmConfig.getOsArch(); + final String sourceOsMachine = this.vmConfig.getOsMachine(); + + // transform OS loader for local editing + // check if OS loader is specified + if ( sourceOsLoader != null && !sourceOsLoader.isEmpty() ) { + // OS loader is specified so transform path to specified firmware path + // First, lookup QEMU firmware loader for target + String targetOsLoader = null; + try { + targetOsLoader = QemuFirmwareUtil.lookupTargetOsLoaderDefaultFwSpecDir( sourceOsLoader, sourceOsArch, + sourceOsMachine ); + } catch ( FirmwareException e ) { + throw new VirtualizationConfigurationException( e.getLocalizedMessage() ); + } + + // Second, set target QEMU firmware loader if specified + if ( targetOsLoader != null && !targetOsLoader.isEmpty() ) { + this.vmConfig.setOsLoader( targetOsLoader ); + } + } + } + @Override public boolean addEmptyHddTemplate() { diff --git a/src/test/java/org/openslx/firmware/QemuFirmwareTest.java b/src/test/java/org/openslx/firmware/QemuFirmwareTest.java new file mode 100644 index 0000000..3088265 --- /dev/null +++ b/src/test/java/org/openslx/firmware/QemuFirmwareTest.java @@ -0,0 +1,45 @@ +package org.openslx.firmware; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; + +import java.io.File; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +public class QemuFirmwareTest +{ + @Test + @DisplayName( "Test parsing of valid QEMU firmware specification file" ) + public void testQemuFirmwareFromFwSpecValid() + { + final File fwSpecFile = QemuFirmwareTestResources.getQemuFirmwareSpecFile( "60-edk2-x86_64.json" ); + + final QemuFirmware firmware = QemuFirmware.fromFwSpec( fwSpecFile ); + + assertNotNull( firmware ); + assertEquals( "UEFI firmware for x86_64", firmware.getDescription() ); + assertEquals( 1, firmware.getInterfaceTypes().size() ); + assertEquals( "uefi", firmware.getInterfaceTypes().get( 0 ) ); + assertEquals( "/usr/share/qemu/edk2-x86_64-code.fd", firmware.getMapping().getExecutable().getFileName() ); + assertEquals( "/usr/share/qemu/edk2-i386-vars.fd", firmware.getMapping().getNvramTemplate().getFileName() ); + assertEquals( 1, firmware.getTargets().size() ); + assertEquals( "x86_64", firmware.getTargets().get( 0 ).getArchitecture() ); + assertEquals( 2, firmware.getTargets().get( 0 ).getMachines().size() ); + assertEquals( "pc-i440fx-*", firmware.getTargets().get( 0 ).getMachines().get( 0 ) ); + assertEquals( "pc-q35-*", firmware.getTargets().get( 0 ).getMachines().get( 1 ) ); + assertEquals( 3, firmware.getFeatures().size() ); + assertEquals( 0, firmware.getTags().size() ); + } + + @Test + @DisplayName( "Test parsing of invalid QEMU firmware specification file" ) + public void testQemuFirmwareFromFwSpecInvalid() + { + final QemuFirmware firmware = QemuFirmware.fromFwSpec( null ); + + assertNull( firmware ); + } +} diff --git a/src/test/java/org/openslx/firmware/QemuFirmwareTestResources.java b/src/test/java/org/openslx/firmware/QemuFirmwareTestResources.java new file mode 100644 index 0000000..e4c1aa7 --- /dev/null +++ b/src/test/java/org/openslx/firmware/QemuFirmwareTestResources.java @@ -0,0 +1,100 @@ +package org.openslx.firmware; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLDecoder; +import java.nio.file.Files; +import java.util.Enumeration; +import java.util.HashSet; +import java.util.Set; +import java.util.jar.JarEntry; +import java.util.jar.JarFile; + +import org.apache.commons.io.FileUtils; + +public class QemuFirmwareTestResources +{ + private static final String QEMU_PREFIX_PATH = File.separator + "qemu"; + private static final String QEMU_PREFIX_PATH_FW = QEMU_PREFIX_PATH + File.separator + "firmware"; + + private static final String QEMU_TEMP_PREFIX = "qemu-"; + + public static String getQemuFirmwareSpecPath() + { + String fwSpecDir = null; + + try { + fwSpecDir = getResourceDirectory( QemuFirmwareTestResources.class, QEMU_PREFIX_PATH_FW ); + } catch ( IOException e ) { + fwSpecDir = null; + } + + return fwSpecDir; + } + + private static String getResourceDirectory( Class<?> clazz, String resourceDir ) throws IOException + { + final String fwDirPath = resourceDir.substring( 1 ).concat( File.separator ); + final URL fwResource = clazz.getResource( resourceDir ); + final File fwDirectory; + String fwDirectoryPath = null; + + if ( fwResource != null && "jar".equals( fwResource.getProtocol() ) ) { + // create temporary directory to copy Jar files into it + fwDirectory = Files.createTempDirectory( QEMU_TEMP_PREFIX ).toFile(); + + // obtain file list from a directory within the Jar file + // strip out only the JAR file path + final String jarPath = fwResource.getPath().substring( 5, fwResource.getPath().indexOf( "!" ) ); + final JarFile jar = new JarFile( URLDecoder.decode( jarPath, "UTF-8" ) ); + // get all entries in the Jar file + final Enumeration<JarEntry> jarEntries = jar.entries(); + final Set<String> fileNames = new HashSet<String>(); + while ( jarEntries.hasMoreElements() ) { + final String jarEntryName = jarEntries.nextElement().getName(); + if ( jarEntryName.startsWith( fwDirPath ) ) { + String jarEntry = jarEntryName.substring( fwDirPath.length() ); + if ( !jarEntry.isEmpty() ) { + fileNames.add( jarEntry ); + } + } + } + + // copy each file from the Jar to the temporary directory + fileNames.forEach( fileName -> { + final String resourceFileName = resourceDir + File.separator + fileName; + final File tempFile = new File( fwDirectory.getPath() + File.separator + fileName ); + final InputStream fileInput = QemuFirmwareTestResources.class.getResourceAsStream( resourceFileName ); + try { + FileUtils.copyInputStreamToFile( fileInput, tempFile ); + } catch ( IOException e ) { + e.printStackTrace(); + } + tempFile.deleteOnExit(); + } ); + fwDirectory.deleteOnExit(); + } else if ( fwResource != null && "file".equals( fwResource.getProtocol() ) ) { + fwDirectory = new File( fwResource.getFile() ); + } else { + fwDirectory = null; + } + + try { + fwDirectoryPath = fwDirectory.toURI().toURL().getFile(); + } catch ( MalformedURLException | NullPointerException e ) { + fwDirectoryPath = null; + } + + return fwDirectoryPath; + } + + public static File getQemuFirmwareSpecFile( String fileName ) + { + final String fwSpecFilePath = QEMU_PREFIX_PATH_FW + File.separator + fileName; + final URL fwSpecFileUrl = QemuFirmwareTestResources.class.getResource( fwSpecFilePath ); + return new File( fwSpecFileUrl.getFile() ); + } +} diff --git a/src/test/java/org/openslx/firmware/QemuFirmwareUtilTest.java b/src/test/java/org/openslx/firmware/QemuFirmwareUtilTest.java new file mode 100644 index 0000000..75ce286 --- /dev/null +++ b/src/test/java/org/openslx/firmware/QemuFirmwareUtilTest.java @@ -0,0 +1,98 @@ +package org.openslx.firmware; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + +import java.nio.file.Paths; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.openslx.libvirt.domain.Domain; +import org.openslx.libvirt.domain.DomainTest; + +public class QemuFirmwareUtilTest +{ + @Test + @DisplayName( "Test that lookup of OS loader from Libvirt domain file succeeds" ) + public void testQemuFirmwareUtilLookupTargetOsLoaderValid() throws FirmwareException + { + final String fwSpecPath = QemuFirmwareTestResources.getQemuFirmwareSpecPath(); + final Domain config = DomainTest + .getDomain( "qemu-kvm_default-ubuntu-20-04-vm_transform-non-persistent_uefi.xml" ); + + final String targetOsLoader = QemuFirmwareUtil.lookupTargetOsLoader( fwSpecPath, config.getOsLoader(), + config.getOsArch(), config.getOsMachine() ); + + assertEquals( Paths.get( "/usr/share/qemu/edk2-x86_64-code.fd" ).toString(), targetOsLoader ); + } + + @Test + @DisplayName( "Test that lookup of OS loader from Archlinux path succeeds" ) + public void testQemuFirmwareUtilLookupTargetOsLoaderValidArchlinux() throws FirmwareException + { + final String fwSpecPath = QemuFirmwareTestResources.getQemuFirmwareSpecPath(); + + final String targetOsLoader = QemuFirmwareUtil.lookupTargetOsLoader( fwSpecPath, + "/usr/share/edk2-ovmf/x64/OVMF_CODE.fd", "x86_64", "pc-q35-5.0" ); + + assertEquals( Paths.get( "/usr/share/qemu/edk2-x86_64-code.fd" ).toString(), targetOsLoader ); + } + + @Test + @DisplayName( "Test that lookup of OS loader from Debian path succeeds" ) + public void testQemuFirmwareUtilLookupTargetOsLoaderValidDebian() throws FirmwareException + { + final String fwSpecPath = QemuFirmwareTestResources.getQemuFirmwareSpecPath(); + + final String targetOsLoader = QemuFirmwareUtil.lookupTargetOsLoader( fwSpecPath, + "/usr/share/OVMF/OVMF_CODE.fd", "x86_64", "pc-q35-5.0" ); + + assertEquals( Paths.get( "/usr/share/qemu/edk2-x86_64-code.fd" ).toString(), targetOsLoader ); + } + + @Test + @DisplayName( "Test that lookup of OS loader from CentOS path succeeds" ) + public void testQemuFirmwareUtilLookupTargetOsLoaderValidCentOs() throws FirmwareException + { + final String fwSpecPath = QemuFirmwareTestResources.getQemuFirmwareSpecPath(); + + final String targetOsLoader = QemuFirmwareUtil.lookupTargetOsLoader( fwSpecPath, + "/usr/share/edk2/ovmf/OVMF_CODE.cc.fd", "x86_64", "pc-q35-5.0" ); + + assertEquals( Paths.get( "/usr/share/qemu/edk2-x86_64-code.fd" ).toString(), targetOsLoader ); + } + + @Test + @DisplayName( "Test that lookup of OS loader from OpenSUSE path succeeds" ) + public void testQemuFirmwareUtilLookupTargetOsLoaderValidOpenSuse() throws FirmwareException + { + final String fwSpecPath = QemuFirmwareTestResources.getQemuFirmwareSpecPath(); + + final String targetOsLoader = QemuFirmwareUtil.lookupTargetOsLoader( fwSpecPath, + "/usr/share/qemu/ovmf-x86_64-4m-code.bin", "x86_64", "pc-q35-5.0" ); + + assertEquals( Paths.get( "/usr/share/qemu/edk2-x86_64-code.fd" ).toString(), targetOsLoader ); + } + + @Test + @DisplayName( "Test that lookup of OS loader from Ubuntu path succeeds" ) + public void testQemuFirmwareUtilLookupTargetOsLoaderValidUbuntu() throws FirmwareException + { + final String fwSpecPath = QemuFirmwareTestResources.getQemuFirmwareSpecPath(); + + final String targetOsLoader = QemuFirmwareUtil.lookupTargetOsLoader( fwSpecPath, + "/usr/share/OVMF/OVMF_CODE_4M.fd", "x86_64", "pc-q35-5.0" ); + + assertEquals( Paths.get( "/usr/share/qemu/edk2-x86_64-code.fd" ).toString(), targetOsLoader ); + } + + @Test + @DisplayName( "Test that lookup of non-existent OS loader for non-existent architecture fails" ) + public void testQemuFirmwareUtilLookupTargetOsLoaderInvalid() throws FirmwareException + { + final String fwSpecPath = QemuFirmwareTestResources.getQemuFirmwareSpecPath(); + + assertThrows( FirmwareException.class, () -> QemuFirmwareUtil.lookupTargetOsLoader( fwSpecPath, + Paths.get( "/non/existent/loader.fd" ).toString(), "x87", "pc-q35-6.0" ) ); + } +} diff --git a/src/test/java/org/openslx/libvirt/domain/DomainTest.java b/src/test/java/org/openslx/libvirt/domain/DomainTest.java index 00bf83b..f371e9e 100644 --- a/src/test/java/org/openslx/libvirt/domain/DomainTest.java +++ b/src/test/java/org/openslx/libvirt/domain/DomainTest.java @@ -28,12 +28,12 @@ public class DomainTest LogManager.getRootLogger().setLevel( Level.OFF ); } - private Domain newDomainInstance( String xmlFileName ) + public static Domain getDomain( String xmlFileName ) { Domain domain = null; try { - domain = new Domain( LibvirtXmlTestResources.getLibvirtXmlFile( xmlFileName ) ); + domain = new Domain( LibvirtXmlTestResources.getLibvirtXmlStream( xmlFileName ) ); } catch ( LibvirtXmlDocumentException | LibvirtXmlSerializationException | LibvirtXmlValidationException e ) { String errorMsg = new String( "Cannot prepare requested Libvirt domain XML file from the resources folder" ); fail( errorMsg ); @@ -46,7 +46,7 @@ public class DomainTest @DisplayName( "Get VM type from libvirt XML file" ) public void testGetType() { - Domain vm = this.newDomainInstance( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); + Domain vm = DomainTest.getDomain( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); assertEquals( Domain.Type.KVM.toString(), vm.getType().toString() ); } @@ -54,7 +54,7 @@ public class DomainTest @DisplayName( "Set VM type from libvirt XML file" ) public void testSetType() { - Domain vm = this.newDomainInstance( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); + Domain vm = DomainTest.getDomain( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); vm.setType( Domain.Type.QEMU ); assertEquals( Domain.Type.QEMU.toString(), vm.getType().toString() ); } @@ -63,7 +63,7 @@ public class DomainTest @DisplayName( "Get VM name from libvirt XML file" ) public void testGetName() { - Domain vm = this.newDomainInstance( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); + Domain vm = DomainTest.getDomain( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); assertEquals( "ubuntu-20-04", vm.getName() ); } @@ -71,7 +71,7 @@ public class DomainTest @DisplayName( "Set VM name in libvirt XML file" ) public void testSetName() { - Domain vm = this.newDomainInstance( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); + Domain vm = DomainTest.getDomain( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); vm.setName( "ubuntu-18-04" ); assertEquals( "ubuntu-18-04", vm.getName() ); } @@ -80,7 +80,7 @@ public class DomainTest @DisplayName( "Get VM title from libvirt XML file" ) public void testGetTitle() { - Domain vm = this.newDomainInstance( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); + Domain vm = DomainTest.getDomain( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); assertEquals( "Ubuntu 20.04", vm.getTitle() ); } @@ -88,7 +88,7 @@ public class DomainTest @DisplayName( "Set VM title in libvirt XML file" ) public void testSetTitle() { - Domain vm = this.newDomainInstance( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); + Domain vm = DomainTest.getDomain( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); vm.setTitle( "Ubuntu 18.04" ); assertEquals( "Ubuntu 18.04", vm.getTitle() ); } @@ -97,7 +97,7 @@ public class DomainTest @DisplayName( "Get VM description from libvirt XML file" ) public void testGetDescription() { - Domain vm = this.newDomainInstance( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); + Domain vm = DomainTest.getDomain( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); assertEquals( "Ubuntu 20.04 desktop installation", vm.getDescription() ); } @@ -105,7 +105,7 @@ public class DomainTest @DisplayName( "Set VM description in libvirt XML file" ) public void testSetDescription() { - Domain vm = this.newDomainInstance( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); + Domain vm = DomainTest.getDomain( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); vm.setDescription( "Ubuntu 18.04 server installation" ); assertEquals( "Ubuntu 18.04 server installation", vm.getDescription() ); } @@ -114,7 +114,7 @@ public class DomainTest @DisplayName( "Get VM libosinfo operating system identifier in libvirt XML file" ) public void testGetLibOsInfoOsId() { - Domain vm = this.newDomainInstance( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); + Domain vm = DomainTest.getDomain( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); assertEquals( "http://ubuntu.com/ubuntu/20.04", vm.getLibOsInfoOsId() ); } @@ -122,7 +122,7 @@ public class DomainTest @DisplayName( "Get VM UUID from libvirt XML file" ) public void testGetUuid() { - Domain vm = this.newDomainInstance( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); + Domain vm = DomainTest.getDomain( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); assertEquals( "8dc5433c-0228-49e4-b019-fa2b606aa544", vm.getUuid() ); } @@ -130,7 +130,7 @@ public class DomainTest @DisplayName( "Set VM UUID in libvirt XML file" ) public void testSetUuid() { - Domain vm = this.newDomainInstance( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); + Domain vm = DomainTest.getDomain( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); vm.setUuid( "5ab08167-3d95-400e-ac83-e6af8d150971" ); assertEquals( "5ab08167-3d95-400e-ac83-e6af8d150971", vm.getUuid() ); } @@ -139,7 +139,7 @@ public class DomainTest @DisplayName( "Get VM memory from libvirt XML file" ) public void testGetMemory() { - Domain vm = this.newDomainInstance( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); + Domain vm = DomainTest.getDomain( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); assertEquals( new BigInteger( "4294967296" ).toString(), vm.getMemory().toString() ); } @@ -147,7 +147,7 @@ public class DomainTest @DisplayName( "Set VM memory in libvirt XML file" ) public void testSetMemory() { - Domain vm = this.newDomainInstance( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); + Domain vm = DomainTest.getDomain( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); vm.setMemory( new BigInteger( "12073740288" ) ); assertEquals( new BigInteger( "12073740288" ).toString(), vm.getMemory().toString() ); } @@ -156,7 +156,7 @@ public class DomainTest @DisplayName( "Get current VM memory from libvirt XML file" ) public void testGetCurrentMemory() { - Domain vm = this.newDomainInstance( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); + Domain vm = DomainTest.getDomain( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); assertEquals( new BigInteger( "4294967296" ).toString(), vm.getCurrentMemory().toString() ); } @@ -164,7 +164,7 @@ public class DomainTest @DisplayName( "Set current VM memory in libvirt XML file" ) public void testSetCurrentMemory() { - Domain vm = this.newDomainInstance( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); + Domain vm = DomainTest.getDomain( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); vm.setCurrentMemory( new BigInteger( "8087237632" ) ); assertEquals( new BigInteger( "8087237632" ).toString(), vm.getCurrentMemory().toString() ); } @@ -173,7 +173,7 @@ public class DomainTest @DisplayName( "Get VM number of vCpus from libvirt XML file" ) public void testGetVCpu() { - Domain vm = this.newDomainInstance( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); + Domain vm = DomainTest.getDomain( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); assertEquals( 2, vm.getVCpu() ); } @@ -181,7 +181,7 @@ public class DomainTest @DisplayName( "Set VM number of vCpus in libvirt XML file" ) public void testSetVCpu() { - Domain vm = this.newDomainInstance( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); + Domain vm = DomainTest.getDomain( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); vm.setVCpu( 4 ); assertEquals( 4, vm.getVCpu() ); } @@ -190,7 +190,7 @@ public class DomainTest @DisplayName( "Get VM's OS type from libvirt XML file" ) public void testGetOsType() { - Domain vm = this.newDomainInstance( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); + Domain vm = DomainTest.getDomain( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); assertEquals( OsType.HVM.toString(), vm.getOsType().toString() ); } @@ -198,7 +198,7 @@ public class DomainTest @DisplayName( "Set VM's OS type in libvirt XML file" ) public void testSetOsType() { - Domain vm = this.newDomainInstance( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); + Domain vm = DomainTest.getDomain( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); vm.setOsType( OsType.XEN ); assertEquals( OsType.XEN.toString(), vm.getOsType().toString() ); } @@ -207,7 +207,7 @@ public class DomainTest @DisplayName( "Get VM's OS architecture from libvirt XML file" ) public void testGetOsArch() { - Domain vm = this.newDomainInstance( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); + Domain vm = DomainTest.getDomain( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); assertEquals( "x86_64", vm.getOsArch() ); } @@ -215,7 +215,7 @@ public class DomainTest @DisplayName( "Set VM's OS architecture in libvirt XML file" ) public void testSetOsArch() { - Domain vm = this.newDomainInstance( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); + Domain vm = DomainTest.getDomain( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); vm.setOsArch( "aarch" ); assertEquals( "aarch", vm.getOsArch() ); } @@ -224,7 +224,7 @@ public class DomainTest @DisplayName( "Get VM's OS machine from libvirt XML file" ) public void testGetOsMachine() { - Domain vm = this.newDomainInstance( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); + Domain vm = DomainTest.getDomain( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); assertEquals( "pc-q35-5.1", vm.getOsMachine() ); } @@ -232,7 +232,7 @@ public class DomainTest @DisplayName( "Set VM's OS machine in libvirt XML file" ) public void testSetOsMachine() { - Domain vm = this.newDomainInstance( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); + Domain vm = DomainTest.getDomain( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); vm.setOsMachine( "pc" ); assertEquals( "pc", vm.getOsMachine() ); } @@ -241,7 +241,7 @@ public class DomainTest @DisplayName( "Get VM's OS loader from libvirt XML file" ) public void testGetOsLoader() { - Domain vm = this.newDomainInstance( "qemu-kvm_default-ubuntu-20-04-vm_uefi.xml" ); + Domain vm = DomainTest.getDomain( "qemu-kvm_default-ubuntu-20-04-vm_uefi.xml" ); assertEquals( "/usr/share/edk2-ovmf/x64/OVMF_CODE.fd", vm.getOsLoader() ); } @@ -249,7 +249,7 @@ public class DomainTest @DisplayName( "Set VM's OS loader in libvirt XML file" ) public void testSetOsLoader() { - Domain vm = this.newDomainInstance( "qemu-kvm_default-ubuntu-20-04-vm_uefi.xml" ); + Domain vm = DomainTest.getDomain( "qemu-kvm_default-ubuntu-20-04-vm_uefi.xml" ); vm.setOsLoader( "/usr/share/qemu/edk2-x86_64-code.fd" ); assertEquals( "/usr/share/qemu/edk2-x86_64-code.fd", vm.getOsLoader() ); } @@ -258,7 +258,7 @@ public class DomainTest @DisplayName( "Get VM's OS Nvram from libvirt XML file" ) public void testGetOsNvram() { - Domain vm = this.newDomainInstance( "qemu-kvm_default-ubuntu-20-04-vm_uefi.xml" ); + Domain vm = DomainTest.getDomain( "qemu-kvm_default-ubuntu-20-04-vm_uefi.xml" ); assertEquals( "/var/lib/libvirt/nvram/guest_VARS.fd", vm.getOsNvram() ); } @@ -266,7 +266,7 @@ public class DomainTest @DisplayName( "Set VM's OS Nvram in libvirt XML file" ) public void testSetOsNvram() { - Domain vm = this.newDomainInstance( "qemu-kvm_default-ubuntu-20-04-vm_uefi.xml" ); + Domain vm = DomainTest.getDomain( "qemu-kvm_default-ubuntu-20-04-vm_uefi.xml" ); vm.setOsNvram( "/tmp/nvram-tmp/tmp_VARS.fd" ); assertEquals( "/tmp/nvram-tmp/tmp_VARS.fd", vm.getOsNvram() ); } @@ -275,7 +275,7 @@ public class DomainTest @DisplayName( "Get VM CPU model from libvirt XML file" ) public void testGetCpuModel() { - Domain vm = this.newDomainInstance( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); + Domain vm = DomainTest.getDomain( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); assertNull( vm.getCpuModel() ); } @@ -283,7 +283,7 @@ public class DomainTest @DisplayName( "Set VM CPU model in libvirt XML file" ) public void testSetCpuModel() { - Domain vm = this.newDomainInstance( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); + Domain vm = DomainTest.getDomain( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); vm.setCpuModel( "core2duo" ); assertEquals( "core2duo", vm.getCpuModel() ); } @@ -292,7 +292,7 @@ public class DomainTest @DisplayName( "Get VM CPU mode from libvirt XML file" ) public void testGetCpuModelMode() { - Domain vm = this.newDomainInstance( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); + Domain vm = DomainTest.getDomain( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); assertEquals( CpuMode.HOST_MODEL.toString(), vm.getCpuMode().toString() ); } @@ -300,7 +300,7 @@ public class DomainTest @DisplayName( "Set VM CPU mode in libvirt XML file" ) public void testSetCpuModelMode() { - Domain vm = this.newDomainInstance( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); + Domain vm = DomainTest.getDomain( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); vm.setCpuMode( CpuMode.HOST_PASSTHROUGH ); assertEquals( CpuMode.HOST_PASSTHROUGH.toString(), vm.getCpuMode().toString() ); } @@ -309,7 +309,7 @@ public class DomainTest @DisplayName( "Get VM CPU check from libvirt XML file" ) public void testGetCpuCheck() { - Domain vm = this.newDomainInstance( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); + Domain vm = DomainTest.getDomain( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); assertEquals( CpuCheck.PARTIAL.toString(), vm.getCpuCheck().toString() ); } @@ -317,7 +317,7 @@ public class DomainTest @DisplayName( "Set VM CPU check in libvirt XML file" ) public void testSetCpuCheck() { - Domain vm = this.newDomainInstance( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); + Domain vm = DomainTest.getDomain( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); vm.setCpuCheck( CpuCheck.NONE ); assertEquals( CpuCheck.NONE.toString(), vm.getCpuCheck().toString() ); } @@ -326,7 +326,7 @@ public class DomainTest @DisplayName( "Get VM CPU dies from libvirt XML file" ) public void testGetCpuDies() { - Domain vm = this.newDomainInstance( "qemu-kvm_default-ubuntu-20-04-vm_cpu-topology.xml" ); + Domain vm = DomainTest.getDomain( "qemu-kvm_default-ubuntu-20-04-vm_cpu-topology.xml" ); assertEquals( 2, vm.getCpuDies() ); } @@ -334,7 +334,7 @@ public class DomainTest @DisplayName( "Set VM CPU dies in libvirt XML file" ) public void testSetCpuDies() { - Domain vm = this.newDomainInstance( "qemu-kvm_default-ubuntu-20-04-vm_cpu-topology.xml" ); + Domain vm = DomainTest.getDomain( "qemu-kvm_default-ubuntu-20-04-vm_cpu-topology.xml" ); vm.setCpuDies( 3 ); assertEquals( 3, vm.getCpuDies() ); } @@ -343,7 +343,7 @@ public class DomainTest @DisplayName( "Get VM CPU sockets from libvirt XML file" ) public void testGetCpuSockets() { - Domain vm = this.newDomainInstance( "qemu-kvm_default-ubuntu-20-04-vm_cpu-topology.xml" ); + Domain vm = DomainTest.getDomain( "qemu-kvm_default-ubuntu-20-04-vm_cpu-topology.xml" ); assertEquals( 3, vm.getCpuSockets() ); } @@ -351,7 +351,7 @@ public class DomainTest @DisplayName( "Set VM CPU sockets in libvirt XML file" ) public void testSetCpuSockets() { - Domain vm = this.newDomainInstance( "qemu-kvm_default-ubuntu-20-04-vm_cpu-topology.xml" ); + Domain vm = DomainTest.getDomain( "qemu-kvm_default-ubuntu-20-04-vm_cpu-topology.xml" ); vm.setCpuSockets( 2 ); assertEquals( 2, vm.getCpuSockets() ); } @@ -360,7 +360,7 @@ public class DomainTest @DisplayName( "Get VM CPU cores from libvirt XML file" ) public void testGetCpuCores() { - Domain vm = this.newDomainInstance( "qemu-kvm_default-ubuntu-20-04-vm_cpu-topology.xml" ); + Domain vm = DomainTest.getDomain( "qemu-kvm_default-ubuntu-20-04-vm_cpu-topology.xml" ); assertEquals( 4, vm.getCpuCores() ); } @@ -368,7 +368,7 @@ public class DomainTest @DisplayName( "Set VM CPU cores in libvirt XML file" ) public void testSetCpuCores() { - Domain vm = this.newDomainInstance( "qemu-kvm_default-ubuntu-20-04-vm_cpu-topology.xml" ); + Domain vm = DomainTest.getDomain( "qemu-kvm_default-ubuntu-20-04-vm_cpu-topology.xml" ); vm.setCpuCores( 8 ); assertEquals( 8, vm.getCpuCores() ); } @@ -377,7 +377,7 @@ public class DomainTest @DisplayName( "Get VM CPU threads from libvirt XML file" ) public void testGetCpuThreads() { - Domain vm = this.newDomainInstance( "qemu-kvm_default-ubuntu-20-04-vm_cpu-topology.xml" ); + Domain vm = DomainTest.getDomain( "qemu-kvm_default-ubuntu-20-04-vm_cpu-topology.xml" ); assertEquals( 1, vm.getCpuThreads() ); } @@ -385,7 +385,7 @@ public class DomainTest @DisplayName( "Set VM CPU threads in libvirt XML file" ) public void testSetCpuThreads() { - Domain vm = this.newDomainInstance( "qemu-kvm_default-ubuntu-20-04-vm_cpu-topology.xml" ); + Domain vm = DomainTest.getDomain( "qemu-kvm_default-ubuntu-20-04-vm_cpu-topology.xml" ); vm.setCpuThreads( 2 ); assertEquals( 2, vm.getCpuThreads() ); } @@ -394,7 +394,7 @@ public class DomainTest @DisplayName( "Get VM emulator binary from libvirt XML file" ) public void testGetDevicesEmulator() { - Domain vm = this.newDomainInstance( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); + Domain vm = DomainTest.getDomain( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); assertEquals( "/usr/bin/qemu-system-x86_64", vm.getDevicesEmulator() ); } @@ -402,7 +402,7 @@ public class DomainTest @DisplayName( "Set VM emulator binary in libvirt XML file" ) public void testSetDevicesEmulator() { - Domain vm = this.newDomainInstance( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); + Domain vm = DomainTest.getDomain( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); vm.setDevicesEmulator( "/usr/bin/qemu-system-i386" ); assertEquals( "/usr/bin/qemu-system-i386", vm.getDevicesEmulator() ); } @@ -411,7 +411,7 @@ public class DomainTest @DisplayName( "Get all VM devices from libvirt XML file" ) public void testGetDevices() { - Domain vm = this.newDomainInstance( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); + Domain vm = DomainTest.getDomain( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); assertEquals( 22, vm.getDevices().size() ); } @@ -419,7 +419,7 @@ public class DomainTest @DisplayName( "Get all VM controller devices from libvirt XML file" ) public void testGetControllerDevices() { - Domain vm = this.newDomainInstance( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); + Domain vm = DomainTest.getDomain( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); assertEquals( 14, vm.getControllerDevices().size() ); } @@ -427,7 +427,7 @@ public class DomainTest @DisplayName( "Get all VM disk devices from libvirt XML file" ) public void testGetDiskDevices() { - Domain vm = this.newDomainInstance( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); + Domain vm = DomainTest.getDomain( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); assertEquals( 3, vm.getDiskDevices().size() ); } @@ -435,7 +435,7 @@ public class DomainTest @DisplayName( "Get all VM file system devices from libvirt XML file" ) public void testGetFileSystemDevices() { - Domain vm = this.newDomainInstance( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); + Domain vm = DomainTest.getDomain( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); assertEquals( 0, vm.getFileSystemDevices().size() ); } @@ -443,7 +443,7 @@ public class DomainTest @DisplayName( "Get all VM hostdev devices from libvirt XML file" ) public void testGetHostdevDevices() { - Domain vm = this.newDomainInstance( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); + Domain vm = DomainTest.getDomain( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); assertEquals( 0, vm.getHostdevDevices().size() ); } @@ -451,7 +451,7 @@ public class DomainTest @DisplayName( "Get all VM interface devices from libvirt XML file" ) public void testGetInterfaceDevices() { - Domain vm = this.newDomainInstance( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); + Domain vm = DomainTest.getDomain( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); assertEquals( 1, vm.getInterfaceDevices().size() ); } @@ -459,7 +459,7 @@ public class DomainTest @DisplayName( "Get all VM graphic devices from libvirt XML file" ) public void testGetGraphicDevices() { - Domain vm = this.newDomainInstance( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); + Domain vm = DomainTest.getDomain( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); assertEquals( 1, vm.getGraphicDevices().size() ); } @@ -467,7 +467,7 @@ public class DomainTest @DisplayName( "Get all VM parallel port devices from libvirt XML file" ) public void testGetParallelDevices() { - Domain vm = this.newDomainInstance( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); + Domain vm = DomainTest.getDomain( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); assertEquals( 0, vm.getParallelDevices().size() ); } @@ -475,7 +475,7 @@ public class DomainTest @DisplayName( "Get all VM serial port devices from libvirt XML file" ) public void testGetSerialDevices() { - Domain vm = this.newDomainInstance( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); + Domain vm = DomainTest.getDomain( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); assertEquals( 1, vm.getSerialDevices().size() ); } @@ -483,7 +483,7 @@ public class DomainTest @DisplayName( "Get all VM sound devices from libvirt XML file" ) public void testGetSoundDevices() { - Domain vm = this.newDomainInstance( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); + Domain vm = DomainTest.getDomain( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); assertEquals( 1, vm.getSoundDevices().size() ); } @@ -491,7 +491,7 @@ public class DomainTest @DisplayName( "Get all VM video devices from libvirt XML file" ) public void testGetVideoDevices() { - Domain vm = this.newDomainInstance( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); + Domain vm = DomainTest.getDomain( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); assertEquals( 1, vm.getVideoDevices().size() ); } @@ -499,7 +499,7 @@ public class DomainTest @DisplayName( "Get all QEMU command line arguments from libvirt XML file" ) public void testGetQemuCmdlnArguments() { - Domain vm = this.newDomainInstance( "qemu-kvm_default-ubuntu-20-04-vm_qemu-cmdln.xml" ); + Domain vm = DomainTest.getDomain( "qemu-kvm_default-ubuntu-20-04-vm_qemu-cmdln.xml" ); assertEquals( 2, vm.getQemuCmdlnArguments().size() ); } @@ -507,7 +507,7 @@ public class DomainTest @DisplayName( "Set QEMU command line arguments in libvirt XML file" ) public void testAddQemuCmdlnArguments() { - Domain vm = this.newDomainInstance( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); + Domain vm = DomainTest.getDomain( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); assertEquals( 0, vm.getQemuCmdlnArguments().size() ); vm.addQemuCmdlnArgument( "-set" ); diff --git a/src/test/resources/qemu/firmware/50-edk2-i386-secure.json b/src/test/resources/qemu/firmware/50-edk2-i386-secure.json new file mode 100644 index 0000000..9838f16 --- /dev/null +++ b/src/test/resources/qemu/firmware/50-edk2-i386-secure.json @@ -0,0 +1,34 @@ +{ + "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/src/test/resources/qemu/firmware/50-edk2-x86_64-secure.json b/src/test/resources/qemu/firmware/50-edk2-x86_64-secure.json new file mode 100644 index 0000000..12fa688 --- /dev/null +++ b/src/test/resources/qemu/firmware/50-edk2-x86_64-secure.json @@ -0,0 +1,35 @@ +{ + "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/src/test/resources/qemu/firmware/60-edk2-aarch64.json b/src/test/resources/qemu/firmware/60-edk2-aarch64.json new file mode 100644 index 0000000..52a65c7 --- /dev/null +++ b/src/test/resources/qemu/firmware/60-edk2-aarch64.json @@ -0,0 +1,31 @@ +{ + "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/src/test/resources/qemu/firmware/60-edk2-arm.json b/src/test/resources/qemu/firmware/60-edk2-arm.json new file mode 100644 index 0000000..8dc6e0f --- /dev/null +++ b/src/test/resources/qemu/firmware/60-edk2-arm.json @@ -0,0 +1,31 @@ +{ + "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/src/test/resources/qemu/firmware/60-edk2-i386.json b/src/test/resources/qemu/firmware/60-edk2-i386.json new file mode 100644 index 0000000..f0929ed --- /dev/null +++ b/src/test/resources/qemu/firmware/60-edk2-i386.json @@ -0,0 +1,33 @@ +{ + "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/src/test/resources/qemu/firmware/60-edk2-x86_64.json b/src/test/resources/qemu/firmware/60-edk2-x86_64.json new file mode 100644 index 0000000..d0b6542 --- /dev/null +++ b/src/test/resources/qemu/firmware/60-edk2-x86_64.json @@ -0,0 +1,34 @@ +{ + "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": [ + + ] +} |