Merge pull request #1 from behanceops/more-rds2-support

More rds2 support
This commit is contained in:
mfulleratlassian 2015-01-27 08:03:21 +11:00
commit 23ff33b145
4 changed files with 70 additions and 37 deletions

View File

@ -339,6 +339,29 @@ class SubnetGroup(object):
</DBSubnetGroup>""")
return template.render(subnet_group=self)
def to_json(self):
template = Template("""{
"DBSubnetGroup": {
"VpcId": "{{ subnet_group.vpc_id }}",
"SubnetGroupStatus": "{{ subnet_group.status }}",
"DBSubnetGroupDescription": "{{ subnet_group.description }}",
"DBSubnetGroupName": "{{ subnet_group.subnet_name }}",
"Subnets": {
"Subnet": [
{% for subnet in subnet_group.subnets %}{
"SubnetStatus": "Active",
"SubnetIdentifier": "{{ subnet.id }}",
"SubnetAvailabilityZone": {
"Name": "{{ subnet.availability_zone }}",
"ProvisionedIopsCapable": "false"
}
}{%- if not loop.last -%},{%- endif -%}{% endfor %}
]
}
}
}""")
return template.render(subnet_group=self)
@classmethod
def create_from_cloudformation_json(cls, resource_name, cloudformation_json, region_name):
properties = cloudformation_json['Properties']

View File

@ -139,7 +139,6 @@ class RDS2Response(BaseResponse):
template = self.response_template(AUTHORIZE_SECURITY_GROUP_TEMPLATE)
return template.render(security_group=security_group)
# TODO: Update function to new method
def create_dbsubnet_group(self):
subnet_name = self._get_param('DBSubnetGroupName')
description = self._get_param('DBSubnetGroupDescription')
@ -149,7 +148,6 @@ class RDS2Response(BaseResponse):
template = self.response_template(CREATE_SUBNET_GROUP_TEMPLATE)
return template.render(subnet_group=subnet_group)
# TODO: Update function to new method
def describe_dbsubnet_groups(self):
subnet_name = self._get_param('DBSubnetGroupName')
subnet_groups = self.backend.describe_subnet_groups(subnet_name)
@ -303,27 +301,28 @@ AUTHORIZE_SECURITY_GROUP_TEMPLATE = """<AuthorizeDBSecurityGroupIngressResponse
</ResponseMetadata>
</AuthorizeDBSecurityGroupIngressResponse>"""
CREATE_SUBNET_GROUP_TEMPLATE = """<CreateDBSubnetGroupResponse xmlns="http://rds.amazonaws.com/doc/2014-09-01/">
<CreateDBSubnetGroupResult>
{{ subnet_group.to_xml() }}
</CreateDBSubnetGroupResult>
<ResponseMetadata>
<RequestId>3a401b3f-bb9e-11d3-f4c6-37db295f7674</RequestId>
</ResponseMetadata>
</CreateDBSubnetGroupResponse>"""
CREATE_SUBNET_GROUP_TEMPLATE = """{
"CreateDBSubnetGroupResponse": {
"CreateDBSubnetGroupResult":
{{ subnet_group.to_json() }},
"ResponseMetadata": { "RequestId": "3a401b3f-bb9e-11d3-f4c6-37db295f7674" }
}
}"""
DESCRIBE_SUBNET_GROUPS_TEMPLATE = """{
"DescribeDBSubnetGroupsResponse": {
"DescribeDBSubnetGroupsResult": {
"DBSubnetGroups": [
{% for subnet_group in subnet_groups %}
{{ subnet_group.to_json() }}{%- if not loop.last -%},{%- endif -%}
{% endfor %}
],
"Marker": null
},
"ResponseMetadata": { "RequestId": "b783db3b-b98c-11d3-fbc7-5c0aad74da7c" }
}
}"""
DESCRIBE_SUBNET_GROUPS_TEMPLATE = """<DescribeDBSubnetGroupsResponse xmlns="http://rds.amazonaws.com/doc/2014-09-01/">
<DescribeDBSubnetGroupsResult>
<DBSubnetGroups>
{% for subnet_group in subnet_groups %}
{{ subnet_group.to_xml() }}
{% endfor %}
</DBSubnetGroups>
</DescribeDBSubnetGroupsResult>
<ResponseMetadata>
<RequestId>b783db3b-b98c-11d3-fbc7-5c0aad74da7c</RequestId>
</ResponseMetadata>
</DescribeDBSubnetGroupsResponse>"""
DELETE_SUBNET_GROUP_TEMPLATE = """<DeleteDBSubnetGroupResponse xmlns="http://rds.amazonaws.com/doc/2014-09-01/">
<ResponseMetadata>

View File

@ -3,6 +3,7 @@ from .responses import RDS2Response
url_bases = [
"https?://rds.(.+).amazonaws.com",
"https?://rds.amazonaws.com",
]
url_paths = {

View File

@ -322,21 +322,31 @@ def test_delete_non_existant_database():
# list(subnet_group.subnet_ids).should.equal(subnet_ids)
#
#
#@mock_ec2
#@mock_rds2
#def test_describe_database_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_subnet_group("db_subnet2", "my db subnet", [subnet.id])
#
# list(conn.get_all_db_subnet_groups()).should.have.length_of(2)
# list(conn.get_all_db_subnet_groups("db_subnet1")).should.have.length_of(1)
#
# conn.get_all_db_subnet_groups.when.called_with("not-a-subnet").should.throw(BotoServerError)
@mock_ec2
@mock_rds2
def test_describe_database_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_subnet_group("db_subnet2", "my db subnet", [subnet.id])
resp = conn.describe_db_subnet_groups()
groups_resp = resp['DescribeDBSubnetGroupsResponse']
subnet_groups = groups_resp['DescribeDBSubnetGroupsResult']['DBSubnetGroups']
subnet_groups.should.have.length_of(2)
subnets = groups_resp['DescribeDBSubnetGroupsResult']['DBSubnetGroups'][0]['DBSubnetGroup']['Subnets']
subnets.should.have.length_of(1)
list(resp).should.have.length_of(1)
list(groups_resp).should.have.length_of(2)
list(conn.describe_db_subnet_groups("db_subnet1")).should.have.length_of(1)
conn.describe_db_subnet_groups.when.called_with("not-a-subnet").should.throw(BotoServerError)
#
#
#@mock_ec2