Search in sources :

Example 11 with DiskEncryptionSetDeletionRequest

use of com.sequenceiq.cloudbreak.cloud.model.encryption.DiskEncryptionSetDeletionRequest in project cloudbreak by hortonworks.

the class AzureEncryptionResourcesTest method testDeleteDiskEncryptionSetShouldThrowExceptionWhenVaultResourceGroupIsNotFound.

@Test
public void testDeleteDiskEncryptionSetShouldThrowExceptionWhenVaultResourceGroupIsNotFound() {
    List<CloudResource> resources = getResources("/subscriptions/dummySubscriptionId/resourceGroups/dummyDesResourceGroup/providers/" + "Microsoft.Compute/diskEncryptionSets/dummyDesId");
    DiskEncryptionSetDeletionRequest deletionRequest = new DiskEncryptionSetDeletionRequest.Builder().withCloudCredential(cloudCredential).withCloudContext(cloudContext).withCloudResources(resources).build();
    initCloudResourceHelper(resources);
    EncryptionSetIdentity identity = new EncryptionSetIdentity().withType(DiskEncryptionSetIdentityType.SYSTEM_ASSIGNED);
    ReflectionTestUtils.setField(identity, "principalId", DES_PRINCIPAL_ID);
    DiskEncryptionSetInner des = (DiskEncryptionSetInner) new DiskEncryptionSetInner().withEncryptionType(DiskEncryptionSetType.ENCRYPTION_AT_REST_WITH_CUSTOMER_KEY).withActiveKey(new KeyForDiskEncryptionSet().withKeyUrl("https://dummyVaultName.vault.azure.net/keys/dummyKeyName/dummyKeyVersion").withSourceVault(new SourceVault().withId("invaildSourceVault"))).withIdentity(identity).withLocation("dummyRegion");
    when(azureClient.getDiskEncryptionSetByName(any(), any())).thenReturn(des);
    when(azureClientService.getClient(cloudCredential)).thenReturn(azureClient);
    initRetry();
    initExceptionConversion();
    initActionFailedExceptionConversion();
    verifyActionFailedException(IllegalArgumentException.class, () -> underTest.deleteDiskEncryptionSet(deletionRequest), "Failed to deduce vault resource group name from source vault ID " + "\"invaildSourceVault\"");
}
Also used : SourceVault(com.microsoft.azure.management.compute.SourceVault) KeyForDiskEncryptionSet(com.microsoft.azure.management.compute.KeyForDiskEncryptionSet) DiskEncryptionSetDeletionRequest(com.sequenceiq.cloudbreak.cloud.model.encryption.DiskEncryptionSetDeletionRequest) EncryptionSetIdentity(com.microsoft.azure.management.compute.EncryptionSetIdentity) DiskEncryptionSetInner(com.microsoft.azure.management.compute.implementation.DiskEncryptionSetInner) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 12 with DiskEncryptionSetDeletionRequest

use of com.sequenceiq.cloudbreak.cloud.model.encryption.DiskEncryptionSetDeletionRequest in project cloudbreak by hortonworks.

the class AzureEncryptionResourcesTest method testDeleteDiskEncryptionSetShouldDeduceValidResourceGroupAndDiskEncryptionSetNameWhenDesAndVaultHaveSameResourceGroup.

@Test
public void testDeleteDiskEncryptionSetShouldDeduceValidResourceGroupAndDiskEncryptionSetNameWhenDesAndVaultHaveSameResourceGroup() {
    List<CloudResource> resources = getResources("/subscriptions/dummySubscriptionId/resourceGroups/dummyResourceGroup/providers/" + "Microsoft.Compute/diskEncryptionSets/dummyDesId");
    DiskEncryptionSetDeletionRequest deletionRequest = new DiskEncryptionSetDeletionRequest.Builder().withCloudCredential(cloudCredential).withCloudContext(cloudContext).withCloudResources(resources).build();
    initCloudResourceHelper(resources);
    EncryptionSetIdentity identity = new EncryptionSetIdentity().withType(DiskEncryptionSetIdentityType.SYSTEM_ASSIGNED);
    ReflectionTestUtils.setField(identity, "principalId", DES_PRINCIPAL_ID);
    DiskEncryptionSetInner des = (DiskEncryptionSetInner) new DiskEncryptionSetInner().withEncryptionType(DiskEncryptionSetType.ENCRYPTION_AT_REST_WITH_CUSTOMER_KEY).withActiveKey(new KeyForDiskEncryptionSet().withKeyUrl("https://dummyVaultName.vault.azure.net/keys/dummyKeyName/dummyKeyVersion").withSourceVault(new SourceVault().withId("/subscriptions/dummySubs/resourceGroups/dummyResourceGroup/providers/Microsoft.KeyVault/vaults/dummyVaultName"))).withIdentity(identity).withLocation("dummyRegion");
    when(azureClient.getDiskEncryptionSetByName(any(), any())).thenReturn(des);
    when(azureClientService.getClient(cloudCredential)).thenReturn(azureClient);
    when(azureClient.keyVaultExists("dummyResourceGroup", "dummyVaultName")).thenReturn(Boolean.TRUE);
    initRetry();
    underTest.deleteDiskEncryptionSet(deletionRequest);
    verify(azureClient).deleteDiskEncryptionSet("dummyResourceGroup", "dummyDesId");
    verify(azureClient).removeKeyVaultAccessPolicyFromServicePrincipal("dummyResourceGroup", "dummyVaultName", DES_PRINCIPAL_ID);
    verify(persistenceNotifier).notifyDeletion(deletionRequest.getCloudResources().iterator().next(), deletionRequest.getCloudContext());
}
Also used : SourceVault(com.microsoft.azure.management.compute.SourceVault) KeyForDiskEncryptionSet(com.microsoft.azure.management.compute.KeyForDiskEncryptionSet) DiskEncryptionSetDeletionRequest(com.sequenceiq.cloudbreak.cloud.model.encryption.DiskEncryptionSetDeletionRequest) EncryptionSetIdentity(com.microsoft.azure.management.compute.EncryptionSetIdentity) DiskEncryptionSetInner(com.microsoft.azure.management.compute.implementation.DiskEncryptionSetInner) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 13 with DiskEncryptionSetDeletionRequest

use of com.sequenceiq.cloudbreak.cloud.model.encryption.DiskEncryptionSetDeletionRequest in project cloudbreak by hortonworks.

the class AzureEncryptionResourcesTest method testDeleteDiskEncryptionSetExceptionThrownWhenInvalidCredential.

@Test
void testDeleteDiskEncryptionSetExceptionThrownWhenInvalidCredential() {
    List<CloudResource> resources = getResources("dummyDesId");
    DiskEncryptionSetDeletionRequest deletionRequest = new DiskEncryptionSetDeletionRequest.Builder().withCloudCredential(cloudCredential).withCloudContext(cloudContext).withCloudResources(resources).build();
    initCloudResourceHelper(resources);
    when(azureClientService.getClient(cloudCredential)).thenThrow(new UnsupportedOperationException("Serious problem"));
    initExceptionConversion();
    verifyException(UnsupportedOperationException.class, () -> underTest.deleteDiskEncryptionSet(deletionRequest), "Serious problem");
}
Also used : DiskEncryptionSetDeletionRequest(com.sequenceiq.cloudbreak.cloud.model.encryption.DiskEncryptionSetDeletionRequest) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 14 with DiskEncryptionSetDeletionRequest

use of com.sequenceiq.cloudbreak.cloud.model.encryption.DiskEncryptionSetDeletionRequest in project cloudbreak by hortonworks.

the class AzureEncryptionResourcesTest method testDeleteDiskEncryptionSetShouldDeduceValidDiskEncryptionSetNameAndCheckAndDeleteResourceGroupWhenDesResourceGroupIsCreatedByCDP.

@Test
public void testDeleteDiskEncryptionSetShouldDeduceValidDiskEncryptionSetNameAndCheckAndDeleteResourceGroupWhenDesResourceGroupIsCreatedByCDP() {
    CloudResource desCloudResource = new CloudResource.Builder().name("Des").type(AZURE_DISK_ENCRYPTION_SET).reference("/subscriptions/dummySubscriptionId/resourceGroups/dummy-CDP_DES-ResourceGroup/providers/" + "Microsoft.Compute/diskEncryptionSets/dummyDesId").status(CREATED).build();
    CloudResource rgCloudResource = new CloudResource.Builder().name("dummy-CDP_DES-ResourceGroup").type(AZURE_RESOURCE_GROUP).reference("uniqueDummyId").status(CREATED).build();
    List<CloudResource> resources = List.of(desCloudResource, rgCloudResource);
    DiskEncryptionSetDeletionRequest deletionRequest = new DiskEncryptionSetDeletionRequest.Builder().withCloudCredential(cloudCredential).withCloudContext(cloudContext).withCloudResources(resources).build();
    EncryptionSetIdentity identity = new EncryptionSetIdentity().withType(DiskEncryptionSetIdentityType.SYSTEM_ASSIGNED);
    ReflectionTestUtils.setField(identity, "principalId", DES_PRINCIPAL_ID);
    DiskEncryptionSetInner des = (DiskEncryptionSetInner) new DiskEncryptionSetInner().withEncryptionType(DiskEncryptionSetType.ENCRYPTION_AT_REST_WITH_CUSTOMER_KEY).withActiveKey(new KeyForDiskEncryptionSet().withKeyUrl("https://dummyVaultName.vault.azure.net/keys/dummyKeyName/dummyKeyVersion").withSourceVault(new SourceVault().withId("/subscriptions/dummySubs/resourceGroups/dummyVaultResourceGroup/providers/Microsoft.KeyVault/vaults/dummyVaultName"))).withIdentity(identity).withLocation("dummyRegion");
    when(cloudResourceHelper.getResourceTypeFromList(AZURE_DISK_ENCRYPTION_SET, resources)).thenReturn(resources.isEmpty() ? Optional.empty() : Optional.of(resources.get(0)));
    when(cloudResourceHelper.getResourceTypeFromList(AZURE_RESOURCE_GROUP, resources)).thenReturn(resources.isEmpty() ? Optional.empty() : Optional.of(resources.get(1)));
    when(azureClient.getDiskEncryptionSetByName(any(), any())).thenReturn(des);
    when(azureClientService.getClient(cloudCredential)).thenReturn(azureClient);
    when(azureClient.resourceGroupExists(eq("dummy-CDP_DES-ResourceGroup"))).thenReturn(Boolean.TRUE);
    when(azureClient.keyVaultExists("dummyVaultResourceGroup", "dummyVaultName")).thenReturn(Boolean.TRUE);
    initRetry();
    underTest.deleteDiskEncryptionSet(deletionRequest);
    verify(azureClient).deleteDiskEncryptionSet("dummy-CDP_DES-ResourceGroup", "dummyDesId");
    verify(azureClient).removeKeyVaultAccessPolicyFromServicePrincipal("dummyVaultResourceGroup", "dummyVaultName", DES_PRINCIPAL_ID);
    verify(azureClient).deleteResourceGroup("dummy-CDP_DES-ResourceGroup");
    verify(persistenceNotifier).notifyDeletion(deletionRequest.getCloudResources().get(0), deletionRequest.getCloudContext());
    verify(persistenceNotifier).notifyDeletion(deletionRequest.getCloudResources().get(1), deletionRequest.getCloudContext());
}
Also used : SourceVault(com.microsoft.azure.management.compute.SourceVault) KeyForDiskEncryptionSet(com.microsoft.azure.management.compute.KeyForDiskEncryptionSet) DiskEncryptionSetDeletionRequest(com.sequenceiq.cloudbreak.cloud.model.encryption.DiskEncryptionSetDeletionRequest) EncryptionSetIdentity(com.microsoft.azure.management.compute.EncryptionSetIdentity) DiskEncryptionSetInner(com.microsoft.azure.management.compute.implementation.DiskEncryptionSetInner) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)14 DiskEncryptionSetDeletionRequest (com.sequenceiq.cloudbreak.cloud.model.encryption.DiskEncryptionSetDeletionRequest)14 Test (org.junit.jupiter.api.Test)14 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)11 EncryptionSetIdentity (com.microsoft.azure.management.compute.EncryptionSetIdentity)5 KeyForDiskEncryptionSet (com.microsoft.azure.management.compute.KeyForDiskEncryptionSet)5 SourceVault (com.microsoft.azure.management.compute.SourceVault)5 DiskEncryptionSetInner (com.microsoft.azure.management.compute.implementation.DiskEncryptionSetInner)5 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)4 CloudConnector (com.sequenceiq.cloudbreak.cloud.CloudConnector)3 EncryptionResources (com.sequenceiq.cloudbreak.cloud.EncryptionResources)3 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)3 CloudPlatformConnectors (com.sequenceiq.cloudbreak.cloud.init.CloudPlatformConnectors)3 CloudPlatformVariant (com.sequenceiq.cloudbreak.cloud.model.CloudPlatformVariant)3 Location (com.sequenceiq.cloudbreak.cloud.model.Location)3 Platform (com.sequenceiq.cloudbreak.cloud.model.Platform)3 Region (com.sequenceiq.cloudbreak.cloud.model.Region)3 Variant (com.sequenceiq.cloudbreak.cloud.model.Variant)3 CreatedDiskEncryptionSet (com.sequenceiq.cloudbreak.cloud.model.encryption.CreatedDiskEncryptionSet)3 DiskEncryptionSetCreationRequest (com.sequenceiq.cloudbreak.cloud.model.encryption.DiskEncryptionSetCreationRequest)3