You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ko...@apache.org on 2015/05/19 18:21:26 UTC
[40/50] [abbrv] git commit: updated refs/heads/CLOUDSTACK-8301 to
8ff9000
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 <ro...@shapeblue.com>
This closes #255
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/0cdb4b61
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/0cdb4b61
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/0cdb4b61
Branch: refs/heads/CLOUDSTACK-8301
Commit: 0cdb4b610865fa5493cc79e9c9ef310bdf09ccaf
Parents: 9d8a62d
Author: wilderrodrigues <wr...@schubergphilis.com>
Authored: Mon May 18 14:30:36 2015 +0200
Committer: Rohit Yadav <ro...@shapeblue.com>
Committed: Mon May 18 20:07:02 2015 +0200
----------------------------------------------------------------------
.../kvm/resource/LibvirtComputingResource.java | 2 +
.../LibvirtGetHostStatsCommandWrapper.java | 10 +-
.../resource/wrapper/LibvirtRequestWrapper.java | 120 +++++++++----------
.../wrapper/LibvirtUtilitiesHelper.java | 4 +
.../resource/LibvirtComputingResourceTest.java | 11 +-
5 files changed, 83 insertions(+), 64 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/0cdb4b61/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java
----------------------------------------------------------------------
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 a04074b..995a8cf 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;
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/0cdb4b61/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtGetHostStatsCommandWrapper.java
----------------------------------------------------------------------
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 ba9ba18..45713cb 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<GetH
@Override
public Answer execute(final GetHostStatsCommand command, final LibvirtComputingResource libvirtComputingResource) {
- final Script cpuScript = new Script("/bin/bash", s_logger);
+ final LibvirtUtilitiesHelper libvirtUtilitiesHelper = libvirtComputingResource.getLibvirtUtilitiesHelper();
+ final String bashScriptPath = libvirtUtilitiesHelper.retrieveBashScriptPath();
+
+
+ final Script cpuScript = new Script(bashScriptPath, s_logger);
cpuScript.add("-c");
cpuScript.add("idle=$(top -b -n 1| awk -F, '/^[%]*[Cc]pu/{$0=$4; gsub(/[^0-9.,]+/,\"\"); print }'); echo $idle");
@@ -50,7 +54,7 @@ public final class LibvirtGetHostStatsCommandWrapper extends CommandWrapper<GetH
final double cpuUtil = 100.0D - Double.parseDouble(parser.getLine());
long freeMem = 0;
- final Script memScript = new Script("/bin/bash", s_logger);
+ final Script memScript = new Script(bashScriptPath, s_logger);
memScript.add("-c");
memScript.add("freeMem=$(free|grep cache:|awk '{print $4}');echo $freeMem");
final OutputInterpreter.OneLineParser Memparser = new OutputInterpreter.OneLineParser();
@@ -61,7 +65,7 @@ public final class LibvirtGetHostStatsCommandWrapper extends CommandWrapper<GetH
}
freeMem = Long.parseLong(Memparser.getLine());
- final Script totalMem = new Script("/bin/bash", s_logger);
+ final Script totalMem = new Script(bashScriptPath, s_logger);
totalMem.add("-c");
totalMem.add("free|grep Mem:|awk '{print $2}'");
final OutputInterpreter.OneLineParser totMemparser = new OutputInterpreter.OneLineParser();
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/0cdb4b61/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtRequestWrapper.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtRequestWrapper.java b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtRequestWrapper.java
index b181426..9f157eb 100644
--- a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtRequestWrapper.java
+++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtRequestWrapper.java
@@ -99,66 +99,66 @@ public class LibvirtRequestWrapper extends RequestWrapper {
@SuppressWarnings("rawtypes")
private void init() {
// LibvirtComputingResource commands
- final Hashtable<Class<? extends Command>, CommandWrapper> linbvirtCommands = new Hashtable<Class<? extends Command>, 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());
-
- resources.put(LibvirtComputingResource.class, linbvirtCommands);
+ final Hashtable<Class<? extends Command>, CommandWrapper> libvirtCommands = new Hashtable<Class<? extends Command>, CommandWrapper>();
+
+ 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, libvirtCommands);
}
public static LibvirtRequestWrapper getInstance() {
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/0cdb4b61/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtUtilitiesHelper.java
----------------------------------------------------------------------
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 dfff12d..98bf642 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
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/0cdb4b61/plugins/hypervisors/kvm/test/com/cloud/hypervisor/kvm/resource/LibvirtComputingResourceTest.java
----------------------------------------------------------------------
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 36227a5..7f378a3 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