Search in sources :

Example 6 with AzureVMAgentTemplate

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

the class ITAzureVMCloud method createProvisionedAgentThrowsExceptionWhenNoDeployments.

@Test
public void createProvisionedAgentThrowsExceptionWhenNoDeployments() {
    try {
        final String vmName = "fakeVM";
        final String deploymentName = "fakeDeployment";
        final ProvisioningActivity.Id provisioningId = new ProvisioningActivity.Id(vmName, deploymentName);
        AzureVMAgentTemplate templateMock = mock(AzureVMAgentTemplate.class);
        AzureVMCloud cloudMock = spy(new AzureVMCloud("", "xyz", "42", "0", "new", testEnv.azureResourceGroup, null, null));
        when(templateMock.retrieveAzureCloudReference()).thenReturn(cloudMock);
        Assert.assertThrows(AzureCloudException.class, () -> cloudMock.createProvisionedAgent(provisioningId, templateMock, vmName, deploymentName));
    } catch (Exception e) {
        LOGGER.log(Level.SEVERE, null, e);
        Assert.fail(e.getMessage());
    }
}
Also used : ProvisioningActivity(org.jenkinsci.plugins.cloudstats.ProvisioningActivity) AzureVMCloud(com.microsoft.azure.vmagent.AzureVMCloud) AzureVMAgentTemplate(com.microsoft.azure.vmagent.AzureVMAgentTemplate) AzureCloudException(com.microsoft.azure.vmagent.exceptions.AzureCloudException) Test(org.junit.Test)

Example 7 with AzureVMAgentTemplate

use of com.microsoft.azure.vmagent.AzureVMAgentTemplate 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 8 with AzureVMAgentTemplate

use of com.microsoft.azure.vmagent.AzureVMAgentTemplate 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 9 with AzureVMAgentTemplate

use of com.microsoft.azure.vmagent.AzureVMAgentTemplate 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 10 with AzureVMAgentTemplate

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

AzureVMAgentTemplate (com.microsoft.azure.vmagent.AzureVMAgentTemplate)11 AzureVMCloud (com.microsoft.azure.vmagent.AzureVMCloud)10 Test (org.junit.Test)7 AzureCloudException (com.microsoft.azure.vmagent.exceptions.AzureCloudException)6 ManagementException (com.azure.core.management.exception.ManagementException)4 AzureVMAgent (com.microsoft.azure.vmagent.AzureVMAgent)4 AzureVMDeploymentInfo (com.microsoft.azure.vmagent.AzureVMDeploymentInfo)4 IOException (java.io.IOException)4 PublicIpAddress (com.azure.resourcemanager.network.models.PublicIpAddress)2 AzureTagPair (com.microsoft.azure.vmagent.AzureTagPair)2 AzureVMCloudRetensionStrategy (com.microsoft.azure.vmagent.AzureVMCloudRetensionStrategy)2 ProvisioningActivity (org.jenkinsci.plugins.cloudstats.ProvisioningActivity)2 StandardUsernamePasswordCredentials (com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials)1 Node (hudson.model.Node)1 Secret (hudson.util.Secret)1 ArrayList (java.util.ArrayList)1 Jenkins (jenkins.model.Jenkins)1 Ignore (org.junit.Ignore)1 LocalData (org.jvnet.hudson.test.recipes.LocalData)1