Search in sources :

Example 1 with DEFAULT_NIC_SPEC

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);
    }
}
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) DiskState(com.vmware.photon.controller.model.resources.DiskService.DiskState) AzureTestUtil.createPrivateImageSource(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.createPrivateImageSource) AzureTestUtil.createImageSource(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.createImageSource) ImageSource(com.vmware.photon.controller.model.adapters.util.instance.BaseComputeInstanceContext.ImageSource) VMResourceSpec(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.VMResourceSpec) ServiceDocumentQueryResult(com.vmware.xenon.common.ServiceDocumentQueryResult) AzureBaseTest(com.vmware.photon.controller.model.adapters.azure.base.AzureBaseTest) Test(org.junit.Test)

Example 2 with DEFAULT_NIC_SPEC

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());
        }
    }
}
Also used : ProvisionComputeTaskService(com.vmware.photon.controller.model.tasks.ProvisionComputeTaskService) AzureTestUtil.deleteVMs(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.deleteVMs) PhotonModelMetricServices(com.vmware.photon.controller.model.PhotonModelMetricServices) AZURE_RESOURCE_GROUP_LOCATION(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.AZURE_RESOURCE_GROUP_LOCATION) AzureBaseTest(com.vmware.photon.controller.model.adapters.azure.base.AzureBaseTest) Azure(com.microsoft.azure.management.Azure) CloudBlobContainer(com.microsoft.azure.storage.blob.CloudBlobContainer) After(org.junit.After) CloudPageBlob(com.microsoft.azure.storage.blob.CloudPageBlob) IMAGE_REFERENCE(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.IMAGE_REFERENCE) STORAGE_CONNECTION_STRING(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.STORAGE_CONNECTION_STRING) Before(org.junit.Before) DEFAULT_NIC_SPEC(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.DEFAULT_NIC_SPEC) CloudBlobClient(com.microsoft.azure.storage.blob.CloudBlobClient) TestUtils(com.vmware.photon.controller.model.tasks.TestUtils) Test(org.junit.Test) AzureTestUtil.createVMResourceFromSpec(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.createVMResourceFromSpec) CloudStorageAccount(com.microsoft.azure.storage.CloudStorageAccount) Collectors(java.util.stream.Collectors) List(java.util.List) BaseComputeInstanceContext(com.vmware.photon.controller.model.adapters.util.instance.BaseComputeInstanceContext) AzureTestUtil.createImageSource(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.createImageSource) AzureTestUtil.generateName(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.generateName) UriUtils(com.vmware.xenon.common.UriUtils) ComputeService(com.vmware.photon.controller.model.resources.ComputeService) DiskService(com.vmware.photon.controller.model.resources.DiskService) Assert.assertEquals(org.junit.Assert.assertEquals) SdkContext(com.microsoft.azure.management.resources.fluentcore.utils.SdkContext) Azure(com.microsoft.azure.management.Azure) CloudBlobClient(com.microsoft.azure.storage.blob.CloudBlobClient) BaseComputeInstanceContext(com.vmware.photon.controller.model.adapters.util.instance.BaseComputeInstanceContext) CloudStorageAccount(com.microsoft.azure.storage.CloudStorageAccount) DiskService(com.vmware.photon.controller.model.resources.DiskService) CloudBlobContainer(com.microsoft.azure.storage.blob.CloudBlobContainer) CloudPageBlob(com.microsoft.azure.storage.blob.CloudPageBlob) AzureBaseTest(com.vmware.photon.controller.model.adapters.azure.base.AzureBaseTest) Test(org.junit.Test)

Aggregations

PhotonModelMetricServices (com.vmware.photon.controller.model.PhotonModelMetricServices)2 AzureBaseTest (com.vmware.photon.controller.model.adapters.azure.base.AzureBaseTest)2 DEFAULT_NIC_SPEC (com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.DEFAULT_NIC_SPEC)2 IMAGE_REFERENCE (com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.IMAGE_REFERENCE)2 AzureTestUtil.createImageSource (com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.createImageSource)2 AzureTestUtil.createVMResourceFromSpec (com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.createVMResourceFromSpec)2 AzureTestUtil.deleteVMs (com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.deleteVMs)2 AzureTestUtil.generateName (com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.generateName)2 DiskService (com.vmware.photon.controller.model.resources.DiskService)2 ProvisionComputeTaskService (com.vmware.photon.controller.model.tasks.ProvisionComputeTaskService)2 TestUtils (com.vmware.photon.controller.model.tasks.TestUtils)2 UriUtils (com.vmware.xenon.common.UriUtils)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 After (org.junit.After)2 Assert.assertEquals (org.junit.Assert.assertEquals)2 Test (org.junit.Test)2 Azure (com.microsoft.azure.management.Azure)1 DataDisk (com.microsoft.azure.management.compute.DataDisk)1 OSDisk (com.microsoft.azure.management.compute.OSDisk)1