Skip to content

Commit

Permalink
[DBInstance] Add support for IO2 storage (aws-cloudformation#528)
Browse files Browse the repository at this point in the history
* [DBInstance] Add support for IO2 storage

Co-authored-by: Valentin Shirshov <vshir@amazon.com>
  • Loading branch information
khebul and Valentin Shirshov authored Apr 3, 2024
1 parent 6b13508 commit cf44c35
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ public enum StorageType {
GP2("gp2"),
GP3("gp3"),
IO1("io1"),
MAGNETIC("magnetic");
MAGNETIC("magnetic"),
IO2("io2");

private final String value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ public static ModifyDbInstanceRequest modifyDbInstanceRequest(
}

private static Boolean isProvisionedIoStorage(final ResourceModel model) {
return isIo1Storage(model) || isGp3Storage(model);
return isIo1Storage(model) || isIo2Storage(model) || isGp3Storage(model);
}

private static Boolean isGp3Storage(final ResourceModel model) {
Expand All @@ -561,6 +561,10 @@ private static Boolean isIo1Storage(final ResourceModel model) {
(StringUtils.isEmpty(model.getStorageType()) && model.getIops() != null);
}

private static Boolean isIo2Storage(final ResourceModel model) {
return StorageType.IO2.toString().equalsIgnoreCase(model.getStorageType());
}

private static Boolean shouldDisableDomain(final ResourceModel previous, final ResourceModel desired) {
return ObjectUtils.allNull(desired.getDomain(), desired.getDomainAuthSecretArn(), desired.getDomainDnsIps(),
desired.getDomainFqdn(), desired.getDomainOu(), desired.getDomainIAMRoleName())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -927,6 +927,17 @@ public void modifyDbInstanceRequest_shouldIncludeAllocatedStorage_ifStorageTypeI
assertThat(request.allocatedStorage()).isEqualTo(ALLOCATED_STORAGE);
}

@Test
public void modifyDbInstanceRequest_shouldIncludeAllocatedStorageANdIops_ifStorageTypeIsIo1_andStorageTypeChangedToIo2() {
final ResourceModel previous = RESOURCE_MODEL_BLDR().storageType("io1").iops(1000).allocatedStorage("100").build();
final ResourceModel desired = RESOURCE_MODEL_BLDR().storageType("io2").iops(1000).allocatedStorage("100").build();

final ModifyDbInstanceRequest request = Translator.modifyDbInstanceRequest(previous, desired, false);

assertThat(request.iops()).isEqualTo(1000);
assertThat(request.allocatedStorage()).isEqualTo(100);
}

@Test
public void modifyDbInstanceRequest_shouldIncludeAllocatedStorage_ifStorageTypeIsImplicitIo1_andIopsOnlyChanged() {
final ResourceModel previous = RESOURCE_MODEL_BLDR().storageType(null).iops(1000).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1816,4 +1816,48 @@ public void handleRequest_stopAutomaticBackupReplication() {
verifyNoMoreInteractions(crossRegionRdsProxy.client());
verify(rdsProxy.client(), times(4)).describeDBInstances(any(DescribeDbInstancesRequest.class));
}

@Test
public void handleRequest_updateStorageTypeFromIo1ToIo2() {
final CallbackContext context = new CallbackContext();
context.setCreated(true);
context.setUpdated(false);
context.setRebooted(true);
context.setUpdatedRoles(true);
context.setAddTagsComplete(true);
context.setAutomaticBackupReplicationStarted(true);
context.setAutomaticBackupReplicationStopped(true);

when(rdsProxy.client().modifyDBInstance(any(ModifyDbInstanceRequest.class)))
.thenReturn(ModifyDbInstanceResponse.builder().build());
when(rdsProxy.client().describeEvents(any(DescribeEventsRequest.class)))
.thenReturn(DescribeEventsResponse.builder().build());

test_handleRequest_base(
context,
() -> DB_INSTANCE_ACTIVE.toBuilder()
.build(),
() -> RESOURCE_MODEL_BLDR()
.storageType("io1")
.allocatedStorage("100")
.iops(1000)
.build(),
() -> RESOURCE_MODEL_BLDR()
.storageType("io2")
.allocatedStorage("100")
.iops(1000)
.build(),
expectSuccess()
);

verify(rdsProxy.client(), times(3)).describeDBInstances(any(DescribeDbInstancesRequest.class));

final ArgumentCaptor<ModifyDbInstanceRequest> argumentCaptor = ArgumentCaptor.forClass(ModifyDbInstanceRequest.class);
verify(rdsProxy.client()).modifyDBInstance(argumentCaptor.capture());
Assertions.assertThat(argumentCaptor.getValue().iops()).isEqualTo(1000);
Assertions.assertThat(argumentCaptor.getValue().allocatedStorage()).isEqualTo(100);
Assertions.assertThat(argumentCaptor.getValue().storageType()).isEqualTo("io2");

verify(rdsProxy.client(), times(1)).describeEvents(any(DescribeEventsRequest.class));
}
}

0 comments on commit cf44c35

Please sign in to comment.