modify_db_instance should be able to rename DB instances (#1367)
This commit is contained in:
parent
9e1a233549
commit
796fa6647b
@ -107,6 +107,9 @@ class RDSResponse(BaseResponse):
|
|||||||
def modify_db_instance(self):
|
def modify_db_instance(self):
|
||||||
db_instance_identifier = self._get_param('DBInstanceIdentifier')
|
db_instance_identifier = self._get_param('DBInstanceIdentifier')
|
||||||
db_kwargs = self._get_db_kwargs()
|
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(
|
database = self.backend.modify_database(
|
||||||
db_instance_identifier, db_kwargs)
|
db_instance_identifier, db_kwargs)
|
||||||
template = self.response_template(MODIFY_DATABASE_TEMPLATE)
|
template = self.response_template(MODIFY_DATABASE_TEMPLATE)
|
||||||
|
@ -736,6 +736,10 @@ class RDS2Backend(BaseBackend):
|
|||||||
|
|
||||||
def modify_database(self, db_instance_identifier, db_kwargs):
|
def modify_database(self, db_instance_identifier, db_kwargs):
|
||||||
database = self.describe_databases(db_instance_identifier)[0]
|
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)
|
database.update(db_kwargs)
|
||||||
return database
|
return database
|
||||||
|
|
||||||
|
@ -135,6 +135,9 @@ class RDS2Response(BaseResponse):
|
|||||||
def modify_db_instance(self):
|
def modify_db_instance(self):
|
||||||
db_instance_identifier = self._get_param('DBInstanceIdentifier')
|
db_instance_identifier = self._get_param('DBInstanceIdentifier')
|
||||||
db_kwargs = self._get_db_kwargs()
|
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(
|
database = self.backend.modify_database(
|
||||||
db_instance_identifier, db_kwargs)
|
db_instance_identifier, db_kwargs)
|
||||||
template = self.response_template(MODIFY_DATABASE_TEMPLATE)
|
template = self.response_template(MODIFY_DATABASE_TEMPLATE)
|
||||||
|
@ -225,6 +225,28 @@ def test_modify_db_instance():
|
|||||||
instances['DBInstances'][0]['AllocatedStorage'].should.equal(20)
|
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
|
@mock_rds2
|
||||||
def test_modify_non_existant_database():
|
def test_modify_non_existant_database():
|
||||||
conn = boto3.client('rds', region_name='us-west-2')
|
conn = boto3.client('rds', region_name='us-west-2')
|
||||||
|
Loading…
Reference in New Issue
Block a user