summaryrefslogtreecommitdiffstats
path: root/core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/configuration/TransformationTestUtils.java
blob: 248df102d6c84d9403baa657531c086b026edb43 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package org.openslx.runvirt.plugin.qemu.configuration;

import static org.junit.jupiter.api.Assertions.fail;

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.runvirt.plugin.qemu.cmdln.CommandLineArgs;
import org.openslx.runvirt.plugin.qemu.cmdln.CommandLineArgs.CmdLnOption;
import org.openslx.runvirt.plugin.qemu.cmdln.CommandLineArgsException;
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_VM_NAME      = "archlinux";
	public static final String DEFAULT_VM_UUID      = "4ec504d5-5eac-482f-a344-dbf1dd4956c8";
	public static final String DEFAULT_VM_DSPLNAME  = "Archlinux";
	public static final String DEFAULT_VM_OS        = "Windows 10 (x64)";
	public static final String DEFAULT_VM_NCPUS     = "16";
	public static final String DEFAULT_VM_MEM       = "1024";
	public static final String DEFAULT_VM_HDD0      = "/mnt/vm/windows.qcow2";
	public static final String DEFAULT_VM_FLOPPY0   = "/mnt/vm/floppy0.qcow2";
	public static final String DEFAULT_VM_FLOPPY1   = "/mnt/vm/floppy1.qcow2";
	public static final String DEFAULT_VM_CDROM0    = "/dev/sr0";
	public static final String DEFAULT_VM_CDROM1    = "/mnt/image.iso";
	public static final String DEFAULT_VM_PARALLEL0 = "/dev/parport0";
	public static final String DEFAULT_VM_SERIAL0   = "/dev/ttyS0";
	public static final String DEFAULT_VM_MAC0      = "ca:06:29:84:f0:6d";
	public static final String DEFAULT_VM_FSSRC0    = "/mnt/shared/folder0";
	public static final String DEFAULT_VM_FSTGT0    = "folder0";
	public static final String DEFAULT_VM_FSSRC1    = "/mnt/shared/folder1";
	public static final String DEFAULT_VM_FSTGT1    = "folder1";
	public static final String DEFAULT_VM_GPU0_DESC = "10de:1d01";
	public static final String DEFAULT_VM_GPU0_ADDR = "0000:00:02.0";
	public static final String DEFAULT_VM_NVGPUIDS0 = DEFAULT_VM_GPU0_DESC + "," + DEFAULT_VM_GPU0_ADDR;
	public static final String DEFAULT_VM_ILMDEVID0 = "4186049f-d192-4c69-8d4f-b0f277ef095f";
	// @formatter:on

	private static final String[] DEFAULT_CMDLN_ARGS = {
			CommandLineArgsTest.CMDLN_PREFIX_OPTION_LONG + CmdLnOption.FIRMWARE.getLongOption(),
			TransformationTestUtils.DEFAULT_FW_PATH,
			CommandLineArgsTest.CMDLN_PREFIX_OPTION_LONG + CmdLnOption.VM_NAME.getLongOption(),
			TransformationTestUtils.DEFAULT_VM_NAME,
			CommandLineArgsTest.CMDLN_PREFIX_OPTION_LONG + CmdLnOption.VM_UUID.getLongOption(),
			TransformationTestUtils.DEFAULT_VM_UUID,
			CommandLineArgsTest.CMDLN_PREFIX_OPTION_LONG + CmdLnOption.VM_DSPLNAME.getLongOption(),
			TransformationTestUtils.DEFAULT_VM_DSPLNAME,
			CommandLineArgsTest.CMDLN_PREFIX_OPTION_LONG + CmdLnOption.VM_OS.getLongOption(),
			TransformationTestUtils.DEFAULT_VM_OS,
			CommandLineArgsTest.CMDLN_PREFIX_OPTION_LONG + CmdLnOption.VM_NCPUS.getLongOption(),
			TransformationTestUtils.DEFAULT_VM_NCPUS,
			CommandLineArgsTest.CMDLN_PREFIX_OPTION_LONG + CmdLnOption.VM_MEM.getLongOption(),
			TransformationTestUtils.DEFAULT_VM_MEM,
			CommandLineArgsTest.CMDLN_PREFIX_OPTION_LONG + CmdLnOption.VM_HDD0.getLongOption(),
			TransformationTestUtils.DEFAULT_VM_HDD0,
			CommandLineArgsTest.CMDLN_PREFIX_OPTION_LONG + CmdLnOption.VM_FLOPPY0.getLongOption(),
			TransformationTestUtils.DEFAULT_VM_FLOPPY0,
			CommandLineArgsTest.CMDLN_PREFIX_OPTION_LONG + CmdLnOption.VM_FLOPPY1.getLongOption(),
			TransformationTestUtils.DEFAULT_VM_FLOPPY1,
			CommandLineArgsTest.CMDLN_PREFIX_OPTION_LONG + CmdLnOption.VM_CDROM0.getLongOption(),
			TransformationTestUtils.DEFAULT_VM_CDROM0,
			CommandLineArgsTest.CMDLN_PREFIX_OPTION_LONG + CmdLnOption.VM_CDROM1.getLongOption(),
			TransformationTestUtils.DEFAULT_VM_CDROM1,
			CommandLineArgsTest.CMDLN_PREFIX_OPTION_LONG + CmdLnOption.VM_PARALLEL0.getLongOption(),
			TransformationTestUtils.DEFAULT_VM_PARALLEL0,
			CommandLineArgsTest.CMDLN_PREFIX_OPTION_LONG + CmdLnOption.VM_SERIAL0.getLongOption(),
			TransformationTestUtils.DEFAULT_VM_SERIAL0,
			CommandLineArgsTest.CMDLN_PREFIX_OPTION_LONG + CmdLnOption.VM_MAC0.getLongOption(),
			TransformationTestUtils.DEFAULT_VM_MAC0,
			CommandLineArgsTest.CMDLN_PREFIX_OPTION_LONG + CmdLnOption.VM_FSSRC0.getLongOption(),
			TransformationTestUtils.DEFAULT_VM_FSSRC0,
			CommandLineArgsTest.CMDLN_PREFIX_OPTION_LONG + CmdLnOption.VM_FSTGT0.getLongOption(),
			TransformationTestUtils.DEFAULT_VM_FSTGT0,
			CommandLineArgsTest.CMDLN_PREFIX_OPTION_LONG + CmdLnOption.VM_FSSRC1.getLongOption(),
			TransformationTestUtils.DEFAULT_VM_FSSRC1,
			CommandLineArgsTest.CMDLN_PREFIX_OPTION_LONG + CmdLnOption.VM_FSTGT1.getLongOption(),
			TransformationTestUtils.DEFAULT_VM_FSTGT1,
			CommandLineArgsTest.CMDLN_PREFIX_OPTION_LONG + CmdLnOption.VM_NVGPUIDS0.getLongOption(),
			TransformationTestUtils.DEFAULT_VM_NVGPUIDS0,
			CommandLineArgsTest.CMDLN_PREFIX_OPTION_LONG + CmdLnOption.VM_ILMDEVID0.getLongOption(),
			TransformationTestUtils.DEFAULT_VM_ILMDEVID0
	};

	private static CommandLineArgs getCmdLnArgs( String[] args )
	{
		final CommandLineArgs cmdLnArgs = new CommandLineArgs();

		try {
			cmdLnArgs.parseCmdLnArgs( args );
		} catch ( CommandLineArgsException e ) {
			fail( e.getLocalizedMessage() );
		}

		return cmdLnArgs;
	}

	public static CommandLineArgs getDefaultCmdLnArgs()
	{
		return TransformationTestUtils.getCmdLnArgs( TransformationTestUtils.DEFAULT_CMDLN_ARGS );
	}

	public static CommandLineArgs getEmptyCmdLnArgs()
	{
		return TransformationTestUtils.getCmdLnArgs( new String[] {} );
	}

	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;
	}

	public static Domain getDefaultDomain()
	{
		return TransformationTestUtils.getDomain( "qemu-kvm_default-ubuntu-20-04-vm_transform-non-persistent.xml" );
	}
}