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());
}
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\"");
}
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\"");
}
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());
}
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());
}
Aggregations