mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(docdb): store and return cluster and instance settings (#2651)
* fix(docdb): store and return cluster and instance settings CreateDBCluster and ModifyDBCluster dropped DBSubnetGroupName, DBClusterParameterGroupName, VpcSecurityGroupIds, StorageEncrypted, KmsKeyId, BackupRetentionPeriod, both windows, DeletionProtection and tags; instances dropped AutoMinorVersionUpgrade, PreferredMaintenanceWindow, CopyTagsToSnapshot and PromotionTier. Describe now returns what was given, or the defaults a live account assigns, and refuses what a live account refuses before any container is started: an unknown subnet group, parameter group, security group or KMS key, a KMS key on an unencrypted cluster, a retention period outside 1..354, malformed or overlapping windows. Records persisted before these fields existed are filled in with the defaults on read. Port is not taken from the request: the port a cluster reports is the one it is reachable on. Closes #2614 * fix(docdb): enforce deletion protection, parameter group family and undrivable windows DeleteDBCluster refuses a cluster with DeletionProtection, before any state changes. A named parameter group must belong to the family of the engine version the cluster will run, judged on modify against the requested version rather than the stored one; a cluster on a default group follows an engine version change to the new family's default. A window given without its counterpart that leaves no daily half hour for the derived one is refused with the live wording instead of a derived window that overlaps. * fix(docdb): refuse an engine version change that keeps a custom group of the old family * fix(docdb): judge a retained parameter group by its stored family, not its name * fix(docdb): classify a retained parameter group through the RDS catalogue, not its name --------- Co-authored-by: Priamo Germosen <6233424+pgermosen@users.noreply.github.com>
This commit is contained in:
1 parent
231c0972b0
commit
f019573bf1
14 files changed
+1224
-28
No files matched your search
+116
@@ -0,0 +1,116 @@
|
||||
package io.github.hectorvent.floci.services.docdb;
|
||||
|
||||
import io.github.hectorvent.floci.services.kms.KmsService;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import jakarta.inject.Inject;
|
||||
import io.quarkus.test.junit.QuarkusTestProfile;
|
||||
import io.quarkus.test.junit.TestProfile;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static io.restassured.http.ContentType.URLENC;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
|
||||
/**
|
||||
* The settings a DocumentDB cluster is created with come back from DescribeDBClusters, as on a
|
||||
* live account — through the Query protocol, with a real KMS key from the KMS store and the
|
||||
* default subnet group, parameter group and security group.
|
||||
*/
|
||||
@QuarkusTest
|
||||
@TestProfile(DocDbClusterSettingsIntegrationTest.NoContainersProfile.class)
|
||||
class DocDbClusterSettingsIntegrationTest {
|
||||
|
||||
public static class NoContainersProfile implements QuarkusTestProfile {
|
||||
@Override
|
||||
public Map<String, String> getConfigOverrides() {
|
||||
return Map.of("floci.services.rds.mock", "true", "floci.services.docdb.mock", "true");
|
||||
}
|
||||
}
|
||||
|
||||
private static final String ID = "settings-cluster";
|
||||
|
||||
@Inject
|
||||
KmsService kmsService;
|
||||
|
||||
private static io.restassured.specification.RequestSpecification rds(String action) {
|
||||
return given().header("Authorization",
|
||||
"AWS4-HMAC-SHA256 Credential=test/20260615/us-east-1/rds/aws4_request, "
|
||||
+ "SignedHeaders=content-type;host, Signature=test")
|
||||
.contentType(URLENC)
|
||||
.formParam("Action", action)
|
||||
.formParam("Version", "2014-10-31");
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void cleanUp() {
|
||||
rds("DeleteDBInstance").formParam("DBInstanceIdentifier", ID + "-1").when().post("/");
|
||||
rds("DeleteDBCluster").formParam("DBClusterIdentifier", ID).formParam("SkipFinalSnapshot", "true").when().post("/");
|
||||
}
|
||||
|
||||
@Test
|
||||
void settingsGivenOnCreateComeBackFromDescribeAndModifyChangesThem() {
|
||||
String keyArn = kmsService.createKey("docdb settings", "us-east-1").getArn();
|
||||
|
||||
rds("CreateDBCluster")
|
||||
.formParam("DBClusterIdentifier", ID)
|
||||
.formParam("Engine", "docdb")
|
||||
.formParam("MasterUsername", "u")
|
||||
.formParam("MasterUserPassword", "secret99password")
|
||||
.formParam("StorageEncrypted", "true")
|
||||
.formParam("KmsKeyId", keyArn)
|
||||
.formParam("BackupRetentionPeriod", "5")
|
||||
.formParam("PreferredBackupWindow", "23:30-00:00")
|
||||
.formParam("PreferredMaintenanceWindow", "Sun:03:00-Sun:04:00")
|
||||
.formParam("Tags.Tag.1.Key", "Name")
|
||||
.formParam("Tags.Tag.1.Value", ID)
|
||||
.when().post("/")
|
||||
.then().statusCode(200)
|
||||
.body(containsString("<KmsKeyId>" + keyArn + "</KmsKeyId>"));
|
||||
|
||||
rds("DescribeDBClusters").formParam("DBClusterIdentifier", ID)
|
||||
.when().post("/")
|
||||
.then().statusCode(200)
|
||||
.body(containsString("<DBSubnetGroup>default</DBSubnetGroup>"))
|
||||
.body(containsString("<DBClusterParameterGroup>default.docdb5.0</DBClusterParameterGroup>"))
|
||||
.body(containsString("<StorageEncrypted>true</StorageEncrypted>"))
|
||||
.body(containsString("<KmsKeyId>" + keyArn + "</KmsKeyId>"))
|
||||
.body(containsString("<BackupRetentionPeriod>5</BackupRetentionPeriod>"))
|
||||
.body(containsString("<PreferredBackupWindow>23:30-00:00</PreferredBackupWindow>"))
|
||||
.body(containsString("<PreferredMaintenanceWindow>sun:03:00-sun:04:00</PreferredMaintenanceWindow>"))
|
||||
.body(containsString("<VpcSecurityGroupId>sg-"));
|
||||
|
||||
rds("ListTagsForResource").formParam("ResourceName", "arn:aws:rds:us-east-1:000000000000:cluster:" + ID)
|
||||
.when().post("/").then().statusCode(200).body(containsString("<Value>" + ID + "</Value>"));
|
||||
|
||||
rds("CreateDBInstance")
|
||||
.formParam("DBInstanceIdentifier", ID + "-1")
|
||||
.formParam("DBInstanceClass", "db.t3.medium")
|
||||
.formParam("Engine", "docdb")
|
||||
.formParam("DBClusterIdentifier", ID)
|
||||
.formParam("AutoMinorVersionUpgrade", "false")
|
||||
.formParam("Tags.Tag.1.Key", "Name")
|
||||
.formParam("Tags.Tag.1.Value", ID + "-1")
|
||||
.when().post("/")
|
||||
.then().statusCode(200)
|
||||
.body(containsString("<AutoMinorVersionUpgrade>false</AutoMinorVersionUpgrade>"))
|
||||
.body(containsString("<PreferredMaintenanceWindow>sun:03:00-sun:04:00</PreferredMaintenanceWindow>"))
|
||||
.body(containsString("<StorageEncrypted>true</StorageEncrypted>"));
|
||||
|
||||
rds("ModifyDBCluster").formParam("DBClusterIdentifier", ID)
|
||||
.formParam("BackupRetentionPeriod", "7")
|
||||
.formParam("PreferredBackupWindow", "02:00-02:30")
|
||||
.when().post("/")
|
||||
.then().statusCode(200)
|
||||
.body(containsString("<BackupRetentionPeriod>7</BackupRetentionPeriod>"))
|
||||
.body(containsString("<PreferredBackupWindow>02:00-02:30</PreferredBackupWindow>"));
|
||||
|
||||
rds("ModifyDBCluster").formParam("DBClusterIdentifier", ID)
|
||||
.formParam("PreferredMaintenanceWindow", "mon:02:15-mon:02:45")
|
||||
.when().post("/")
|
||||
.then().statusCode(400)
|
||||
.body(containsString("The backup window and maintenance window must not overlap."));
|
||||
}
|
||||
}
|
||||
+7
-2
@@ -10,6 +10,9 @@ import io.github.hectorvent.floci.services.docdb.container.DocDbContainerManager
|
||||
import io.github.hectorvent.floci.services.docdb.model.DocDbCluster;
|
||||
import io.github.hectorvent.floci.services.docdb.model.DocDbInstance;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import io.github.hectorvent.floci.services.ec2.Ec2Service;
|
||||
import io.github.hectorvent.floci.services.kms.KmsService;
|
||||
import io.github.hectorvent.floci.services.rds.RdsService;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
@@ -51,7 +54,8 @@ class DocDbLegacyMigrationRaceTest {
|
||||
when(servicesConfig.docdb()).thenReturn(docdbConfig);
|
||||
when(docdbConfig.mock()).thenReturn(true);
|
||||
service = new DocDbService(config, new RegionResolver("us-east-1", "000000000000"),
|
||||
Mockito.mock(DocDbContainerManager.class), storageFactory);
|
||||
Mockito.mock(DocDbContainerManager.class), storageFactory,
|
||||
Mockito.mock(RdsService.class), Mockito.mock(Ec2Service.class), Mockito.mock(KmsService.class));
|
||||
}
|
||||
|
||||
private void freshService() {
|
||||
@@ -70,7 +74,8 @@ class DocDbLegacyMigrationRaceTest {
|
||||
when(docdbConfig.mock()).thenReturn(true);
|
||||
|
||||
service = new DocDbService(config, new RegionResolver("us-east-1", "000000000000"),
|
||||
Mockito.mock(DocDbContainerManager.class), storageFactory);
|
||||
Mockito.mock(DocDbContainerManager.class), storageFactory,
|
||||
Mockito.mock(RdsService.class), Mockito.mock(Ec2Service.class), Mockito.mock(KmsService.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -3,6 +3,7 @@ package io.github.hectorvent.floci.services.docdb;
|
||||
import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.RegionResolver;
|
||||
import io.github.hectorvent.floci.core.common.BackupWindows;
|
||||
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
|
||||
import io.github.hectorvent.floci.core.storage.StorageBackend;
|
||||
import io.github.hectorvent.floci.core.storage.StorageFactory;
|
||||
@@ -11,8 +12,21 @@ import io.github.hectorvent.floci.services.docdb.model.DocDbCluster;
|
||||
import io.github.hectorvent.floci.services.docdb.model.DocDbInstance;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import io.github.hectorvent.floci.services.docdb.model.DocDbClusterSettings;
|
||||
import io.github.hectorvent.floci.services.docdb.model.DocDbInstanceSettings;
|
||||
import io.github.hectorvent.floci.services.ec2.Ec2Service;
|
||||
import io.github.hectorvent.floci.services.ec2.model.SecurityGroup;
|
||||
import io.github.hectorvent.floci.services.kms.KmsService;
|
||||
import io.github.hectorvent.floci.services.kms.model.KmsKey;
|
||||
import io.github.hectorvent.floci.services.rds.RdsService;
|
||||
import io.github.hectorvent.floci.services.rds.model.DbSubnetGroup;
|
||||
import io.github.hectorvent.floci.services.rds.model.DbClusterParameterGroup;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.mockito.ArgumentMatchers.anyList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
@@ -29,6 +43,9 @@ class DocDbServiceTest {
|
||||
|
||||
private DocDbService docDbService;
|
||||
private DocDbContainerManager containerManager;
|
||||
private RdsService rdsService;
|
||||
private Ec2Service ec2Service;
|
||||
private KmsService kmsService;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
@@ -45,7 +62,14 @@ class DocDbServiceTest {
|
||||
|
||||
containerManager = Mockito.mock(DocDbContainerManager.class);
|
||||
RegionResolver regionResolver = new RegionResolver("us-east-1", "000000000000");
|
||||
docDbService = new DocDbService(config, regionResolver, containerManager, storageFactory);
|
||||
rdsService = Mockito.mock(RdsService.class);
|
||||
ec2Service = Mockito.mock(Ec2Service.class);
|
||||
kmsService = Mockito.mock(KmsService.class);
|
||||
when(kmsService.describeKey(any(), any())).thenThrow(new AwsException("NotFoundException", "Key not found", 404));
|
||||
when(rdsService.isManagedClusterParameterGroup(any())).thenAnswer(inv ->
|
||||
List.of("default.docdb3.6", "default.docdb4.0", "default.docdb5.0").contains(inv.<String>getArgument(0)));
|
||||
docDbService = new DocDbService(config, regionResolver, containerManager, storageFactory,
|
||||
rdsService, ec2Service, kmsService);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -145,7 +169,8 @@ class DocDbServiceTest {
|
||||
when(noDaemonContainerManager.tryStart(anyString(), anyString(), anyString(), anyString()))
|
||||
.thenReturn(null);
|
||||
RegionResolver regionResolver = new RegionResolver("us-east-1", "000000000000");
|
||||
DocDbService noDaemonService = new DocDbService(config, regionResolver, noDaemonContainerManager, storageFactory);
|
||||
DocDbService noDaemonService = new DocDbService(config, regionResolver, noDaemonContainerManager, storageFactory,
|
||||
rdsService, ec2Service, kmsService);
|
||||
|
||||
DocDbCluster created = noDaemonService.createDbCluster(
|
||||
"no-docker-cluster", null, "admin", "secret", false);
|
||||
@@ -209,7 +234,8 @@ class DocDbServiceTest {
|
||||
when(docdbConfig.mock()).thenReturn(true);
|
||||
DocDbService service = new DocDbService(config,
|
||||
new RegionResolver("us-east-1", "000000000000"),
|
||||
Mockito.mock(DocDbContainerManager.class), storageFactory);
|
||||
Mockito.mock(DocDbContainerManager.class), storageFactory,
|
||||
Mockito.mock(RdsService.class), Mockito.mock(Ec2Service.class), Mockito.mock(KmsService.class));
|
||||
|
||||
DocDbCluster legacy = new DocDbCluster();
|
||||
legacy.setDbClusterIdentifier("bare-key-cluster");
|
||||
@@ -229,4 +255,308 @@ class DocDbServiceTest {
|
||||
// And it lists there, once rather than twice.
|
||||
assertEquals(1, service.listDbClusters(null).size());
|
||||
}
|
||||
|
||||
private static final String KEY_ARN = "arn:aws:kms:us-east-1:000000000000:key/k1";
|
||||
|
||||
private void knownReferences() {
|
||||
when(rdsService.getDbSubnetGroup(eq("sng"), any())).thenReturn(new DbSubnetGroup());
|
||||
when(rdsService.getDbSubnetGroup(eq("nope"), any())).thenThrow(new AwsException("DBSubnetGroupNotFoundFault", "x", 404));
|
||||
when(rdsService.getDbClusterParameterGroup(eq("pg"), any())).thenReturn(new DbClusterParameterGroup("pg", "docdb5.0", "d"));
|
||||
when(rdsService.getDbClusterParameterGroup(eq("nope"), any())).thenThrow(new AwsException("DBClusterParameterGroupNotFound", "x", 404));
|
||||
SecurityGroup sg = new SecurityGroup();
|
||||
sg.setGroupId("sg-1");
|
||||
when(ec2Service.describeSecurityGroups(any(), eq(List.of("sg-1")), any(), any())).thenReturn(List.of(sg));
|
||||
when(ec2Service.describeSecurityGroups(any(), eq(List.of("sg-nope")), any(), any())).thenReturn(List.of());
|
||||
KmsKey key = new KmsKey();
|
||||
key.setKeyId("k1");
|
||||
key.setArn(KEY_ARN);
|
||||
key.setEnabled(true);
|
||||
key.setKeyState("Enabled");
|
||||
Mockito.doReturn(key).when(kmsService).describeKey("alias/docs", "us-east-1");
|
||||
Mockito.doReturn(key).when(kmsService).describeKey(KEY_ARN, "us-east-1");
|
||||
}
|
||||
|
||||
@Test
|
||||
void createDbClusterStoresPlacementEncryptionBackupSettingsAndTags() {
|
||||
knownReferences();
|
||||
DocDbCluster created = docDbService.createDbCluster("c1", "5.0.0", "u", "pw", false,
|
||||
new DocDbClusterSettings("sng", "pg", List.of("sg-1"), true, "alias/docs", 5,
|
||||
"23:30-00:00", "Sun:03:00-Sun:04:00", true),
|
||||
Map.of("Name", "c1"));
|
||||
|
||||
DocDbCluster stored = docDbService.getDbCluster("c1");
|
||||
assertEquals("sng", stored.getDbSubnetGroupName());
|
||||
assertEquals("pg", stored.getDbClusterParameterGroupName());
|
||||
assertEquals(List.of("sg-1"), stored.getVpcSecurityGroupIds());
|
||||
assertTrue(stored.isStorageEncrypted());
|
||||
assertEquals(KEY_ARN, stored.getKmsKeyId());
|
||||
assertEquals(5, stored.getBackupRetentionPeriod());
|
||||
assertEquals("23:30-00:00", stored.getPreferredBackupWindow());
|
||||
assertEquals("sun:03:00-sun:04:00", stored.getPreferredMaintenanceWindow());
|
||||
assertTrue(stored.isDeletionProtection());
|
||||
assertEquals(Map.of("Name", "c1"), stored.getTags());
|
||||
assertEquals(created.getDbClusterArn(), stored.getDbClusterArn());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createDbClusterWithoutSettingsTakesAwsDefaults() {
|
||||
docDbService.createDbCluster("c1", "5.0.0", "u", "pw", false);
|
||||
DocDbCluster stored = docDbService.getDbCluster("c1");
|
||||
assertEquals("default", stored.getDbSubnetGroupName());
|
||||
assertEquals("default.docdb5.0", stored.getDbClusterParameterGroupName());
|
||||
assertEquals(List.of(Ec2Service.defaultSecurityGroupId("us-east-1")), stored.getVpcSecurityGroupIds());
|
||||
assertFalse(stored.isStorageEncrypted());
|
||||
assertNull(stored.getKmsKeyId());
|
||||
assertEquals(1, stored.getBackupRetentionPeriod());
|
||||
assertEquals("04:00-06:00", stored.getPreferredBackupWindow());
|
||||
assertEquals("mon:00:00-mon:03:00", stored.getPreferredMaintenanceWindow());
|
||||
assertFalse(stored.isDeletionProtection());
|
||||
}
|
||||
|
||||
@Test
|
||||
void recordsPersistedBeforeSettingsWereStoredReadBackWithTheAwsDefaults() {
|
||||
StorageBackend<String, DocDbCluster> clusterStore = AccountAwareStorageBackend.inMemory("000000000000");
|
||||
StorageBackend<String, DocDbInstance> instanceStore = AccountAwareStorageBackend.inMemory("000000000000");
|
||||
StorageFactory storageFactory = Mockito.mock(StorageFactory.class);
|
||||
when(storageFactory.create(anyString(), anyString(), any())).thenAnswer(inv ->
|
||||
"docdb-clusters.json".equals(inv.getArgument(1)) ? clusterStore : instanceStore);
|
||||
EmulatorConfig config = Mockito.mock(EmulatorConfig.class);
|
||||
var servicesConfig = Mockito.mock(EmulatorConfig.ServicesConfig.class);
|
||||
var docdbConfig = Mockito.mock(EmulatorConfig.DocDbServiceConfig.class);
|
||||
when(config.services()).thenReturn(servicesConfig);
|
||||
when(servicesConfig.docdb()).thenReturn(docdbConfig);
|
||||
when(docdbConfig.mock()).thenReturn(true);
|
||||
DocDbService service = new DocDbService(config, new RegionResolver("us-east-1", "000000000000"),
|
||||
containerManager, storageFactory, rdsService, ec2Service, kmsService);
|
||||
|
||||
DocDbCluster legacy = new DocDbCluster();
|
||||
legacy.setDbClusterIdentifier("old");
|
||||
legacy.setEngineVersion("4.0.0");
|
||||
legacy.setDbClusterArn("arn:aws:rds:us-east-1:000000000000:cluster:old");
|
||||
clusterStore.put("us-east-1::old", legacy);
|
||||
DocDbInstance legacyInstance = new DocDbInstance();
|
||||
legacyInstance.setDbInstanceIdentifier("old-1");
|
||||
legacyInstance.setDbClusterIdentifier("old");
|
||||
legacyInstance.setDbInstanceArn("arn:aws:rds:us-east-1:000000000000:db:old-1");
|
||||
instanceStore.put("us-east-1::old-1", legacyInstance);
|
||||
|
||||
for (DocDbCluster read : List.of(service.getDbCluster("old"),
|
||||
service.listDbClusters(null).iterator().next(),
|
||||
service.listDbClusters("arn:aws:rds:us-east-1:000000000000:cluster:old").iterator().next())) {
|
||||
assertEquals("default", read.getDbSubnetGroupName());
|
||||
assertEquals("default.docdb4.0", read.getDbClusterParameterGroupName());
|
||||
assertEquals(List.of(Ec2Service.defaultSecurityGroupId("us-east-1")), read.getVpcSecurityGroupIds());
|
||||
assertEquals(1, read.getBackupRetentionPeriod());
|
||||
assertEquals("04:00-06:00", read.getPreferredBackupWindow());
|
||||
assertEquals("mon:00:00-mon:03:00", read.getPreferredMaintenanceWindow());
|
||||
assertFalse(read.isStorageEncrypted());
|
||||
assertFalse(read.isDeletionProtection());
|
||||
}
|
||||
assertEquals("default", clusterStore.get("us-east-1::old").orElseThrow().getDbSubnetGroupName());
|
||||
|
||||
DocDbInstance readInstance = service.getDbInstance("old-1");
|
||||
assertEquals("mon:00:00-mon:03:00", readInstance.getPreferredMaintenanceWindow());
|
||||
assertTrue(readInstance.isAutoMinorVersionUpgrade());
|
||||
assertEquals(1, readInstance.getPromotionTier());
|
||||
assertEquals("mon:00:00-mon:03:00",
|
||||
instanceStore.get("us-east-1::old-1").orElseThrow().getPreferredMaintenanceWindow());
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteDbClusterRefusesAProtectedClusterUntilProtectionIsTurnedOff() {
|
||||
docDbService.createDbCluster("c1", "5.0.0", "u", "pw", false,
|
||||
new DocDbClusterSettings(null, null, null, null, null, null, null, null, true), Map.of());
|
||||
AwsException e = assertThrows(AwsException.class, () -> docDbService.deleteDbCluster("c1"));
|
||||
assertEquals("InvalidParameterCombination", e.getErrorCode());
|
||||
assertEquals("Cannot delete protected Cluster, please disable deletion protection and try again.", e.getMessage());
|
||||
assertEquals("available", docDbService.getDbCluster("c1").getStatus());
|
||||
|
||||
docDbService.modifyDbCluster("c1", null, null,
|
||||
new DocDbClusterSettings(null, null, null, null, null, null, null, null, false));
|
||||
docDbService.deleteDbCluster("c1");
|
||||
assertThrows(AwsException.class, () -> docDbService.getDbCluster("c1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void parameterGroupMustBelongToTheEngineVersionTheClusterWillRun() {
|
||||
knownReferences();
|
||||
when(rdsService.getDbClusterParameterGroup(eq("pg4"), any()))
|
||||
.thenReturn(new DbClusterParameterGroup("pg4", "docdb4.0", "d"));
|
||||
String expected = "The Parameter Group pg4 with DBParameterGroupFamily docdb4.0 cannot be used for this "
|
||||
+ "instance. Please use a Parameter Group with DBParameterGroupFamily docdb5.0";
|
||||
|
||||
AwsException e = refused(new DocDbClusterSettings(null, "pg4", null, null, null, null, null, null, null));
|
||||
assertEquals("InvalidParameterCombination", e.getErrorCode());
|
||||
assertEquals(expected, e.getMessage());
|
||||
|
||||
docDbService.createDbCluster("c1", "5.0.0", "u", "pw", false);
|
||||
e = assertThrows(AwsException.class, () -> docDbService.modifyDbCluster("c1", null, null,
|
||||
new DocDbClusterSettings(null, "pg4", null, null, null, null, null, null, null)));
|
||||
assertEquals(expected, e.getMessage());
|
||||
assertEquals("default.docdb5.0", docDbService.getDbCluster("c1").getDbClusterParameterGroupName());
|
||||
|
||||
// judged against the version the cluster will have, not the one it has
|
||||
e = assertThrows(AwsException.class, () -> docDbService.modifyDbCluster("c1", "4.0.0", null,
|
||||
new DocDbClusterSettings(null, "pg", null, null, null, null, null, null, null)));
|
||||
assertEquals("The Parameter Group pg with DBParameterGroupFamily docdb5.0 cannot be used for this "
|
||||
+ "instance. Please use a Parameter Group with DBParameterGroupFamily docdb4.0", e.getMessage());
|
||||
assertEquals("5.0.0", docDbService.getDbCluster("c1").getEngineVersion());
|
||||
|
||||
docDbService.modifyDbCluster("c1", "4.0.0", null, new DocDbClusterSettings(null, "pg4", null, null, null, null, null, null, null));
|
||||
assertEquals("pg4", docDbService.getDbCluster("c1").getDbClusterParameterGroupName());
|
||||
|
||||
// a custom group of the old family is not carried across an engine version change
|
||||
e = assertThrows(AwsException.class, () -> docDbService.modifyDbCluster("c1", "5.0.0", null));
|
||||
assertEquals("InvalidParameterCombination", e.getErrorCode());
|
||||
assertEquals("The current DB cluster parameter group pg4 is custom. You must explicitly specify a new "
|
||||
+ "DB cluster parameter group, either default or custom, for the engine version upgrade.", e.getMessage());
|
||||
assertEquals("4.0.0", docDbService.getDbCluster("c1").getEngineVersion());
|
||||
docDbService.modifyDbCluster("c1", "5.0.0", null, new DocDbClusterSettings(null, "pg", null, null, null, null, null, null, null));
|
||||
assertEquals("pg", docDbService.getDbCluster("c1").getDbClusterParameterGroupName());
|
||||
assertEquals("5.0.0", docDbService.getDbCluster("c1").getEngineVersion());
|
||||
|
||||
// the group's stored family decides, whatever its name says
|
||||
when(rdsService.getDbClusterParameterGroup(eq("mine-docdb5.0"), any()))
|
||||
.thenReturn(new DbClusterParameterGroup("mine-docdb5.0", "docdb4.0", "d"));
|
||||
docDbService.createDbCluster("c3", "4.0.0", "u", "pw", false,
|
||||
new DocDbClusterSettings(null, "mine-docdb5.0", null, null, null, null, null, null, null), Map.of());
|
||||
e = assertThrows(AwsException.class, () -> docDbService.modifyDbCluster("c3", "5.0.0", null));
|
||||
assertEquals("InvalidParameterCombination", e.getErrorCode());
|
||||
assertEquals("4.0.0", docDbService.getDbCluster("c3").getEngineVersion());
|
||||
|
||||
// a custom group is not a default one because of its name
|
||||
when(rdsService.getDbClusterParameterGroup(eq("default.mine"), any()))
|
||||
.thenReturn(new DbClusterParameterGroup("default.mine", "docdb4.0", "d"));
|
||||
docDbService.createDbCluster("c4", "4.0.0", "u", "pw", false,
|
||||
new DocDbClusterSettings(null, "default.mine", null, null, null, null, null, null, null), Map.of());
|
||||
e = assertThrows(AwsException.class, () -> docDbService.modifyDbCluster("c4", "5.0.0", null));
|
||||
assertEquals("InvalidParameterCombination", e.getErrorCode());
|
||||
assertEquals("default.mine", docDbService.getDbCluster("c4").getDbClusterParameterGroupName());
|
||||
|
||||
// a cluster on a default group follows the engine version to the new family's default
|
||||
docDbService.createDbCluster("c2", "4.0.0", "u", "pw", false);
|
||||
docDbService.modifyDbCluster("c2", "5.0.0", null);
|
||||
assertEquals("default.docdb5.0", docDbService.getDbCluster("c2").getDbClusterParameterGroupName());
|
||||
}
|
||||
|
||||
@Test
|
||||
void aWindowThatLeavesNoRoomForTheDerivedOneIsRefused() {
|
||||
AwsException e = refused(new DocDbClusterSettings(null, null, null, null, null, null, "00:00-23:45", null, null));
|
||||
assertEquals("InvalidParameterValue", e.getErrorCode());
|
||||
assertEquals("The specified backup window overlaps all available default maintenance windows. "
|
||||
+ "Shrink the backup window or specify a non-overlapping maintenance window.", e.getMessage());
|
||||
e = refused(new DocDbClusterSettings(null, null, null, null, null, null, "23:00-22:59", null, null));
|
||||
assertEquals("The specified backup window overlaps all available default maintenance windows. "
|
||||
+ "Shrink the backup window or specify a non-overlapping maintenance window.", e.getMessage());
|
||||
e = refused(new DocDbClusterSettings(null, null, null, null, null, null, null, "mon:00:00-mon:23:45", null));
|
||||
assertEquals("The specified maintenance window overlaps all available default backup windows. "
|
||||
+ "Shrink the maintenance window or specify a non-overlapping backup window.", e.getMessage());
|
||||
|
||||
docDbService.createDbCluster("c1", "5.0.0", "u", "pw", false,
|
||||
new DocDbClusterSettings(null, null, null, null, null, null, "22:00-23:50", null, null), Map.of());
|
||||
DocDbCluster stored = docDbService.getDbCluster("c1");
|
||||
assertEquals("22:00-23:50", stored.getPreferredBackupWindow());
|
||||
assertFalse(BackupWindows.overlap(stored.getPreferredBackupWindow(), stored.getPreferredMaintenanceWindow()));
|
||||
}
|
||||
|
||||
private AwsException refused(DocDbClusterSettings settings) {
|
||||
return assertThrows(AwsException.class, () -> docDbService.createDbCluster(
|
||||
"c1", "5.0.0", "u", "pw", false, settings, Map.of()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createDbClusterRefusesWhatALiveAccountRefusesBeforeStartingAContainer() {
|
||||
knownReferences();
|
||||
AwsException e;
|
||||
e = refused(new DocDbClusterSettings(null, null, null, false, KEY_ARN, null, null, null, null));
|
||||
assertEquals("InvalidParameterCombination", e.getErrorCode());
|
||||
assertEquals("You cannot specify KMS key for unencrypted clusters.", e.getMessage());
|
||||
e = refused(new DocDbClusterSettings(null, null, null, null, KEY_ARN, null, null, null, null));
|
||||
assertEquals("InvalidParameterCombination", e.getErrorCode());
|
||||
e = refused(new DocDbClusterSettings(null, null, null, true, "alias/nope", null, null, null, null));
|
||||
assertEquals("KMSKeyNotAccessibleFault", e.getErrorCode());
|
||||
assertEquals("The specified KMS key [alias/nope] does not exist, is not enabled or you do not have permissions to access it.", e.getMessage());
|
||||
e = refused(new DocDbClusterSettings("nope", null, null, null, null, null, null, null, null));
|
||||
assertEquals("DBSubnetGroupNotFoundFault", e.getErrorCode());
|
||||
assertEquals("DB subnet group 'nope' does not exist.", e.getMessage());
|
||||
e = refused(new DocDbClusterSettings(null, "nope", null, null, null, null, null, null, null));
|
||||
assertEquals("DBClusterParameterGroupNotFound", e.getErrorCode());
|
||||
assertEquals("DBClusterParameterGroup not found: nope", e.getMessage());
|
||||
e = refused(new DocDbClusterSettings(null, null, List.of("sg-nope"), null, null, null, null, null, null));
|
||||
assertEquals("InvalidParameterValue", e.getErrorCode());
|
||||
assertEquals("Invalid security group , groupId= sg-nope, groupName=.", e.getMessage());
|
||||
e = refused(new DocDbClusterSettings(null, null, null, null, null, 0, null, null, null));
|
||||
assertEquals("Invalid backup retention period: 0. Retention period must be between 1 and 354.", e.getMessage());
|
||||
e = refused(new DocDbClusterSettings(null, null, null, null, null, null, "25:00-26:00", null, null));
|
||||
assertEquals("Invalid backup window time '25:00' specified. Should be specified as a time hh24:mi (24H Clock UTC). Example: 03:15", e.getMessage());
|
||||
e = refused(new DocDbClusterSettings(null, null, null, null, null, null, "02:00-02:10", null, null));
|
||||
assertEquals("Backup window must be at least 30 minutes.", e.getMessage());
|
||||
e = refused(new DocDbClusterSettings(null, null, null, null, null, null, null, "xxx:00:00-xxx:01:00", null));
|
||||
assertEquals("Invalid maintenance window time 'xxx:00:00' specified. Should be specified as a time ddd:hh24:mi (24H Clock UTC). Example: Mon:00:15", e.getMessage());
|
||||
e = refused(new DocDbClusterSettings(null, null, null, null, null, null, "02:00-02:30", "tue:02:15-tue:02:45", null));
|
||||
assertEquals("The backup window and maintenance window must not overlap.", e.getMessage());
|
||||
assertThrows(AwsException.class, () -> docDbService.getDbCluster("c1"));
|
||||
verify(containerManager, never()).tryStart(any(), any(), any(), any());
|
||||
|
||||
// a window given alone is paired with a default clear of it
|
||||
docDbService.createDbCluster("alone", "5.0.0", "u", "pw", false,
|
||||
new DocDbClusterSettings(null, null, null, null, null, null, "00:30-01:00", null, null), Map.of());
|
||||
assertEquals("mon:01:00-mon:01:30", docDbService.getDbCluster("alone").getPreferredMaintenanceWindow());
|
||||
}
|
||||
|
||||
@Test
|
||||
void modifyDbClusterAppliesGivenSettingsChecksTheStoredWindowAndChangesNothingWhenRefused() {
|
||||
knownReferences();
|
||||
docDbService.createDbCluster("c1", "5.0.0", "u", "pw", false,
|
||||
new DocDbClusterSettings(null, null, null, true, KEY_ARN, 5, "01:00-01:30", "thu:10:00-thu:10:30", null),
|
||||
Map.of());
|
||||
|
||||
docDbService.modifyDbCluster("c1", null, null,
|
||||
new DocDbClusterSettings(null, "pg", List.of("sg-1"), null, null, 7, "02:00-02:30", "wed:05:00-wed:06:00", true));
|
||||
DocDbCluster stored = docDbService.getDbCluster("c1");
|
||||
assertEquals(7, stored.getBackupRetentionPeriod());
|
||||
assertEquals("02:00-02:30", stored.getPreferredBackupWindow());
|
||||
assertEquals("wed:05:00-wed:06:00", stored.getPreferredMaintenanceWindow());
|
||||
assertEquals("pg", stored.getDbClusterParameterGroupName());
|
||||
assertEquals(List.of("sg-1"), stored.getVpcSecurityGroupIds());
|
||||
assertTrue(stored.isDeletionProtection());
|
||||
assertTrue(stored.isStorageEncrypted());
|
||||
assertEquals(KEY_ARN, stored.getKmsKeyId());
|
||||
|
||||
AwsException overlap = assertThrows(AwsException.class, () -> docDbService.modifyDbCluster("c1", null, null,
|
||||
new DocDbClusterSettings(null, null, null, null, null, null, null, "mon:02:15-mon:02:45", null)));
|
||||
assertEquals("The backup window and maintenance window must not overlap.", overlap.getMessage());
|
||||
AwsException badPg = assertThrows(AwsException.class, () -> docDbService.modifyDbCluster("c1", null, null,
|
||||
new DocDbClusterSettings(null, "nope", null, null, null, 9, null, null, null)));
|
||||
assertEquals("DBClusterParameterGroupNotFound", badPg.getErrorCode());
|
||||
assertEquals(7, docDbService.getDbCluster("c1").getBackupRetentionPeriod());
|
||||
assertEquals("wed:05:00-wed:06:00", docDbService.getDbCluster("c1").getPreferredMaintenanceWindow());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createDbInstanceStoresSettingsAndTagsAndTakesTheClustersMaintenanceWindow() {
|
||||
knownReferences();
|
||||
docDbService.createDbCluster("c1", "5.0.0", "u", "pw", false,
|
||||
new DocDbClusterSettings(null, null, null, null, null, null, null, "thu:10:00-thu:10:30", null), Map.of());
|
||||
docDbService.createDbInstance("i1", "c1", "db.t3.medium", null, false,
|
||||
new DocDbInstanceSettings(false, "mon:05:00-mon:06:00", true, 2), Map.of("Name", "i1"));
|
||||
docDbService.createDbInstance("i2", "c1", "db.t3.medium", null, false);
|
||||
|
||||
DocDbInstance i1 = docDbService.getDbInstance("i1");
|
||||
assertFalse(i1.isAutoMinorVersionUpgrade());
|
||||
assertEquals("mon:05:00-mon:06:00", i1.getPreferredMaintenanceWindow());
|
||||
assertTrue(i1.isCopyTagsToSnapshot());
|
||||
assertEquals(2, i1.getPromotionTier());
|
||||
assertEquals(Map.of("Name", "i1"), i1.getTags());
|
||||
DocDbInstance i2 = docDbService.getDbInstance("i2");
|
||||
assertTrue(i2.isAutoMinorVersionUpgrade());
|
||||
assertEquals("thu:10:00-thu:10:30", i2.getPreferredMaintenanceWindow());
|
||||
assertFalse(i2.isCopyTagsToSnapshot());
|
||||
assertEquals(1, i2.getPromotionTier());
|
||||
|
||||
docDbService.modifyDbInstance("i2", null, null, new DocDbInstanceSettings(false, null, true, null));
|
||||
assertFalse(docDbService.getDbInstance("i2").isAutoMinorVersionUpgrade());
|
||||
assertTrue(docDbService.getDbInstance("i2").isCopyTagsToSnapshot());
|
||||
assertEquals("thu:10:00-thu:10:30", docDbService.getDbInstance("i2").getPreferredMaintenanceWindow());
|
||||
}
|
||||
}
|
||||
@@ -93,7 +93,10 @@ class RdsServiceTest {
|
||||
"postgres15",
|
||||
"postgres16",
|
||||
"postgres17",
|
||||
"postgres18");
|
||||
"postgres18",
|
||||
"docdb3.6",
|
||||
"docdb4.0",
|
||||
"docdb5.0");
|
||||
|
||||
private RdsService rdsService;
|
||||
private RdsContainerManager containerManager;
|
||||
|
||||
Reference in new issue
Block a user