Added db_subnet_group support
This commit is contained in:
parent
8614b50898
commit
42ab9312bb
@ -60,8 +60,8 @@ class Database(object):
|
|||||||
if self.db_subnet_group_name:
|
if self.db_subnet_group_name:
|
||||||
self.db_subnet_group = rds2_backends[self.region].describe_subnet_groups(self.db_subnet_group_name)[0]
|
self.db_subnet_group = rds2_backends[self.region].describe_subnet_groups(self.db_subnet_group_name)[0]
|
||||||
else:
|
else:
|
||||||
self.db_subnet_group = []
|
self.db_subnet_group = None
|
||||||
self.db_security_groups = kwargs.get('security_groups', ['a'])
|
self.security_groups = kwargs.get('security_groups', [])
|
||||||
self.vpc_security_group_ids = kwargs.get('vpc_security_group_ids', [])
|
self.vpc_security_group_ids = kwargs.get('vpc_security_group_ids', [])
|
||||||
self.preferred_maintenance_window = kwargs.get('preferred_maintenance_window', 'wed:06:38-wed:07:08')
|
self.preferred_maintenance_window = kwargs.get('preferred_maintenance_window', 'wed:06:38-wed:07:08')
|
||||||
self.db_parameter_group_name = kwargs.get('db_parameter_group_name', None)
|
self.db_parameter_group_name = kwargs.get('db_parameter_group_name', None)
|
||||||
@ -174,37 +174,14 @@ class Database(object):
|
|||||||
"DBParameterGroupName": "{{ database.db_parameter_group_name }}"
|
"DBParameterGroupName": "{{ database.db_parameter_group_name }}"
|
||||||
}
|
}
|
||||||
},{%- endif %}
|
},{%- endif %}
|
||||||
"DBSecurityGroups": [{
|
"DBSecurityGroups": [
|
||||||
{% for security_group in database.db_security_groups -%}{%- if loop.index != 1 -%},{%- endif -%}
|
{% for security_group in database.security_groups -%}{%- if loop.index != 1 -%},{%- endif -%}
|
||||||
"DBSecurityGroup": {
|
{"DBSecurityGroup": {
|
||||||
"Status": "active",
|
"Status": "active",
|
||||||
"DBSecurityGroupName": "{{ security_group }}"
|
"DBSecurityGroupName": "{{ security_group }}"
|
||||||
}{% endfor %}
|
}}{% endfor %}
|
||||||
}],{%- if database.db_subnet_group -%}
|
],
|
||||||
"DBSubnetGroup": {
|
{%- if database.db_subnet_group -%}{{ database.db_subnet_group.to_json() }},{%- endif %}
|
||||||
"DBSubnetGroupDescription": "nabil-db-subnet-group",
|
|
||||||
"DBSubnetGroupName": "nabil-db-subnet-group",
|
|
||||||
"SubnetGroupStatus": "Complete",
|
|
||||||
"Subnets": [
|
|
||||||
{
|
|
||||||
"SubnetAvailabilityZone": {
|
|
||||||
"Name": "us-west-2c",
|
|
||||||
"ProvisionedIopsCapable": false
|
|
||||||
},
|
|
||||||
"SubnetIdentifier": "subnet-c0ea0099",
|
|
||||||
"SubnetStatus": "Active"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"SubnetAvailabilityZone": {
|
|
||||||
"Name": "us-west-2a",
|
|
||||||
"ProvisionedIopsCapable": false
|
|
||||||
},
|
|
||||||
"SubnetIdentifier": "subnet-ff885d88",
|
|
||||||
"SubnetStatus": "Active"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"VpcId": "vpc-8e6ab6eb"
|
|
||||||
},{%- endif %}
|
|
||||||
"Engine": "{{ database.engine }}",
|
"Engine": "{{ database.engine }}",
|
||||||
"EngineVersion": "{{ database.engine_version }}",
|
"EngineVersion": "{{ database.engine_version }}",
|
||||||
"LatestRestorableTime": null,
|
"LatestRestorableTime": null,
|
||||||
@ -386,8 +363,7 @@ class SubnetGroup(object):
|
|||||||
return template.render(subnet_group=self)
|
return template.render(subnet_group=self)
|
||||||
|
|
||||||
def to_json(self):
|
def to_json(self):
|
||||||
template = Template("""{
|
template = Template(""""DBSubnetGroup": {
|
||||||
"DBSubnetGroup": {
|
|
||||||
"VpcId": "{{ subnet_group.vpc_id }}",
|
"VpcId": "{{ subnet_group.vpc_id }}",
|
||||||
"SubnetGroupStatus": "{{ subnet_group.status }}",
|
"SubnetGroupStatus": "{{ subnet_group.status }}",
|
||||||
"DBSubnetGroupDescription": "{{ subnet_group.description }}",
|
"DBSubnetGroupDescription": "{{ subnet_group.description }}",
|
||||||
@ -404,8 +380,7 @@ class SubnetGroup(object):
|
|||||||
}{%- if not loop.last -%},{%- endif -%}{% endfor %}
|
}{%- if not loop.last -%},{%- endif -%}{% endfor %}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}""")
|
||||||
}""")
|
|
||||||
return template.render(subnet_group=self)
|
return template.render(subnet_group=self)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
@ -394,7 +394,7 @@ AUTHORIZE_SECURITY_GROUP_TEMPLATE = """{
|
|||||||
CREATE_SUBNET_GROUP_TEMPLATE = """{
|
CREATE_SUBNET_GROUP_TEMPLATE = """{
|
||||||
"CreateDBSubnetGroupResponse": {
|
"CreateDBSubnetGroupResponse": {
|
||||||
"CreateDBSubnetGroupResult":
|
"CreateDBSubnetGroupResult":
|
||||||
{{ subnet_group.to_json() }},
|
{ {{ subnet_group.to_json() }} },
|
||||||
"ResponseMetadata": { "RequestId": "3a401b3f-bb9e-11d3-f4c6-37db295f7674" }
|
"ResponseMetadata": { "RequestId": "3a401b3f-bb9e-11d3-f4c6-37db295f7674" }
|
||||||
}
|
}
|
||||||
}"""
|
}"""
|
||||||
@ -404,7 +404,7 @@ DESCRIBE_SUBNET_GROUPS_TEMPLATE = """{
|
|||||||
"DescribeDBSubnetGroupsResult": {
|
"DescribeDBSubnetGroupsResult": {
|
||||||
"DBSubnetGroups": [
|
"DBSubnetGroups": [
|
||||||
{% for subnet_group in subnet_groups %}
|
{% for subnet_group in subnet_groups %}
|
||||||
{{ subnet_group.to_json() }}{%- if not loop.last -%},{%- endif -%}
|
{ {{ subnet_group.to_json() }} }{%- if not loop.last -%},{%- endif -%}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
],
|
],
|
||||||
"Marker": null
|
"Marker": null
|
||||||
@ -414,11 +414,7 @@ DESCRIBE_SUBNET_GROUPS_TEMPLATE = """{
|
|||||||
}"""
|
}"""
|
||||||
|
|
||||||
|
|
||||||
DELETE_SUBNET_GROUP_TEMPLATE = """<DeleteDBSubnetGroupResponse xmlns="http://rds.amazonaws.com/doc/2014-09-01/">
|
DELETE_SUBNET_GROUP_TEMPLATE = """{"DeleteDBSubnetGroupResponse": {"ResponseMetadata": {"RequestId": "13785dd5-a7fc-11e4-bb9c-7f371d0859b0"}}}"""
|
||||||
<ResponseMetadata>
|
|
||||||
<RequestId>6295e5ab-bbf3-11d3-f4c6-37db295f7674</RequestId>
|
|
||||||
</ResponseMetadata>
|
|
||||||
</DeleteDBSubnetGroupResponse>"""
|
|
||||||
|
|
||||||
CREATE_OPTION_GROUP_TEMPLATE = """{
|
CREATE_OPTION_GROUP_TEMPLATE = """{
|
||||||
"CreateOptionGroupResponse": {
|
"CreateOptionGroupResponse": {
|
||||||
|
@ -4,7 +4,7 @@ import boto.rds2
|
|||||||
import boto.vpc
|
import boto.vpc
|
||||||
from boto.exception import BotoServerError
|
from boto.exception import BotoServerError
|
||||||
import sure # noqa
|
import sure # noqa
|
||||||
|
import json
|
||||||
from moto import mock_ec2, mock_rds2
|
from moto import mock_ec2, mock_rds2
|
||||||
from tests.helpers import disable_on_py3
|
from tests.helpers import disable_on_py3
|
||||||
|
|
||||||
@ -435,35 +435,63 @@ def test_security_group_authorize():
|
|||||||
result['DescribeDBSecurityGroupsResponse']['DescribeDBSecurityGroupsResult']['DBSecurityGroups'][0]['IPRanges'].should.equal(['10.3.2.45/32', '10.3.2.46/32'])
|
result['DescribeDBSecurityGroupsResponse']['DescribeDBSecurityGroupsResult']['DBSecurityGroups'][0]['IPRanges'].should.equal(['10.3.2.45/32', '10.3.2.46/32'])
|
||||||
|
|
||||||
|
|
||||||
#@disable_on_py3()
|
@disable_on_py3()
|
||||||
#@mock_rds2
|
@mock_rds2
|
||||||
#def test_add_security_group_to_database():
|
def test_add_security_group_to_database():
|
||||||
# conn = boto.rds2.connect_to_region("us-west-2")
|
conn = boto.rds2.connect_to_region("us-west-2")
|
||||||
#
|
|
||||||
# database = conn.create_dbinstance("db-master-1", 10, 'db.m1.small', 'root', 'hunter2')
|
conn.create_db_instance(db_instance_identifier='db-master-1',
|
||||||
# security_group = conn.create_dbsecurity_group('db_sg', 'DB Security Group')
|
allocated_storage=10,
|
||||||
# database.modify(security_groups=[security_group])
|
engine='postgres',
|
||||||
#
|
db_instance_class='db.m1.small',
|
||||||
# database = conn.get_all_dbinstances()[0]
|
master_username='root',
|
||||||
# list(database.security_groups).should.have.length_of(1)
|
master_user_password='hunter2')
|
||||||
#
|
result = conn.describe_db_instances()
|
||||||
# database.security_groups[0].name.should.equal("db_sg")
|
result['DescribeDBInstancesResponse']['DescribeDBInstancesResult']['DBInstances'][0]['DBSecurityGroups'].should.equal([])
|
||||||
#
|
conn.create_db_security_group('db_sg', 'DB Security Group')
|
||||||
#
|
conn.modify_db_instance(db_instance_identifier='db-master-1',
|
||||||
#@mock_ec2
|
db_security_groups=['db_sg'])
|
||||||
#@mock_rds2
|
result = conn.describe_db_instances()
|
||||||
#def test_add_database_subnet_group():
|
result['DescribeDBInstancesResponse']['DescribeDBInstancesResult']['DBInstances'][0]['DBSecurityGroups'][0]['DBSecurityGroup']['DBSecurityGroupName'].should.equal('db_sg')
|
||||||
# vpc_conn = boto.vpc.connect_to_region("us-west-2")
|
|
||||||
# vpc = vpc_conn.create_vpc("10.0.0.0/16")
|
|
||||||
# subnet1 = vpc_conn.create_subnet(vpc.id, "10.1.0.0/24")
|
@mock_ec2
|
||||||
# subnet2 = vpc_conn.create_subnet(vpc.id, "10.2.0.0/24")
|
@mock_rds2
|
||||||
#
|
def test_create_database_subnet_group():
|
||||||
# subnet_ids = [subnet1.id, subnet2.id]
|
vpc_conn = boto.vpc.connect_to_region("us-west-2")
|
||||||
# conn = boto.rds2.connect_to_region("us-west-2")
|
vpc = vpc_conn.create_vpc("10.0.0.0/16")
|
||||||
# subnet_group = conn.create_db_subnet_group("db_subnet", "my db subnet", subnet_ids)
|
subnet1 = vpc_conn.create_subnet(vpc.id, "10.1.0.0/24")
|
||||||
# subnet_group.name.should.equal('db_subnet')
|
subnet2 = vpc_conn.create_subnet(vpc.id, "10.2.0.0/24")
|
||||||
# subnet_group.description.should.equal("my db subnet")
|
|
||||||
# list(subnet_group.subnet_ids).should.equal(subnet_ids)
|
subnet_ids = [subnet1.id, subnet2.id]
|
||||||
|
conn = boto.rds2.connect_to_region("us-west-2")
|
||||||
|
result = conn.create_db_subnet_group("db_subnet", "my db subnet", subnet_ids)
|
||||||
|
result['CreateDBSubnetGroupResponse']['CreateDBSubnetGroupResult']['DBSubnetGroup']['DBSubnetGroupName'].should.equal("db_subnet")
|
||||||
|
result['CreateDBSubnetGroupResponse']['CreateDBSubnetGroupResult']['DBSubnetGroup']['DBSubnetGroupDescription'].should.equal("my db subnet")
|
||||||
|
subnets = result['CreateDBSubnetGroupResponse']['CreateDBSubnetGroupResult']['DBSubnetGroup']['Subnets']
|
||||||
|
subnet_group_ids = [subnets['Subnet'][0]['SubnetIdentifier'], subnets['Subnet'][1]['SubnetIdentifier']]
|
||||||
|
list(subnet_group_ids).should.equal(subnet_ids)
|
||||||
|
|
||||||
|
|
||||||
|
@disable_on_py3()
|
||||||
|
@mock_ec2
|
||||||
|
@mock_rds2
|
||||||
|
def test_create_database_in_subnet_group():
|
||||||
|
vpc_conn = boto.vpc.connect_to_region("us-west-2")
|
||||||
|
vpc = vpc_conn.create_vpc("10.0.0.0/16")
|
||||||
|
subnet = vpc_conn.create_subnet(vpc.id, "10.1.0.0/24")
|
||||||
|
|
||||||
|
conn = boto.rds2.connect_to_region("us-west-2")
|
||||||
|
conn.create_db_subnet_group("db_subnet1", "my db subnet", [subnet.id])
|
||||||
|
conn.create_db_instance(db_instance_identifier='db-master-1',
|
||||||
|
allocated_storage=10,
|
||||||
|
engine='postgres',
|
||||||
|
db_instance_class='db.m1.small',
|
||||||
|
master_username='root',
|
||||||
|
master_user_password='hunter2',
|
||||||
|
db_subnet_group_name='db_subnet1')
|
||||||
|
result = conn.describe_db_instances("db-master-1")
|
||||||
|
result['DescribeDBInstancesResponse']['DescribeDBInstancesResult']['DBInstances'][0]['DBSubnetGroup']['DBSubnetGroupName'].should.equal("db_subnet1")
|
||||||
|
|
||||||
|
|
||||||
@mock_ec2
|
@mock_ec2
|
||||||
@ -493,41 +521,29 @@ def test_describe_database_subnet_group():
|
|||||||
conn.describe_db_subnet_groups.when.called_with("not-a-subnet").should.throw(BotoServerError)
|
conn.describe_db_subnet_groups.when.called_with("not-a-subnet").should.throw(BotoServerError)
|
||||||
|
|
||||||
|
|
||||||
#@mock_ec2
|
@mock_ec2
|
||||||
#@mock_rds2
|
@mock_rds2
|
||||||
#def test_delete_database_subnet_group():
|
def test_delete_database_subnet_group():
|
||||||
# vpc_conn = boto.vpc.connect_to_region("us-west-2")
|
vpc_conn = boto.vpc.connect_to_region("us-west-2")
|
||||||
# vpc = vpc_conn.create_vpc("10.0.0.0/16")
|
vpc = vpc_conn.create_vpc("10.0.0.0/16")
|
||||||
# subnet = vpc_conn.create_subnet(vpc.id, "10.1.0.0/24")
|
subnet = vpc_conn.create_subnet(vpc.id, "10.1.0.0/24")
|
||||||
#
|
|
||||||
# conn = boto.rds2.connect_to_region("us-west-2")
|
conn = boto.rds2.connect_to_region("us-west-2")
|
||||||
# conn.create_db_subnet_group("db_subnet1", "my db subnet", [subnet.id])
|
result = conn.describe_db_subnet_groups()
|
||||||
# list(conn.get_all_db_subnet_groups()).should.have.length_of(1)
|
result['DescribeDBSubnetGroupsResponse']['DescribeDBSubnetGroupsResult']['DBSubnetGroups'].should.have.length_of(0)
|
||||||
#
|
|
||||||
# conn.delete_db_subnet_group("db_subnet1")
|
conn.create_db_subnet_group("db_subnet1", "my db subnet", [subnet.id])
|
||||||
# list(conn.get_all_db_subnet_groups()).should.have.length_of(0)
|
result = conn.describe_db_subnet_groups()
|
||||||
#
|
result['DescribeDBSubnetGroupsResponse']['DescribeDBSubnetGroupsResult']['DBSubnetGroups'].should.have.length_of(1)
|
||||||
# conn.delete_db_subnet_group.when.called_with("db_subnet1").should.throw(BotoServerError)
|
|
||||||
#
|
conn.delete_db_subnet_group("db_subnet1")
|
||||||
#
|
result = conn.describe_db_subnet_groups()
|
||||||
#@disable_on_py3()
|
result['DescribeDBSubnetGroupsResponse']['DescribeDBSubnetGroupsResult']['DBSubnetGroups'].should.have.length_of(0)
|
||||||
#@mock_ec2
|
|
||||||
#@mock_rds2
|
conn.delete_db_subnet_group.when.called_with("db_subnet1").should.throw(BotoServerError)
|
||||||
#def test_create_database_in_subnet_group():
|
|
||||||
# vpc_conn = boto.vpc.connect_to_region("us-west-2")
|
|
||||||
# vpc = vpc_conn.create_vpc("10.0.0.0/16")
|
|
||||||
# subnet = vpc_conn.create_subnet(vpc.id, "10.1.0.0/24")
|
|
||||||
#
|
|
||||||
# conn = boto.rds2.connect_to_region("us-west-2")
|
|
||||||
# conn.create_db_subnet_group("db_subnet1", "my db subnet", [subnet.id])
|
|
||||||
#
|
|
||||||
# database = conn.create_dbinstance("db-master-1", 10, 'db.m1.small',
|
|
||||||
# 'root', 'hunter2', db_subnet_group_name="db_subnet1")
|
|
||||||
#
|
|
||||||
# database = conn.get_all_dbinstances("db-master-1")[0]
|
|
||||||
# database.subnet_group.name.should.equal("db_subnet1")
|
|
||||||
#
|
|
||||||
#
|
|
||||||
#@disable_on_py3()
|
#@disable_on_py3()
|
||||||
#@mock_rds2
|
#@mock_rds2
|
||||||
#def test_create_database_replica():
|
#def test_create_database_replica():
|
||||||
|
Loading…
Reference in New Issue
Block a user