diff --git a/moto/rds2/models.py b/moto/rds2/models.py
index 6aefd81f1..ad2f9b3f1 100644
--- a/moto/rds2/models.py
+++ b/moto/rds2/models.py
@@ -88,12 +88,14 @@ class Database(object):
def address(self):
return "{0}.aaaaaaaaaa.{1}.rds.amazonaws.com".format(self.db_instance_identifier, self.region)
+ # TODO: confirm how this should represent in the RESULT JSON
def add_replica(self, replica):
self.replicas.append(replica.db_instance_identifier)
def remove_replica(self, replica):
self.replicas.remove(replica.db_instance_identifier)
+ # TODO: confirm how this should represent in the RESULT JSON
def set_as_replica(self):
self.is_replica = True
self.replicas = []
@@ -223,7 +225,11 @@ class Database(object):
"Endpoint": null,
"InstanceCreateTime": null,
"Iops": null,
- "ReadReplicaDBInstanceIdentifiers": [],
+ "ReadReplicaDBInstanceIdentifiers": [{%- for replica in database.replicas -%}
+ {%- if not loop.first -%},{%- endif -%}
+ "{{ replica }}"
+ {%- endfor -%}
+ ],
"ReadReplicaSourceDBInstanceIdentifier": null,
"SecondaryAvailabilityZone": null,
"StatusInfos": null,
diff --git a/moto/rds2/responses.py b/moto/rds2/responses.py
index f0ac52faa..918de9969 100644
--- a/moto/rds2/responses.py
+++ b/moto/rds2/responses.py
@@ -90,16 +90,20 @@ class RDS2Response(BaseResponse):
template = self.response_template(DESCRIBE_DATABASES_TEMPLATE)
return template.render(databases=databases)
- # TODO: Update function to new method
def modify_dbinstance(self):
+ return self.modify_db_instance()
+
+ def modify_db_instance(self):
db_instance_identifier = self._get_param('DBInstanceIdentifier')
db_kwargs = self._get_db_kwargs()
database = self.backend.modify_database(db_instance_identifier, db_kwargs)
template = self.response_template(MODIFY_DATABASE_TEMPLATE)
return template.render(database=database)
- # TODO: Update function to new method
def delete_dbinstance(self):
+ return self.delete_db_instance()
+
+ def delete_db_instance(self):
db_instance_identifier = self._get_param('DBInstanceIdentifier')
database = self.backend.delete_database(db_instance_identifier)
template = self.response_template(DELETE_DATABASE_TEMPLATE)
@@ -222,14 +226,14 @@ CREATE_DATABASE_TEMPLATE = """{
}
}"""
-CREATE_DATABASE_REPLICA_TEMPLATE = """
-
- {{ database.to_xml() }}
-
-
- ba8dedf0-bb9a-11d3-855b-576787000e19
-
-"""
+CREATE_DATABASE_REPLICA_TEMPLATE = """{
+ "CreateDBInstanceResponse": {
+ "CreateDBInstanceResult": {
+ {{ database.to_json() }}
+ },
+ "ResponseMetadata": { "RequestId": "523e3218-afc7-11c3-90f5-f90431260ab4" }
+ }
+}"""
DESCRIBE_DATABASES_TEMPLATE = """{
"DescribeDBInstanceResponse": {
@@ -243,23 +247,24 @@ DESCRIBE_DATABASES_TEMPLATE = """{
}
}"""
-MODIFY_DATABASE_TEMPLATE = """
-
- {{ database.to_xml() }}
-
-
- f643f1ac-bbfe-11d3-f4c6-37db295f7674
-
-"""
+MODIFY_DATABASE_TEMPLATE = """{"ModifyDBInstanceResponse": {
+ "ModifyDBInstanceResult": {
+ {{ database.to_json() }},
+ "ResponseMetadata": {
+ "RequestId": "bb58476c-a1a8-11e4-99cf-55e92d4bbada"
+ }
+ }
+ }
+}"""
-DELETE_DATABASE_TEMPLATE = """
-
- {{ database.to_xml() }}
-
-
- 7369556f-b70d-11c3-faca-6ba18376ea1b
-
-"""
+# TODO: update delete DB TEMPLATE
+DELETE_DATABASE_TEMPLATE = """{
+ "DeleteDBInstanceResponse": {
+ "DeleteDBInstanceResult": {
+ },
+ "ResponseMetadata": { "RequestId": "523e3218-afc7-11c3-90f5-f90431260ab4" }
+ }
+}"""
CREATE_SECURITY_GROUP_TEMPLATE = """
diff --git a/tests/test_rds2/test_rds2.py b/tests/test_rds2/test_rds2.py
index 017869789..e2801c1c7 100644
--- a/tests/test_rds2/test_rds2.py
+++ b/tests/test_rds2/test_rds2.py
@@ -58,12 +58,53 @@ def test_get_databases():
instances['DescribeDBInstanceResponse']['DescribeDBInstanceResult'][0]['DBInstance']['DBInstanceIdentifier'].should.equal("db-master-1")
+@disable_on_py3()
@mock_rds2
def test_describe_non_existant_database():
conn = boto.rds2.connect_to_region("us-west-2")
conn.describe_db_instances.when.called_with("not-a-db").should.throw(BotoServerError)
+@disable_on_py3()
+@mock_rds2
+def test_modify_db_instance():
+ conn = boto.rds2.connect_to_region("us-west-2")
+ database = 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_security_groups=["my_sg"])
+ instances = conn.describe_db_instances('db-master-1')
+ instances['DescribeDBInstanceResponse']['DescribeDBInstanceResult'][0]['DBInstance']['AllocatedStorage'].should.equal('10')
+ conn.modify_db_instance(db_instance_identifier='db-master-1', allocated_storage=20, apply_immediately=True)
+ instances = conn.describe_db_instances('db-master-1')
+ instances['DescribeDBInstanceResponse']['DescribeDBInstanceResult'][0]['DBInstance']['AllocatedStorage'].should.equal('20')
+
+
+@disable_on_py3()
+@mock_rds2
+def test_delete_database():
+ conn = boto.rds2.connect_to_region("us-west-2")
+ instances = conn.describe_db_instances()
+ list(instances['DescribeDBInstanceResponse']['DescribeDBInstanceResult']).should.have.length_of(0)
+ 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_security_groups=["my_sg"])
+ instances = conn.describe_db_instances()
+ list(instances['DescribeDBInstanceResponse']['DescribeDBInstanceResult']).should.have.length_of(1)
+
+ conn.delete_db_instance("db-master-1")
+ instances = conn.describe_db_instances()
+ list(instances['DescribeDBInstanceResponse']['DescribeDBInstanceResult']).should.have.length_of(0)
+
+
+@disable_on_py3()
@mock_rds2
def test_create_option_group():
conn = boto.rds2.connect_to_region("us-west-2")
@@ -74,24 +115,28 @@ def test_create_option_group():
option_group['CreateOptionGroupResponse']['CreateOptionGroupResult']['OptionGroup']['MajorEngineVersion'].should.equal('5.6')
+@disable_on_py3()
@mock_rds2
def test_create_option_group_bad_engine_name():
conn = boto.rds2.connect_to_region("us-west-2")
conn.create_option_group.when.called_with('test', 'invalid_engine', '5.6', 'test invalid engine').should.throw(BotoServerError)
+@disable_on_py3()
@mock_rds2
def test_create_option_group_bad_engine_major_version():
conn = boto.rds2.connect_to_region("us-west-2")
conn.create_option_group.when.called_with('test', 'mysql', '6.6.6', 'test invalid engine version').should.throw(BotoServerError)
+@disable_on_py3()
@mock_rds2
def test_create_option_group_empty_description():
conn = boto.rds2.connect_to_region("us-west-2")
conn.create_option_group.when.called_with('test', 'mysql', '5.6', '').should.throw(BotoServerError)
+@disable_on_py3()
@mock_rds2
def test_create_option_group_duplicate():
conn = boto.rds2.connect_to_region("us-west-2")
@@ -99,6 +144,7 @@ def test_create_option_group_duplicate():
conn.create_option_group.when.called_with('test', 'mysql', '5.6', 'foo').should.throw(BotoServerError)
+@disable_on_py3()
@mock_rds2
def test_describe_option_group():
conn = boto.rds2.connect_to_region("us-west-2")
@@ -107,12 +153,14 @@ def test_describe_option_group():
option_groups['DescribeOptionGroupsResponse']['DescribeOptionGroupsResult']['OptionGroupsList'][0]['OptionGroupName'].should.equal('test')
+@disable_on_py3()
@mock_rds2
def test_describe_non_existant_option_group():
conn = boto.rds2.connect_to_region("us-west-2")
conn.describe_option_groups.when.called_with("not-a-option-group").should.throw(BotoServerError)
+@disable_on_py3()
@mock_rds2
def test_delete_option_group():
conn = boto.rds2.connect_to_region("us-west-2")
@@ -123,6 +171,7 @@ def test_delete_option_group():
conn.describe_option_groups.when.called_with('test').should.throw(BotoServerError)
+@disable_on_py3()
@mock_rds2
def test_delete_non_existant_option_group():
conn = boto.rds2.connect_to_region("us-west-2")
@@ -142,10 +191,12 @@ def test_describe_option_group_options():
conn.describe_option_group_options.when.called_with('mysql', 'non-existent').should.throw(BotoServerError)
+@disable_on_py3()
@mock_rds2
def test_modify_option_group():
conn = boto.rds2.connect_to_region("us-west-2")
conn.create_option_group('test', 'mysql', '5.6', 'test option group')
+ # TODO: create option and validate before deleting.
# if Someone can tell me how the hell to use this function
# to add options to an option_group, I can finish coding this.
result = conn.modify_option_group('test', [], ['MEMCACHED'], True)
@@ -154,7 +205,7 @@ def test_modify_option_group():
result['ModifyOptionGroupResponse']['ModifyOptionGroupResult']['OptionGroupName'].should.equal('test')
-
+@disable_on_py3()
@mock_rds2
def test_modify_option_group_no_options():
conn = boto.rds2.connect_to_region("us-west-2")
@@ -162,31 +213,21 @@ def test_modify_option_group_no_options():
conn.modify_option_group.when.called_with('test').should.throw(BotoServerError)
+@disable_on_py3()
@mock_rds2
def test_modify_non_existant_option_group():
conn = boto.rds2.connect_to_region("us-west-2")
conn.modify_option_group.when.called_with('non-existant', [('OptionName', 'Port', 'DBSecurityGroupMemberships', 'VpcSecurityGroupMemberships', 'OptionSettings')]).should.throw(BotoServerError)
+@disable_on_py3()
+@mock_rds2
+def test_delete_non_existant_database():
+ conn = boto.rds2.connect_to_region("us-west-2")
+ conn.delete_db_instance.when.called_with("not-a-db").should.throw(BotoServerError)
+
+
#@disable_on_py3()
-#@mock_rds2
-#def test_delete_database():
-# conn = boto.rds2.connect_to_region("us-west-2")
-# list(conn.get_all_dbinstances()).should.have.length_of(0)
-#
-# conn.create_dbinstance("db-master-1", 10, 'db.m1.small', 'root', 'hunter2')
-# list(conn.get_all_dbinstances()).should.have.length_of(1)
-#
-# conn.delete_dbinstance("db-master-1")
-# list(conn.get_all_dbinstances()).should.have.length_of(0)
-#
-#
-#@mock_rds2
-#def test_delete_non_existant_database():
-# conn = boto.rds2.connect_to_region("us-west-2")
-# conn.delete_dbinstance.when.called_with("not-a-db").should.throw(BotoServerError)
-
-
#@mock_rds2
#def test_create_database_security_group():
# conn = boto.rds2.connect_to_region("us-west-2")
@@ -338,20 +379,30 @@ def test_modify_non_existant_option_group():
#def test_create_database_replica():
# conn = boto.rds2.connect_to_region("us-west-2")
#
-# primary = conn.create_dbinstance("db-master-1", 10, 'db.m1.small', 'root', 'hunter2')
+# 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_security_groups=["my_sg"])
#
-# replica = conn.create_dbinstance_read_replica("replica", "db-master-1", "db.m1.small")
-# replica.id.should.equal("replica")
-# replica.instance_class.should.equal("db.m1.small")
-# status_info = replica.status_infos[0]
-# status_info.normal.should.equal(True)
-# status_info.status_type.should.equal('read replication')
-# status_info.status.should.equal('replicating')
-#
-# primary = conn.get_all_dbinstances("db-master-1")[0]
-# primary.read_replica_dbinstance_identifiers[0].should.equal("replica")
-#
-# conn.delete_dbinstance("replica")
-#
-# primary = conn.get_all_dbinstances("db-master-1")[0]
-# list(primary.read_replica_dbinstance_identifiers).should.have.length_of(0)
+# # TODO: confirm the RESULT JSON
+# replica = conn.create_db_instance_read_replica("replica", "db-master-1", "db.m1.small")
+# print replica
+ #replica.id.should.equal("replica")
+ #replica.instance_class.should.equal("db.m1.small")
+ #status_info = replica.status_infos[0]
+ #status_info.normal.should.equal(True)
+ #status_info.status_type.should.equal('read replication')
+ #status_info.status.should.equal('replicating')
+
+ # TODO: formulate checks on read replica status
+# primary = conn.describe_db_instances("db-master-1")
+# print primary
+ #primary.read_replica_dbinstance_identifiers[0].should.equal("replica")
+
+ #conn.delete_dbinstance("replica")
+
+ #primary = conn.get_all_dbinstances("db-master-1")[0]
+ #list(primary.read_replica_dbinstance_identifiers).should.have.length_of(0)