diff --git a/moto/rds/responses.py b/moto/rds/responses.py index 0895a8bf2..987a6f21a 100644 --- a/moto/rds/responses.py +++ b/moto/rds/responses.py @@ -107,6 +107,9 @@ class RDSResponse(BaseResponse): def modify_db_instance(self): db_instance_identifier = self._get_param('DBInstanceIdentifier') db_kwargs = self._get_db_kwargs() + new_db_instance_identifier = self._get_param('NewDBInstanceIdentifier') + if new_db_instance_identifier: + db_kwargs['new_db_instance_identifier'] = new_db_instance_identifier database = self.backend.modify_database( db_instance_identifier, db_kwargs) template = self.response_template(MODIFY_DATABASE_TEMPLATE) diff --git a/moto/rds2/models.py b/moto/rds2/models.py index cca72efbd..268ae5af2 100644 --- a/moto/rds2/models.py +++ b/moto/rds2/models.py @@ -736,6 +736,10 @@ class RDS2Backend(BaseBackend): def modify_database(self, db_instance_identifier, db_kwargs): database = self.describe_databases(db_instance_identifier)[0] + if 'new_db_instance_identifier' in db_kwargs: + del self.databases[db_instance_identifier] + db_instance_identifier = db_kwargs['db_instance_identifier'] = db_kwargs.pop('new_db_instance_identifier') + self.databases[db_instance_identifier] = database database.update(db_kwargs) return database diff --git a/moto/rds2/responses.py b/moto/rds2/responses.py index bf76660aa..3e093221d 100644 --- a/moto/rds2/responses.py +++ b/moto/rds2/responses.py @@ -135,6 +135,9 @@ class RDS2Response(BaseResponse): def modify_db_instance(self): db_instance_identifier = self._get_param('DBInstanceIdentifier') db_kwargs = self._get_db_kwargs() + new_db_instance_identifier = self._get_param('NewDBInstanceIdentifier') + if new_db_instance_identifier: + db_kwargs['new_db_instance_identifier'] = new_db_instance_identifier database = self.backend.modify_database( db_instance_identifier, db_kwargs) template = self.response_template(MODIFY_DATABASE_TEMPLATE) diff --git a/tests/test_rds2/test_rds2.py b/tests/test_rds2/test_rds2.py index 47b5cf9f9..183a183b1 100644 --- a/tests/test_rds2/test_rds2.py +++ b/tests/test_rds2/test_rds2.py @@ -225,6 +225,28 @@ def test_modify_db_instance(): instances['DBInstances'][0]['AllocatedStorage'].should.equal(20) +@mock_rds2 +def test_rename_db_instance(): + conn = boto3.client('rds', region_name='us-west-2') + database = 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") + list(instances['DBInstances']).should.have.length_of(1) + conn.describe_db_instances.when.called_with(DBInstanceIdentifier="db-master-2").should.throw(ClientError) + conn.modify_db_instance(DBInstanceIdentifier='db-master-1', + NewDBInstanceIdentifier='db-master-2', + ApplyImmediately=True) + conn.describe_db_instances.when.called_with(DBInstanceIdentifier="db-master-1").should.throw(ClientError) + instances = conn.describe_db_instances(DBInstanceIdentifier="db-master-2") + list(instances['DBInstances']).should.have.length_of(1) + + @mock_rds2 def test_modify_non_existant_database(): conn = boto3.client('rds', region_name='us-west-2')