From 4f822f58e87a23b5e08c1ea09d5f7798ae2ee486 Mon Sep 17 00:00:00 2001 From: Chris Henry Date: Mon, 26 Jan 2015 13:33:11 -0500 Subject: [PATCH 1/7] Loosen the url pattern a bit. I was seeing boto send requests to rds.amazonaws.com --- moto/rds2/urls.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/moto/rds2/urls.py b/moto/rds2/urls.py index 3c8a129a8..6881a1119 100644 --- a/moto/rds2/urls.py +++ b/moto/rds2/urls.py @@ -2,7 +2,7 @@ from __future__ import unicode_literals from .responses import RDS2Response url_bases = [ - "https?://rds.(.+).amazonaws.com", + "https?://rds(.+).amazonaws.com", ] url_paths = { From 850b15d849f43918db49d0b848f74b4feec7e0f0 Mon Sep 17 00:00:00 2001 From: Chris Henry Date: Mon, 26 Jan 2015 13:33:46 -0500 Subject: [PATCH 2/7] Add a to_json method to SubnetGroup. --- moto/rds2/models.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/moto/rds2/models.py b/moto/rds2/models.py index ad2f9b3f1..846d070ab 100644 --- a/moto/rds2/models.py +++ b/moto/rds2/models.py @@ -339,6 +339,29 @@ class SubnetGroup(object): """) 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'] From 25d0c0926d9cb34bd9a19cc59414ddbd7ac26bb8 Mon Sep 17 00:00:00 2001 From: Chris Henry Date: Mon, 26 Jan 2015 13:34:21 -0500 Subject: [PATCH 3/7] Change CREATE_SUBNET_GROUP_TEMPLATE to json. --- moto/rds2/responses.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/moto/rds2/responses.py b/moto/rds2/responses.py index 918de9969..91f4c381e 100644 --- a/moto/rds2/responses.py +++ b/moto/rds2/responses.py @@ -303,14 +303,13 @@ AUTHORIZE_SECURITY_GROUP_TEMPLATE = """ """ -CREATE_SUBNET_GROUP_TEMPLATE = """ - - {{ subnet_group.to_xml() }} - - - 3a401b3f-bb9e-11d3-f4c6-37db295f7674 - -""" +CREATE_SUBNET_GROUP_TEMPLATE = """{ + "CreateDBSubnetGroupResponse": { + "CreateDBSubnetGroupResult": + {{ subnet_group.to_json() }}, + "ResponseMetadata": { "RequestId": "3a401b3f-bb9e-11d3-f4c6-37db295f7674" } + } +}""" DESCRIBE_SUBNET_GROUPS_TEMPLATE = """ From 2352e27c3ec58e62b1c5b32bfb3c75a849aca586 Mon Sep 17 00:00:00 2001 From: Chris Henry Date: Mon, 26 Jan 2015 13:35:28 -0500 Subject: [PATCH 4/7] Remove todo. --- moto/rds2/responses.py | 1 - 1 file changed, 1 deletion(-) diff --git a/moto/rds2/responses.py b/moto/rds2/responses.py index 91f4c381e..b6325b321 100644 --- a/moto/rds2/responses.py +++ b/moto/rds2/responses.py @@ -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') From 1ccf1191cdf865d050f261952c6581010c1a9f5e Mon Sep 17 00:00:00 2001 From: Chris Henry Date: Mon, 26 Jan 2015 13:54:40 -0500 Subject: [PATCH 5/7] Instead of a regex, add a second url pattern --- moto/rds2/urls.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/moto/rds2/urls.py b/moto/rds2/urls.py index 6881a1119..d21084766 100644 --- a/moto/rds2/urls.py +++ b/moto/rds2/urls.py @@ -2,7 +2,8 @@ from __future__ import unicode_literals from .responses import RDS2Response url_bases = [ - "https?://rds(.+).amazonaws.com", + "https?://rds.(.+).amazonaws.com", + "https?://rds.amazonaws.com", ] url_paths = { From bba08f05b1607ce1fd6ae40021367ac63233f285 Mon Sep 17 00:00:00 2001 From: Chris Henry Date: Mon, 26 Jan 2015 15:38:56 -0500 Subject: [PATCH 6/7] Change the describe subnet groups over to json. --- moto/rds2/responses.py | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/moto/rds2/responses.py b/moto/rds2/responses.py index b6325b321..f013be0f4 100644 --- a/moto/rds2/responses.py +++ b/moto/rds2/responses.py @@ -148,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) @@ -310,18 +309,20 @@ CREATE_SUBNET_GROUP_TEMPLATE = """{ } }""" -DESCRIBE_SUBNET_GROUPS_TEMPLATE = """ - - - {% for subnet_group in subnet_groups %} - {{ subnet_group.to_xml() }} - {% endfor %} - - - - b783db3b-b98c-11d3-fbc7-5c0aad74da7c - -""" +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" } + } +}""" + DELETE_SUBNET_GROUP_TEMPLATE = """ From bcf4e97752d882d2749d66559f1959c3bc4c0b84 Mon Sep 17 00:00:00 2001 From: Chris Henry Date: Mon, 26 Jan 2015 15:39:34 -0500 Subject: [PATCH 7/7] Uncomment existing subnet groups test and add more assertions. --- tests/test_rds2/test_rds2.py | 40 ++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/tests/test_rds2/test_rds2.py b/tests/test_rds2/test_rds2.py index e2801c1c7..40e3d24b2 100644 --- a/tests/test_rds2/test_rds2.py +++ b/tests/test_rds2/test_rds2.py @@ -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