use of com.microsoft.azure.vmagent.AzureVMAgentTemplate in project azure-vm-agents-plugin by jenkinsci.
the class ITAzureVMManagementServiceDelegate method uploadCustomScript.
private void uploadCustomScript(String uploadFileName, String writtenData) {
AzureVMAgentTemplate templateMock = mock(AzureVMAgentTemplate.class);
when(templateMock.getStorageAccountName()).thenReturn(testEnv.azureStorageAccountName);
when(templateMock.getResourceGroupName()).thenReturn(testEnv.azureResourceGroup);
when(templateMock.getLocation()).thenReturn(testEnv.azureLocation);
when(templateMock.getInitScript()).thenReturn(writtenData);
when(templateMock.getTerminateScript()).thenReturn(writtenData);
when(templateMock.getStorageAccountType()).thenReturn(SkuName.STANDARD_LRS.toString());
when(templateMock.getResourceGroupReferenceType()).thenReturn(testEnv.azureResourceGroupReferenceType);
AzureVMCloud cloudMock = mock(AzureVMCloud.class);
when(cloudMock.getCloudName()).thenReturn("testCloudName");
when(templateMock.retrieveAzureCloudReference()).thenReturn(cloudMock);
try {
delegate.uploadCustomScript(templateMock, uploadFileName);
final String downloadedData = downloadFromAzure(testEnv.azureResourceGroup, testEnv.azureStorageAccountName, Constants.CONFIG_CONTAINER_NAME, uploadFileName);
/*Data padded before upload to Page Blob so we need to use strip*/
Assert.assertEquals(StringUtils.strip(writtenData), StringUtils.strip(downloadedData));
} catch (Exception e) {
LOGGER.log(Level.SEVERE, null, e);
Assert.fail(e.getMessage());
}
}
use of com.microsoft.azure.vmagent.AzureVMAgentTemplate 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);
}
use of com.microsoft.azure.vmagent.AzureVMAgentTemplate in project azure-vm-agents-plugin by jenkinsci.
the class IntegrationTest method createDefaultDeployment.
protected AzureVMDeploymentInfo createDefaultDeployment(int numberOfAgents, boolean usePrivateIP, boolean enableMSI, boolean enableUAMI, boolean ephemeralOSDisk, String nsgName, AzureVMAgentCleanUpTask.DeploymentRegistrar deploymentRegistrar) throws Exception {
final String templateName = "t" + TestEnvironment.GenerateRandomString(7);
final String osType = OS_TYPE;
final String initScript = "echo \"" + UUID.randomUUID().toString() + "\"";
final String terminateScript = "echo \"" + UUID.randomUUID().toString() + "\"";
final String launchMethod = Constants.LAUNCH_METHOD_SSH;
final String vmUser = "tstVmUser";
final Secret vmPassword = Secret.fromString(TestEnvironment.GenerateRandomString(16) + "AA@@12345@#$%^&*-_!+=[]{}|\\:`,.?/~\\\"();\'");
final String storageType = SkuName.STANDARD_LRS.toString();
StandardUsernamePasswordCredentials vmCredentials = mock(StandardUsernamePasswordCredentials.class);
when(vmCredentials.getUsername()).thenReturn(vmUser);
when(vmCredentials.getPassword()).thenReturn(vmPassword);
if (deploymentRegistrar == null) {
deploymentRegistrar = AzureVMAgentCleanUpTask.DeploymentRegistrar.getInstance();
}
AzureVMAgentTemplate templateMock = mock(AzureVMAgentTemplate.class);
AzureVMCloud cloudMock = mock(AzureVMCloud.class);
when(cloudMock.getCloudName()).thenReturn("testCloud");
when(cloudMock.getCloudTags()).thenReturn(testEnv.customTags);
when(templateMock.getResourceGroupName()).thenReturn(testEnv.azureResourceGroup);
when(templateMock.getResourceGroupReferenceType()).thenReturn(testEnv.azureResourceGroupReferenceType);
when(templateMock.getStorageAccountName()).thenReturn(testEnv.azureStorageAccountName);
when(templateMock.getLocation()).thenReturn(testEnv.azureLocation);
when(templateMock.getAvailabilityType()).thenReturn(new AzureVMAgentTemplate.AvailabilityTypeClass(testEnv.availabilitySet));
when(templateMock.getTemplateName()).thenReturn(templateName);
when(templateMock.getOsType()).thenReturn(osType);
when(templateMock.getInitScript()).thenReturn(initScript);
when(templateMock.getTerminateScript()).thenReturn(terminateScript);
when(templateMock.getAgentLaunchMethod()).thenReturn(launchMethod);
when(templateMock.getImageTopLevelType()).thenReturn(Constants.IMAGE_TOP_LEVEL_ADVANCED);
when(templateMock.isTopLevelType(Constants.IMAGE_TOP_LEVEL_BASIC)).thenReturn(false);
when(templateMock.getTags()).thenReturn(testEnv.templateTags);
when(templateMock.getImageReference()).thenReturn(new AzureVMAgentTemplate.ImageReferenceTypeClass(null, testEnv.azureImageId, testEnv.azureImagePublisher, testEnv.azureImageOffer, testEnv.azureImageSku, testEnv.azureImageVersion, null, null, null, null, null));
when(templateMock.getVirtualMachineSize()).thenReturn(testEnv.azureImageSize);
when(templateMock.getVMCredentials()).thenReturn(vmCredentials);
when(templateMock.retrieveAzureCloudReference()).thenReturn(cloudMock);
when(templateMock.getUsePrivateIP()).thenReturn(!usePrivateIP);
when(templateMock.getNsgName()).thenReturn(nsgName);
when(templateMock.getStorageAccountType()).thenReturn(storageType);
when(templateMock.getOsDiskStorageAccountType()).thenReturn(storageType);
when(templateMock.getDiskType()).thenReturn(Constants.DISK_MANAGED);
when(templateMock.getOsDiskSize()).thenReturn(testEnv.osDiskSize);
when(templateMock.isPreInstallSsh()).thenReturn(true);
when(templateMock.isEnableMSI()).thenReturn(enableMSI);
when(templateMock.isEnableUAMI()).thenReturn(enableUAMI);
when(templateMock.isEphemeralOSDisk()).thenReturn(ephemeralOSDisk);
AzureVMDeploymentInfo ret = delegate.createDeployment(templateMock, numberOfAgents, deploymentRegistrar);
List<String> vmNames = new ArrayList<>();
for (int i = 0; i < numberOfAgents; i++) {
vmNames.add(ret.getVmBaseName() + i);
}
// wait for deployment to complete
// wait 10 minutes
final int maxTries = 20;
for (int i = 0; i < maxTries; i++) {
if (areAllVMsDeployed(vmNames)) {
return ret;
}
try {
Thread.sleep(30 * 1000);
} catch (InterruptedException ex) {
// ignore
}
}
throw new Exception("Deployment is not completed after 10 minutes");
}
use of com.microsoft.azure.vmagent.AzureVMAgentTemplate 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.AzureVMAgentTemplate 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());
}
}
Aggregations