Search in sources :

Example 11 with AzureVMCloud

use of com.microsoft.azure.vmagent.AzureVMCloud 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)

Example 12 with AzureVMCloud

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

the class AdvancedConfigAsCodeTest method importAdvancedConfiguration.

@Test
public void importAdvancedConfiguration() {
    AzureVMCloud cloud = (AzureVMCloud) r.jenkins.clouds.get(0);
    // cloud
    assertThat(cloud.getCloudName(), is("azure"));
    assertThat(cloud.getCloudTags().get(0), is(new AzureTagPair("author", "gavin")));
    assertThat(cloud.getAzureCredentialsId(), is("azure-cred"));
    assertThat(cloud.getDeploymentTimeout(), is(1200));
    assertThat(cloud.getMaxVirtualMachinesLimit(), is(10));
    assertThat(cloud.getNewResourceGroupName(), nullValue());
    assertThat(cloud.getExistingResourceGroupName(), is("vm-agents"));
    assertThat(cloud.getResourceGroupReferenceType(), is("existing"));
    // vmTemplate
    AzureVMAgentTemplate template = cloud.getVmTemplates().get(0);
    assertThat(template.getAgentLaunchMethod(), is("SSH"));
    assertThat(template.getBuiltInImage(), is("Windows Server 2016"));
    assertThat(template.getCredentialsId(), is("admin-cred"));
    assertThat(template.getDiskType(), is("managed"));
    assertThat(template.getDoNotUseMachineIfInitFails(), is(true));
    assertThat(template.isEnableMSI(), is(false));
    assertThat(template.isEnableUAMI(), is(false));
    assertThat(template.getExecuteInitScriptAsRoot(), is(true));
    AzureVMAgentTemplate.ImageReferenceTypeClass imageReference = template.getImageReference();
    assertThat(imageReference.getVersion(), nullValue());
    assertThat(imageReference.getGalleryImageVersion(), is("latest"));
    assertThat(imageReference.getGalleryImageDefinition(), is("Linux"));
    assertThat(imageReference.getGalleryName(), is("gallery"));
    assertThat(imageReference.getGalleryResourceGroup(), is("gallery"));
    assertThat(imageReference.getGallerySubscriptionId(), is("e5587777-5750-4d2e-9e45-d6fbae67b8ea"));
    assertThat(template.getImageTopLevelType(), is("advanced"));
    assertThat(template.isInstallDocker(), is(false));
    assertThat(template.isInstallGit(), is(false));
    assertThat(template.isInstallMaven(), is(false));
    assertThat(template.getLabels(), is("linux"));
    assertThat(template.getLocation(), is("UK South"));
    assertThat(template.getNewStorageAccountName(), is("agent-storage"));
    assertThat(template.getNoOfParallelJobs(), is(1));
    assertThat(template.getOsDiskSize(), is(40));
    assertThat(template.getOsType(), is("Linux"));
    assertThat(template.isPreInstallSsh(), is(false));
    AzureVMCloudRetensionStrategy retentionStrategy = (AzureVMCloudRetensionStrategy) template.getRetentionStrategy();
    assertThat(retentionStrategy.getIdleTerminationMinutes(), is(40L));
    assertThat(template.isShutdownOnIdle(), is(false));
    assertThat(template.getStorageAccountNameReferenceType(), is("new"));
    assertThat(template.getStorageAccountType(), is("Standard_LRS"));
    assertThat(template.isTemplateDisabled(), is(false));
    assertThat(template.getTemplateName(), is("azure"));
    assertThat(template.getUsageMode(), is(Node.Mode.NORMAL));
    assertThat(template.getUsePrivateIP(), is(true));
    assertThat(template.getVirtualMachineSize(), is("Standard_A2"));
}
Also used : AzureVMCloud(com.microsoft.azure.vmagent.AzureVMCloud) AzureVMAgentTemplate(com.microsoft.azure.vmagent.AzureVMAgentTemplate) AzureVMCloudRetensionStrategy(com.microsoft.azure.vmagent.AzureVMCloudRetensionStrategy) AzureTagPair(com.microsoft.azure.vmagent.AzureTagPair) Test(org.junit.Test)

Example 13 with AzureVMCloud

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

the class BasicConfigAsCodeTest method importBasicConfiguration.

@Test
public void importBasicConfiguration() {
    AzureVMCloud cloud = (AzureVMCloud) r.jenkins.clouds.get(0);
    // cloud
    assertThat(cloud.getCloudName(), is("azure"));
    assertThat(cloud.getAzureCredentialsId(), is("azure-cred"));
    assertThat(cloud.getDeploymentTimeout(), is(1200));
    assertThat(cloud.getMaxVirtualMachinesLimit(), is(10));
    assertThat(cloud.getNewResourceGroupName(), is("vm-agent"));
    assertThat(cloud.getResourceGroupReferenceType(), is("new"));
    // vmTemplate
    AzureVMAgentTemplate template = cloud.getVmTemplates().get(0);
    assertThat(template.getAgentLaunchMethod(), is("SSH"));
    assertThat(template.getBuiltInImage(), is("Ubuntu 16.14 LTS"));
    assertThat(template.getCredentialsId(), is("admin-cred"));
    assertThat(template.getDiskType(), is("managed"));
    assertThat(template.getDoNotUseMachineIfInitFails(), is(true));
    assertThat(template.isEnableMSI(), is(false));
    assertThat(template.isEnableUAMI(), is(false));
    assertThat(template.isEphemeralOSDisk(), is(false));
    assertThat(template.getExecuteInitScriptAsRoot(), is(true));
    assertThat(template.getTags(), contains(new AzureTagPair("env", "test")));
    AzureVMAgentTemplate.ImageReferenceTypeClass imageReference = template.getImageReference();
    assertThat(imageReference.getVersion(), is("latest"));
    assertThat(template.getImageTopLevelType(), is("basic"));
    assertThat(template.isInstallDocker(), is(true));
    assertThat(template.isInstallGit(), is(true));
    assertThat(template.isInstallMaven(), is(true));
    assertThat(template.getLabels(), is("ubuntu"));
    assertThat(template.getLocation(), is("East US"));
    assertThat(template.getNewStorageAccountName(), is("agent-storage"));
    assertThat(template.getNoOfParallelJobs(), is(1));
    assertThat(template.getOsDiskSize(), is(0));
    assertThat(template.getOsType(), is("Linux"));
    assertThat(template.isPreInstallSsh(), is(true));
    AzureVMCloudRetensionStrategy retentionStrategy = (AzureVMCloudRetensionStrategy) template.getRetentionStrategy();
    assertThat(retentionStrategy.getIdleTerminationMinutes(), is(60L));
    assertThat(template.isShutdownOnIdle(), is(false));
    assertThat(template.getStorageAccountNameReferenceType(), is("new"));
    assertThat(template.getStorageAccountType(), is("Standard_LRS"));
    assertThat(template.isTemplateDisabled(), is(false));
    assertThat(template.getTemplateName(), is("ubuntu"));
    assertThat(template.getUsageMode(), is(Node.Mode.NORMAL));
    assertThat(template.getUsePrivateIP(), is(false));
    assertThat(template.getVirtualMachineSize(), is("Standard_DS2_v2"));
}
Also used : AzureVMCloud(com.microsoft.azure.vmagent.AzureVMCloud) AzureVMAgentTemplate(com.microsoft.azure.vmagent.AzureVMAgentTemplate) AzureVMCloudRetensionStrategy(com.microsoft.azure.vmagent.AzureVMCloudRetensionStrategy) AzureTagPair(com.microsoft.azure.vmagent.AzureTagPair) Test(org.junit.Test)

Aggregations

AzureVMCloud (com.microsoft.azure.vmagent.AzureVMCloud)13 AzureVMAgentTemplate (com.microsoft.azure.vmagent.AzureVMAgentTemplate)10 Test (org.junit.Test)10 AzureVMDeploymentInfo (com.microsoft.azure.vmagent.AzureVMDeploymentInfo)6 AzureCloudException (com.microsoft.azure.vmagent.exceptions.AzureCloudException)6 ManagementException (com.azure.core.management.exception.ManagementException)5 AzureVMAgent (com.microsoft.azure.vmagent.AzureVMAgent)4 IOException (java.io.IOException)4 AzureVMAgentCleanUpTask (com.microsoft.azure.vmagent.AzureVMAgentCleanUpTask)3 DeploymentRegistrar (com.microsoft.azure.vmagent.AzureVMAgentCleanUpTask.DeploymentRegistrar)3 PublicIpAddress (com.azure.resourcemanager.network.models.PublicIpAddress)2 AzureTagPair (com.microsoft.azure.vmagent.AzureTagPair)2 AzureVMCloudRetensionStrategy (com.microsoft.azure.vmagent.AzureVMCloudRetensionStrategy)2 AzureUtil (com.microsoft.azure.vmagent.util.AzureUtil)2 ProvisioningActivity (org.jenkinsci.plugins.cloudstats.ProvisioningActivity)2 GenericResource (com.azure.resourcemanager.resources.models.GenericResource)1 StandardUsernamePasswordCredentials (com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials)1 Node (hudson.model.Node)1 TaskListener (hudson.model.TaskListener)1 Secret (hudson.util.Secret)1