use of com.microsoft.azure.vmagent.AzureVMCloud in project azure-vm-agents-plugin by jenkinsci.
the class AzureVMAgentTemplateReadResolveTest method readResolve.
@Test
@LocalData
public void readResolve() {
Jenkins.CloudList clouds = j.jenkins.clouds;
assertThat(clouds, hasSize(1));
AzureVMCloud cloud = (AzureVMCloud) clouds.get(0);
assertThat(cloud.getCloudName(), is("myAzure"));
assertThat(cloud.getVmTemplates(), hasSize(1));
AzureVMAgentTemplate template = cloud.getVmTemplates().get(0);
AzureVMAgentTemplate.ImageReferenceTypeClass reference = template.getImageReference();
assertThat(reference.getPublisher(), is("Canonical"));
assertThat(reference.getOffer(), is("UbuntuServer"));
assertThat(reference.getSku(), is("16.04-LTS"));
assertThat(reference.getVersion(), is("latest"));
assertThat(reference.getType(), is(ImageReferenceType.REFERENCE));
}
use of com.microsoft.azure.vmagent.AzureVMCloud in project azure-vm-agents-plugin by jenkinsci.
the class ITAzureVMAgentCleanUpTask method cleanDeploymentsTest.
@Test
public void cleanDeploymentsTest() throws Exception {
final AzureVMDeploymentInfo deploymentInfo = createDefaultDeployment(1, null);
final String cloudName = "fake_cloud_name";
final DeploymentRegistrar deploymentRegistrar = DeploymentRegistrar.getInstance();
deploymentRegistrar.registerDeployment(cloudName, testEnv.azureResourceGroup, deploymentInfo.getDeploymentName(), null);
AzureVMAgentCleanUpTask cleanUpMock = spy(AzureVMAgentCleanUpTask.class);
AzureVMCloud cloudMock = mock(AzureVMCloud.class);
when(cloudMock.getCloudName()).thenReturn(cloudName);
when(cloudMock.getAzureClient()).thenReturn(azureClient);
when(cloudMock.getServiceDelegate()).thenReturn(delegate);
when(cleanUpMock.getCloud(cloudName)).thenReturn(cloudMock);
doNothing().when(cleanUpMock).execute(any(TaskListener.class));
// should be a no-op, the timeout is 1 day
cleanUpMock.cleanDeployments(60 * 24, -1);
Assert.assertTrue(azureClient.deployments().checkExistence(testEnv.azureResourceGroup, deploymentInfo.getDeploymentName()));
// should delete all deployments
cleanUpMock.cleanDeployments(-1, -1);
// give time for azure to realize that the deployment was deleted
Thread.sleep(10 * 1000);
Assert.assertFalse(azureClient.deployments().checkExistence(testEnv.azureResourceGroup, deploymentInfo.getDeploymentName()));
}
use of com.microsoft.azure.vmagent.AzureVMCloud in project azure-vm-agents-plugin by jenkinsci.
the class ITAzureVMCloud method createProvisionedAgentWorksWhenDeploymentExists.
@Ignore
@Test
public void createProvisionedAgentWorksWhenDeploymentExists() {
try {
final AzureVMDeploymentInfo deploymentInfo = createDefaultDeployment(1, null);
final String vmName = deploymentInfo.getVmBaseName() + "0";
final String vmDNS = azureClient.virtualMachines().getByResourceGroup(testEnv.azureResourceGroup, vmName).getPrimaryPublicIPAddress().fqdn();
final String deploymentName = deploymentInfo.getDeploymentName();
final String templateName = "createTemplate";
final String templateDesc = "createTemplateDesc";
final String agentWorkspace = "createTemplateAgentWorkspace";
final int noOfParallelJobs = 2;
final Node.Mode useAgentAlwaysIfAvail = Node.Mode.NORMAL;
final String templateLabels = "label1 label2";
final String credentialsId = "cred_id";
final String jvmOptions = "";
final boolean isShutdownOnIdle = false;
final int retentionTimeInMin = 30;
final String initScript = "";
final String terminateScript = "";
final String agentLaunchMethod = Constants.LAUNCH_METHOD_SSH;
final boolean executeInitScriptAsRoot = true;
final boolean doNotUseMachineIfInitFails = true;
final boolean enableMSI = false;
final boolean enableUAMI = false;
final boolean ephemeralOSDisk = false;
final ProvisioningActivity.Id provisioningId = new ProvisioningActivity.Id(vmName, deploymentName);
AzureVMAgentTemplate templateMock = mock(AzureVMAgentTemplate.class);
AzureVMCloud cloudMock = spy(new AzureVMCloud("", credentialsId, "42", "30", "new", testEnv.azureResourceGroup, null, null));
when(templateMock.retrieveAzureCloudReference()).thenReturn(cloudMock);
when(templateMock.getTemplateName()).thenReturn(templateName);
when(templateMock.getTemplateDesc()).thenReturn(templateDesc);
when(templateMock.getAgentWorkspace()).thenReturn(agentWorkspace);
when(templateMock.getNoOfParallelJobs()).thenReturn(noOfParallelJobs);
when(templateMock.getUsageMode()).thenReturn(useAgentAlwaysIfAvail);
when(templateMock.getLabels()).thenReturn(templateLabels);
when(templateMock.getCredentialsId()).thenReturn(credentialsId);
when(templateMock.getJvmOptions()).thenReturn(jvmOptions);
when(templateMock.isShutdownOnIdle()).thenReturn(isShutdownOnIdle);
when(templateMock.getRetentionTimeInMin()).thenReturn(retentionTimeInMin);
when(templateMock.getInitScript()).thenReturn(initScript);
when(templateMock.getTerminateScript()).thenReturn(terminateScript);
when(templateMock.getAgentLaunchMethod()).thenReturn(agentLaunchMethod);
when(templateMock.getResourceGroupName()).thenReturn(testEnv.azureResourceGroup);
when(templateMock.getExecuteInitScriptAsRoot()).thenReturn(executeInitScriptAsRoot);
when(templateMock.getDoNotUseMachineIfInitFails()).thenReturn(doNotUseMachineIfInitFails);
when(templateMock.isEnableMSI()).thenReturn(enableMSI);
when(templateMock.isEnableUAMI()).thenReturn(enableUAMI);
when(templateMock.isEphemeralOSDisk()).thenReturn(ephemeralOSDisk);
AzureVMAgent newAgent = cloudMock.createProvisionedAgent(provisioningId, templateMock, vmName, deploymentName);
Assert.assertEquals(vmDNS, newAgent.getPublicDNSName());
Assert.assertEquals(Constants.DEFAULT_SSH_PORT, newAgent.getSshPort());
Assert.assertEquals(templateName, newAgent.getTemplateName());
Assert.assertEquals(templateDesc, newAgent.getNodeDescription());
Assert.assertEquals(noOfParallelJobs, newAgent.getNumExecutors());
Assert.assertEquals(useAgentAlwaysIfAvail, newAgent.getMode());
Assert.assertEquals(templateLabels, newAgent.getLabelString());
Assert.assertEquals(jvmOptions, newAgent.getJvmOptions());
Assert.assertEquals(retentionTimeInMin, newAgent.getRetentionTimeInMin());
Assert.assertEquals(initScript, newAgent.getInitScript());
Assert.assertEquals(terminateScript, newAgent.getTerminateScript());
Assert.assertEquals(agentLaunchMethod, newAgent.getAgentLaunchMethod());
Assert.assertEquals(executeInitScriptAsRoot, newAgent.getExecuteInitScriptAsRoot());
Assert.assertEquals(doNotUseMachineIfInitFails, newAgent.getDoNotUseMachineIfInitFails());
Assert.assertEquals(enableMSI, newAgent.isEnableMSI());
Assert.assertEquals(enableUAMI, newAgent.isEnableUAMI());
Assert.assertEquals(ephemeralOSDisk, newAgent.isEphemeralOSDisk());
} catch (Exception e) {
LOGGER.log(Level.SEVERE, null, e);
Assert.fail(e.getMessage());
}
}
use of com.microsoft.azure.vmagent.AzureVMCloud 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());
}
}
use of com.microsoft.azure.vmagent.AzureVMCloud 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());
}
}
Aggregations