use of com.azure.resourcemanager.network.models.NetworkInterface 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);
}
use of com.azure.resourcemanager.network.models.NetworkInterface in project azure-vm-agents-plugin by jenkinsci.
the class ITAzureVMManagementServiceDelegate method canDeployMultipleTimes.
@Test
public void canDeployMultipleTimes() {
try {
AzureVMAgentCleanUpTask.DeploymentRegistrar deploymentRegistrar = mock(AzureVMAgentCleanUpTask.DeploymentRegistrar.class);
when(deploymentRegistrar.getDeploymentTag()).thenReturn(new AzureUtil.DeploymentTag("some_tag/123"));
AzureVMAgentCleanUpTask.DeploymentRegistrar deploymentRegistrar2 = mock(AzureVMAgentCleanUpTask.DeploymentRegistrar.class);
when(deploymentRegistrar2.getDeploymentTag()).thenReturn(new AzureUtil.DeploymentTag("other_tag/123"));
AzureVMDeploymentInfo firstDeployment = createDefaultDeployment(1, deploymentRegistrar);
AzureVMDeploymentInfo secondDeployment = createDefaultDeployment(1, deploymentRegistrar);
AzureVMDeploymentInfo thirdDeployment = createDefaultDeployment(1, deploymentRegistrar2);
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 List<String> baseVMNames = Arrays.asList(firstDeployment.getVmBaseName(), secondDeployment.getVmBaseName(), thirdDeployment.getVmBaseName());
for (String base : baseVMNames) {
final String baseName = base + "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);
}
} catch (Exception e) {
LOGGER.log(Level.SEVERE, null, e);
Assert.fail(e.getMessage());
}
}
use of com.azure.resourcemanager.network.models.NetworkInterface in project azure-vm-agents-plugin by jenkinsci.
the class ITAzureVMManagementServiceDelegate method createDeploymentWithMSI.
@Test
public void createDeploymentWithMSI() throws Exception {
AzureVMAgentCleanUpTask.DeploymentRegistrar deploymentRegistrar = mock(AzureVMAgentCleanUpTask.DeploymentRegistrar.class);
when(deploymentRegistrar.getDeploymentTag()).thenReturn(new AzureUtil.DeploymentTag("some_tag/123"));
AzureVMDeploymentInfo deploymentInfo;
deploymentInfo = createDefaultDeployment(1, true, true, false, 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";
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);
Assert.assertTrue(actualVM.isManagedServiceIdentityEnabled());
}
Aggregations