Search in sources :

Example 16 with DataDisk

use of com.microsoft.azure.management.compute.DataDisk 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());
}
Also used : NicSpec(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.AzureNicSpecs.NicSpec) NetworkManagementClientImpl(com.microsoft.azure.management.network.implementation.NetworkManagementClientImpl) ProvisionComputeTaskService(com.vmware.photon.controller.model.tasks.ProvisionComputeTaskService) IpAssignment(com.vmware.photon.controller.model.resources.NetworkInterfaceDescriptionService.IpAssignment) AzureTestUtil.deleteVMs(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.deleteVMs) SHARED_NETWORK_NIC_SPEC(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.SHARED_NETWORK_NIC_SPEC) VirtualNetworkInner(com.microsoft.azure.management.network.implementation.VirtualNetworkInner) DISK_CONTROLLER_NUMBER(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.DISK_CONTROLLER_NUMBER) AzureUriPaths(com.vmware.photon.controller.model.adapters.azure.AzureUriPaths) NetworkInterfaceStateWithDescription(com.vmware.photon.controller.model.resources.NetworkInterfaceService.NetworkInterfaceStateWithDescription) ResourceGroupState(com.vmware.photon.controller.model.resources.ResourceGroupService.ResourceGroupState) Map(java.util.Map) After(org.junit.After) StorageDescription(com.vmware.photon.controller.model.resources.StorageDescriptionService.StorageDescription) Assert.fail(org.junit.Assert.fail) ServiceDocumentQueryResult(com.vmware.xenon.common.ServiceDocumentQueryResult) ProvisioningUtils(com.vmware.photon.controller.model.tasks.ProvisioningUtils) OSDisk(com.microsoft.azure.management.compute.OSDisk) EnumSet(java.util.EnumSet) ResourceEnumerationTaskService(com.vmware.photon.controller.model.tasks.ResourceEnumerationTaskService) AzureConstants(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants) DEFAULT_NIC_SPEC(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.DEFAULT_NIC_SPEC) ComputeStatsResponse(com.vmware.photon.controller.model.adapterapi.ComputeStatsResponse) ComputeStatsRequest(com.vmware.photon.controller.model.adapterapi.ComputeStatsRequest) NetworkInterfaceState(com.vmware.photon.controller.model.resources.NetworkInterfaceService.NetworkInterfaceState) StatelessService(com.vmware.xenon.common.StatelessService) VMResourceSpec(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.VMResourceSpec) TestUtils(com.vmware.photon.controller.model.tasks.TestUtils) DiskState(com.vmware.photon.controller.model.resources.DiskService.DiskState) UUID(java.util.UUID) AzureTestUtil.createPrivateImageSource(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.createPrivateImageSource) AzureTestUtil.createVMResourceFromSpec(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.createVMResourceFromSpec) Collectors(java.util.stream.Collectors) NO_PUBLIC_IP_NIC_SPEC(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.NO_PUBLIC_IP_NIC_SPEC) List(java.util.List) AzureUtils(com.vmware.photon.controller.model.adapters.azure.utils.AzureUtils) AzureTestUtil.createImageSource(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.createImageSource) StorageDescriptionService(com.vmware.photon.controller.model.resources.StorageDescriptionService) UriUtils(com.vmware.xenon.common.UriUtils) Optional(java.util.Optional) NetworkSecurityGroupInner(com.microsoft.azure.management.network.implementation.NetworkSecurityGroupInner) AzureEnumerationAdapterService(com.vmware.photon.controller.model.adapters.azure.enumeration.AzureEnumerationAdapterService) TaskOption(com.vmware.photon.controller.model.tasks.TaskOption) DiskService(com.vmware.photon.controller.model.resources.DiskService) AzureTestUtil.createDefaultResourceGroupState(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.createDefaultResourceGroupState) ComputeProperties(com.vmware.photon.controller.model.ComputeProperties) ResourceGroupStateType(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.ResourceGroupStateType) ResourceGroupInner(com.microsoft.azure.management.resources.implementation.ResourceGroupInner) PhotonModelMetricServices(com.vmware.photon.controller.model.PhotonModelMetricServices) Function(java.util.function.Function) AzureBaseTest(com.vmware.photon.controller.model.adapters.azure.base.AzureBaseTest) ProvisionComputeTaskState(com.vmware.photon.controller.model.tasks.ProvisionComputeTaskService.ProvisionComputeTaskState) AzureTestUtil.createDefaultVMResource(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.createDefaultVMResource) Level(java.util.logging.Level) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) EnumerationAction(com.vmware.photon.controller.model.adapterapi.EnumerationAction) Assume(org.junit.Assume) IMAGE_REFERENCE(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.IMAGE_REFERENCE) VirtualMachineInner(com.microsoft.azure.management.compute.implementation.VirtualMachineInner) AzureNicSpecs(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.AzureNicSpecs) PRIVATE_IP_NIC_SPEC(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.PRIVATE_IP_NIC_SPEC) DataDisk(com.microsoft.azure.management.compute.DataDisk) Assert.assertNotNull(org.junit.Assert.assertNotNull) Operation(com.vmware.xenon.common.Operation) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) ImageSource(com.vmware.photon.controller.model.adapters.util.instance.BaseComputeInstanceContext.ImageSource) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) AZURE_CUSTOM_DATA_DISK_SIZE(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.AZURE_CUSTOM_DATA_DISK_SIZE) Assert.assertNull(org.junit.Assert.assertNull) Ignore(org.junit.Ignore) AzureTestUtil.generateName(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.generateName) Assert.assertEquals(org.junit.Assert.assertEquals) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) OSDisk(com.microsoft.azure.management.compute.OSDisk) DataDisk(com.microsoft.azure.management.compute.DataDisk) Optional(java.util.Optional) VirtualMachineInner(com.microsoft.azure.management.compute.implementation.VirtualMachineInner) DiskState(com.vmware.photon.controller.model.resources.DiskService.DiskState)

Example 17 with DataDisk

use of com.microsoft.azure.management.compute.DataDisk in project photon-model by vmware.

the class AzureDiskEnumerationServiceTest method testVMAndDiskEnumeration.

@Test
public void testVMAndDiskEnumeration() throws Throwable {
    // Exit if it is mock
    if (this.isMock) {
        return;
    }
    this.resourceGroup = SdkContext.randomResourceName(RESOURCE_GROUP_NAME, RESOURCE_GROUP_NAME.length() + 5);
    // Create a vm with one additional disk
    VirtualMachine vm = getAzureSdkClients().getComputeManager().virtualMachines().define("TestVM").withRegion(Region.US_WEST).withNewResourceGroup(this.resourceGroup).withNewPrimaryNetwork("10.0.0.0/28").withPrimaryPrivateIPAddressDynamic().withoutPrimaryPublicIPAddress().withPopularLinuxImage(KnownLinuxVirtualMachineImage.UBUNTU_SERVER_16_04_LTS).withRootUsername(AzureTestUtil.AZURE_ADMIN_USERNAME).withRootPassword(AzureTestUtil.AZURE_ADMIN_PASSWORD).withNewDataDisk(5).create();
    assertNotNull(vm);
    DataDisk dataDisk = vm.storageProfile().dataDisks().get(0);
    assertNotNull(dataDisk);
    ComputeEnumerateResourceRequest resourceRequest = kickOffEnumeration();
    ComputeEnumerateAdapterRequest request = new ComputeEnumerateAdapterRequest(resourceRequest, this.authState, this.computeHost);
    // Run VM enumeration
    patchServiceSynchronously(AzureComputeEnumerationAdapterService.SELF_LINK, request);
    // Run disk enumeration
    patchServiceSynchronously(AzureDiskEnumerationAdapterService.SELF_LINK, request);
    // Verify disk state is created in local store
    Map<String, DiskState> diskStateMap = ProvisioningUtils.getResourceStates(getHost(), DiskService.FACTORY_LINK, DiskState.class);
    assertTrue(diskStateMap.keySet().stream().anyMatch(s -> s.equalsIgnoreCase(dataDisk.managedDisk().id())));
    // Detach disk
    vm.update().withoutDataDisk(dataDisk.lun()).apply();
    // Run Disk enumeration
    patchServiceSynchronously(AzureDiskEnumerationAdapterService.SELF_LINK, request);
    // Verify if the status of disk state is updated to Available state or not
    diskStateMap = ProvisioningUtils.getResourceStates(getHost(), DiskService.FACTORY_LINK, DiskState.class);
    diskStateMap.values().forEach(diskState -> {
        if (diskState.name.equalsIgnoreCase(dataDisk.name())) {
            assertTrue("Status of disk state should be Available", diskState.status.equals(DiskService.DiskStatus.AVAILABLE));
        }
    });
}
Also used : VirtualMachine(com.microsoft.azure.management.compute.VirtualMachine) ComputeEnumerateResourceRequest(com.vmware.photon.controller.model.adapterapi.ComputeEnumerateResourceRequest) Region(com.microsoft.azure.management.resources.fluentcore.arm.Region) AzureBaseTest(com.vmware.photon.controller.model.adapters.azure.base.AzureBaseTest) TagsUtil(com.vmware.photon.controller.model.adapters.util.TagsUtil) Level(java.util.logging.Level) TagState(com.vmware.photon.controller.model.resources.TagService.TagState) Map(java.util.Map) After(org.junit.After) EnumerationAction(com.vmware.photon.controller.model.adapterapi.EnumerationAction) ProvisioningUtils(com.vmware.photon.controller.model.tasks.ProvisioningUtils) AzureTestUtil(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil) AzureConstants(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants) DataDisk(com.microsoft.azure.management.compute.DataDisk) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) DiskState(com.vmware.photon.controller.model.resources.DiskService.DiskState) Test(org.junit.Test) TimeUnit(java.util.concurrent.TimeUnit) Disk(com.microsoft.azure.management.compute.Disk) UriUtils(com.vmware.xenon.common.UriUtils) PhotonModelConstants(com.vmware.photon.controller.model.constants.PhotonModelConstants) ComputeEnumerateAdapterRequest(com.vmware.photon.controller.model.adapters.util.ComputeEnumerateAdapterRequest) KnownLinuxVirtualMachineImage(com.microsoft.azure.management.compute.KnownLinuxVirtualMachineImage) DiskService(com.vmware.photon.controller.model.resources.DiskService) SdkContext(com.microsoft.azure.management.resources.fluentcore.utils.SdkContext) DataDisk(com.microsoft.azure.management.compute.DataDisk) ComputeEnumerateResourceRequest(com.vmware.photon.controller.model.adapterapi.ComputeEnumerateResourceRequest) ComputeEnumerateAdapterRequest(com.vmware.photon.controller.model.adapters.util.ComputeEnumerateAdapterRequest) DiskState(com.vmware.photon.controller.model.resources.DiskService.DiskState) VirtualMachine(com.microsoft.azure.management.compute.VirtualMachine) AzureBaseTest(com.vmware.photon.controller.model.adapters.azure.base.AzureBaseTest) Test(org.junit.Test)

Aggregations

DataDisk (com.microsoft.azure.management.compute.DataDisk)17 VirtualMachineUnmanagedDataDisk (com.microsoft.azure.management.compute.VirtualMachineUnmanagedDataDisk)8 VirtualMachineDataDisk (com.microsoft.azure.management.compute.VirtualMachineDataDisk)7 DiskState (com.vmware.photon.controller.model.resources.DiskService.DiskState)5 Map (java.util.Map)5 OSDisk (com.microsoft.azure.management.compute.OSDisk)4 DiskService (com.vmware.photon.controller.model.resources.DiskService)4 Operation (com.vmware.xenon.common.Operation)4 ArrayList (java.util.ArrayList)4 Disk (com.microsoft.azure.management.compute.Disk)3 VirtualMachine (com.microsoft.azure.management.compute.VirtualMachine)3 ManagedDiskParametersInner (com.microsoft.azure.management.compute.implementation.ManagedDiskParametersInner)3 VirtualMachineInner (com.microsoft.azure.management.compute.implementation.VirtualMachineInner)3 AzureConstants (com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants)3 UriUtils (com.vmware.xenon.common.UriUtils)3 Level (java.util.logging.Level)3 StorageProfile (com.microsoft.azure.management.compute.StorageProfile)2 VirtualHardDisk (com.microsoft.azure.management.compute.VirtualHardDisk)2 NetworkManagementClientImpl (com.microsoft.azure.management.network.implementation.NetworkManagementClientImpl)2 NetworkSecurityGroupInner (com.microsoft.azure.management.network.implementation.NetworkSecurityGroupInner)2