From 0cdb4b610865fa5493cc79e9c9ef310bdf09ccaf Mon Sep 17 00:00:00 2001 From: wilderrodrigues Date: Mon, 18 May 2015 14:30:36 +0200 Subject: [PATCH] Fixing the testGetHostStatsCommand test under LibvirtComputingResourceTest. - Removed the expected value from the Test annotation - Mocking the bash path in order to avoid environment/OS issues Fixing typo on LibvirtRequestWrapper - Replace linbvirtCommands by libvirtCommands on LibvirtRequestWrapper Signed-off-by: Rohit Yadav This closes #255 --- .../resource/LibvirtComputingResource.java | 2 + .../LibvirtGetHostStatsCommandWrapper.java | 10 +- .../wrapper/LibvirtRequestWrapper.java | 116 +++++++++--------- .../wrapper/LibvirtUtilitiesHelper.java | 4 + .../LibvirtComputingResourceTest.java | 11 +- 5 files changed, 81 insertions(+), 62 deletions(-) diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java index a04074bee94..995a8cfd2ec 100644 --- a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java +++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java @@ -194,6 +194,8 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv public static final String SSHPRVKEYPATH = SSHKEYSPATH + File.separator + "id_rsa.cloud"; public static final String SSHPUBKEYPATH = SSHKEYSPATH + File.separator + "id_rsa.pub.cloud"; + public static final String BASH_SCRIPT_PATH = "/bin/bash"; + private String _mountPoint = "/mnt"; private StorageLayer _storage; private KVMStoragePoolManager _storagePoolMgr; diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtGetHostStatsCommandWrapper.java b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtGetHostStatsCommandWrapper.java index ba9ba188dad..45713cb3083 100644 --- a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtGetHostStatsCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtGetHostStatsCommandWrapper.java @@ -37,7 +37,11 @@ public final class LibvirtGetHostStatsCommandWrapper extends CommandWrapper, CommandWrapper> linbvirtCommands = new Hashtable, CommandWrapper>(); + final Hashtable, CommandWrapper> libvirtCommands = new Hashtable, CommandWrapper>(); - linbvirtCommands.put(StopCommand.class, new LibvirtStopCommandWrapper()); - linbvirtCommands.put(GetVmStatsCommand.class, new LibvirtGetVmStatsCommandWrapper()); - linbvirtCommands.put(GetVmDiskStatsCommand.class, new LibvirtGetVmDiskStatsCommandWrapper()); - linbvirtCommands.put(RebootRouterCommand.class, new LibvirtRebootRouterCommandWrapper()); - linbvirtCommands.put(RebootCommand.class, new LibvirtRebootCommandWrapper()); - linbvirtCommands.put(GetHostStatsCommand.class, new LibvirtGetHostStatsCommandWrapper()); - linbvirtCommands.put(CheckHealthCommand.class, new LibvirtCheckHealthCommandWrapper()); - linbvirtCommands.put(PrepareForMigrationCommand.class, new LibvirtPrepareForMigrationCommandWrapper()); - linbvirtCommands.put(MigrateCommand.class, new LibvirtMigrateCommandWrapper()); - linbvirtCommands.put(PingTestCommand.class, new LibvirtPingTestCommandWrapper()); - linbvirtCommands.put(CheckVirtualMachineCommand.class, new LibvirtCheckVirtualMachineCommandWrapper()); - linbvirtCommands.put(ReadyCommand.class, new LibvirtReadyCommandWrapper()); - linbvirtCommands.put(AttachIsoCommand.class, new LibvirtAttachIsoCommandWrapper()); - linbvirtCommands.put(AttachVolumeCommand.class, new LibvirtAttachVolumeCommandWrapper()); - linbvirtCommands.put(WatchConsoleProxyLoadCommand.class, new LibvirtWatchConsoleProxyLoadCommandWrapper()); - linbvirtCommands.put(CheckConsoleProxyLoadCommand.class, new LibvirtCheckConsoleProxyLoadCommandWrapper()); - linbvirtCommands.put(GetVncPortCommand.class, new LibvirtGetVncPortCommandWrapper()); - linbvirtCommands.put(ModifySshKeysCommand.class, new LibvirtModifySshKeysCommandWrapper()); - linbvirtCommands.put(MaintainCommand.class, new LibvirtMaintainCommandWrapper()); - linbvirtCommands.put(CreateCommand.class, new LibvirtCreateCommandWrapper()); - linbvirtCommands.put(DestroyCommand.class, new LibvirtDestroyCommandWrapper()); - linbvirtCommands.put(PrimaryStorageDownloadCommand.class, new LibvirtPrimaryStorageDownloadCommandWrapper()); - linbvirtCommands.put(GetStorageStatsCommand.class, new LibvirtGetStorageStatsCommandWrapper()); - linbvirtCommands.put(UpgradeSnapshotCommand.class, new LibvirtUpgradeSnapshotCommandWrapper()); - linbvirtCommands.put(DeleteStoragePoolCommand.class, new LibvirtDeleteStoragePoolCommandWrapper()); - linbvirtCommands.put(OvsSetupBridgeCommand.class, new LibvirtOvsSetupBridgeCommandWrapper()); - linbvirtCommands.put(OvsDestroyBridgeCommand.class, new LibvirtOvsDestroyBridgeCommandWrapper()); - linbvirtCommands.put(OvsFetchInterfaceCommand.class, new LibvirtOvsFetchInterfaceCommandWrapper()); - linbvirtCommands.put(OvsVpcPhysicalTopologyConfigCommand.class, new LibvirtOvsVpcPhysicalTopologyConfigCommandWrapper()); - linbvirtCommands.put(OvsVpcRoutingPolicyConfigCommand.class, new LibvirtOvsVpcRoutingPolicyConfigCommandWrapper()); - linbvirtCommands.put(CreateStoragePoolCommand.class, new LibvirtCreateStoragePoolCommandWrapper()); - linbvirtCommands.put(ModifyStoragePoolCommand.class, new LibvirtModifyStoragePoolCommandWrapper()); - linbvirtCommands.put(CleanupNetworkRulesCmd.class, new LibvirtCleanupNetworkRulesCommandWrapper()); - linbvirtCommands.put(NetworkRulesVmSecondaryIpCommand.class, new LibvirtNetworkRulesVmSecondaryIpCommandWrapper()); - linbvirtCommands.put(NetworkRulesSystemVmCommand.class, new LibvirtNetworkRulesSystemVmCommandWrapper()); - linbvirtCommands.put(CheckSshCommand.class, new LibvirtCheckSshCommandWrapper()); - linbvirtCommands.put(CheckNetworkCommand.class, new LibvirtCheckNetworkCommandWrapper()); - linbvirtCommands.put(OvsDestroyTunnelCommand.class, new LibvirtOvsDestroyTunnelCommandWrapper()); - linbvirtCommands.put(CheckOnHostCommand.class, new LibvirtCheckOnHostCommandWrapper()); - linbvirtCommands.put(OvsCreateTunnelCommand.class, new LibvirtOvsCreateTunnelCommandWrapper()); - linbvirtCommands.put(CreateVolumeFromSnapshotCommand.class, new LibvirtCreateVolumeFromSnapshotCommandWrapper()); - linbvirtCommands.put(FenceCommand.class, new LibvirtFenceCommandWrapper()); - linbvirtCommands.put(SecurityGroupRulesCmd.class, new LibvirtSecurityGroupRulesCommandWrapper()); - linbvirtCommands.put(PlugNicCommand.class, new LibvirtPlugNicCommandWrapper()); - linbvirtCommands.put(UnPlugNicCommand.class, new LibvirtUnPlugNicCommandWrapper()); - linbvirtCommands.put(NetworkUsageCommand.class, new LibvirtNetworkUsageCommandWrapper()); - linbvirtCommands.put(CreatePrivateTemplateFromVolumeCommand.class, new LibvirtCreatePrivateTemplateFromVolumeCommandWrapper()); - linbvirtCommands.put(ManageSnapshotCommand.class, new LibvirtManageSnapshotCommandWrapper()); - linbvirtCommands.put(BackupSnapshotCommand.class, new LibvirtBackupSnapshotCommandWrapper()); - linbvirtCommands.put(CreatePrivateTemplateFromSnapshotCommand.class, new LibvirtCreatePrivateTemplateFromSnapshotCommandWrapper()); - linbvirtCommands.put(CopyVolumeCommand.class, new LibvirtCopyVolumeCommandWrapper()); - linbvirtCommands.put(PvlanSetupCommand.class, new LibvirtPvlanSetupCommandWrapper()); - linbvirtCommands.put(ResizeVolumeCommand.class, new LibvirtResizeVolumeCommandWrapper()); - linbvirtCommands.put(NetworkElementCommand.class, new LibvirtNetworkElementCommandWrapper()); - linbvirtCommands.put(StorageSubSystemCommand.class, new LibvirtStorageSubSystemCommandWrapper()); - linbvirtCommands.put(StartCommand.class, new LibvirtStartCommandWrapper()); + libvirtCommands.put(StopCommand.class, new LibvirtStopCommandWrapper()); + libvirtCommands.put(GetVmStatsCommand.class, new LibvirtGetVmStatsCommandWrapper()); + libvirtCommands.put(GetVmDiskStatsCommand.class, new LibvirtGetVmDiskStatsCommandWrapper()); + libvirtCommands.put(RebootRouterCommand.class, new LibvirtRebootRouterCommandWrapper()); + libvirtCommands.put(RebootCommand.class, new LibvirtRebootCommandWrapper()); + libvirtCommands.put(GetHostStatsCommand.class, new LibvirtGetHostStatsCommandWrapper()); + libvirtCommands.put(CheckHealthCommand.class, new LibvirtCheckHealthCommandWrapper()); + libvirtCommands.put(PrepareForMigrationCommand.class, new LibvirtPrepareForMigrationCommandWrapper()); + libvirtCommands.put(MigrateCommand.class, new LibvirtMigrateCommandWrapper()); + libvirtCommands.put(PingTestCommand.class, new LibvirtPingTestCommandWrapper()); + libvirtCommands.put(CheckVirtualMachineCommand.class, new LibvirtCheckVirtualMachineCommandWrapper()); + libvirtCommands.put(ReadyCommand.class, new LibvirtReadyCommandWrapper()); + libvirtCommands.put(AttachIsoCommand.class, new LibvirtAttachIsoCommandWrapper()); + libvirtCommands.put(AttachVolumeCommand.class, new LibvirtAttachVolumeCommandWrapper()); + libvirtCommands.put(WatchConsoleProxyLoadCommand.class, new LibvirtWatchConsoleProxyLoadCommandWrapper()); + libvirtCommands.put(CheckConsoleProxyLoadCommand.class, new LibvirtCheckConsoleProxyLoadCommandWrapper()); + libvirtCommands.put(GetVncPortCommand.class, new LibvirtGetVncPortCommandWrapper()); + libvirtCommands.put(ModifySshKeysCommand.class, new LibvirtModifySshKeysCommandWrapper()); + libvirtCommands.put(MaintainCommand.class, new LibvirtMaintainCommandWrapper()); + libvirtCommands.put(CreateCommand.class, new LibvirtCreateCommandWrapper()); + libvirtCommands.put(DestroyCommand.class, new LibvirtDestroyCommandWrapper()); + libvirtCommands.put(PrimaryStorageDownloadCommand.class, new LibvirtPrimaryStorageDownloadCommandWrapper()); + libvirtCommands.put(GetStorageStatsCommand.class, new LibvirtGetStorageStatsCommandWrapper()); + libvirtCommands.put(UpgradeSnapshotCommand.class, new LibvirtUpgradeSnapshotCommandWrapper()); + libvirtCommands.put(DeleteStoragePoolCommand.class, new LibvirtDeleteStoragePoolCommandWrapper()); + libvirtCommands.put(OvsSetupBridgeCommand.class, new LibvirtOvsSetupBridgeCommandWrapper()); + libvirtCommands.put(OvsDestroyBridgeCommand.class, new LibvirtOvsDestroyBridgeCommandWrapper()); + libvirtCommands.put(OvsFetchInterfaceCommand.class, new LibvirtOvsFetchInterfaceCommandWrapper()); + libvirtCommands.put(OvsVpcPhysicalTopologyConfigCommand.class, new LibvirtOvsVpcPhysicalTopologyConfigCommandWrapper()); + libvirtCommands.put(OvsVpcRoutingPolicyConfigCommand.class, new LibvirtOvsVpcRoutingPolicyConfigCommandWrapper()); + libvirtCommands.put(CreateStoragePoolCommand.class, new LibvirtCreateStoragePoolCommandWrapper()); + libvirtCommands.put(ModifyStoragePoolCommand.class, new LibvirtModifyStoragePoolCommandWrapper()); + libvirtCommands.put(CleanupNetworkRulesCmd.class, new LibvirtCleanupNetworkRulesCommandWrapper()); + libvirtCommands.put(NetworkRulesVmSecondaryIpCommand.class, new LibvirtNetworkRulesVmSecondaryIpCommandWrapper()); + libvirtCommands.put(NetworkRulesSystemVmCommand.class, new LibvirtNetworkRulesSystemVmCommandWrapper()); + libvirtCommands.put(CheckSshCommand.class, new LibvirtCheckSshCommandWrapper()); + libvirtCommands.put(CheckNetworkCommand.class, new LibvirtCheckNetworkCommandWrapper()); + libvirtCommands.put(OvsDestroyTunnelCommand.class, new LibvirtOvsDestroyTunnelCommandWrapper()); + libvirtCommands.put(CheckOnHostCommand.class, new LibvirtCheckOnHostCommandWrapper()); + libvirtCommands.put(OvsCreateTunnelCommand.class, new LibvirtOvsCreateTunnelCommandWrapper()); + libvirtCommands.put(CreateVolumeFromSnapshotCommand.class, new LibvirtCreateVolumeFromSnapshotCommandWrapper()); + libvirtCommands.put(FenceCommand.class, new LibvirtFenceCommandWrapper()); + libvirtCommands.put(SecurityGroupRulesCmd.class, new LibvirtSecurityGroupRulesCommandWrapper()); + libvirtCommands.put(PlugNicCommand.class, new LibvirtPlugNicCommandWrapper()); + libvirtCommands.put(UnPlugNicCommand.class, new LibvirtUnPlugNicCommandWrapper()); + libvirtCommands.put(NetworkUsageCommand.class, new LibvirtNetworkUsageCommandWrapper()); + libvirtCommands.put(CreatePrivateTemplateFromVolumeCommand.class, new LibvirtCreatePrivateTemplateFromVolumeCommandWrapper()); + libvirtCommands.put(ManageSnapshotCommand.class, new LibvirtManageSnapshotCommandWrapper()); + libvirtCommands.put(BackupSnapshotCommand.class, new LibvirtBackupSnapshotCommandWrapper()); + libvirtCommands.put(CreatePrivateTemplateFromSnapshotCommand.class, new LibvirtCreatePrivateTemplateFromSnapshotCommandWrapper()); + libvirtCommands.put(CopyVolumeCommand.class, new LibvirtCopyVolumeCommandWrapper()); + libvirtCommands.put(PvlanSetupCommand.class, new LibvirtPvlanSetupCommandWrapper()); + libvirtCommands.put(ResizeVolumeCommand.class, new LibvirtResizeVolumeCommandWrapper()); + libvirtCommands.put(NetworkElementCommand.class, new LibvirtNetworkElementCommandWrapper()); + libvirtCommands.put(StorageSubSystemCommand.class, new LibvirtStorageSubSystemCommandWrapper()); + libvirtCommands.put(StartCommand.class, new LibvirtStartCommandWrapper()); - resources.put(LibvirtComputingResource.class, linbvirtCommands); + resources.put(LibvirtComputingResource.class, libvirtCommands); } public static LibvirtRequestWrapper getInstance() { diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtUtilitiesHelper.java b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtUtilitiesHelper.java index dfff12d0ab9..98bf642e0d5 100644 --- a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtUtilitiesHelper.java +++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtUtilitiesHelper.java @@ -82,4 +82,8 @@ public class LibvirtUtilitiesHelper { public String retrieveSshPrvKeyPath() { return LibvirtComputingResource.SSHPRVKEYPATH; } + + public String retrieveBashScriptPath() { + return LibvirtComputingResource.BASH_SCRIPT_PATH; + } } \ No newline at end of file diff --git a/plugins/hypervisors/kvm/test/com/cloud/hypervisor/kvm/resource/LibvirtComputingResourceTest.java b/plugins/hypervisors/kvm/test/com/cloud/hypervisor/kvm/resource/LibvirtComputingResourceTest.java index 36227a55035..7f378a346e8 100644 --- a/plugins/hypervisors/kvm/test/com/cloud/hypervisor/kvm/resource/LibvirtComputingResourceTest.java +++ b/plugins/hypervisors/kvm/test/com/cloud/hypervisor/kvm/resource/LibvirtComputingResourceTest.java @@ -916,19 +916,28 @@ public class LibvirtComputingResourceTest { } } - @Test(expected = NumberFormatException.class) + @Test public void testGetHostStatsCommand() { // A bit difficult to test due to the logger being passed and the parser itself relying on the connection. // Have to spend some more time afterwards in order to refactor the wrapper itself. + final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class); + final String bashScriptPath = "/path"; + final String uuid = "e8d6b4d0-bc6d-4613-b8bb-cb9e0600f3c6"; final GetHostStatsCommand command = new GetHostStatsCommand(uuid, "summer", 1l); + when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper); + when(libvirtUtilitiesHelper.retrieveBashScriptPath()).thenReturn(bashScriptPath); + final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance(); assertNotNull(wrapper); final Answer answer = wrapper.execute(command, libvirtComputingResource); assertFalse(answer.getResult()); + + verify(libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper(); + verify(libvirtUtilitiesHelper, times(1)).retrieveBashScriptPath(); } @Test