From 96768a5133953ea3fa57ab4f7eac145e98637739 Mon Sep 17 00:00:00 2001 From: Manuel Bentele Date: Mon, 17 May 2021 14:49:24 +0200 Subject: [qemu] Show virt-manager in debug mode to inspect Libvirt VM --- .../vmchooser/plugins/qemu/run-virt.include | 1 + .../java/org/openslx/runvirt/plugin/qemu/App.java | 14 ++++- .../runvirt/plugin/qemu/cmdln/CommandLineArgs.java | 12 ++++ .../org/openslx/runvirt/plugin/qemu/AppTest.java | 8 +-- .../plugin/qemu/cmdln/CommandLineArgsTest.java | 67 ++++++++++++++++++++++ 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 @@ -127,6 +127,17 @@ public class CommandLineArgs return this.cmdLn.hasOption( CmdLnOption.HELP.getShortOption() ); } + /** + * 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}. * @@ -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"; @@ -69,6 +72,70 @@ public class CommandLineArgsTest assertTrue( cmdLn.isHelpAquired() ); } + @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 -- cgit v1.2.3-55-g7522