From e3fc799b95b223bbdf3713958807d1b77a5958f4 Mon Sep 17 00:00:00 2001 From: steffyP Date: Tue, 22 Feb 2022 00:32:37 +0100 Subject: [PATCH] RDS modify-db-instance: raise DBParameterGroupNotFoundError if the DBParameterGroupName does not exist (#4879) --- moto/rds2/models.py | 6 ++++++ tests/test_rds2/test_rds2.py | 21 +++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/moto/rds2/models.py b/moto/rds2/models.py index bd2610518..740cae63b 100644 --- a/moto/rds2/models.py +++ b/moto/rds2/models.py @@ -455,6 +455,12 @@ class Database(CloudFormationModel): ) ] else: + if ( + self.db_parameter_group_name + not in rds2_backends[self.region].db_parameter_groups + ): + raise DBParameterGroupNotFoundError(self.db_parameter_group_name) + return [ rds2_backends[self.region].db_parameter_groups[ self.db_parameter_group_name diff --git a/tests/test_rds2/test_rds2.py b/tests/test_rds2/test_rds2.py index ab792ff7b..5b98c7e68 100644 --- a/tests/test_rds2/test_rds2.py +++ b/tests/test_rds2/test_rds2.py @@ -396,6 +396,27 @@ def test_modify_db_instance(): ].should.equal("sg-123456") +@mock_rds2 +def test_modify_db_instance_not_existent_db_parameter_group_name(): + conn = boto3.client("rds", region_name="us-west-2") + conn.create_db_instance( + DBInstanceIdentifier="db-master-1", + AllocatedStorage=10, + DBInstanceClass="postgres", + Engine="db.m1.small", + MasterUsername="root", + MasterUserPassword="hunter2", + Port=1234, + DBSecurityGroups=["my_sg"], + ) + instances = conn.describe_db_instances(DBInstanceIdentifier="db-master-1") + instances["DBInstances"][0]["AllocatedStorage"].should.equal(10) + conn.modify_db_instance.when.called_with( + DBInstanceIdentifier="db-master-1", + DBParameterGroupName="test-sqlserver-se-2017", + ).should.throw(ClientError) + + @mock_rds2 def test_rename_db_instance(): conn = boto3.client("rds", region_name="us-west-2")