use of com.azure.resourcemanager.compute.models.PowerState in project azure-vm-agents-plugin by jenkinsci.
the class ITAzureVMManagementServiceDelegate method shutdownVMTest.
@Test
public void shutdownVMTest() {
try {
final String vmName = "vmshutdown";
VirtualMachine vm = createAzureVM(vmName);
Assert.assertEquals(PowerState.RUNNING, vm.powerState());
AzureVMAgent agentMock = mock(AzureVMAgent.class);
when(agentMock.getNodeName()).thenReturn(vmName);
when(agentMock.getResourceGroupName()).thenReturn(testEnv.azureResourceGroup);
delegate.shutdownVirtualMachine(agentMock);
PowerState state = azureClient.virtualMachines().getByResourceGroup(testEnv.azureResourceGroup, vmName).powerState();
assertThat(state, anyOf(is(PowerState.STOPPING), is(PowerState.STOPPED), is(PowerState.DEALLOCATING), is(PowerState.DEALLOCATED)));
} catch (Exception e) {
LOGGER.log(Level.SEVERE, null, e);
Assert.fail(e.getMessage());
}
}
use of com.azure.resourcemanager.compute.models.PowerState in project azure-vm-agents-plugin by jenkinsci.
the class ITAzureVMManagementServiceDelegate method startVMTest.
@Test
public void startVMTest() {
try {
final String vmName = "vmstart";
VirtualMachine vm = createAzureVM(vmName);
Assert.assertEquals(PowerState.RUNNING, vm.powerState());
AzureVMAgent agentMock = mock(AzureVMAgent.class);
when(agentMock.getNodeName()).thenReturn(vmName);
when(agentMock.getResourceGroupName()).thenReturn(testEnv.azureResourceGroup);
delegate.startVirtualMachine(agentMock);
Assert.assertEquals(PowerState.RUNNING, azureClient.virtualMachines().getByResourceGroup(testEnv.azureResourceGroup, vmName).powerState());
azureClient.virtualMachines().getByResourceGroup(testEnv.azureResourceGroup, vmName).powerOff();
PowerState state2 = azureClient.virtualMachines().getByResourceGroup(testEnv.azureResourceGroup, vmName).powerState();
Assert.assertTrue(state2.toString(), state2.equals(PowerState.STOPPED) || state2.toString().equalsIgnoreCase("powerstate/stopping"));
delegate.startVirtualMachine(agentMock);
PowerState state = azureClient.virtualMachines().getByResourceGroup(testEnv.azureResourceGroup, vmName).powerState();
Assert.assertTrue(state.equals(PowerState.RUNNING) || state.equals(PowerState.STARTING));
} catch (Exception e) {
LOGGER.log(Level.SEVERE, null, e);
Assert.fail(e.getMessage());
}
}
use of com.azure.resourcemanager.compute.models.PowerState in project azure-vm-agents-plugin by jenkinsci.
the class ITAzureVMManagementServiceDelegate method restartVMTest.
@Test
public void restartVMTest() throws IOException, AzureCloudException {
final String vmName = "vmrestart";
VirtualMachine vm = createAzureVM(vmName);
Assert.assertEquals(PowerState.RUNNING, vm.powerState());
AzureVMAgent agentMock = mock(AzureVMAgent.class);
when(agentMock.getNodeName()).thenReturn(vmName);
when(agentMock.getResourceGroupName()).thenReturn(testEnv.azureResourceGroup);
delegate.restartVirtualMachine(agentMock);
PowerState state = azureClient.virtualMachines().getByResourceGroup(testEnv.azureResourceGroup, vmName).powerState();
Assert.assertTrue(state.equals(PowerState.RUNNING) || state.equals(PowerState.STARTING));
azureClient.virtualMachines().getByResourceGroup(testEnv.azureResourceGroup, vmName).powerOff();
PowerState state2 = azureClient.virtualMachines().getByResourceGroup(testEnv.azureResourceGroup, vmName).powerState();
Assert.assertTrue(state2.toString(), state2.equals(PowerState.STOPPED) || state2.toString().equalsIgnoreCase("powerstate/stopping"));
try {
// restart throws exception when the VM is already stopped
delegate.restartVirtualMachine(agentMock);
Assert.fail("Expect throwing AzureCloudException but not");
} catch (AzureCloudException ex) {
// Expect exception
}
}
Aggregations