use of com.microsoft.azure.vmagent.AzureVMAgent 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.microsoft.azure.vmagent.AzureVMAgent in project azure-vm-agents-plugin by jenkinsci.
the class ITAzureVMManagementServiceDelegate method isVMAliveOrHealthyTest.
@Test
public void isVMAliveOrHealthyTest() {
try {
final String vmName = "vmexists";
VirtualMachine vm = createAzureVM(vmName);
Assert.assertNotNull(vm);
AzureVMAgent agentMock = mock(AzureVMAgent.class);
when(agentMock.getNodeName()).thenReturn(vmName);
when(agentMock.getResourceGroupName()).thenReturn(testEnv.azureResourceGroup);
Assert.assertTrue(delegate.isVMAliveOrHealthy(agentMock));
vm.powerOff();
Assert.assertFalse(delegate.isVMAliveOrHealthy(agentMock));
vm.deallocate();
Assert.assertFalse(delegate.isVMAliveOrHealthy(agentMock));
azureClient.virtualMachines().deleteByResourceGroup(testEnv.azureResourceGroup, vmName);
try {
delegate.isVMAliveOrHealthy(agentMock);
Assert.fail("isVMAliveOrHealthy should have thrown an exception");
} catch (Exception e) {
Assert.assertTrue(true);
}
} catch (Exception e) {
LOGGER.log(Level.SEVERE, null, e);
Assert.fail(e.getMessage());
}
}
use of com.microsoft.azure.vmagent.AzureVMAgent 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.microsoft.azure.vmagent.AzureVMAgent in project azure-vm-agents-plugin by jenkinsci.
the class ITAzureVMManagementServiceDelegate method virtualMachineExistsTest.
@Test
public void virtualMachineExistsTest() throws IOException, AzureCloudException {
final String vmName = "vmexists";
createAzureVM(vmName);
AzureVMAgent agentMock = mock(AzureVMAgent.class);
when(agentMock.getNodeName()).thenReturn(vmName);
when(agentMock.getResourceGroupName()).thenReturn(testEnv.azureResourceGroup);
when(agentMock.getServiceDelegate()).thenReturn(delegate);
Assert.assertTrue("The deployed VM doesn't exist: " + vmName, AzureVMManagementServiceDelegate.virtualMachineExists(agentMock));
// invalid VM name
when(agentMock.getNodeName()).thenReturn(vmName + "a");
Assert.assertFalse("The deployed VM exists: " + vmName, AzureVMManagementServiceDelegate.virtualMachineExists(agentMock));
}
use of com.microsoft.azure.vmagent.AzureVMAgent in project azure-vm-agents-plugin by jenkinsci.
the class ITAzureVMManagementServiceDelegate method setVirtualMachineDetailsCommonVerification.
private void setVirtualMachineDetailsCommonVerification(String vmName, String fqdn, String privateIP, String publicIp) throws Exception {
AzureVMAgent agentMock = mock(AzureVMAgent.class);
AzureVMAgentTemplate templateMock = mock(AzureVMAgentTemplate.class);
AzureVMCloud cloudMock = mock(AzureVMCloud.class);
when(templateMock.retrieveAzureCloudReference()).thenReturn(cloudMock);
when(templateMock.getResourceGroupName()).thenReturn(testEnv.azureResourceGroup);
when(agentMock.getNodeName()).thenReturn(vmName);
delegate.setVirtualMachineDetails(agentMock, templateMock);
verify(agentMock).setPublicDNSName(fqdn);
verify(agentMock).setSshPort(Constants.DEFAULT_SSH_PORT);
verify(agentMock).setPublicIP(publicIp);
verify(agentMock).setPrivateIP(privateIP);
}
Aggregations