use of com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.AZURE_CUSTOM_DATA_DISK_SIZE in project photon-model by vmware.
the class TestAzureProvisionTask method assertConfigurationOfDisks.
private void assertConfigurationOfDisks(int numberOfAdditionalDisks, int numberOfDataDisksOnImage) {
ComputeState vm = getHost().getServiceState(null, ComputeState.class, UriUtils.buildUri(getHost(), this.vmState.documentSelfLink));
List<DiskState> diskStates = vm.diskLinks.stream().map(diskLink -> getHost().getServiceState(null, DiskState.class, UriUtils.buildUri(getHost(), diskLink))).collect(Collectors.toList());
if (numberOfDataDisksOnImage == 0) {
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);
assertNotNull(diskState.customProperties);
assertNotNull(diskState.customProperties.get(DISK_CONTROLLER_NUMBER));
}
}
}
if (this.isMock) {
// return. Nothing to check on Azure.
return;
}
final String vmRGName = vm.customProperties.get(ComputeProperties.RESOURCE_GROUP_NAME);
VirtualMachineInner provisionedVM = null;
try {
provisionedVM = AzureTestUtil.getAzureVirtualMachine(getAzureSdkClients().getComputeManagementClientImpl(), vmRGName, this.vmState.name.replace('_', '-'));
} catch (Exception e) {
fail("Unable to get Azure VM details: " + e.getMessage());
}
final Function<String, Optional<DiskState>> findDiskStateByName = diskName -> diskStates.stream().filter(dS -> diskName.equals(dS.name)).findFirst();
// Validate boot DiskState against Azure osDisk
{
final OSDisk azureOsDisk = provisionedVM.storageProfile().osDisk();
Optional<DiskState> bootDiskOpt = findDiskStateByName.apply(azureOsDisk.name());
if (bootDiskOpt.isPresent()) {
final DiskState bootDiskState = bootDiskOpt.get();
assertNotNull("Azure OS Disk with name '" + azureOsDisk.name() + "' does not match any DiskState by name", bootDiskState);
if (bootDiskState.customProperties != null && bootDiskState.customProperties.containsKey(AzureConstants.AZURE_MANAGED_DISK_TYPE)) {
assertEquals("Boot DiskState.id does not match Azure managed disk id", azureOsDisk.managedDisk().id(), bootDiskState.id);
} else {
assertEquals("Boot DiskState.id does not match Azure.osDisk.vhd.uri", AzureUtils.canonizeId(azureOsDisk.vhd().uri()), bootDiskState.id);
}
assertEquals("OS Disk size of the VM in azure does not match with the intended size", AzureTestUtil.AZURE_CUSTOM_OSDISK_SIZE, azureOsDisk.diskSizeGB() * 1024);
} else {
fail("Mismatch in boot disk name.");
}
}
for (DataDisk azureDataDisk : provisionedVM.storageProfile().dataDisks()) {
Optional<DiskState> dataDiskOpt = findDiskStateByName.apply(azureDataDisk.name());
if (dataDiskOpt.isPresent()) {
DiskState dataDiskState = dataDiskOpt.get();
assertNotNull("Azure Data Disk with name '" + azureDataDisk.name() + "' does not match any DiskState by name", dataDiskState);
if (dataDiskState.customProperties != null && dataDiskState.customProperties.containsKey(AzureConstants.AZURE_MANAGED_DISK_TYPE)) {
assertEquals("Data Disk State id does not match Azure managed disk id.", azureDataDisk.managedDisk().id(), dataDiskState.id);
} else {
assertEquals("Data Disk State id does not match Azure DataDisk.vhd.uri", AzureUtils.canonizeId(azureDataDisk.vhd().uri()), dataDiskState.id);
}
// assert size of each of the attached disks only in case of public image
if (numberOfDataDisksOnImage == 0) {
assertEquals("Mismatch in intended size of data disks " + azureDataDisk.name(), AZURE_CUSTOM_DATA_DISK_SIZE, azureDataDisk.diskSizeGB().longValue() * 1024);
}
assertEquals("LUN of DiskState does not match Azure.dataDisk.lun", String.valueOf(azureDataDisk.lun()), dataDiskState.customProperties.get(DISK_CONTROLLER_NUMBER));
} else {
fail("Data Disks not found.");
}
}
assertEquals("Mismatch in number of data disks found on VM in azure", numberOfAdditionalDisks + numberOfDataDisksOnImage, provisionedVM.storageProfile().dataDisks().size());
}
Aggregations