From ebe48e74435d1151a559eabed78b25d46214594b Mon Sep 17 00:00:00 2001 From: Akira Noda <61897166+tsugumi-sys@users.noreply.github.com> Date: Wed, 10 May 2023 23:48:17 +0900 Subject: [PATCH] RDS: add SourceType field for response (#6306) --- moto/rds/models.py | 4 ++ tests/test_rds/test_rds_export_tasks.py | 54 ++++++++++++++++++++++++- 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/moto/rds/models.py b/moto/rds/models.py index bdc823243..ea79565e3 100644 --- a/moto/rds/models.py +++ b/moto/rds/models.py @@ -1136,6 +1136,9 @@ class ExportTask(BaseModel): self.status = "complete" self.created_at = iso_8601_datetime_with_milliseconds(datetime.datetime.now()) + self.source_type = ( + "SNAPSHOT" if type(snapshot) is DatabaseSnapshot else "CLUSTER" + ) def to_xml(self) -> str: template = Template( @@ -1161,6 +1164,7 @@ class ExportTask(BaseModel): {{ 1 }} + {{ task.source_type }} """ ) return template.render(task=self, snapshot=self.snapshot) diff --git a/tests/test_rds/test_rds_export_tasks.py b/tests/test_rds/test_rds_export_tasks.py index 2f614ef26..3ef0a3b0c 100644 --- a/tests/test_rds/test_rds_export_tasks.py +++ b/tests/test_rds/test_rds_export_tasks.py @@ -25,6 +25,30 @@ def _prepare_db_snapshot(client, snapshot_name="snapshot-1"): return resp["DBSnapshot"]["DBSnapshotArn"] +def _prepare_db_cluster_snapshot(client, snapshot_name="cluster-snapshot-1"): + db_cluster_identifier = "db-cluster-primary-1" + client.create_db_cluster( + AvailabilityZones=[ + "us-west-2", + ], + BackupRetentionPeriod=1, + DBClusterIdentifier=db_cluster_identifier, + DBClusterParameterGroupName="db-cluster-primary-1-group", + DatabaseName="staging-postgres", + Engine="postgres", + EngineVersion="5.6.10a", + MasterUserPassword="hunterxhunder", + MasterUsername="root", + Port=3306, + StorageEncrypted=True, + ) + resp = client.create_db_cluster_snapshot( + DBClusterSnapshotIdentifier=snapshot_name, + DBClusterIdentifier=db_cluster_identifier, + ) + return resp["DBClusterSnapshot"]["DBClusterSnapshotArn"] + + @mock_rds def test_start_export_task_fails_unknown_snapshot(): client = boto3.client("rds", region_name="us-west-2") @@ -44,7 +68,7 @@ def test_start_export_task_fails_unknown_snapshot(): @mock_rds -def test_start_export_task(): +def test_start_export_task_db(): client = boto3.client("rds", region_name="us-west-2") source_arn = _prepare_db_snapshot(client) @@ -67,6 +91,34 @@ def test_start_export_task(): "arn:aws:kms:::key/0ea3fef3-80a7-4778-9d8c-1c0c6EXAMPLE" ) export["ExportOnly"].should.equal(["schema.table"]) + export["SourceType"].should.equal("SNAPSHOT") + + +@mock_rds +def test_start_export_task_db_cluster(): + client = boto3.client("rds", region_name="us-west-2") + source_arn = _prepare_db_cluster_snapshot(client) + + export = client.start_export_task( + ExportTaskIdentifier="export-snapshot-1", + SourceArn=source_arn, + S3BucketName="export-bucket", + S3Prefix="snaps/", + IamRoleArn="arn:aws:iam:::role/export-role", + KmsKeyId="arn:aws:kms:::key/0ea3fef3-80a7-4778-9d8c-1c0c6EXAMPLE", + ExportOnly=["schema.table"], + ) + + export["ExportTaskIdentifier"].should.equal("export-snapshot-1") + export["SourceArn"].should.equal(source_arn) + export["S3Bucket"].should.equal("export-bucket") + export["S3Prefix"].should.equal("snaps/") + export["IamRoleArn"].should.equal("arn:aws:iam:::role/export-role") + export["KmsKeyId"].should.equal( + "arn:aws:kms:::key/0ea3fef3-80a7-4778-9d8c-1c0c6EXAMPLE" + ) + export["ExportOnly"].should.equal(["schema.table"]) + export["SourceType"].should.equal("CLUSTER") @mock_rds