@Test public void createVmGroupThrowsException() throws Exception { vmGroupMockInitializationOnExceptionThrown(); VmInputs vmInputs = getVmInputs(); List<String> vmList = getList(); when(vimPortMock.reconfigureComputeResourceTask(any(ManagedObjectReference.class), any(ClusterConfigSpecEx.class), any(Boolean.class))) .thenThrow(new RuntimeFaultFaultMsg(CLUSTER_CONFIGURATION_FAILED, new RuntimeFault())); thrownException.expectMessage(CLUSTER_CONFIGURATION_FAILED); clusterComputeResourceService.createVmGroup(httpInputsMock, vmInputs, vmList); }
@Test public void deleteVmGroupThrowsException() throws Exception { vmGroupMockInitializationOnExceptionThrown(); VmInputs vmInputs = getVmInputs(); when(vimPortMock.reconfigureComputeResourceTask(any(ManagedObjectReference.class), any(ClusterConfigSpecEx.class), any(Boolean.class))) .thenThrow(new RuntimeFaultFaultMsg(CLUSTER_CONFIGURATION_FAILED, new RuntimeFault())); thrownException.expectMessage(CLUSTER_CONFIGURATION_FAILED); clusterComputeResourceService.deleteVmGroup(httpInputsMock, vmInputs); }
@Test public void createHostGroupThrowsException() throws Exception { hostGroupMockInitializationOnExceptionThrown(); VmInputs vmInputs = getVmInputs(); List<String> hostList = getList(); when(vimPortMock.reconfigureComputeResourceTask(any(ManagedObjectReference.class), any(ClusterConfigSpecEx.class), any(Boolean.class))) .thenThrow(new RuntimeFaultFaultMsg(CLUSTER_CONFIGURATION_FAILED, new RuntimeFault())); thrownException.expectMessage(CLUSTER_CONFIGURATION_FAILED); clusterComputeResourceService.createHostGroup(httpInputsMock, vmInputs, hostList); }
@Test public void deleteHostGroupThrowsException() throws Exception { hostGroupMockInitializationOnExceptionThrown(); VmInputs vmInputs = getVmInputs(); when(vimPortMock.reconfigureComputeResourceTask(any(ManagedObjectReference.class), any(ClusterConfigSpecEx.class), any(Boolean.class))) .thenThrow(new RuntimeFaultFaultMsg(CLUSTER_CONFIGURATION_FAILED, new RuntimeFault())); thrownException.expectMessage(CLUSTER_CONFIGURATION_FAILED); clusterComputeResourceService.deleteHostGroup(httpInputsMock, vmInputs); }
private void commonMockInitializations() throws Exception { when(connectionResourcesMock.getVimPortType()).thenReturn(vimPortMock); when(connectionResourcesMock.getConnection()).thenReturn(connectionMock); when(taskMock.getValue()).thenReturn("task-12345"); when(connectionMock.disconnect()).thenReturn(connectionMock); when(vimPortMock.reconfigureComputeResourceTask(any(ManagedObjectReference.class), any(ClusterConfigSpecEx.class), any(Boolean.class))) .thenReturn(taskMock); when(httpInputsMock.isCloseSession()).thenReturn(true); }
private void commonVerifications() throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg { verify(connectionResourcesMock, times(1)).getConnection(); verify(connectionResourcesMock, times(1)).getVimPortType(); verify(morObjectHandlerMock, times(1)).getSpecificMor(any(ConnectionResources.class), any(ManagedObjectReference.class), any(String.class), any(String.class)); verify(vimPortMock, times(1)).reconfigureComputeResourceTask(any(ManagedObjectReference.class), any(ClusterConfigSpecEx.class), any(Boolean.class)); verify(taskMock, times(1)).getValue(); verify(connectionMock, times(1)).disconnect(); }
@Override public void setRestartPriorityForVM(VirtualMachineMO vmMo, String priority) throws Exception { if (vmMo == null || StringUtils.isBlank(priority)) { return; } if (!isHAEnabled()) { s_logger.debug("Couldn't set restart priority for VM: " + vmMo.getName() + ", HA disabled in the cluster"); return; } ManagedObjectReference vmMor = vmMo.getMor(); if (vmMor == null || !vmMor.getType().equals("VirtualMachine")) { s_logger.debug("Failed to set restart priority for VM: " + vmMo.getName() + ", invalid VM object reference"); return; } String currentVmRestartPriority = getRestartPriorityForVM(vmMo); if (StringUtils.isNotBlank(currentVmRestartPriority) && currentVmRestartPriority.equalsIgnoreCase(priority)) { return; } ClusterDasVmSettings clusterDasVmSettings = new ClusterDasVmSettings(); clusterDasVmSettings.setRestartPriority(priority); ClusterDasVmConfigInfo clusterDasVmConfigInfo = new ClusterDasVmConfigInfo(); clusterDasVmConfigInfo.setKey(vmMor); clusterDasVmConfigInfo.setDasSettings(clusterDasVmSettings); ClusterDasVmConfigSpec clusterDasVmConfigSpec = new ClusterDasVmConfigSpec(); clusterDasVmConfigSpec.setOperation((StringUtils.isNotBlank(currentVmRestartPriority)) ? ArrayUpdateOperation.EDIT : ArrayUpdateOperation.ADD); clusterDasVmConfigSpec.setInfo(clusterDasVmConfigInfo); ClusterConfigSpecEx clusterConfigSpecEx = new ClusterConfigSpecEx(); ClusterDasConfigInfo clusterDasConfigInfo = new ClusterDasConfigInfo(); clusterConfigSpecEx.setDasConfig(clusterDasConfigInfo); clusterConfigSpecEx.getDasVmConfigSpec().add(clusterDasVmConfigSpec); ManagedObjectReference morTask = _context.getService().reconfigureComputeResourceTask(_mor, clusterConfigSpecEx, true); boolean result = _context.getVimClient().waitForTask(morTask); if (result) { _context.waitForTaskProgressDone(morTask); if (s_logger.isTraceEnabled()) s_logger.trace("vCenter API trace - setRestartPriority done(successfully)"); } else { if (s_logger.isTraceEnabled()) s_logger.trace("vCenter API trace - setRestartPriority done(failed)"); s_logger.error("Set restart priority failed for VM: " + vmMo.getName() + " due to " + TaskMO.getTaskFailureInfo(_context, morTask)); } }