summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManuel Bentele2021-05-17 14:49:24 +0200
committerManuel Bentele2021-05-17 14:49:24 +0200
commit96768a5133953ea3fa57ab4f7eac145e98637739 (patch)
tree5c449b178924ba8953bb16bce9f18c0fe32baaad
parent[qemu] Keep track of defined VMs to automatically close them before program exit (diff)
downloadmltk-96768a5133953ea3fa57ab4f7eac145e98637739.tar.gz
mltk-96768a5133953ea3fa57ab4f7eac145e98637739.tar.xz
mltk-96768a5133953ea3fa57ab4f7eac145e98637739.zip
[qemu] Show virt-manager in debug mode to inspect Libvirt VM
-rw-r--r--core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemu/run-virt.include1
-rw-r--r--core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/App.java14
-rw-r--r--core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/cmdln/CommandLineArgs.java12
-rw-r--r--core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/AppTest.java8
-rw-r--r--core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/cmdln/CommandLineArgsTest.java67
5 files changed, 96 insertions, 6 deletions
diff --git a/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemu/run-virt.include b/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemu/run-virt.include
index 90a00c6e..b7e43df9 100644
--- a/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemu/run-virt.include
+++ b/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemu/run-virt.include
@@ -29,6 +29,7 @@ run_plugin() {
# call the Libvirt Java tool to finalize configuration and start VM
declare -rg VIRTCMD="java -jar /opt/openslx/share/java/runvirt-plugin-qemu.jar"
+ isset DEBUG && VIRTCMDOPTS+=( "-debug" "${DEBUG}" )
isset VM_CLEANNAME && VIRTCMDOPTS+=( "-vmname" "${VM_CLEANNAME}" )
isset VM_DISPLAYNAME && VIRTCMDOPTS+=( "-vmdsplname" "${VM_DISPLAYNAME}" )
isset VM_OS_TYPE && VIRTCMDOPTS+=( "-vmos" "${VM_OS_TYPE}" )
diff --git a/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/App.java b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/App.java
index e5bc4780..a3e1c5b7 100644
--- a/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/App.java
+++ b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/App.java
@@ -29,6 +29,7 @@ import org.openslx.runvirt.plugin.qemu.virtualization.LibvirtHypervisorQemu;
import org.openslx.runvirt.plugin.qemu.virtualization.LibvirtHypervisorQemu.QemuSessionType;
import org.openslx.runvirt.viewer.Viewer;
import org.openslx.runvirt.viewer.ViewerException;
+import org.openslx.runvirt.viewer.ViewerVirtManager;
import org.openslx.runvirt.viewer.ViewerVirtViewer;
import org.openslx.runvirt.virtualization.LibvirtHypervisor;
import org.openslx.runvirt.virtualization.LibvirtHypervisorException;
@@ -182,8 +183,17 @@ public class App
System.exit( 7 );
}
- // display Libvirt VM with a specific viewer on the screen
- final Viewer vmViewer = new ViewerVirtViewer( vm, hypervisor );
+ // create specific viewer to display Libvirt VM
+ final Viewer vmViewer;
+ if ( cmdLn.isDebugEnabled() ) {
+ // create specific Virtual Machine Manager viewer if debug mode is enabled
+ vmViewer = new ViewerVirtManager( vm, hypervisor );
+ } else {
+ // create Virtual Viewer if debug mode is disabled
+ vmViewer = new ViewerVirtViewer( vm, hypervisor );
+ }
+
+ // display Libvirt VM with the specific viewer on the screen
try {
vmViewer.display();
} catch ( ViewerException e ) {
diff --git a/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/cmdln/CommandLineArgs.java b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/cmdln/CommandLineArgs.java
index 03df8923..eb7c8739 100644
--- a/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/cmdln/CommandLineArgs.java
+++ b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/cmdln/CommandLineArgs.java
@@ -128,6 +128,17 @@ public class CommandLineArgs
}
/**
+ * Returns the state of the command line option {@link CmdLnOption#DEBUG}.
+ *
+ * @return state of the command line option {@link CmdLnOption#DEBUG}.
+ */
+ public boolean isDebugEnabled()
+ {
+ final String debugArg = this.getArgument( CmdLnOption.DEBUG );
+ return ( "true".equals( debugArg ) ) ? true : false;
+ }
+
+ /**
* Returns the argument of the command line option {@link CmdLnOption#VM_CFGINP}.
*
* @return argument of the command line option {@link CmdLnOption#VM_CFGINP}.
@@ -344,6 +355,7 @@ public class CommandLineArgs
{
// @formatter:off
HELP ( 'h', "help", false, "" ),
+ DEBUG ( 'b', "debug", true, "Enable or disable debug mode" ),
VM_CFGINP ( 'i', "vmcfginp", true, "File name of an existing and filtered Libvirt domain XML configuration file" ),
VM_CFGOUT ( 'o', "vmcfgout", true, "File name to output a finalized Libvirt domain XML configuration file" ),
VM_NAME ( 'n', "vmname", true, "Name for the virtual machine" ),
diff --git a/core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/AppTest.java b/core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/AppTest.java
index 9f8f925f..a7929ab0 100644
--- a/core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/AppTest.java
+++ b/core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/AppTest.java
@@ -63,7 +63,7 @@ public class AppTest
assertTrue( shortHelpOptionCorrectOutput.contains( App.APP_DESC ) );
// test that no error was logged and output is available
- assertEquals( 2026, shortHelpOptionCorrectOutput.length() );
+ assertEquals( 2093, shortHelpOptionCorrectOutput.length() );
assertEquals( 0, shortHelpOptionCorrectErrOutput.length() );
}
@@ -91,7 +91,7 @@ public class AppTest
assertTrue( longHelpOptionCorrectOutput.contains( App.APP_DESC ) );
// test that no error was logged and output is available
- assertEquals( 2026, longHelpOptionCorrectOutput.length() );
+ assertEquals( 2093, longHelpOptionCorrectOutput.length() );
assertEquals( 0, longHelpOptionCorrectErrOutput.length() );
}
@@ -119,7 +119,7 @@ public class AppTest
assertTrue( shortHelpOptionIncorrectOutput.contains( App.APP_DESC ) );
// test that error was logged and output is available
- assertEquals( 2026, shortHelpOptionIncorrectOutput.length() );
+ assertEquals( 2093, shortHelpOptionIncorrectOutput.length() );
assertEquals( 0, shortHelpOptionIncorrectErrOutput.length() );
}
@@ -147,7 +147,7 @@ public class AppTest
assertTrue( longHelpOptionIncorrectOutput.contains( App.APP_DESC ) );
// test that error was logged and output is available
- assertEquals( 2026, longHelpOptionIncorrectOutput.length() );
+ assertEquals( 2093, longHelpOptionIncorrectOutput.length() );
assertEquals( 0, longHelpOptionIncorrectErrOutput.length() );
}
diff --git a/core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/cmdln/CommandLineArgsTest.java b/core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/cmdln/CommandLineArgsTest.java
index ee3e0d1d..972f5e4b 100644
--- a/core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/cmdln/CommandLineArgsTest.java
+++ b/core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/cmdln/CommandLineArgsTest.java
@@ -1,6 +1,7 @@
package org.openslx.runvirt.plugin.qemu.cmdln;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -16,6 +17,8 @@ public class CommandLineArgsTest
public static final String CMDLN_PREFIX_OPTION_SHORT = "-";
public static final String CMDLN_PREFIX_OPTION_LONG = "--";
+ private static final String CMDLN_TEST_DEBUG_OFF = "false";
+ private static final String CMDLN_TEST_DEBUG_ON = "true";
private static final String CMDLN_TEST_NAME = "test";
private static final String CMDLN_TEST_FILENAME = System.getProperty( "user.dir" ) + File.separator + CMDLN_TEST_NAME;
private static final String CMDLN_TEST_UUID = "c9570672-cbae-4cbd-801a-881b281b8d79";
@@ -70,6 +73,70 @@ public class CommandLineArgsTest
}
@Test
+ @DisplayName( "Test the parsing of the enabled debug command line option (short version)" )
+ public void testCmdlnOptionDebugEnabledShort() throws CommandLineArgsException
+ {
+ final String[] args = {
+ CMDLN_PREFIX_OPTION_SHORT + CmdLnOption.DEBUG.getShortOption(),
+ CMDLN_TEST_DEBUG_ON
+ };
+
+ CommandLineArgs cmdLn = new CommandLineArgs( args );
+
+ assertTrue( cmdLn.isDebugEnabled() );
+ }
+
+ @Test
+ @DisplayName( "Test the parsing of the enabled debug command line option (long version)" )
+ public void testCmdlnOptionDebugEnabledLong() throws CommandLineArgsException
+ {
+ final String[] args = {
+ CMDLN_PREFIX_OPTION_LONG + CmdLnOption.DEBUG.getLongOption(),
+ CMDLN_TEST_DEBUG_ON
+ };
+
+ CommandLineArgs cmdLn = new CommandLineArgs( args );
+
+ assertTrue( cmdLn.isDebugEnabled() );
+ }
+
+ @Test
+ @DisplayName( "Test the parsing of the disabled debug command line option (short version)" )
+ public void testCmdlnOptionDebugDisabledShort() throws CommandLineArgsException
+ {
+ final String[] argsDebugOff = {
+ CMDLN_PREFIX_OPTION_SHORT + CmdLnOption.DEBUG.getShortOption(),
+ CMDLN_TEST_DEBUG_OFF
+ };
+
+ final String[] argsDebugMissing = {};
+
+ CommandLineArgs cmdLnDebugOff = new CommandLineArgs( argsDebugOff );
+ CommandLineArgs cmdLnDebugMissing = new CommandLineArgs( argsDebugMissing );
+
+ assertFalse( cmdLnDebugOff.isDebugEnabled() );
+ assertFalse( cmdLnDebugMissing.isDebugEnabled() );
+ }
+
+ @Test
+ @DisplayName( "Test the parsing of the disabled debug command line option (long version)" )
+ public void testCmdlnOptionDebugDisabledLong() throws CommandLineArgsException
+ {
+ final String[] argsDebugOff = {
+ CMDLN_PREFIX_OPTION_LONG + CmdLnOption.DEBUG.getLongOption(),
+ CMDLN_TEST_DEBUG_OFF
+ };
+
+ final String[] argsDebugMissing = {};
+
+ CommandLineArgs cmdLnDebugOff = new CommandLineArgs( argsDebugOff );
+ CommandLineArgs cmdLnDebugMissing = new CommandLineArgs( argsDebugMissing );
+
+ assertFalse( cmdLnDebugOff.isDebugEnabled() );
+ assertFalse( cmdLnDebugMissing.isDebugEnabled() );
+ }
+
+ @Test
@DisplayName( "Test the parsing of the VM configuration input command line option (short version)" )
public void testCmdlnOptionVmCfgInpShort() throws CommandLineArgsException
{