Add support for OptionGroupName in create_db_instance
This commit is contained in:
parent
108dc6b049
commit
4fd0b5c710
@ -60,6 +60,15 @@ class DBParameterGroupNotFoundError(RDSClientError):
|
|||||||
'DB Parameter Group {0} not found.'.format(db_parameter_group_name))
|
'DB Parameter Group {0} not found.'.format(db_parameter_group_name))
|
||||||
|
|
||||||
|
|
||||||
|
class OptionGroupNotFoundFaultError(RDSClientError):
|
||||||
|
|
||||||
|
def __init__(self, option_group_name):
|
||||||
|
super(OptionGroupNotFoundFaultError, self).__init__(
|
||||||
|
'OptionGroupNotFoundFault',
|
||||||
|
'Specified OptionGroupName: {0} not found.'.format(option_group_name)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class InvalidDBClusterStateFaultError(RDSClientError):
|
class InvalidDBClusterStateFaultError(RDSClientError):
|
||||||
|
|
||||||
def __init__(self, database_identifier):
|
def __init__(self, database_identifier):
|
||||||
|
@ -20,6 +20,7 @@ from .exceptions import (RDSClientError,
|
|||||||
DBSecurityGroupNotFoundError,
|
DBSecurityGroupNotFoundError,
|
||||||
DBSubnetGroupNotFoundError,
|
DBSubnetGroupNotFoundError,
|
||||||
DBParameterGroupNotFoundError,
|
DBParameterGroupNotFoundError,
|
||||||
|
OptionGroupNotFoundFaultError,
|
||||||
InvalidDBClusterStateFaultError,
|
InvalidDBClusterStateFaultError,
|
||||||
InvalidDBInstanceStateError,
|
InvalidDBInstanceStateError,
|
||||||
SnapshotQuotaExceededError,
|
SnapshotQuotaExceededError,
|
||||||
@ -100,6 +101,8 @@ class Database(BaseModel):
|
|||||||
'preferred_backup_window', '13:14-13:44')
|
'preferred_backup_window', '13:14-13:44')
|
||||||
self.license_model = kwargs.get('license_model', 'general-public-license')
|
self.license_model = kwargs.get('license_model', 'general-public-license')
|
||||||
self.option_group_name = kwargs.get('option_group_name', None)
|
self.option_group_name = kwargs.get('option_group_name', None)
|
||||||
|
if self.option_group_name and self.option_group_name not in rds2_backends[self.region].option_groups:
|
||||||
|
raise OptionGroupNotFoundFaultError(self.option_group_name)
|
||||||
self.default_option_groups = {"MySQL": "default.mysql5.6",
|
self.default_option_groups = {"MySQL": "default.mysql5.6",
|
||||||
"mysql": "default.mysql5.6",
|
"mysql": "default.mysql5.6",
|
||||||
"postgres": "default.postgres9.3"
|
"postgres": "default.postgres9.3"
|
||||||
@ -175,6 +178,10 @@ class Database(BaseModel):
|
|||||||
<LicenseModel>{{ database.license_model }}</LicenseModel>
|
<LicenseModel>{{ database.license_model }}</LicenseModel>
|
||||||
<EngineVersion>{{ database.engine_version }}</EngineVersion>
|
<EngineVersion>{{ database.engine_version }}</EngineVersion>
|
||||||
<OptionGroupMemberships>
|
<OptionGroupMemberships>
|
||||||
|
<OptionGroupMembership>
|
||||||
|
<OptionGroupName>{{ database.option_group_name }}</OptionGroupName>
|
||||||
|
<Status>in-sync</Status>
|
||||||
|
</OptionGroupMembership>
|
||||||
</OptionGroupMemberships>
|
</OptionGroupMemberships>
|
||||||
<DBParameterGroups>
|
<DBParameterGroups>
|
||||||
{% for db_parameter_group in database.db_parameter_groups() %}
|
{% for db_parameter_group in database.db_parameter_groups() %}
|
||||||
@ -875,13 +882,16 @@ class RDS2Backend(BaseBackend):
|
|||||||
|
|
||||||
def create_option_group(self, option_group_kwargs):
|
def create_option_group(self, option_group_kwargs):
|
||||||
option_group_id = option_group_kwargs['name']
|
option_group_id = option_group_kwargs['name']
|
||||||
valid_option_group_engines = {'mysql': ['5.6'],
|
valid_option_group_engines = {'mariadb': ['10.0', '10.1', '10.2', '10.3'],
|
||||||
'oracle-se1': ['11.2'],
|
'mysql': ['5.5', '5.6', '5.7', '8.0'],
|
||||||
'oracle-se': ['11.2'],
|
'oracle-se2': ['11.2', '12.1', '12.2'],
|
||||||
'oracle-ee': ['11.2'],
|
'oracle-se1': ['11.2', '12.1', '12.2'],
|
||||||
|
'oracle-se': ['11.2', '12.1', '12.2'],
|
||||||
|
'oracle-ee': ['11.2', '12.1', '12.2'],
|
||||||
'sqlserver-se': ['10.50', '11.00'],
|
'sqlserver-se': ['10.50', '11.00'],
|
||||||
'sqlserver-ee': ['10.50', '11.00']
|
'sqlserver-ee': ['10.50', '11.00'],
|
||||||
}
|
'sqlserver-ex': ['10.50', '11.00'],
|
||||||
|
'sqlserver-web': ['10.50', '11.00']}
|
||||||
if option_group_kwargs['name'] in self.option_groups:
|
if option_group_kwargs['name'] in self.option_groups:
|
||||||
raise RDSClientError('OptionGroupAlreadyExistsFault',
|
raise RDSClientError('OptionGroupAlreadyExistsFault',
|
||||||
'An option group named {0} already exists.'.format(option_group_kwargs['name']))
|
'An option group named {0} already exists.'.format(option_group_kwargs['name']))
|
||||||
@ -907,8 +917,7 @@ class RDS2Backend(BaseBackend):
|
|||||||
if option_group_name in self.option_groups:
|
if option_group_name in self.option_groups:
|
||||||
return self.option_groups.pop(option_group_name)
|
return self.option_groups.pop(option_group_name)
|
||||||
else:
|
else:
|
||||||
raise RDSClientError(
|
raise OptionGroupNotFoundFaultError(option_group_name)
|
||||||
'OptionGroupNotFoundFault', 'Specified OptionGroupName: {0} not found.'.format(option_group_name))
|
|
||||||
|
|
||||||
def describe_option_groups(self, option_group_kwargs):
|
def describe_option_groups(self, option_group_kwargs):
|
||||||
option_group_list = []
|
option_group_list = []
|
||||||
@ -937,8 +946,7 @@ class RDS2Backend(BaseBackend):
|
|||||||
else:
|
else:
|
||||||
option_group_list.append(option_group)
|
option_group_list.append(option_group)
|
||||||
if not len(option_group_list):
|
if not len(option_group_list):
|
||||||
raise RDSClientError('OptionGroupNotFoundFault',
|
raise OptionGroupNotFoundFaultError(option_group_kwargs['name'])
|
||||||
'Specified OptionGroupName: {0} not found.'.format(option_group_kwargs['name']))
|
|
||||||
return option_group_list[marker:max_records + marker]
|
return option_group_list[marker:max_records + marker]
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@ -967,8 +975,7 @@ class RDS2Backend(BaseBackend):
|
|||||||
|
|
||||||
def modify_option_group(self, option_group_name, options_to_include=None, options_to_remove=None, apply_immediately=None):
|
def modify_option_group(self, option_group_name, options_to_include=None, options_to_remove=None, apply_immediately=None):
|
||||||
if option_group_name not in self.option_groups:
|
if option_group_name not in self.option_groups:
|
||||||
raise RDSClientError('OptionGroupNotFoundFault',
|
raise OptionGroupNotFoundFaultError(option_group_name)
|
||||||
'Specified OptionGroupName: {0} not found.'.format(option_group_name))
|
|
||||||
if not options_to_include and not options_to_remove:
|
if not options_to_include and not options_to_remove:
|
||||||
raise RDSClientError('InvalidParameterValue',
|
raise RDSClientError('InvalidParameterValue',
|
||||||
'At least one option must be added, modified, or removed.')
|
'At least one option must be added, modified, or removed.')
|
||||||
|
@ -34,7 +34,7 @@ class RDS2Response(BaseResponse):
|
|||||||
"master_user_password": self._get_param('MasterUserPassword'),
|
"master_user_password": self._get_param('MasterUserPassword'),
|
||||||
"master_username": self._get_param('MasterUsername'),
|
"master_username": self._get_param('MasterUsername'),
|
||||||
"multi_az": self._get_bool_param("MultiAZ"),
|
"multi_az": self._get_bool_param("MultiAZ"),
|
||||||
# OptionGroupName
|
"option_group_name": self._get_param("OptionGroupName"),
|
||||||
"port": self._get_param('Port'),
|
"port": self._get_param('Port'),
|
||||||
# PreferredBackupWindow
|
# PreferredBackupWindow
|
||||||
# PreferredMaintenanceWindow
|
# PreferredMaintenanceWindow
|
||||||
|
@ -37,6 +37,38 @@ def test_create_database():
|
|||||||
db_instance['InstanceCreateTime'].should.be.a("datetime.datetime")
|
db_instance['InstanceCreateTime'].should.be.a("datetime.datetime")
|
||||||
|
|
||||||
|
|
||||||
|
@mock_rds2
|
||||||
|
def test_create_database_non_existing_option_group():
|
||||||
|
conn = boto3.client('rds', region_name='us-west-2')
|
||||||
|
database = conn.create_db_instance.when.called_with(
|
||||||
|
DBInstanceIdentifier='db-master-1',
|
||||||
|
AllocatedStorage=10,
|
||||||
|
Engine='postgres',
|
||||||
|
DBName='staging-postgres',
|
||||||
|
DBInstanceClass='db.m1.small',
|
||||||
|
OptionGroupName='non-existing').should.throw(ClientError)
|
||||||
|
|
||||||
|
|
||||||
|
@mock_rds2
|
||||||
|
def test_create_database_with_option_group():
|
||||||
|
conn = boto3.client('rds', region_name='us-west-2')
|
||||||
|
conn.create_option_group(OptionGroupName='my-og',
|
||||||
|
EngineName='mysql',
|
||||||
|
MajorEngineVersion='5.6',
|
||||||
|
OptionGroupDescription='test option group')
|
||||||
|
database = conn.create_db_instance(DBInstanceIdentifier='db-master-1',
|
||||||
|
AllocatedStorage=10,
|
||||||
|
Engine='postgres',
|
||||||
|
DBName='staging-postgres',
|
||||||
|
DBInstanceClass='db.m1.small',
|
||||||
|
OptionGroupName='my-og')
|
||||||
|
db_instance = database['DBInstance']
|
||||||
|
db_instance['AllocatedStorage'].should.equal(10)
|
||||||
|
db_instance['DBInstanceClass'].should.equal('db.m1.small')
|
||||||
|
db_instance['DBName'].should.equal('staging-postgres')
|
||||||
|
db_instance['OptionGroupMemberships'][0]['OptionGroupName'].should.equal('my-og')
|
||||||
|
|
||||||
|
|
||||||
@mock_rds2
|
@mock_rds2
|
||||||
def test_stop_database():
|
def test_stop_database():
|
||||||
conn = boto3.client('rds', region_name='us-west-2')
|
conn = boto3.client('rds', region_name='us-west-2')
|
||||||
@ -205,6 +237,7 @@ def test_get_databases_paginated():
|
|||||||
resp3 = conn.describe_db_instances(MaxRecords=100)
|
resp3 = conn.describe_db_instances(MaxRecords=100)
|
||||||
resp3["DBInstances"].should.have.length_of(51)
|
resp3["DBInstances"].should.have.length_of(51)
|
||||||
|
|
||||||
|
|
||||||
@mock_rds2
|
@mock_rds2
|
||||||
def test_describe_non_existant_database():
|
def test_describe_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