Skip to content

Commit

Permalink
Merge pull request #1 from behanceops/more-rds2-support
Browse files Browse the repository at this point in the history
More rds2 support
  • Loading branch information
mfulleratlassian committed Jan 26, 2015
2 parents 8671f1e + bcf4e97 commit 23ff33b
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 37 deletions.
23 changes: 23 additions & 0 deletions moto/rds2/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,29 @@ def to_xml(self):
</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']
Expand Down
43 changes: 21 additions & 22 deletions moto/rds2/responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ def authorize_dbsecurity_group_ingress(self):
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')
Expand All @@ -149,7 +148,6 @@ def create_dbsubnet_group(self):
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)
Expand Down Expand Up @@ -303,27 +301,28 @@ def modify_option_group(self):
</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>
Expand Down
1 change: 1 addition & 0 deletions moto/rds2/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

url_bases = [
"https?://rds.(.+).amazonaws.com",
"https?://rds.amazonaws.com",
]

url_paths = {
Expand Down
40 changes: 25 additions & 15 deletions tests/test_rds2/test_rds2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 23ff33b

Please sign in to comment.