use of com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.DEFAULT_NIC_SPEC in project photon-model by vmware.
the class TestAzureProvisionTask method testProvisionDataDisksAndEnumeration.
/**
* Creates Azure instance with 2 data disks via provision task and enumerate the disks
* and verify disk duplication in local store.
*/
@Test
public void testProvisionDataDisksAndEnumeration() throws Throwable {
ImageSource imageSource = createImageSource(getHost(), this.endpointState, IMAGE_REFERENCE);
// Create a Azure VM compute resource with 2 additional disks.
int numberOfAdditionalDisks = 2;
VMResourceSpec vmResourceSpec = new VMResourceSpec(getHost(), this.computeHost, this.endpointState, azureVMName).withImageSource(imageSource).withNicSpecs(DEFAULT_NIC_SPEC).withNumberOfAdditionalDisks(numberOfAdditionalDisks).withManagedDisk(false);
// create Azure VM compute resource.
this.vmState = createVMResourceFromSpec(vmResourceSpec);
kickOffProvisionTask();
runEnumeration();
// Assert if 2 additional disks were created
List<DiskState> diskStates = this.vmState.diskLinks.stream().map(diskLink -> getHost().getServiceState(null, DiskState.class, UriUtils.buildUri(getHost(), diskLink))).collect(Collectors.toList());
for (DiskState diskState : diskStates) {
if (diskState.bootOrder == 1) {
assertEquals("OS Disk size does not match", AzureTestUtil.AZURE_CUSTOM_OSDISK_SIZE, diskState.capacityMBytes);
} else {
assertEquals("Data Disk size does not match", AzureTestUtil.AZURE_CUSTOM_DATA_DISK_SIZE, diskState.capacityMBytes);
if (!this.isMock) {
assertNotNull(diskState.customProperties);
assertNotNull(diskState.customProperties.get(DISK_CONTROLLER_NUMBER));
}
}
}
// Run enumeration second time to verify disk states are not duplicated
runEnumeration();
ServiceDocumentQueryResult result = ProvisioningUtils.queryAllFactoryResources(this.host, DiskService.FACTORY_LINK);
List<DiskState> diskList = result.documents.keySet().stream().map(diskLink -> getHost().getServiceState(null, DiskState.class, UriUtils.buildUri(getHost(), diskLink))).collect(Collectors.toList());
for (DiskState diskState : diskStates) {
long nameCount = diskList.stream().filter(ds -> ds.name.equalsIgnoreCase(diskState.name)).count();
String msg = String.format("Duplicate of DiskState %s must not be present. ", diskState.name);
assertEquals(msg, 1, nameCount);
long idCount = diskList.stream().filter(ds -> ds.id.equalsIgnoreCase(diskState.id)).count();
String idMsg = String.format("Duplicate of DiskState ID %s must not be present. ", diskState.id);
assertEquals(idMsg, 1, idCount);
}
}
use of com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.DEFAULT_NIC_SPEC in project photon-model by vmware.
the class TestAzureDeleteTask method testProvisionWithPersistentUnmanagedDisk.
/**
* Creates a Azure unmanaged instance with persist options for disks. Checks if VHD blob cleanup happens according to the persist flag.
*/
@Test
public void testProvisionWithPersistentUnmanagedDisk() throws Throwable {
BaseComputeInstanceContext.ImageSource imageSource = createImageSource(getHost(), this.endpointState, IMAGE_REFERENCE);
// Create a Azure VM compute resource with 2 additional disks.
int numberOfAdditionalDisks = 3;
AzureTestUtil.VMResourceSpec vmResourceSpec = new AzureTestUtil.VMResourceSpec(getHost(), this.computeHost, this.endpointState, azureVMName).withImageSource(imageSource).withNicSpecs(DEFAULT_NIC_SPEC).withNumberOfAdditionalDisks(numberOfAdditionalDisks).withPersistentDisks(AzureTestUtil.VMResourceSpec.PersistentDisks.SOME).withExistingStorageAccount(storageAccountName, resourceGroupName).withManagedDisk(false);
// create Azure VM compute resource.
this.vmState = createVMResourceFromSpec(vmResourceSpec);
kickOffProvisionTask();
List<DiskService.DiskState> diskStates = this.vmState.diskLinks.stream().map(diskLink -> getHost().getServiceState(null, DiskService.DiskState.class, UriUtils.buildUri(getHost(), diskLink))).collect(Collectors.toList());
int computeStatesToRemain = 1;
deleteVMs(getHost(), this.vmState.documentSelfLink, this.isMock, computeStatesToRemain);
// assertions
if (!this.isMock) {
Azure az = getAzureSdkClients().getAzureClient();
String key = az.storageAccounts().getByResourceGroup(resourceGroupName, storageAccountName).getKeys().get(0).value();
CloudStorageAccount cloudStorageAccount = CloudStorageAccount.parse(String.format(STORAGE_CONNECTION_STRING, storageAccountName, key));
CloudBlobClient client = cloudStorageAccount.createCloudBlobClient();
CloudBlobContainer container = client.getContainerReference("vhds");
for (DiskService.DiskState diskState : diskStates) {
String vhdBlobName = diskState.id.substring(diskState.id.lastIndexOf("/") + 1);
CloudPageBlob blob = container.getPageBlobReference(vhdBlobName);
assertEquals("Disk VHD blob should persist", diskState.persistent, blob.exists());
}
}
}
Aggregations