Search in sources :

Example 11 with AzureVMDeploymentInfo

use of com.microsoft.azure.vmagent.AzureVMDeploymentInfo in project azure-vm-agents-plugin by jenkinsci.

the class ITAzureVMManagementServiceDelegate method createDeploymentWithPurchasePlan.

/**
 * This test requires legal terms accepted in order for it to pass
 * You can run: az vm image accept-terms --urn kali-linux:kali-linux:kali:2018.4.0
 */
@Test
public void createDeploymentWithPurchasePlan() throws Exception {
    testEnv.azureImagePublisher = "kali-linux";
    testEnv.azureImageOffer = "kali-linux";
    testEnv.azureImageSku = "kali";
    AzureVMAgentCleanUpTask.DeploymentRegistrar deploymentRegistrar = mock(AzureVMAgentCleanUpTask.DeploymentRegistrar.class);
    when(deploymentRegistrar.getDeploymentTag()).thenReturn(new AzureUtil.DeploymentTag("some_tag/123"));
    AzureVMDeploymentInfo deploymentInfo;
    deploymentInfo = createDefaultDeployment(1, deploymentRegistrar);
    verify(deploymentRegistrar).registerDeployment("testCloud", testEnv.azureResourceGroup, deploymentInfo.getDeploymentName(), null);
    Network actualVNet = null;
    StorageAccount actualStorageAcc = null;
    try {
        actualVNet = azureClient.networks().getByResourceGroup(testEnv.azureResourceGroup, "jenkinsarm-vnet");
        actualStorageAcc = azureClient.storageAccounts().getByResourceGroup(testEnv.azureResourceGroup, testEnv.azureStorageAccountName);
    } catch (Exception e) {
        LOGGER.log(Level.SEVERE, null, e);
    }
    Assert.assertNotNull("The deployed VNet doesn't exist: " + testEnv.azureResourceGroup, actualVNet);
    Assert.assertNotNull("The deployed Storage Account doesn't exist: " + testEnv.azureResourceGroup, actualStorageAcc);
    final String baseName = deploymentInfo.getVmBaseName() + "0";
    final String commonAssertMsg = testEnv.azureResourceGroup + ":" + baseName;
    VirtualMachine actualVM = null;
    NetworkInterface actualNetIface = null;
    PublicIpAddress actualIP = null;
    try {
        actualVM = azureClient.virtualMachines().getByResourceGroup(testEnv.azureResourceGroup, baseName);
        actualNetIface = azureClient.networkInterfaces().getByResourceGroup(testEnv.azureResourceGroup, baseName + "NIC");
        actualIP = azureClient.publicIpAddresses().getByResourceGroup(testEnv.azureResourceGroup, baseName + "IPName");
    } catch (Exception e) {
        LOGGER.log(Level.SEVERE, null, e);
    }
    Assert.assertNotNull("The deployed VM doesn't exist: " + commonAssertMsg, actualVM);
    Assert.assertNotNull("The deployed Network interface doesn't exist: " + commonAssertMsg, actualNetIface);
    Assert.assertNotNull("The deployed public IP doesn't exist: " + commonAssertMsg, actualIP);
}
Also used : PublicIpAddress(com.azure.resourcemanager.network.models.PublicIpAddress) AzureVMAgentCleanUpTask(com.microsoft.azure.vmagent.AzureVMAgentCleanUpTask) AzureVMDeploymentInfo(com.microsoft.azure.vmagent.AzureVMDeploymentInfo) StorageAccount(com.azure.resourcemanager.storage.models.StorageAccount) Network(com.azure.resourcemanager.network.models.Network) AzureUtil(com.microsoft.azure.vmagent.util.AzureUtil) NetworkInterface(com.azure.resourcemanager.network.models.NetworkInterface) AzureCloudException(com.microsoft.azure.vmagent.exceptions.AzureCloudException) IOException(java.io.IOException) ManagementException(com.azure.core.management.exception.ManagementException) VirtualMachine(com.azure.resourcemanager.compute.models.VirtualMachine) Test(org.junit.Test)

Example 12 with AzureVMDeploymentInfo

use of com.microsoft.azure.vmagent.AzureVMDeploymentInfo in project azure-vm-agents-plugin by jenkinsci.

the class ITAzureVMManagementServiceDelegate method createDeploymentWithPrivateIPTest.

@Test
public void createDeploymentWithPrivateIPTest() throws Exception {
    AzureVMAgentCleanUpTask.DeploymentRegistrar deploymentRegistrar = mock(AzureVMAgentCleanUpTask.DeploymentRegistrar.class);
    when(deploymentRegistrar.getDeploymentTag()).thenReturn(new AzureUtil.DeploymentTag("some_tag/123"));
    AzureVMDeploymentInfo deploymentInfo = createDefaultDeployment(1, false, deploymentRegistrar);
    verify(deploymentRegistrar).registerDeployment("testCloud", testEnv.azureResourceGroup, deploymentInfo.getDeploymentName(), null);
    Network actualVNet = null;
    StorageAccount actualStorageAcc = null;
    try {
        actualVNet = azureClient.networks().getByResourceGroup(testEnv.azureResourceGroup, "jenkinsarm-vnet");
        actualStorageAcc = azureClient.storageAccounts().getByResourceGroup(testEnv.azureResourceGroup, testEnv.azureStorageAccountName);
    } catch (Exception e) {
        LOGGER.log(Level.SEVERE, null, e);
    }
    Assert.assertNotNull("The deployed VNet doesn't exist: " + testEnv.azureResourceGroup, actualVNet);
    Assert.assertNotNull("The deployed Storage Account doesn't exist: " + testEnv.azureResourceGroup, actualStorageAcc);
    final String baseName = deploymentInfo.getVmBaseName() + "0";
    VirtualMachine actualVM = null;
    NetworkInterface actualNetIface = null;
    PublicIpAddress actualIP = null;
    String privateIP = "";
    try {
        actualVM = azureClient.virtualMachines().getByResourceGroup(testEnv.azureResourceGroup, baseName);
        actualNetIface = azureClient.networkInterfaces().getByResourceGroup(testEnv.azureResourceGroup, baseName + "NIC");
        privateIP = actualNetIface.primaryPrivateIP();
        actualIP = azureClient.publicIpAddresses().getByResourceGroup(testEnv.azureResourceGroup, baseName + "IPName");
    } catch (Exception e) {
        LOGGER.log(Level.SEVERE, null, e);
    }
    Assert.assertNotNull("The deployed VM doesn't exist", actualVM);
    Assert.assertNotNull("The deployed Network interface doesn't exist", actualNetIface);
    Assert.assertTrue("The deployed VM doesn't have a private IP", privateIP != null && !privateIP.isEmpty());
    Assert.assertNull("The deployed VM shouldn't have a public IP", actualIP);
}
Also used : PublicIpAddress(com.azure.resourcemanager.network.models.PublicIpAddress) AzureVMAgentCleanUpTask(com.microsoft.azure.vmagent.AzureVMAgentCleanUpTask) AzureVMDeploymentInfo(com.microsoft.azure.vmagent.AzureVMDeploymentInfo) StorageAccount(com.azure.resourcemanager.storage.models.StorageAccount) Network(com.azure.resourcemanager.network.models.Network) AzureUtil(com.microsoft.azure.vmagent.util.AzureUtil) NetworkInterface(com.azure.resourcemanager.network.models.NetworkInterface) AzureCloudException(com.microsoft.azure.vmagent.exceptions.AzureCloudException) IOException(java.io.IOException) ManagementException(com.azure.core.management.exception.ManagementException) VirtualMachine(com.azure.resourcemanager.compute.models.VirtualMachine) Test(org.junit.Test)

Example 13 with AzureVMDeploymentInfo

use of com.microsoft.azure.vmagent.AzureVMDeploymentInfo in project azure-vm-agents-plugin by jenkinsci.

the class ITAzureVMManagementServiceDelegate method attachPublicIP.

@Test
public void attachPublicIP() {
    try {
        final AzureVMDeploymentInfo deploymentInfo = createDefaultDeployment(1, false, null);
        final String nodeName = deploymentInfo.getVmBaseName() + "0";
        final String privateIP = azureClient.virtualMachines().getByResourceGroup(testEnv.azureResourceGroup, nodeName).getPrimaryNetworkInterface().primaryPrivateIP();
        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(templateMock.getLocation()).thenReturn(testEnv.azureLocation);
        when(agentMock.getNodeName()).thenReturn(nodeName);
        delegate.attachPublicIP(agentMock, templateMock);
        final PublicIpAddress publicIP = azureClient.virtualMachines().getByResourceGroup(testEnv.azureResourceGroup, nodeName).getPrimaryPublicIPAddress();
        Assert.assertNotNull(publicIP);
        verify(agentMock).setPublicDNSName(publicIP.fqdn());
        verify(agentMock).setSshPort(Constants.DEFAULT_SSH_PORT);
        verify(agentMock).setPublicIP(publicIP.ipAddress());
        verify(agentMock).setPrivateIP(privateIP);
    } catch (Exception e) {
        LOGGER.log(Level.SEVERE, null, e);
        Assert.fail(e.getMessage());
    }
}
Also used : PublicIpAddress(com.azure.resourcemanager.network.models.PublicIpAddress) AzureVMAgent(com.microsoft.azure.vmagent.AzureVMAgent) AzureVMDeploymentInfo(com.microsoft.azure.vmagent.AzureVMDeploymentInfo) AzureVMCloud(com.microsoft.azure.vmagent.AzureVMCloud) AzureVMAgentTemplate(com.microsoft.azure.vmagent.AzureVMAgentTemplate) AzureCloudException(com.microsoft.azure.vmagent.exceptions.AzureCloudException) IOException(java.io.IOException) ManagementException(com.azure.core.management.exception.ManagementException) Test(org.junit.Test)

Example 14 with AzureVMDeploymentInfo

use of com.microsoft.azure.vmagent.AzureVMDeploymentInfo in project azure-vm-agents-plugin by jenkinsci.

the class ITAzureVMManagementServiceDelegate method setVirtualMachineDetailsWithPrivateIP.

@Test
public void setVirtualMachineDetailsWithPrivateIP() {
    try {
        final AzureVMDeploymentInfo deploymentInfo = createDefaultDeployment(1, false, null);
        final String nodeName = deploymentInfo.getVmBaseName() + "0";
        final String ip = azureClient.virtualMachines().getByResourceGroup(testEnv.azureResourceGroup, nodeName).getPrimaryNetworkInterface().primaryPrivateIP();
        setVirtualMachineDetailsCommonVerification(nodeName, ip, ip, "");
    } catch (Exception e) {
        LOGGER.log(Level.SEVERE, null, e);
        Assert.fail(e.getMessage());
    }
}
Also used : AzureVMDeploymentInfo(com.microsoft.azure.vmagent.AzureVMDeploymentInfo) AzureCloudException(com.microsoft.azure.vmagent.exceptions.AzureCloudException) IOException(java.io.IOException) ManagementException(com.azure.core.management.exception.ManagementException) Test(org.junit.Test)

Example 15 with AzureVMDeploymentInfo

use of com.microsoft.azure.vmagent.AzureVMDeploymentInfo in project azure-vm-agents-plugin by jenkinsci.

the class ITAzureVMManagementServiceDelegate method attachPublicIPIsNoOpWhenAlreadyExists.

@Test
public void attachPublicIPIsNoOpWhenAlreadyExists() {
    try {
        final AzureVMDeploymentInfo deploymentInfo = createDefaultDeployment(1, true, null);
        final String nodeName = deploymentInfo.getVmBaseName() + "0";
        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(templateMock.getLocation()).thenReturn(testEnv.azureLocation);
        when(agentMock.getNodeName()).thenReturn(nodeName);
        final String initialPublicIPId = azureClient.virtualMachines().getByResourceGroup(testEnv.azureResourceGroup, nodeName).getPrimaryPublicIPAddress().id();
        delegate.attachPublicIP(agentMock, templateMock);
        final PublicIpAddress publicIP = azureClient.virtualMachines().getByResourceGroup(testEnv.azureResourceGroup, nodeName).getPrimaryPublicIPAddress();
        Assert.assertNotNull(publicIP);
        Assert.assertEquals(initialPublicIPId, publicIP.id());
        verify(agentMock, never()).setPublicDNSName(any(String.class));
        verify(agentMock, never()).setSshPort(any(int.class));
        verify(agentMock, never()).setPublicIP(any(String.class));
        verify(agentMock, never()).setPrivateIP(any(String.class));
    } catch (Exception e) {
        LOGGER.log(Level.SEVERE, null, e);
        Assert.fail(e.getMessage());
    }
}
Also used : PublicIpAddress(com.azure.resourcemanager.network.models.PublicIpAddress) AzureVMAgent(com.microsoft.azure.vmagent.AzureVMAgent) AzureVMDeploymentInfo(com.microsoft.azure.vmagent.AzureVMDeploymentInfo) AzureVMCloud(com.microsoft.azure.vmagent.AzureVMCloud) AzureVMAgentTemplate(com.microsoft.azure.vmagent.AzureVMAgentTemplate) AzureCloudException(com.microsoft.azure.vmagent.exceptions.AzureCloudException) IOException(java.io.IOException) ManagementException(com.azure.core.management.exception.ManagementException) Test(org.junit.Test)

Aggregations

AzureVMDeploymentInfo (com.microsoft.azure.vmagent.AzureVMDeploymentInfo)17 Test (org.junit.Test)16 AzureCloudException (com.microsoft.azure.vmagent.exceptions.AzureCloudException)15 ManagementException (com.azure.core.management.exception.ManagementException)14 IOException (java.io.IOException)14 PublicIpAddress (com.azure.resourcemanager.network.models.PublicIpAddress)10 AzureVMAgentCleanUpTask (com.microsoft.azure.vmagent.AzureVMAgentCleanUpTask)10 AzureUtil (com.microsoft.azure.vmagent.util.AzureUtil)9 VirtualMachine (com.azure.resourcemanager.compute.models.VirtualMachine)8 Network (com.azure.resourcemanager.network.models.Network)7 NetworkInterface (com.azure.resourcemanager.network.models.NetworkInterface)7 StorageAccount (com.azure.resourcemanager.storage.models.StorageAccount)7 AzureVMCloud (com.microsoft.azure.vmagent.AzureVMCloud)6 AzureVMAgentTemplate (com.microsoft.azure.vmagent.AzureVMAgentTemplate)4 AzureVMAgent (com.microsoft.azure.vmagent.AzureVMAgent)3 DeploymentRegistrar (com.microsoft.azure.vmagent.AzureVMAgentCleanUpTask.DeploymentRegistrar)2 AvailabilitySet (com.azure.resourcemanager.compute.models.AvailabilitySet)1 NetworkSecurityGroup (com.azure.resourcemanager.network.models.NetworkSecurityGroup)1 GenericResource (com.azure.resourcemanager.resources.models.GenericResource)1 StandardUsernamePasswordCredentials (com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials)1