support default ports in RDS

This commit is contained in:
Jack Danger Canty 2017-05-08 20:05:46 -10:00
parent df84675ae6
commit 6d8aa9d8f1
2 changed files with 32 additions and 0 deletions

View File

@ -57,6 +57,8 @@ class Database(BaseModel):
self.source_db_identifier = kwargs.get("source_db_identifier")
self.db_instance_class = kwargs.get('db_instance_class')
self.port = kwargs.get('port')
if self.port is None:
self.port = Database.default_port(self.engine)
self.db_instance_identifier = kwargs.get('db_instance_identifier')
self.db_name = kwargs.get("db_name")
self.publicly_accessible = kwargs.get("publicly_accessible")
@ -241,6 +243,22 @@ class Database(BaseModel):
return self.port
raise UnformattedGetAttTemplateException()
@staticmethod
def default_port(engine):
return {
'mysql': 3306,
'mariadb': 3306,
'postgres': 5432,
'oracle-ee': 1521,
'oracle-se2': 1521,
'oracle-se1': 1521,
'oracle-se': 1521,
'sqlserver-ee': 1433,
'sqlserver-ex': 1433,
'sqlserver-se': 1433,
'sqlserver-web': 1433,
}[engine]
@classmethod
def create_from_cloudformation_json(cls, resource_name, cloudformation_json, region_name):
properties = cloudformation_json['Properties']

View File

@ -973,6 +973,20 @@ def test_create_db_instance_with_parameter_group():
'ParameterApplyStatus'].should.equal('in-sync')
@disable_on_py3()
@mock_rds2
def test_create_database_with_default_port():
conn = boto3.client('rds', region_name='us-west-2')
database = conn.create_db_instance(DBInstanceIdentifier='db-master-1',
AllocatedStorage=10,
Engine='postgres',
DBInstanceClass='db.m1.small',
MasterUsername='root',
MasterUserPassword='hunter2',
DBSecurityGroups=["my_sg"])
database['DBInstance']['Endpoint']['Port'].should.equal(5432)
@disable_on_py3()
@mock_rds2
def test_modify_db_instance_with_parameter_group():