Search in sources :

Example 1 with DiskEncryptionSetDeletionRequest

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

the class AzureEncryptionResourcesTest method testDeleteDiskEncryptionSetWhenExceptionDuringDiskEncryptionSetExistenceCheck.

@Test
void testDeleteDiskEncryptionSetWhenExceptionDuringDiskEncryptionSetExistenceCheck() {
    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);
    when(azureClient.getDiskEncryptionSetByName(any(), any())).thenThrow(new UnsupportedOperationException("Serious problem"));
    when(azureClientService.getClient(cloudCredential)).thenReturn(azureClient);
    initRetry();
    initExceptionConversion();
    initActionFailedExceptionConversion();
    verifyActionFailedException(UnsupportedOperationException.class, () -> underTest.deleteDiskEncryptionSet(deletionRequest), "Serious problem");
    verify(azureClient, never()).deleteDiskEncryptionSet("dummyResourceGroup", "dummyDesId");
    verify(persistenceNotifier, never()).notifyDeletion(deletionRequest.getCloudResources().iterator().next(), deletionRequest.getCloudContext());
}
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 2 with DiskEncryptionSetDeletionRequest

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

the class AzureEncryptionResourcesTest method testDeleteDiskEncryptionSetShouldThrowExceptionWhenResourceGroupIsNotFound.

@Test
public void testDeleteDiskEncryptionSetShouldThrowExceptionWhenResourceGroupIsNotFound() {
    List<CloudResource> resources = getResources("/subscriptions/dummySubscriptionId/resourceGroups/wrongValuesFramed/diskEncryptionSets/dummyDesName");
    DiskEncryptionSetDeletionRequest deletionRequest = new DiskEncryptionSetDeletionRequest.Builder().withCloudCredential(cloudCredential).withCloudContext(cloudContext).withCloudResources(resources).build();
    initCloudResourceHelper(resources);
    when(azureClientService.getClient(cloudCredential)).thenReturn(azureClient);
    initExceptionConversion();
    verifyException(IllegalArgumentException.class, () -> underTest.deleteDiskEncryptionSet(deletionRequest), "Failed to deduce Disk Encryption Set's resource group name from given resource id " + "\"/subscriptions/dummySubscriptionId/resourceGroups/wrongValuesFramed/diskEncryptionSets/dummyDesName\"");
}
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 3 with DiskEncryptionSetDeletionRequest

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

the class AzureEncryptionResourcesTest method testDeleteDiskEncryptionSetShouldThrowExceptionWhenDiskEncryptionSetNameIsNotFound.

@Test
public void testDeleteDiskEncryptionSetShouldThrowExceptionWhenDiskEncryptionSetNameIsNotFound() {
    List<CloudResource> resources = getResources("dummyDesId");
    DiskEncryptionSetDeletionRequest deletionRequest = new DiskEncryptionSetDeletionRequest.Builder().withCloudCredential(cloudCredential).withCloudContext(cloudContext).withCloudResources(resources).build();
    initCloudResourceHelper(resources);
    when(azureClientService.getClient(cloudCredential)).thenReturn(azureClient);
    initExceptionConversion();
    verifyException(IllegalArgumentException.class, () -> underTest.deleteDiskEncryptionSet(deletionRequest), "Failed to deduce Disk Encryption Set name from given resource id \"dummyDesId\"");
}
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 4 with DiskEncryptionSetDeletionRequest

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

the class AzureEncryptionResourcesTest method testDeleteDiskEncryptionSetShouldDeduceValidDiskEncryptionSetNameAndResourceGroupWhenDesAndVaultDoNotHaveSameResourceGroup.

@Test
public void testDeleteDiskEncryptionSetShouldDeduceValidDiskEncryptionSetNameAndResourceGroupWhenDesAndVaultDoNotHaveSameResourceGroup() {
    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("/subscriptions/dummySubs/resourceGroups/dummyVaultResourceGroup/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("dummyVaultResourceGroup", "dummyVaultName")).thenReturn(Boolean.TRUE);
    initRetry();
    underTest.deleteDiskEncryptionSet(deletionRequest);
    verify(azureClient).deleteDiskEncryptionSet("dummyDesResourceGroup", "dummyDesId");
    verify(azureClient).removeKeyVaultAccessPolicyFromServicePrincipal("dummyVaultResourceGroup", "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 5 with DiskEncryptionSetDeletionRequest

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

the class AzureEncryptionResourcesTest method testDeleteDiskEncryptionSetShouldDeduceValidDiskEncryptionSetNameAndShouldNotDeleteResourceGroupWhenNotCreatedByCDP.

@Test
public void testDeleteDiskEncryptionSetShouldDeduceValidDiskEncryptionSetNameAndShouldNotDeleteResourceGroupWhenNotCreatedByCDP() {
    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();
    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");
    initCloudResourceHelper(resources);
    when(azureClient.getDiskEncryptionSetByName(any(), any())).thenReturn(des);
    when(azureClientService.getClient(cloudCredential)).thenReturn(azureClient);
    when(azureClient.keyVaultExists("dummyVaultResourceGroup", "dummyVaultName")).thenReturn(Boolean.TRUE);
    initRetry();
    underTest.deleteDiskEncryptionSet(deletionRequest);
    verify(azureClient).deleteDiskEncryptionSet("dummyResourceGroup", "dummyDesId");
    verify(azureClient, never()).deleteResourceGroup("dummyResourceGroup");
    verify(azureClient).removeKeyVaultAccessPolicyFromServicePrincipal("dummyVaultResourceGroup", "dummyVaultName", DES_PRINCIPAL_ID);
    verify(persistenceNotifier).notifyDeletion(deletionRequest.getCloudResources().get(0), 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