| 
									
										
										
										
											2015-01-19 07:38:10 +11:00
										 |  |  | from __future__ import unicode_literals | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-31 04:21:24 -08:00
										 |  |  | from botocore.exceptions import ClientError | 
					
						
							| 
									
										
										
										
											2017-01-11 18:02:51 -08:00
										 |  |  | import boto3 | 
					
						
							| 
									
										
										
										
											2021-02-13 03:12:02 -08:00
										 |  |  | import pytest | 
					
						
							| 
									
										
										
										
											2015-01-19 07:38:10 +11:00
										 |  |  | import sure  # noqa | 
					
						
							| 
									
										
										
										
											2017-01-11 18:02:51 -08:00
										 |  |  | from moto import mock_ec2, mock_kms, mock_rds2 | 
					
						
							| 
									
										
										
										
											2020-12-02 01:23:01 +05:30
										 |  |  | from moto.core import ACCOUNT_ID | 
					
						
							| 
									
										
										
										
											2015-01-19 07:38:10 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_rds2 | 
					
						
							|  |  |  | def test_create_database(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto3.client("rds", region_name="us-west-2") | 
					
						
							|  |  |  |     database = conn.create_db_instance( | 
					
						
							|  |  |  |         DBInstanceIdentifier="db-master-1", | 
					
						
							|  |  |  |         AllocatedStorage=10, | 
					
						
							|  |  |  |         Engine="postgres", | 
					
						
							|  |  |  |         DBName="staging-postgres", | 
					
						
							|  |  |  |         DBInstanceClass="db.m1.small", | 
					
						
							|  |  |  |         LicenseModel="license-included", | 
					
						
							|  |  |  |         MasterUsername="root", | 
					
						
							|  |  |  |         MasterUserPassword="hunter2", | 
					
						
							|  |  |  |         Port=1234, | 
					
						
							|  |  |  |         DBSecurityGroups=["my_sg"], | 
					
						
							|  |  |  |         VpcSecurityGroupIds=["sg-123456"], | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     db_instance = database["DBInstance"] | 
					
						
							|  |  |  |     db_instance["AllocatedStorage"].should.equal(10) | 
					
						
							|  |  |  |     db_instance["DBInstanceClass"].should.equal("db.m1.small") | 
					
						
							|  |  |  |     db_instance["LicenseModel"].should.equal("license-included") | 
					
						
							|  |  |  |     db_instance["MasterUsername"].should.equal("root") | 
					
						
							|  |  |  |     db_instance["DBSecurityGroups"][0]["DBSecurityGroupName"].should.equal("my_sg") | 
					
						
							|  |  |  |     db_instance["DBInstanceArn"].should.equal( | 
					
						
							| 
									
										
										
										
											2021-06-23 18:03:11 +01:00
										 |  |  |         "arn:aws:rds:us-west-2:{}:db:db-master-1".format(ACCOUNT_ID) | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     ) | 
					
						
							|  |  |  |     db_instance["DBInstanceStatus"].should.equal("available") | 
					
						
							|  |  |  |     db_instance["DBName"].should.equal("staging-postgres") | 
					
						
							|  |  |  |     db_instance["DBInstanceIdentifier"].should.equal("db-master-1") | 
					
						
							|  |  |  |     db_instance["IAMDatabaseAuthenticationEnabled"].should.equal(False) | 
					
						
							|  |  |  |     db_instance["DbiResourceId"].should.contain("db-") | 
					
						
							|  |  |  |     db_instance["CopyTagsToSnapshot"].should.equal(False) | 
					
						
							|  |  |  |     db_instance["InstanceCreateTime"].should.be.a("datetime.datetime") | 
					
						
							|  |  |  |     db_instance["VpcSecurityGroups"][0]["VpcSecurityGroupId"].should.equal("sg-123456") | 
					
						
							| 
									
										
										
										
											2017-08-14 00:27:15 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-15 00:55:09 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-15 16:18:37 -04:00
										 |  |  | @mock_rds2 | 
					
						
							|  |  |  | def test_create_database_no_allocated_storage(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto3.client("rds", region_name="us-west-2") | 
					
						
							| 
									
										
										
										
											2019-10-15 16:18:37 -04:00
										 |  |  |     database = conn.create_db_instance( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         DBInstanceIdentifier="db-master-1", | 
					
						
							|  |  |  |         Engine="postgres", | 
					
						
							|  |  |  |         DBName="staging-postgres", | 
					
						
							|  |  |  |         DBInstanceClass="db.m1.small", | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     db_instance = database["DBInstance"] | 
					
						
							|  |  |  |     db_instance["Engine"].should.equal("postgres") | 
					
						
							|  |  |  |     db_instance["StorageType"].should.equal("gp2") | 
					
						
							|  |  |  |     db_instance["AllocatedStorage"].should.equal(20) | 
					
						
							| 
									
										
										
										
											2019-10-15 16:18:37 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-11 22:43:42 +02:00
										 |  |  | @mock_rds2 | 
					
						
							|  |  |  | def test_create_database_non_existing_option_group(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto3.client("rds", region_name="us-west-2") | 
					
						
							| 
									
										
										
										
											2019-07-11 22:43:42 +02:00
										 |  |  |     database = conn.create_db_instance.when.called_with( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         DBInstanceIdentifier="db-master-1", | 
					
						
							| 
									
										
										
										
											2019-07-11 22:43:42 +02:00
										 |  |  |         AllocatedStorage=10, | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         Engine="postgres", | 
					
						
							|  |  |  |         DBName="staging-postgres", | 
					
						
							|  |  |  |         DBInstanceClass="db.m1.small", | 
					
						
							|  |  |  |         OptionGroupName="non-existing", | 
					
						
							|  |  |  |     ).should.throw(ClientError) | 
					
						
							| 
									
										
										
										
											2019-07-11 22:43:42 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_rds2 | 
					
						
							|  |  |  | def test_create_database_with_option_group(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto3.client("rds", region_name="us-west-2") | 
					
						
							|  |  |  |     conn.create_option_group( | 
					
						
							|  |  |  |         OptionGroupName="my-og", | 
					
						
							|  |  |  |         EngineName="mysql", | 
					
						
							|  |  |  |         MajorEngineVersion="5.6", | 
					
						
							|  |  |  |         OptionGroupDescription="test option group", | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     database = conn.create_db_instance( | 
					
						
							|  |  |  |         DBInstanceIdentifier="db-master-1", | 
					
						
							|  |  |  |         AllocatedStorage=10, | 
					
						
							|  |  |  |         Engine="postgres", | 
					
						
							|  |  |  |         DBName="staging-postgres", | 
					
						
							|  |  |  |         DBInstanceClass="db.m1.small", | 
					
						
							|  |  |  |         OptionGroupName="my-og", | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     db_instance = database["DBInstance"] | 
					
						
							|  |  |  |     db_instance["AllocatedStorage"].should.equal(10) | 
					
						
							|  |  |  |     db_instance["DBInstanceClass"].should.equal("db.m1.small") | 
					
						
							|  |  |  |     db_instance["DBName"].should.equal("staging-postgres") | 
					
						
							|  |  |  |     db_instance["OptionGroupMemberships"][0]["OptionGroupName"].should.equal("my-og") | 
					
						
							| 
									
										
										
										
											2019-07-11 22:43:42 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-14 00:27:15 +10:00
										 |  |  | @mock_rds2 | 
					
						
							|  |  |  | def test_stop_database(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto3.client("rds", region_name="us-west-2") | 
					
						
							|  |  |  |     database = conn.create_db_instance( | 
					
						
							|  |  |  |         DBInstanceIdentifier="db-master-1", | 
					
						
							|  |  |  |         AllocatedStorage=10, | 
					
						
							|  |  |  |         Engine="postgres", | 
					
						
							|  |  |  |         DBName="staging-postgres", | 
					
						
							|  |  |  |         DBInstanceClass="db.m1.small", | 
					
						
							|  |  |  |         LicenseModel="license-included", | 
					
						
							|  |  |  |         MasterUsername="root", | 
					
						
							|  |  |  |         MasterUserPassword="hunter2", | 
					
						
							|  |  |  |         Port=1234, | 
					
						
							|  |  |  |         DBSecurityGroups=["my_sg"], | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     mydb = conn.describe_db_instances( | 
					
						
							|  |  |  |         DBInstanceIdentifier=database["DBInstance"]["DBInstanceIdentifier"] | 
					
						
							|  |  |  |     )["DBInstances"][0] | 
					
						
							|  |  |  |     mydb["DBInstanceStatus"].should.equal("available") | 
					
						
							| 
									
										
										
										
											2017-08-15 00:55:09 +10:00
										 |  |  |     # test stopping database should shutdown | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     response = conn.stop_db_instance(DBInstanceIdentifier=mydb["DBInstanceIdentifier"]) | 
					
						
							|  |  |  |     response["ResponseMetadata"]["HTTPStatusCode"].should.equal(200) | 
					
						
							|  |  |  |     response["DBInstance"]["DBInstanceStatus"].should.equal("stopped") | 
					
						
							| 
									
										
										
										
											2017-08-14 00:27:15 +10:00
										 |  |  |     # test rdsclient error when trying to stop an already stopped database | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn.stop_db_instance.when.called_with( | 
					
						
							|  |  |  |         DBInstanceIdentifier=mydb["DBInstanceIdentifier"] | 
					
						
							|  |  |  |     ).should.throw(ClientError) | 
					
						
							| 
									
										
										
										
											2017-08-15 00:55:09 +10:00
										 |  |  |     # test stopping a stopped database with snapshot should error and no snapshot should exist for that call | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn.stop_db_instance.when.called_with( | 
					
						
							|  |  |  |         DBInstanceIdentifier=mydb["DBInstanceIdentifier"], | 
					
						
							|  |  |  |         DBSnapshotIdentifier="rocky4570-rds-snap", | 
					
						
							|  |  |  |     ).should.throw(ClientError) | 
					
						
							| 
									
										
										
										
											2017-08-15 00:55:09 +10:00
										 |  |  |     response = conn.describe_db_snapshots() | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     response["DBSnapshots"].should.equal([]) | 
					
						
							| 
									
										
										
										
											2017-08-15 00:55:09 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-14 00:27:15 +10:00
										 |  |  | 
 | 
					
						
							|  |  |  | @mock_rds2 | 
					
						
							|  |  |  | def test_start_database(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto3.client("rds", region_name="us-west-2") | 
					
						
							|  |  |  |     database = conn.create_db_instance( | 
					
						
							|  |  |  |         DBInstanceIdentifier="db-master-1", | 
					
						
							|  |  |  |         AllocatedStorage=10, | 
					
						
							|  |  |  |         Engine="postgres", | 
					
						
							|  |  |  |         DBName="staging-postgres", | 
					
						
							|  |  |  |         DBInstanceClass="db.m1.small", | 
					
						
							|  |  |  |         LicenseModel="license-included", | 
					
						
							|  |  |  |         MasterUsername="root", | 
					
						
							|  |  |  |         MasterUserPassword="hunter2", | 
					
						
							|  |  |  |         Port=1234, | 
					
						
							|  |  |  |         DBSecurityGroups=["my_sg"], | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     mydb = conn.describe_db_instances( | 
					
						
							|  |  |  |         DBInstanceIdentifier=database["DBInstance"]["DBInstanceIdentifier"] | 
					
						
							|  |  |  |     )["DBInstances"][0] | 
					
						
							|  |  |  |     mydb["DBInstanceStatus"].should.equal("available") | 
					
						
							| 
									
										
										
										
											2017-08-15 00:55:09 +10:00
										 |  |  |     # test starting an already started database should error | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn.start_db_instance.when.called_with( | 
					
						
							|  |  |  |         DBInstanceIdentifier=mydb["DBInstanceIdentifier"] | 
					
						
							|  |  |  |     ).should.throw(ClientError) | 
					
						
							| 
									
										
										
										
											2017-11-20 19:07:36 +10:00
										 |  |  |     # stop and test start - should go from stopped to available, create snapshot and check snapshot | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     response = conn.stop_db_instance( | 
					
						
							|  |  |  |         DBInstanceIdentifier=mydb["DBInstanceIdentifier"], | 
					
						
							|  |  |  |         DBSnapshotIdentifier="rocky4570-rds-snap", | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     response["ResponseMetadata"]["HTTPStatusCode"].should.equal(200) | 
					
						
							|  |  |  |     response["DBInstance"]["DBInstanceStatus"].should.equal("stopped") | 
					
						
							| 
									
										
										
										
											2017-08-15 00:55:09 +10:00
										 |  |  |     response = conn.describe_db_snapshots() | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     response["DBSnapshots"][0]["DBSnapshotIdentifier"].should.equal( | 
					
						
							|  |  |  |         "rocky4570-rds-snap" | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     response = conn.start_db_instance(DBInstanceIdentifier=mydb["DBInstanceIdentifier"]) | 
					
						
							|  |  |  |     response["ResponseMetadata"]["HTTPStatusCode"].should.equal(200) | 
					
						
							|  |  |  |     response["DBInstance"]["DBInstanceStatus"].should.equal("available") | 
					
						
							| 
									
										
										
										
											2017-08-15 00:55:09 +10:00
										 |  |  |     # starting database should not remove snapshot | 
					
						
							|  |  |  |     response = conn.describe_db_snapshots() | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     response["DBSnapshots"][0]["DBSnapshotIdentifier"].should.equal( | 
					
						
							|  |  |  |         "rocky4570-rds-snap" | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2017-08-15 00:55:09 +10:00
										 |  |  |     # test stopping database, create snapshot with existing snapshot already created should throw error | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn.stop_db_instance.when.called_with( | 
					
						
							|  |  |  |         DBInstanceIdentifier=mydb["DBInstanceIdentifier"], | 
					
						
							|  |  |  |         DBSnapshotIdentifier="rocky4570-rds-snap", | 
					
						
							|  |  |  |     ).should.throw(ClientError) | 
					
						
							| 
									
										
										
										
											2017-08-15 00:55:09 +10:00
										 |  |  |     # test stopping database not invoking snapshot should succeed. | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     response = conn.stop_db_instance(DBInstanceIdentifier=mydb["DBInstanceIdentifier"]) | 
					
						
							|  |  |  |     response["ResponseMetadata"]["HTTPStatusCode"].should.equal(200) | 
					
						
							|  |  |  |     response["DBInstance"]["DBInstanceStatus"].should.equal("stopped") | 
					
						
							| 
									
										
										
										
											2017-08-15 00:55:09 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-14 00:27:15 +10:00
										 |  |  | 
 | 
					
						
							|  |  |  | @mock_rds2 | 
					
						
							| 
									
										
										
										
											2020-04-16 15:14:37 -04:00
										 |  |  | def test_fail_to_stop_multi_az_and_sqlserver(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto3.client("rds", region_name="us-west-2") | 
					
						
							|  |  |  |     database = conn.create_db_instance( | 
					
						
							|  |  |  |         DBInstanceIdentifier="db-master-1", | 
					
						
							|  |  |  |         AllocatedStorage=10, | 
					
						
							| 
									
										
										
										
											2020-04-16 15:14:37 -04:00
										 |  |  |         Engine="sqlserver-ee", | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         DBName="staging-postgres", | 
					
						
							|  |  |  |         DBInstanceClass="db.m1.small", | 
					
						
							|  |  |  |         LicenseModel="license-included", | 
					
						
							|  |  |  |         MasterUsername="root", | 
					
						
							|  |  |  |         MasterUserPassword="hunter2", | 
					
						
							|  |  |  |         Port=1234, | 
					
						
							|  |  |  |         DBSecurityGroups=["my_sg"], | 
					
						
							|  |  |  |         MultiAZ=True, | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     mydb = conn.describe_db_instances( | 
					
						
							|  |  |  |         DBInstanceIdentifier=database["DBInstance"]["DBInstanceIdentifier"] | 
					
						
							|  |  |  |     )["DBInstances"][0] | 
					
						
							|  |  |  |     mydb["DBInstanceStatus"].should.equal("available") | 
					
						
							| 
									
										
										
										
											2017-08-14 00:27:15 +10:00
										 |  |  |     # multi-az databases arent allowed to be shutdown at this time. | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn.stop_db_instance.when.called_with( | 
					
						
							|  |  |  |         DBInstanceIdentifier=mydb["DBInstanceIdentifier"] | 
					
						
							|  |  |  |     ).should.throw(ClientError) | 
					
						
							| 
									
										
										
										
											2017-08-14 00:27:15 +10:00
										 |  |  |     # multi-az databases arent allowed to be started up at this time. | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn.start_db_instance.when.called_with( | 
					
						
							|  |  |  |         DBInstanceIdentifier=mydb["DBInstanceIdentifier"] | 
					
						
							|  |  |  |     ).should.throw(ClientError) | 
					
						
							| 
									
										
										
										
											2017-08-14 00:27:15 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-15 00:55:09 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-16 15:14:37 -04:00
										 |  |  | @mock_rds2 | 
					
						
							|  |  |  | def test_stop_multi_az_postgres(): | 
					
						
							|  |  |  |     conn = boto3.client("rds", region_name="us-west-2") | 
					
						
							|  |  |  |     database = conn.create_db_instance( | 
					
						
							|  |  |  |         DBInstanceIdentifier="db-master-1", | 
					
						
							|  |  |  |         AllocatedStorage=10, | 
					
						
							|  |  |  |         Engine="postgres", | 
					
						
							|  |  |  |         DBName="staging-postgres", | 
					
						
							|  |  |  |         DBInstanceClass="db.m1.small", | 
					
						
							|  |  |  |         LicenseModel="license-included", | 
					
						
							|  |  |  |         MasterUsername="root", | 
					
						
							|  |  |  |         MasterUserPassword="hunter2", | 
					
						
							|  |  |  |         Port=1234, | 
					
						
							|  |  |  |         DBSecurityGroups=["my_sg"], | 
					
						
							|  |  |  |         MultiAZ=True, | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     mydb = conn.describe_db_instances( | 
					
						
							|  |  |  |         DBInstanceIdentifier=database["DBInstance"]["DBInstanceIdentifier"] | 
					
						
							|  |  |  |     )["DBInstances"][0] | 
					
						
							|  |  |  |     mydb["DBInstanceStatus"].should.equal("available") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = conn.stop_db_instance(DBInstanceIdentifier=mydb["DBInstanceIdentifier"]) | 
					
						
							|  |  |  |     response["ResponseMetadata"]["HTTPStatusCode"].should.equal(200) | 
					
						
							|  |  |  |     response["DBInstance"]["DBInstanceStatus"].should.equal("stopped") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-14 00:27:15 +10:00
										 |  |  | @mock_rds2 | 
					
						
							|  |  |  | def test_fail_to_stop_readreplica(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto3.client("rds", region_name="us-west-2") | 
					
						
							|  |  |  |     database = conn.create_db_instance( | 
					
						
							|  |  |  |         DBInstanceIdentifier="db-master-1", | 
					
						
							|  |  |  |         AllocatedStorage=10, | 
					
						
							|  |  |  |         Engine="postgres", | 
					
						
							|  |  |  |         DBName="staging-postgres", | 
					
						
							|  |  |  |         DBInstanceClass="db.m1.small", | 
					
						
							|  |  |  |         LicenseModel="license-included", | 
					
						
							|  |  |  |         MasterUsername="root", | 
					
						
							|  |  |  |         MasterUserPassword="hunter2", | 
					
						
							|  |  |  |         Port=1234, | 
					
						
							|  |  |  |         DBSecurityGroups=["my_sg"], | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     replica = conn.create_db_instance_read_replica( | 
					
						
							|  |  |  |         DBInstanceIdentifier="db-replica-1", | 
					
						
							|  |  |  |         SourceDBInstanceIdentifier="db-master-1", | 
					
						
							|  |  |  |         DBInstanceClass="db.m1.small", | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     mydb = conn.describe_db_instances( | 
					
						
							|  |  |  |         DBInstanceIdentifier=replica["DBInstance"]["DBInstanceIdentifier"] | 
					
						
							|  |  |  |     )["DBInstances"][0] | 
					
						
							|  |  |  |     mydb["DBInstanceStatus"].should.equal("available") | 
					
						
							| 
									
										
										
										
											2017-08-14 00:27:15 +10:00
										 |  |  |     # read-replicas are not allowed to be stopped at this time. | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn.stop_db_instance.when.called_with( | 
					
						
							|  |  |  |         DBInstanceIdentifier=mydb["DBInstanceIdentifier"] | 
					
						
							|  |  |  |     ).should.throw(ClientError) | 
					
						
							| 
									
										
										
										
											2017-08-14 00:27:15 +10:00
										 |  |  |     # read-replicas are not allowed to be started at this time. | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn.start_db_instance.when.called_with( | 
					
						
							|  |  |  |         DBInstanceIdentifier=mydb["DBInstanceIdentifier"] | 
					
						
							|  |  |  |     ).should.throw(ClientError) | 
					
						
							| 
									
										
										
										
											2015-01-19 07:38:10 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-15 00:55:09 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-19 07:38:10 +11:00
										 |  |  | @mock_rds2 | 
					
						
							|  |  |  | def test_get_databases(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto3.client("rds", region_name="us-west-2") | 
					
						
							| 
									
										
										
										
											2015-01-19 07:38:10 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  |     instances = conn.describe_db_instances() | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     list(instances["DBInstances"]).should.have.length_of(0) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     conn.create_db_instance( | 
					
						
							|  |  |  |         DBInstanceIdentifier="db-master-1", | 
					
						
							|  |  |  |         AllocatedStorage=10, | 
					
						
							|  |  |  |         DBInstanceClass="postgres", | 
					
						
							|  |  |  |         Engine="db.m1.small", | 
					
						
							|  |  |  |         MasterUsername="root", | 
					
						
							|  |  |  |         MasterUserPassword="hunter2", | 
					
						
							|  |  |  |         Port=1234, | 
					
						
							|  |  |  |         DBSecurityGroups=["my_sg"], | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     conn.create_db_instance( | 
					
						
							|  |  |  |         DBInstanceIdentifier="db-master-2", | 
					
						
							|  |  |  |         AllocatedStorage=10, | 
					
						
							|  |  |  |         DBInstanceClass="postgres", | 
					
						
							|  |  |  |         Engine="db.m1.small", | 
					
						
							|  |  |  |         MasterUsername="root", | 
					
						
							|  |  |  |         MasterUserPassword="hunter2", | 
					
						
							|  |  |  |         Port=1234, | 
					
						
							|  |  |  |         DBSecurityGroups=["my_sg"], | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2015-01-19 07:38:10 +11:00
										 |  |  |     instances = conn.describe_db_instances() | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     list(instances["DBInstances"]).should.have.length_of(2) | 
					
						
							| 
									
										
										
										
											2015-01-19 07:38:10 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-11 18:02:51 -08:00
										 |  |  |     instances = conn.describe_db_instances(DBInstanceIdentifier="db-master-1") | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     list(instances["DBInstances"]).should.have.length_of(1) | 
					
						
							|  |  |  |     instances["DBInstances"][0]["DBInstanceIdentifier"].should.equal("db-master-1") | 
					
						
							|  |  |  |     instances["DBInstances"][0]["DBInstanceArn"].should.equal( | 
					
						
							| 
									
										
										
										
											2021-06-23 18:03:11 +01:00
										 |  |  |         "arn:aws:rds:us-west-2:{}:db:db-master-1".format(ACCOUNT_ID) | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     ) | 
					
						
							| 
									
										
										
										
											2015-01-19 07:38:10 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-10 21:58:42 -04:00
										 |  |  | @mock_rds2 | 
					
						
							|  |  |  | def test_get_databases_paginated(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto3.client("rds", region_name="us-west-2") | 
					
						
							| 
									
										
										
										
											2017-05-10 21:58:42 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     for i in range(51): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         conn.create_db_instance( | 
					
						
							|  |  |  |             AllocatedStorage=5, | 
					
						
							|  |  |  |             Port=5432, | 
					
						
							|  |  |  |             DBInstanceIdentifier="rds%d" % i, | 
					
						
							|  |  |  |             DBInstanceClass="db.t1.micro", | 
					
						
							|  |  |  |             Engine="postgres", | 
					
						
							|  |  |  |         ) | 
					
						
							| 
									
										
										
										
											2017-05-10 21:58:42 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     resp = conn.describe_db_instances() | 
					
						
							|  |  |  |     resp["DBInstances"].should.have.length_of(50) | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     resp["Marker"].should.equal(resp["DBInstances"][-1]["DBInstanceIdentifier"]) | 
					
						
							| 
									
										
										
										
											2017-05-10 21:58:42 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     resp2 = conn.describe_db_instances(Marker=resp["Marker"]) | 
					
						
							|  |  |  |     resp2["DBInstances"].should.have.length_of(1) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-18 13:05:07 +09:00
										 |  |  |     resp3 = conn.describe_db_instances(MaxRecords=100) | 
					
						
							|  |  |  |     resp3["DBInstances"].should.have.length_of(51) | 
					
						
							| 
									
										
										
										
											2017-06-20 11:58:18 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-11 22:43:42 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-19 07:38:10 +11:00
										 |  |  | @mock_rds2 | 
					
						
							| 
									
										
										
										
											2020-01-20 15:21:11 -08:00
										 |  |  | def test_describe_non_existent_database(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto3.client("rds", region_name="us-west-2") | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     conn.describe_db_instances.when.called_with( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         DBInstanceIdentifier="not-a-db" | 
					
						
							|  |  |  |     ).should.throw(ClientError) | 
					
						
							| 
									
										
										
										
											2015-01-19 07:38:10 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-22 07:21:49 +11:00
										 |  |  | @mock_rds2 | 
					
						
							|  |  |  | def test_modify_db_instance(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto3.client("rds", region_name="us-west-2") | 
					
						
							|  |  |  |     database = conn.create_db_instance( | 
					
						
							|  |  |  |         DBInstanceIdentifier="db-master-1", | 
					
						
							|  |  |  |         AllocatedStorage=10, | 
					
						
							|  |  |  |         DBInstanceClass="postgres", | 
					
						
							|  |  |  |         Engine="db.m1.small", | 
					
						
							|  |  |  |         MasterUsername="root", | 
					
						
							|  |  |  |         MasterUserPassword="hunter2", | 
					
						
							|  |  |  |         Port=1234, | 
					
						
							|  |  |  |         DBSecurityGroups=["my_sg"], | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     instances = conn.describe_db_instances(DBInstanceIdentifier="db-master-1") | 
					
						
							|  |  |  |     instances["DBInstances"][0]["AllocatedStorage"].should.equal(10) | 
					
						
							|  |  |  |     conn.modify_db_instance( | 
					
						
							|  |  |  |         DBInstanceIdentifier="db-master-1", | 
					
						
							|  |  |  |         AllocatedStorage=20, | 
					
						
							|  |  |  |         ApplyImmediately=True, | 
					
						
							|  |  |  |         VpcSecurityGroupIds=["sg-123456"], | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     instances = conn.describe_db_instances(DBInstanceIdentifier="db-master-1") | 
					
						
							|  |  |  |     instances["DBInstances"][0]["AllocatedStorage"].should.equal(20) | 
					
						
							|  |  |  |     instances["DBInstances"][0]["VpcSecurityGroups"][0][ | 
					
						
							|  |  |  |         "VpcSecurityGroupId" | 
					
						
							|  |  |  |     ].should.equal("sg-123456") | 
					
						
							| 
									
										
										
										
											2015-01-22 07:21:49 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-30 06:41:25 -05:00
										 |  |  | @mock_rds2 | 
					
						
							|  |  |  | def test_rename_db_instance(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto3.client("rds", region_name="us-west-2") | 
					
						
							|  |  |  |     database = conn.create_db_instance( | 
					
						
							|  |  |  |         DBInstanceIdentifier="db-master-1", | 
					
						
							|  |  |  |         AllocatedStorage=10, | 
					
						
							|  |  |  |         DBInstanceClass="postgres", | 
					
						
							|  |  |  |         Engine="db.m1.small", | 
					
						
							|  |  |  |         MasterUsername="root", | 
					
						
							|  |  |  |         MasterUserPassword="hunter2", | 
					
						
							|  |  |  |         Port=1234, | 
					
						
							|  |  |  |         DBSecurityGroups=["my_sg"], | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2017-11-30 06:41:25 -05:00
										 |  |  |     instances = conn.describe_db_instances(DBInstanceIdentifier="db-master-1") | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     list(instances["DBInstances"]).should.have.length_of(1) | 
					
						
							|  |  |  |     conn.describe_db_instances.when.called_with( | 
					
						
							|  |  |  |         DBInstanceIdentifier="db-master-2" | 
					
						
							|  |  |  |     ).should.throw(ClientError) | 
					
						
							|  |  |  |     conn.modify_db_instance( | 
					
						
							|  |  |  |         DBInstanceIdentifier="db-master-1", | 
					
						
							|  |  |  |         NewDBInstanceIdentifier="db-master-2", | 
					
						
							|  |  |  |         ApplyImmediately=True, | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     conn.describe_db_instances.when.called_with( | 
					
						
							|  |  |  |         DBInstanceIdentifier="db-master-1" | 
					
						
							|  |  |  |     ).should.throw(ClientError) | 
					
						
							| 
									
										
										
										
											2017-11-30 06:41:25 -05:00
										 |  |  |     instances = conn.describe_db_instances(DBInstanceIdentifier="db-master-2") | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     list(instances["DBInstances"]).should.have.length_of(1) | 
					
						
							| 
									
										
										
										
											2017-11-30 06:41:25 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-27 08:21:48 +11:00
										 |  |  | @mock_rds2 | 
					
						
							| 
									
										
										
										
											2020-01-20 15:21:11 -08:00
										 |  |  | def test_modify_non_existent_database(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto3.client("rds", region_name="us-west-2") | 
					
						
							|  |  |  |     conn.modify_db_instance.when.called_with( | 
					
						
							|  |  |  |         DBInstanceIdentifier="not-a-db", AllocatedStorage=20, ApplyImmediately=True | 
					
						
							|  |  |  |     ).should.throw(ClientError) | 
					
						
							| 
									
										
										
										
											2015-01-27 08:21:48 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-27 08:21:48 +11:00
										 |  |  | @mock_rds2 | 
					
						
							|  |  |  | def test_reboot_db_instance(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto3.client("rds", region_name="us-west-2") | 
					
						
							|  |  |  |     conn.create_db_instance( | 
					
						
							|  |  |  |         DBInstanceIdentifier="db-master-1", | 
					
						
							|  |  |  |         AllocatedStorage=10, | 
					
						
							|  |  |  |         DBInstanceClass="postgres", | 
					
						
							|  |  |  |         Engine="db.m1.small", | 
					
						
							|  |  |  |         MasterUsername="root", | 
					
						
							|  |  |  |         MasterUserPassword="hunter2", | 
					
						
							|  |  |  |         Port=1234, | 
					
						
							|  |  |  |         DBSecurityGroups=["my_sg"], | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     database = conn.reboot_db_instance(DBInstanceIdentifier="db-master-1") | 
					
						
							|  |  |  |     database["DBInstance"]["DBInstanceIdentifier"].should.equal("db-master-1") | 
					
						
							| 
									
										
										
										
											2015-01-27 08:21:48 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_rds2 | 
					
						
							| 
									
										
										
										
											2020-01-20 15:21:11 -08:00
										 |  |  | def test_reboot_non_existent_database(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto3.client("rds", region_name="us-west-2") | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     conn.reboot_db_instance.when.called_with( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         DBInstanceIdentifier="not-a-db" | 
					
						
							|  |  |  |     ).should.throw(ClientError) | 
					
						
							| 
									
										
										
										
											2015-01-27 08:21:48 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-22 07:21:49 +11:00
										 |  |  | @mock_rds2 | 
					
						
							|  |  |  | def test_delete_database(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto3.client("rds", region_name="us-west-2") | 
					
						
							| 
									
										
										
										
											2015-01-22 07:21:49 +11:00
										 |  |  |     instances = conn.describe_db_instances() | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     list(instances["DBInstances"]).should.have.length_of(0) | 
					
						
							|  |  |  |     conn.create_db_instance( | 
					
						
							|  |  |  |         DBInstanceIdentifier="db-primary-1", | 
					
						
							|  |  |  |         AllocatedStorage=10, | 
					
						
							|  |  |  |         Engine="postgres", | 
					
						
							|  |  |  |         DBInstanceClass="db.m1.small", | 
					
						
							|  |  |  |         MasterUsername="root", | 
					
						
							|  |  |  |         MasterUserPassword="hunter2", | 
					
						
							|  |  |  |         Port=1234, | 
					
						
							|  |  |  |         DBSecurityGroups=["my_sg"], | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2015-01-22 07:21:49 +11:00
										 |  |  |     instances = conn.describe_db_instances() | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     list(instances["DBInstances"]).should.have.length_of(1) | 
					
						
							| 
									
										
										
										
											2015-01-22 07:21:49 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn.delete_db_instance( | 
					
						
							|  |  |  |         DBInstanceIdentifier="db-primary-1", | 
					
						
							|  |  |  |         FinalDBSnapshotIdentifier="primary-1-snapshot", | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2017-06-20 14:46:13 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-22 07:21:49 +11:00
										 |  |  |     instances = conn.describe_db_instances() | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     list(instances["DBInstances"]).should.have.length_of(0) | 
					
						
							| 
									
										
										
										
											2015-01-22 07:21:49 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-20 14:46:13 -07:00
										 |  |  |     # Saved the snapshot | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     snapshots = conn.describe_db_snapshots(DBInstanceIdentifier="db-primary-1").get( | 
					
						
							|  |  |  |         "DBSnapshots" | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     snapshots[0].get("Engine").should.equal("postgres") | 
					
						
							| 
									
										
										
										
											2017-06-20 14:46:13 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-22 07:21:49 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-20 13:51:25 -07:00
										 |  |  | @mock_rds2 | 
					
						
							|  |  |  | def test_create_db_snapshots(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto3.client("rds", region_name="us-west-2") | 
					
						
							| 
									
										
										
										
											2017-06-20 13:51:25 -07:00
										 |  |  |     conn.create_db_snapshot.when.called_with( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         DBInstanceIdentifier="db-primary-1", DBSnapshotIdentifier="snapshot-1" | 
					
						
							|  |  |  |     ).should.throw(ClientError) | 
					
						
							| 
									
										
										
										
											2017-06-20 13:51:25 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn.create_db_instance( | 
					
						
							|  |  |  |         DBInstanceIdentifier="db-primary-1", | 
					
						
							|  |  |  |         AllocatedStorage=10, | 
					
						
							|  |  |  |         Engine="postgres", | 
					
						
							|  |  |  |         DBName="staging-postgres", | 
					
						
							|  |  |  |         DBInstanceClass="db.m1.small", | 
					
						
							|  |  |  |         MasterUsername="root", | 
					
						
							|  |  |  |         MasterUserPassword="hunter2", | 
					
						
							|  |  |  |         Port=1234, | 
					
						
							|  |  |  |         DBSecurityGroups=["my_sg"], | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2017-06-20 13:51:25 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     snapshot = conn.create_db_snapshot( | 
					
						
							|  |  |  |         DBInstanceIdentifier="db-primary-1", DBSnapshotIdentifier="g-1" | 
					
						
							|  |  |  |     ).get("DBSnapshot") | 
					
						
							| 
									
										
										
										
											2017-06-20 13:51:25 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     snapshot.get("Engine").should.equal("postgres") | 
					
						
							|  |  |  |     snapshot.get("DBInstanceIdentifier").should.equal("db-primary-1") | 
					
						
							|  |  |  |     snapshot.get("DBSnapshotIdentifier").should.equal("g-1") | 
					
						
							|  |  |  |     result = conn.list_tags_for_resource(ResourceName=snapshot["DBSnapshotArn"]) | 
					
						
							|  |  |  |     result["TagList"].should.equal([]) | 
					
						
							| 
									
										
										
										
											2018-09-21 08:31:31 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_rds2 | 
					
						
							|  |  |  | def test_create_db_snapshots_copy_tags(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto3.client("rds", region_name="us-west-2") | 
					
						
							| 
									
										
										
										
											2018-09-21 08:31:31 -05:00
										 |  |  |     conn.create_db_snapshot.when.called_with( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         DBInstanceIdentifier="db-primary-1", DBSnapshotIdentifier="snapshot-1" | 
					
						
							|  |  |  |     ).should.throw(ClientError) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     conn.create_db_instance( | 
					
						
							|  |  |  |         DBInstanceIdentifier="db-primary-1", | 
					
						
							|  |  |  |         AllocatedStorage=10, | 
					
						
							|  |  |  |         Engine="postgres", | 
					
						
							|  |  |  |         DBName="staging-postgres", | 
					
						
							|  |  |  |         DBInstanceClass="db.m1.small", | 
					
						
							|  |  |  |         MasterUsername="root", | 
					
						
							|  |  |  |         MasterUserPassword="hunter2", | 
					
						
							|  |  |  |         Port=1234, | 
					
						
							|  |  |  |         DBSecurityGroups=["my_sg"], | 
					
						
							|  |  |  |         CopyTagsToSnapshot=True, | 
					
						
							|  |  |  |         Tags=[{"Key": "foo", "Value": "bar"}, {"Key": "foo1", "Value": "bar1"}], | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     snapshot = conn.create_db_snapshot( | 
					
						
							|  |  |  |         DBInstanceIdentifier="db-primary-1", DBSnapshotIdentifier="g-1" | 
					
						
							|  |  |  |     ).get("DBSnapshot") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     snapshot.get("Engine").should.equal("postgres") | 
					
						
							|  |  |  |     snapshot.get("DBInstanceIdentifier").should.equal("db-primary-1") | 
					
						
							|  |  |  |     snapshot.get("DBSnapshotIdentifier").should.equal("g-1") | 
					
						
							|  |  |  |     result = conn.list_tags_for_resource(ResourceName=snapshot["DBSnapshotArn"]) | 
					
						
							|  |  |  |     result["TagList"].should.equal( | 
					
						
							|  |  |  |         [{"Value": "bar", "Key": "foo"}, {"Value": "bar1", "Key": "foo1"}] | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2017-06-20 13:51:25 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_rds2 | 
					
						
							|  |  |  | def test_describe_db_snapshots(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto3.client("rds", region_name="us-west-2") | 
					
						
							|  |  |  |     conn.create_db_instance( | 
					
						
							|  |  |  |         DBInstanceIdentifier="db-primary-1", | 
					
						
							|  |  |  |         AllocatedStorage=10, | 
					
						
							|  |  |  |         Engine="postgres", | 
					
						
							|  |  |  |         DBName="staging-postgres", | 
					
						
							|  |  |  |         DBInstanceClass="db.m1.small", | 
					
						
							|  |  |  |         MasterUsername="root", | 
					
						
							|  |  |  |         MasterUserPassword="hunter2", | 
					
						
							|  |  |  |         Port=1234, | 
					
						
							|  |  |  |         DBSecurityGroups=["my_sg"], | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     created = conn.create_db_snapshot( | 
					
						
							|  |  |  |         DBInstanceIdentifier="db-primary-1", DBSnapshotIdentifier="snapshot-1" | 
					
						
							|  |  |  |     ).get("DBSnapshot") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     created.get("Engine").should.equal("postgres") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     by_database_id = conn.describe_db_snapshots( | 
					
						
							|  |  |  |         DBInstanceIdentifier="db-primary-1" | 
					
						
							|  |  |  |     ).get("DBSnapshots") | 
					
						
							|  |  |  |     by_snapshot_id = conn.describe_db_snapshots(DBSnapshotIdentifier="snapshot-1").get( | 
					
						
							|  |  |  |         "DBSnapshots" | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2017-06-20 13:51:25 -07:00
										 |  |  |     by_snapshot_id.should.equal(by_database_id) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     snapshot = by_snapshot_id[0] | 
					
						
							|  |  |  |     snapshot.should.equal(created) | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     snapshot.get("Engine").should.equal("postgres") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     conn.create_db_snapshot( | 
					
						
							|  |  |  |         DBInstanceIdentifier="db-primary-1", DBSnapshotIdentifier="snapshot-2" | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     snapshots = conn.describe_db_snapshots(DBInstanceIdentifier="db-primary-1").get( | 
					
						
							|  |  |  |         "DBSnapshots" | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2018-04-19 20:21:27 -07:00
										 |  |  |     snapshots.should.have.length_of(2) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-20 13:51:25 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | @mock_rds2 | 
					
						
							|  |  |  | def test_delete_db_snapshot(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto3.client("rds", region_name="us-west-2") | 
					
						
							|  |  |  |     conn.create_db_instance( | 
					
						
							|  |  |  |         DBInstanceIdentifier="db-primary-1", | 
					
						
							|  |  |  |         AllocatedStorage=10, | 
					
						
							|  |  |  |         Engine="postgres", | 
					
						
							|  |  |  |         DBName="staging-postgres", | 
					
						
							|  |  |  |         DBInstanceClass="db.m1.small", | 
					
						
							|  |  |  |         MasterUsername="root", | 
					
						
							|  |  |  |         MasterUserPassword="hunter2", | 
					
						
							|  |  |  |         Port=1234, | 
					
						
							|  |  |  |         DBSecurityGroups=["my_sg"], | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     conn.create_db_snapshot( | 
					
						
							|  |  |  |         DBInstanceIdentifier="db-primary-1", DBSnapshotIdentifier="snapshot-1" | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     conn.describe_db_snapshots(DBSnapshotIdentifier="snapshot-1").get("DBSnapshots")[0] | 
					
						
							|  |  |  |     conn.delete_db_snapshot(DBSnapshotIdentifier="snapshot-1") | 
					
						
							| 
									
										
										
										
											2017-06-20 13:51:25 -07:00
										 |  |  |     conn.describe_db_snapshots.when.called_with( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         DBSnapshotIdentifier="snapshot-1" | 
					
						
							|  |  |  |     ).should.throw(ClientError) | 
					
						
							| 
									
										
										
										
											2017-06-20 13:51:25 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-19 07:38:10 +11:00
										 |  |  | @mock_rds2 | 
					
						
							|  |  |  | def test_create_option_group(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto3.client("rds", region_name="us-west-2") | 
					
						
							|  |  |  |     option_group = conn.create_option_group( | 
					
						
							|  |  |  |         OptionGroupName="test", | 
					
						
							|  |  |  |         EngineName="mysql", | 
					
						
							|  |  |  |         MajorEngineVersion="5.6", | 
					
						
							|  |  |  |         OptionGroupDescription="test option group", | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     option_group["OptionGroup"]["OptionGroupName"].should.equal("test") | 
					
						
							|  |  |  |     option_group["OptionGroup"]["EngineName"].should.equal("mysql") | 
					
						
							|  |  |  |     option_group["OptionGroup"]["OptionGroupDescription"].should.equal( | 
					
						
							|  |  |  |         "test option group" | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     option_group["OptionGroup"]["MajorEngineVersion"].should.equal("5.6") | 
					
						
							| 
									
										
										
										
											2015-01-19 07:38:10 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-21 07:15:47 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-19 17:03:14 +11:00
										 |  |  | @mock_rds2 | 
					
						
							|  |  |  | def test_create_option_group_bad_engine_name(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto3.client("rds", region_name="us-west-2") | 
					
						
							|  |  |  |     conn.create_option_group.when.called_with( | 
					
						
							|  |  |  |         OptionGroupName="test", | 
					
						
							|  |  |  |         EngineName="invalid_engine", | 
					
						
							|  |  |  |         MajorEngineVersion="5.6", | 
					
						
							|  |  |  |         OptionGroupDescription="test invalid engine", | 
					
						
							|  |  |  |     ).should.throw(ClientError) | 
					
						
							| 
									
										
										
										
											2015-01-19 17:03:14 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_rds2 | 
					
						
							|  |  |  | def test_create_option_group_bad_engine_major_version(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto3.client("rds", region_name="us-west-2") | 
					
						
							|  |  |  |     conn.create_option_group.when.called_with( | 
					
						
							|  |  |  |         OptionGroupName="test", | 
					
						
							|  |  |  |         EngineName="mysql", | 
					
						
							|  |  |  |         MajorEngineVersion="6.6.6", | 
					
						
							|  |  |  |         OptionGroupDescription="test invalid engine version", | 
					
						
							|  |  |  |     ).should.throw(ClientError) | 
					
						
							| 
									
										
										
										
											2015-01-19 17:03:14 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_rds2 | 
					
						
							|  |  |  | def test_create_option_group_empty_description(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto3.client("rds", region_name="us-west-2") | 
					
						
							|  |  |  |     conn.create_option_group.when.called_with( | 
					
						
							|  |  |  |         OptionGroupName="test", | 
					
						
							|  |  |  |         EngineName="mysql", | 
					
						
							|  |  |  |         MajorEngineVersion="5.6", | 
					
						
							|  |  |  |         OptionGroupDescription="", | 
					
						
							|  |  |  |     ).should.throw(ClientError) | 
					
						
							| 
									
										
										
										
											2015-01-19 17:03:14 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-20 21:01:34 +11:00
										 |  |  | @mock_rds2 | 
					
						
							|  |  |  | def test_create_option_group_duplicate(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto3.client("rds", region_name="us-west-2") | 
					
						
							|  |  |  |     conn.create_option_group( | 
					
						
							|  |  |  |         OptionGroupName="test", | 
					
						
							|  |  |  |         EngineName="mysql", | 
					
						
							|  |  |  |         MajorEngineVersion="5.6", | 
					
						
							|  |  |  |         OptionGroupDescription="test option group", | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     conn.create_option_group.when.called_with( | 
					
						
							|  |  |  |         OptionGroupName="test", | 
					
						
							|  |  |  |         EngineName="mysql", | 
					
						
							|  |  |  |         MajorEngineVersion="5.6", | 
					
						
							|  |  |  |         OptionGroupDescription="test option group", | 
					
						
							|  |  |  |     ).should.throw(ClientError) | 
					
						
							| 
									
										
										
										
											2015-01-20 21:01:34 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-19 20:29:32 +11:00
										 |  |  | @mock_rds2 | 
					
						
							|  |  |  | def test_describe_option_group(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto3.client("rds", region_name="us-west-2") | 
					
						
							|  |  |  |     conn.create_option_group( | 
					
						
							|  |  |  |         OptionGroupName="test", | 
					
						
							|  |  |  |         EngineName="mysql", | 
					
						
							|  |  |  |         MajorEngineVersion="5.6", | 
					
						
							|  |  |  |         OptionGroupDescription="test option group", | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     option_groups = conn.describe_option_groups(OptionGroupName="test") | 
					
						
							|  |  |  |     option_groups["OptionGroupsList"][0]["OptionGroupName"].should.equal("test") | 
					
						
							| 
									
										
										
										
											2015-01-19 20:29:32 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-20 07:18:52 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-19 20:29:32 +11:00
										 |  |  | @mock_rds2 | 
					
						
							| 
									
										
										
										
											2020-01-20 15:21:11 -08:00
										 |  |  | def test_describe_non_existent_option_group(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto3.client("rds", region_name="us-west-2") | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     conn.describe_option_groups.when.called_with( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         OptionGroupName="not-a-option-group" | 
					
						
							|  |  |  |     ).should.throw(ClientError) | 
					
						
							| 
									
										
										
										
											2015-01-19 20:29:32 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_rds2 | 
					
						
							|  |  |  | def test_delete_option_group(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto3.client("rds", region_name="us-west-2") | 
					
						
							|  |  |  |     conn.create_option_group( | 
					
						
							|  |  |  |         OptionGroupName="test", | 
					
						
							|  |  |  |         EngineName="mysql", | 
					
						
							|  |  |  |         MajorEngineVersion="5.6", | 
					
						
							|  |  |  |         OptionGroupDescription="test option group", | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     option_groups = conn.describe_option_groups(OptionGroupName="test") | 
					
						
							|  |  |  |     option_groups["OptionGroupsList"][0]["OptionGroupName"].should.equal("test") | 
					
						
							|  |  |  |     conn.delete_option_group(OptionGroupName="test") | 
					
						
							|  |  |  |     conn.describe_option_groups.when.called_with(OptionGroupName="test").should.throw( | 
					
						
							|  |  |  |         ClientError | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2015-01-19 20:29:32 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_rds2 | 
					
						
							| 
									
										
										
										
											2020-01-20 15:21:11 -08:00
										 |  |  | def test_delete_non_existent_option_group(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto3.client("rds", region_name="us-west-2") | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     conn.delete_option_group.when.called_with( | 
					
						
							| 
									
										
										
										
											2020-01-20 15:21:11 -08:00
										 |  |  |         OptionGroupName="non-existent" | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     ).should.throw(ClientError) | 
					
						
							| 
									
										
										
										
											2015-01-19 20:29:32 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-20 07:18:52 +11:00
										 |  |  | @mock_rds2 | 
					
						
							|  |  |  | def test_describe_option_group_options(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto3.client("rds", region_name="us-west-2") | 
					
						
							|  |  |  |     option_group_options = conn.describe_option_group_options(EngineName="sqlserver-ee") | 
					
						
							|  |  |  |     len(option_group_options["OptionGroupOptions"]).should.equal(4) | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     option_group_options = conn.describe_option_group_options( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         EngineName="sqlserver-ee", MajorEngineVersion="11.00" | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     len(option_group_options["OptionGroupOptions"]).should.equal(2) | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     option_group_options = conn.describe_option_group_options( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         EngineName="mysql", MajorEngineVersion="5.6" | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     len(option_group_options["OptionGroupOptions"]).should.equal(1) | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     conn.describe_option_group_options.when.called_with( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         EngineName="non-existent" | 
					
						
							|  |  |  |     ).should.throw(ClientError) | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     conn.describe_option_group_options.when.called_with( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         EngineName="mysql", MajorEngineVersion="non-existent" | 
					
						
							|  |  |  |     ).should.throw(ClientError) | 
					
						
							| 
									
										
										
										
											2015-01-19 20:29:32 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-20 21:01:34 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  | @mock_rds2 | 
					
						
							|  |  |  | def test_modify_option_group(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto3.client("rds", region_name="us-west-2") | 
					
						
							|  |  |  |     conn.create_option_group( | 
					
						
							|  |  |  |         OptionGroupName="test", | 
					
						
							|  |  |  |         EngineName="mysql", | 
					
						
							|  |  |  |         MajorEngineVersion="5.6", | 
					
						
							|  |  |  |         OptionGroupDescription="test option group", | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2015-01-22 07:21:49 +11:00
										 |  |  |     # TODO: create option and validate before deleting. | 
					
						
							| 
									
										
										
										
											2015-01-21 07:15:47 +11:00
										 |  |  |     # if Someone can tell me how the hell to use this function | 
					
						
							|  |  |  |     # to add options to an option_group, I can finish coding this. | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     result = conn.modify_option_group( | 
					
						
							|  |  |  |         OptionGroupName="test", | 
					
						
							|  |  |  |         OptionsToInclude=[], | 
					
						
							|  |  |  |         OptionsToRemove=["MEMCACHED"], | 
					
						
							|  |  |  |         ApplyImmediately=True, | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     result["OptionGroup"]["EngineName"].should.equal("mysql") | 
					
						
							|  |  |  |     result["OptionGroup"]["Options"].should.equal([]) | 
					
						
							|  |  |  |     result["OptionGroup"]["OptionGroupName"].should.equal("test") | 
					
						
							| 
									
										
										
										
											2015-01-21 07:15:47 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-20 21:01:34 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  | @mock_rds2 | 
					
						
							|  |  |  | def test_modify_option_group_no_options(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto3.client("rds", region_name="us-west-2") | 
					
						
							|  |  |  |     conn.create_option_group( | 
					
						
							|  |  |  |         OptionGroupName="test", | 
					
						
							|  |  |  |         EngineName="mysql", | 
					
						
							|  |  |  |         MajorEngineVersion="5.6", | 
					
						
							|  |  |  |         OptionGroupDescription="test option group", | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     conn.modify_option_group.when.called_with(OptionGroupName="test").should.throw( | 
					
						
							|  |  |  |         ClientError | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2015-01-20 21:01:34 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_rds2 | 
					
						
							| 
									
										
										
										
											2020-01-20 15:21:11 -08:00
										 |  |  | def test_modify_non_existent_option_group(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto3.client("rds", region_name="us-west-2") | 
					
						
							|  |  |  |     conn.modify_option_group.when.called_with( | 
					
						
							| 
									
										
										
										
											2020-01-20 15:21:11 -08:00
										 |  |  |         OptionGroupName="non-existent", | 
					
						
							| 
									
										
										
										
											2021-01-31 04:21:24 -08:00
										 |  |  |         OptionsToInclude=[{"OptionName": "test-option"}], | 
					
						
							|  |  |  |     ).should.throw(ClientError, "Specified OptionGroupName: non-existent not found.") | 
					
						
							| 
									
										
										
										
											2015-01-20 21:01:34 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-22 07:21:49 +11:00
										 |  |  | @mock_rds2 | 
					
						
							| 
									
										
										
										
											2020-01-20 15:21:11 -08:00
										 |  |  | def test_delete_non_existent_database(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto3.client("rds", region_name="us-west-2") | 
					
						
							| 
									
										
										
										
											2021-02-13 03:12:02 -08:00
										 |  |  |     with pytest.raises(ClientError) as ex: | 
					
						
							|  |  |  |         conn.delete_db_instance(DBInstanceIdentifier="non-existent") | 
					
						
							|  |  |  |     ex.value.response["Error"]["Code"].should.equal("DBInstanceNotFound") | 
					
						
							|  |  |  |     ex.value.response["Error"]["Message"].should.equal( | 
					
						
							|  |  |  |         "DBInstance non-existent not found." | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2015-01-19 07:38:10 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-27 08:21:48 +11:00
										 |  |  | @mock_rds2 | 
					
						
							|  |  |  | def test_list_tags_invalid_arn(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto3.client("rds", region_name="us-west-2") | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     conn.list_tags_for_resource.when.called_with( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         ResourceName="arn:aws:rds:bad-arn" | 
					
						
							|  |  |  |     ).should.throw(ClientError) | 
					
						
							| 
									
										
										
										
											2015-01-27 08:21:48 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_rds2 | 
					
						
							| 
									
										
										
										
											2015-01-29 07:15:03 +11:00
										 |  |  | def test_list_tags_db(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto3.client("rds", region_name="us-west-2") | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     result = conn.list_tags_for_resource( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         ResourceName="arn:aws:rds:us-west-2:1234567890:db:foo" | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     result["TagList"].should.equal([]) | 
					
						
							| 
									
										
										
										
											2017-03-13 16:48:22 -04:00
										 |  |  |     test_instance = conn.create_db_instance( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         DBInstanceIdentifier="db-with-tags", | 
					
						
							| 
									
										
										
										
											2017-03-13 16:48:22 -04:00
										 |  |  |         AllocatedStorage=10, | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         DBInstanceClass="postgres", | 
					
						
							|  |  |  |         Engine="db.m1.small", | 
					
						
							|  |  |  |         MasterUsername="root", | 
					
						
							|  |  |  |         MasterUserPassword="hunter2", | 
					
						
							| 
									
										
										
										
											2017-03-13 16:48:22 -04:00
										 |  |  |         Port=1234, | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         DBSecurityGroups=["my_sg"], | 
					
						
							|  |  |  |         Tags=[{"Key": "foo", "Value": "bar"}, {"Key": "foo1", "Value": "bar1"}], | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     result = conn.list_tags_for_resource( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         ResourceName=test_instance["DBInstance"]["DBInstanceArn"] | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     result["TagList"].should.equal( | 
					
						
							|  |  |  |         [{"Value": "bar", "Key": "foo"}, {"Value": "bar1", "Key": "foo1"}] | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2015-01-27 08:21:48 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-28 10:17:55 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  | @mock_rds2 | 
					
						
							| 
									
										
										
										
											2015-01-29 07:15:03 +11:00
										 |  |  | def test_add_tags_db(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto3.client("rds", region_name="us-west-2") | 
					
						
							|  |  |  |     conn.create_db_instance( | 
					
						
							|  |  |  |         DBInstanceIdentifier="db-without-tags", | 
					
						
							|  |  |  |         AllocatedStorage=10, | 
					
						
							|  |  |  |         DBInstanceClass="postgres", | 
					
						
							|  |  |  |         Engine="db.m1.small", | 
					
						
							|  |  |  |         MasterUsername="root", | 
					
						
							|  |  |  |         MasterUserPassword="hunter2", | 
					
						
							|  |  |  |         Port=1234, | 
					
						
							|  |  |  |         DBSecurityGroups=["my_sg"], | 
					
						
							|  |  |  |         Tags=[{"Key": "foo", "Value": "bar"}, {"Key": "foo1", "Value": "bar1"}], | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     result = conn.list_tags_for_resource( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         ResourceName="arn:aws:rds:us-west-2:1234567890:db:db-without-tags" | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     list(result["TagList"]).should.have.length_of(2) | 
					
						
							|  |  |  |     conn.add_tags_to_resource( | 
					
						
							|  |  |  |         ResourceName="arn:aws:rds:us-west-2:1234567890:db:db-without-tags", | 
					
						
							|  |  |  |         Tags=[{"Key": "foo", "Value": "fish"}, {"Key": "foo2", "Value": "bar2"}], | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     result = conn.list_tags_for_resource( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         ResourceName="arn:aws:rds:us-west-2:1234567890:db:db-without-tags" | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     list(result["TagList"]).should.have.length_of(3) | 
					
						
							| 
									
										
										
										
											2015-01-28 10:17:55 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_rds2 | 
					
						
							| 
									
										
										
										
											2015-01-29 07:15:03 +11:00
										 |  |  | def test_remove_tags_db(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto3.client("rds", region_name="us-west-2") | 
					
						
							|  |  |  |     conn.create_db_instance( | 
					
						
							|  |  |  |         DBInstanceIdentifier="db-with-tags", | 
					
						
							|  |  |  |         AllocatedStorage=10, | 
					
						
							|  |  |  |         DBInstanceClass="postgres", | 
					
						
							|  |  |  |         Engine="db.m1.small", | 
					
						
							|  |  |  |         MasterUsername="root", | 
					
						
							|  |  |  |         MasterUserPassword="hunter2", | 
					
						
							|  |  |  |         Port=1234, | 
					
						
							|  |  |  |         DBSecurityGroups=["my_sg"], | 
					
						
							|  |  |  |         Tags=[{"Key": "foo", "Value": "bar"}, {"Key": "foo1", "Value": "bar1"}], | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     result = conn.list_tags_for_resource( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         ResourceName="arn:aws:rds:us-west-2:1234567890:db:db-with-tags" | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     list(result["TagList"]).should.have.length_of(2) | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     conn.remove_tags_from_resource( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         ResourceName="arn:aws:rds:us-west-2:1234567890:db:db-with-tags", TagKeys=["foo"] | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     result = conn.list_tags_for_resource( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         ResourceName="arn:aws:rds:us-west-2:1234567890:db:db-with-tags" | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     len(result["TagList"]).should.equal(1) | 
					
						
							| 
									
										
										
										
											2015-01-28 10:17:55 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-21 12:03:13 -05:00
										 |  |  | @mock_rds2 | 
					
						
							|  |  |  | def test_list_tags_snapshot(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto3.client("rds", region_name="us-west-2") | 
					
						
							|  |  |  |     result = conn.list_tags_for_resource( | 
					
						
							|  |  |  |         ResourceName="arn:aws:rds:us-west-2:1234567890:snapshot:foo" | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     result["TagList"].should.equal([]) | 
					
						
							|  |  |  |     conn.create_db_instance( | 
					
						
							|  |  |  |         DBInstanceIdentifier="db-primary-1", | 
					
						
							|  |  |  |         AllocatedStorage=10, | 
					
						
							|  |  |  |         Engine="postgres", | 
					
						
							|  |  |  |         DBName="staging-postgres", | 
					
						
							|  |  |  |         DBInstanceClass="db.m1.small", | 
					
						
							|  |  |  |         MasterUsername="root", | 
					
						
							|  |  |  |         MasterUserPassword="hunter2", | 
					
						
							|  |  |  |         Port=1234, | 
					
						
							|  |  |  |         DBSecurityGroups=["my_sg"], | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     snapshot = conn.create_db_snapshot( | 
					
						
							|  |  |  |         DBInstanceIdentifier="db-primary-1", | 
					
						
							|  |  |  |         DBSnapshotIdentifier="snapshot-with-tags", | 
					
						
							|  |  |  |         Tags=[{"Key": "foo", "Value": "bar"}, {"Key": "foo1", "Value": "bar1"}], | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2018-09-21 12:03:13 -05:00
										 |  |  |     result = conn.list_tags_for_resource( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         ResourceName=snapshot["DBSnapshot"]["DBSnapshotArn"] | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     result["TagList"].should.equal( | 
					
						
							|  |  |  |         [{"Value": "bar", "Key": "foo"}, {"Value": "bar1", "Key": "foo1"}] | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2018-09-21 12:03:13 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_rds2 | 
					
						
							|  |  |  | def test_add_tags_snapshot(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto3.client("rds", region_name="us-west-2") | 
					
						
							|  |  |  |     conn.create_db_instance( | 
					
						
							|  |  |  |         DBInstanceIdentifier="db-primary-1", | 
					
						
							|  |  |  |         AllocatedStorage=10, | 
					
						
							|  |  |  |         Engine="postgres", | 
					
						
							|  |  |  |         DBName="staging-postgres", | 
					
						
							|  |  |  |         DBInstanceClass="db.m1.small", | 
					
						
							|  |  |  |         MasterUsername="root", | 
					
						
							|  |  |  |         MasterUserPassword="hunter2", | 
					
						
							|  |  |  |         Port=1234, | 
					
						
							|  |  |  |         DBSecurityGroups=["my_sg"], | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     snapshot = conn.create_db_snapshot( | 
					
						
							|  |  |  |         DBInstanceIdentifier="db-primary-1", | 
					
						
							|  |  |  |         DBSnapshotIdentifier="snapshot-without-tags", | 
					
						
							|  |  |  |         Tags=[{"Key": "foo", "Value": "bar"}, {"Key": "foo1", "Value": "bar1"}], | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2018-09-21 12:03:13 -05:00
										 |  |  |     result = conn.list_tags_for_resource( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         ResourceName="arn:aws:rds:us-west-2:1234567890:snapshot:snapshot-without-tags" | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     list(result["TagList"]).should.have.length_of(2) | 
					
						
							|  |  |  |     conn.add_tags_to_resource( | 
					
						
							|  |  |  |         ResourceName="arn:aws:rds:us-west-2:1234567890:snapshot:snapshot-without-tags", | 
					
						
							|  |  |  |         Tags=[{"Key": "foo", "Value": "fish"}, {"Key": "foo2", "Value": "bar2"}], | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2018-09-21 12:03:13 -05:00
										 |  |  |     result = conn.list_tags_for_resource( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         ResourceName="arn:aws:rds:us-west-2:1234567890:snapshot:snapshot-without-tags" | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     list(result["TagList"]).should.have.length_of(3) | 
					
						
							| 
									
										
										
										
											2018-09-21 12:03:13 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_rds2 | 
					
						
							|  |  |  | def test_remove_tags_snapshot(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto3.client("rds", region_name="us-west-2") | 
					
						
							|  |  |  |     conn.create_db_instance( | 
					
						
							|  |  |  |         DBInstanceIdentifier="db-primary-1", | 
					
						
							|  |  |  |         AllocatedStorage=10, | 
					
						
							|  |  |  |         Engine="postgres", | 
					
						
							|  |  |  |         DBName="staging-postgres", | 
					
						
							|  |  |  |         DBInstanceClass="db.m1.small", | 
					
						
							|  |  |  |         MasterUsername="root", | 
					
						
							|  |  |  |         MasterUserPassword="hunter2", | 
					
						
							|  |  |  |         Port=1234, | 
					
						
							|  |  |  |         DBSecurityGroups=["my_sg"], | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     snapshot = conn.create_db_snapshot( | 
					
						
							|  |  |  |         DBInstanceIdentifier="db-primary-1", | 
					
						
							|  |  |  |         DBSnapshotIdentifier="snapshot-with-tags", | 
					
						
							|  |  |  |         Tags=[{"Key": "foo", "Value": "bar"}, {"Key": "foo1", "Value": "bar1"}], | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2018-09-21 12:03:13 -05:00
										 |  |  |     result = conn.list_tags_for_resource( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         ResourceName="arn:aws:rds:us-west-2:1234567890:snapshot:snapshot-with-tags" | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     list(result["TagList"]).should.have.length_of(2) | 
					
						
							| 
									
										
										
										
											2018-09-21 12:03:13 -05:00
										 |  |  |     conn.remove_tags_from_resource( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         ResourceName="arn:aws:rds:us-west-2:1234567890:snapshot:snapshot-with-tags", | 
					
						
							|  |  |  |         TagKeys=["foo"], | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2018-09-21 12:03:13 -05:00
										 |  |  |     result = conn.list_tags_for_resource( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         ResourceName="arn:aws:rds:us-west-2:1234567890:snapshot:snapshot-with-tags" | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     len(result["TagList"]).should.equal(1) | 
					
						
							| 
									
										
										
										
											2018-09-21 12:03:13 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-29 07:24:03 +11:00
										 |  |  | @mock_rds2 | 
					
						
							|  |  |  | def test_add_tags_option_group(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto3.client("rds", region_name="us-west-2") | 
					
						
							|  |  |  |     conn.create_option_group( | 
					
						
							|  |  |  |         OptionGroupName="test", | 
					
						
							|  |  |  |         EngineName="mysql", | 
					
						
							|  |  |  |         MajorEngineVersion="5.6", | 
					
						
							|  |  |  |         OptionGroupDescription="test option group", | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     result = conn.list_tags_for_resource( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         ResourceName="arn:aws:rds:us-west-2:1234567890:og:test" | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     list(result["TagList"]).should.have.length_of(0) | 
					
						
							|  |  |  |     conn.add_tags_to_resource( | 
					
						
							|  |  |  |         ResourceName="arn:aws:rds:us-west-2:1234567890:og:test", | 
					
						
							|  |  |  |         Tags=[{"Key": "foo", "Value": "fish"}, {"Key": "foo2", "Value": "bar2"}], | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     result = conn.list_tags_for_resource( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         ResourceName="arn:aws:rds:us-west-2:1234567890:og:test" | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     list(result["TagList"]).should.have.length_of(2) | 
					
						
							| 
									
										
										
										
											2015-01-29 07:24:03 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_rds2 | 
					
						
							|  |  |  | def test_remove_tags_option_group(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto3.client("rds", region_name="us-west-2") | 
					
						
							|  |  |  |     conn.create_option_group( | 
					
						
							|  |  |  |         OptionGroupName="test", | 
					
						
							|  |  |  |         EngineName="mysql", | 
					
						
							|  |  |  |         MajorEngineVersion="5.6", | 
					
						
							|  |  |  |         OptionGroupDescription="test option group", | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     result = conn.list_tags_for_resource( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         ResourceName="arn:aws:rds:us-west-2:1234567890:og:test" | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     conn.add_tags_to_resource( | 
					
						
							|  |  |  |         ResourceName="arn:aws:rds:us-west-2:1234567890:og:test", | 
					
						
							|  |  |  |         Tags=[{"Key": "foo", "Value": "fish"}, {"Key": "foo2", "Value": "bar2"}], | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     result = conn.list_tags_for_resource( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         ResourceName="arn:aws:rds:us-west-2:1234567890:og:test" | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     list(result["TagList"]).should.have.length_of(2) | 
					
						
							|  |  |  |     conn.remove_tags_from_resource( | 
					
						
							|  |  |  |         ResourceName="arn:aws:rds:us-west-2:1234567890:og:test", TagKeys=["foo"] | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     result = conn.list_tags_for_resource( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         ResourceName="arn:aws:rds:us-west-2:1234567890:og:test" | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     list(result["TagList"]).should.have.length_of(1) | 
					
						
							| 
									
										
										
										
											2015-01-29 07:24:03 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-29 17:25:39 +11:00
										 |  |  | @mock_rds2 | 
					
						
							|  |  |  | def test_create_database_security_group(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto3.client("rds", region_name="us-west-2") | 
					
						
							| 
									
										
										
										
											2015-01-29 17:25:39 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     result = conn.create_db_security_group( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         DBSecurityGroupName="db_sg", DBSecurityGroupDescription="DB Security Group" | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     result["DBSecurityGroup"]["DBSecurityGroupName"].should.equal("db_sg") | 
					
						
							|  |  |  |     result["DBSecurityGroup"]["DBSecurityGroupDescription"].should.equal( | 
					
						
							|  |  |  |         "DB Security Group" | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     result["DBSecurityGroup"]["IPRanges"].should.equal([]) | 
					
						
							| 
									
										
										
										
											2015-01-29 17:25:39 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_rds2 | 
					
						
							|  |  |  | def test_get_security_groups(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto3.client("rds", region_name="us-west-2") | 
					
						
							| 
									
										
										
										
											2015-01-29 17:25:39 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  |     result = conn.describe_db_security_groups() | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     result["DBSecurityGroups"].should.have.length_of(0) | 
					
						
							| 
									
										
										
										
											2015-01-29 17:25:39 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     conn.create_db_security_group( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         DBSecurityGroupName="db_sg1", DBSecurityGroupDescription="DB Security Group" | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     conn.create_db_security_group( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         DBSecurityGroupName="db_sg2", DBSecurityGroupDescription="DB Security Group" | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2015-01-29 17:25:39 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  |     result = conn.describe_db_security_groups() | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     result["DBSecurityGroups"].should.have.length_of(2) | 
					
						
							| 
									
										
										
										
											2015-01-29 17:25:39 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-11 18:02:51 -08:00
										 |  |  |     result = conn.describe_db_security_groups(DBSecurityGroupName="db_sg1") | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     result["DBSecurityGroups"].should.have.length_of(1) | 
					
						
							|  |  |  |     result["DBSecurityGroups"][0]["DBSecurityGroupName"].should.equal("db_sg1") | 
					
						
							| 
									
										
										
										
											2015-01-29 17:25:39 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_rds2 | 
					
						
							| 
									
										
										
										
											2020-01-20 15:21:11 -08:00
										 |  |  | def test_get_non_existent_security_group(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto3.client("rds", region_name="us-west-2") | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     conn.describe_db_security_groups.when.called_with( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         DBSecurityGroupName="not-a-sg" | 
					
						
							|  |  |  |     ).should.throw(ClientError) | 
					
						
							| 
									
										
										
										
											2015-01-29 17:25:39 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_rds2 | 
					
						
							|  |  |  | def test_delete_database_security_group(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto3.client("rds", region_name="us-west-2") | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     conn.create_db_security_group( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         DBSecurityGroupName="db_sg", DBSecurityGroupDescription="DB Security Group" | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2015-01-29 17:25:39 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  |     result = conn.describe_db_security_groups() | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     result["DBSecurityGroups"].should.have.length_of(1) | 
					
						
							| 
									
										
										
										
											2015-01-29 17:25:39 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-11 18:02:51 -08:00
										 |  |  |     conn.delete_db_security_group(DBSecurityGroupName="db_sg") | 
					
						
							| 
									
										
										
										
											2015-01-29 17:25:39 +11:00
										 |  |  |     result = conn.describe_db_security_groups() | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     result["DBSecurityGroups"].should.have.length_of(0) | 
					
						
							| 
									
										
										
										
											2015-01-29 17:25:39 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_rds2 | 
					
						
							| 
									
										
										
										
											2020-01-20 15:21:11 -08:00
										 |  |  | def test_delete_non_existent_security_group(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto3.client("rds", region_name="us-west-2") | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     conn.delete_db_security_group.when.called_with( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         DBSecurityGroupName="not-a-db" | 
					
						
							|  |  |  |     ).should.throw(ClientError) | 
					
						
							| 
									
										
										
										
											2015-01-29 17:25:39 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_rds2 | 
					
						
							|  |  |  | def test_security_group_authorize(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto3.client("rds", region_name="us-west-2") | 
					
						
							|  |  |  |     security_group = conn.create_db_security_group( | 
					
						
							|  |  |  |         DBSecurityGroupName="db_sg", DBSecurityGroupDescription="DB Security Group" | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     security_group["DBSecurityGroup"]["IPRanges"].should.equal([]) | 
					
						
							| 
									
										
										
										
											2015-01-29 17:25:39 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn.authorize_db_security_group_ingress( | 
					
						
							|  |  |  |         DBSecurityGroupName="db_sg", CIDRIP="10.3.2.45/32" | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2015-01-29 17:25:39 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-11 18:02:51 -08:00
										 |  |  |     result = conn.describe_db_security_groups(DBSecurityGroupName="db_sg") | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     result["DBSecurityGroups"][0]["IPRanges"].should.have.length_of(1) | 
					
						
							|  |  |  |     result["DBSecurityGroups"][0]["IPRanges"].should.equal( | 
					
						
							|  |  |  |         [{"Status": "authorized", "CIDRIP": "10.3.2.45/32"}] | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     conn.authorize_db_security_group_ingress( | 
					
						
							|  |  |  |         DBSecurityGroupName="db_sg", CIDRIP="10.3.2.46/32" | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2017-01-11 18:02:51 -08:00
										 |  |  |     result = conn.describe_db_security_groups(DBSecurityGroupName="db_sg") | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     result["DBSecurityGroups"][0]["IPRanges"].should.have.length_of(2) | 
					
						
							|  |  |  |     result["DBSecurityGroups"][0]["IPRanges"].should.equal( | 
					
						
							|  |  |  |         [ | 
					
						
							|  |  |  |             {"Status": "authorized", "CIDRIP": "10.3.2.45/32"}, | 
					
						
							|  |  |  |             {"Status": "authorized", "CIDRIP": "10.3.2.46/32"}, | 
					
						
							|  |  |  |         ] | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2015-01-29 17:25:39 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-30 08:18:15 +11:00
										 |  |  | @mock_rds2 | 
					
						
							|  |  |  | def test_add_security_group_to_database(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto3.client("rds", region_name="us-west-2") | 
					
						
							| 
									
										
										
										
											2017-01-11 18:02:51 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn.create_db_instance( | 
					
						
							|  |  |  |         DBInstanceIdentifier="db-master-1", | 
					
						
							|  |  |  |         AllocatedStorage=10, | 
					
						
							|  |  |  |         DBInstanceClass="postgres", | 
					
						
							|  |  |  |         Engine="db.m1.small", | 
					
						
							|  |  |  |         MasterUsername="root", | 
					
						
							|  |  |  |         MasterUserPassword="hunter2", | 
					
						
							|  |  |  |         Port=1234, | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2017-01-11 18:02:51 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-30 08:18:15 +11:00
										 |  |  |     result = conn.describe_db_instances() | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     result["DBInstances"][0]["DBSecurityGroups"].should.equal([]) | 
					
						
							|  |  |  |     conn.create_db_security_group( | 
					
						
							|  |  |  |         DBSecurityGroupName="db_sg", DBSecurityGroupDescription="DB Security Group" | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     conn.modify_db_instance( | 
					
						
							|  |  |  |         DBInstanceIdentifier="db-master-1", DBSecurityGroups=["db_sg"] | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2015-01-30 08:18:15 +11:00
										 |  |  |     result = conn.describe_db_instances() | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     result["DBInstances"][0]["DBSecurityGroups"][0]["DBSecurityGroupName"].should.equal( | 
					
						
							|  |  |  |         "db_sg" | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2017-01-11 18:02:51 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_rds2 | 
					
						
							|  |  |  | def test_list_tags_security_group(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto3.client("rds", region_name="us-west-2") | 
					
						
							| 
									
										
										
										
											2017-01-11 18:02:51 -08:00
										 |  |  |     result = conn.describe_db_subnet_groups() | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     result["DBSubnetGroups"].should.have.length_of(0) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     security_group = conn.create_db_security_group( | 
					
						
							|  |  |  |         DBSecurityGroupName="db_sg", | 
					
						
							|  |  |  |         DBSecurityGroupDescription="DB Security Group", | 
					
						
							|  |  |  |         Tags=[{"Value": "bar", "Key": "foo"}, {"Value": "bar1", "Key": "foo1"}], | 
					
						
							|  |  |  |     )["DBSecurityGroup"]["DBSecurityGroupName"] | 
					
						
							|  |  |  |     resource = "arn:aws:rds:us-west-2:1234567890:secgrp:{0}".format(security_group) | 
					
						
							| 
									
										
										
										
											2017-01-11 18:02:51 -08:00
										 |  |  |     result = conn.list_tags_for_resource(ResourceName=resource) | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     result["TagList"].should.equal( | 
					
						
							|  |  |  |         [{"Value": "bar", "Key": "foo"}, {"Value": "bar1", "Key": "foo1"}] | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2017-01-11 18:02:51 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_rds2 | 
					
						
							|  |  |  | def test_add_tags_security_group(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto3.client("rds", region_name="us-west-2") | 
					
						
							| 
									
										
										
										
											2017-01-11 18:02:51 -08:00
										 |  |  |     result = conn.describe_db_subnet_groups() | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     result["DBSubnetGroups"].should.have.length_of(0) | 
					
						
							| 
									
										
										
										
											2017-01-11 18:02:51 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     security_group = conn.create_db_security_group( | 
					
						
							|  |  |  |         DBSecurityGroupName="db_sg", DBSecurityGroupDescription="DB Security Group" | 
					
						
							|  |  |  |     )["DBSecurityGroup"]["DBSecurityGroupName"] | 
					
						
							| 
									
										
										
										
											2017-01-11 18:02:51 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     resource = "arn:aws:rds:us-west-2:1234567890:secgrp:{0}".format(security_group) | 
					
						
							|  |  |  |     conn.add_tags_to_resource( | 
					
						
							|  |  |  |         ResourceName=resource, | 
					
						
							|  |  |  |         Tags=[{"Value": "bar", "Key": "foo"}, {"Value": "bar1", "Key": "foo1"}], | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2017-01-11 18:02:51 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     result = conn.list_tags_for_resource(ResourceName=resource) | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     result["TagList"].should.equal( | 
					
						
							|  |  |  |         [{"Value": "bar", "Key": "foo"}, {"Value": "bar1", "Key": "foo1"}] | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-11 18:02:51 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | @mock_rds2 | 
					
						
							|  |  |  | def test_remove_tags_security_group(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto3.client("rds", region_name="us-west-2") | 
					
						
							| 
									
										
										
										
											2017-01-11 18:02:51 -08:00
										 |  |  |     result = conn.describe_db_subnet_groups() | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     result["DBSubnetGroups"].should.have.length_of(0) | 
					
						
							| 
									
										
										
										
											2017-01-11 18:02:51 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     security_group = conn.create_db_security_group( | 
					
						
							|  |  |  |         DBSecurityGroupName="db_sg", | 
					
						
							|  |  |  |         DBSecurityGroupDescription="DB Security Group", | 
					
						
							|  |  |  |         Tags=[{"Value": "bar", "Key": "foo"}, {"Value": "bar1", "Key": "foo1"}], | 
					
						
							|  |  |  |     )["DBSecurityGroup"]["DBSecurityGroupName"] | 
					
						
							| 
									
										
										
										
											2017-01-11 18:02:51 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     resource = "arn:aws:rds:us-west-2:1234567890:secgrp:{0}".format(security_group) | 
					
						
							|  |  |  |     conn.remove_tags_from_resource(ResourceName=resource, TagKeys=["foo"]) | 
					
						
							| 
									
										
										
										
											2017-01-11 18:02:51 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     result = conn.list_tags_for_resource(ResourceName=resource) | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     result["TagList"].should.equal([{"Value": "bar1", "Key": "foo1"}]) | 
					
						
							| 
									
										
										
										
											2015-01-30 08:18:15 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_ec2 | 
					
						
							|  |  |  | @mock_rds2 | 
					
						
							|  |  |  | def test_create_database_subnet_group(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     vpc_conn = boto3.client("ec2", "us-west-2") | 
					
						
							|  |  |  |     vpc = vpc_conn.create_vpc(CidrBlock="10.0.0.0/16")["Vpc"] | 
					
						
							|  |  |  |     subnet1 = vpc_conn.create_subnet(VpcId=vpc["VpcId"], CidrBlock="10.0.1.0/24")[ | 
					
						
							|  |  |  |         "Subnet" | 
					
						
							|  |  |  |     ] | 
					
						
							|  |  |  |     subnet2 = vpc_conn.create_subnet(VpcId=vpc["VpcId"], CidrBlock="10.0.2.0/24")[ | 
					
						
							|  |  |  |         "Subnet" | 
					
						
							|  |  |  |     ] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     subnet_ids = [subnet1["SubnetId"], subnet2["SubnetId"]] | 
					
						
							|  |  |  |     conn = boto3.client("rds", region_name="us-west-2") | 
					
						
							|  |  |  |     result = conn.create_db_subnet_group( | 
					
						
							|  |  |  |         DBSubnetGroupName="db_subnet", | 
					
						
							|  |  |  |         DBSubnetGroupDescription="my db subnet", | 
					
						
							|  |  |  |         SubnetIds=subnet_ids, | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     result["DBSubnetGroup"]["DBSubnetGroupName"].should.equal("db_subnet") | 
					
						
							|  |  |  |     result["DBSubnetGroup"]["DBSubnetGroupDescription"].should.equal("my db subnet") | 
					
						
							|  |  |  |     subnets = result["DBSubnetGroup"]["Subnets"] | 
					
						
							|  |  |  |     subnet_group_ids = [subnets[0]["SubnetIdentifier"], subnets[1]["SubnetIdentifier"]] | 
					
						
							| 
									
										
										
										
											2015-01-30 08:18:15 +11:00
										 |  |  |     list(subnet_group_ids).should.equal(subnet_ids) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-03 15:06:06 +01:00
										 |  |  | @mock_ec2 | 
					
						
							|  |  |  | @mock_rds2 | 
					
						
							|  |  |  | def test_modify_database_subnet_group(): | 
					
						
							|  |  |  |     vpc_conn = boto3.client("ec2", "us-west-2") | 
					
						
							|  |  |  |     vpc = vpc_conn.create_vpc(CidrBlock="10.0.0.0/16")["Vpc"] | 
					
						
							|  |  |  |     subnet1 = vpc_conn.create_subnet(VpcId=vpc["VpcId"], CidrBlock="10.0.1.0/24")[ | 
					
						
							|  |  |  |         "Subnet" | 
					
						
							|  |  |  |     ] | 
					
						
							|  |  |  |     subnet2 = vpc_conn.create_subnet(VpcId=vpc["VpcId"], CidrBlock="10.0.2.0/24")[ | 
					
						
							|  |  |  |         "Subnet" | 
					
						
							|  |  |  |     ] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     conn = boto3.client("rds", region_name="us-west-2") | 
					
						
							|  |  |  |     conn.create_db_subnet_group( | 
					
						
							|  |  |  |         DBSubnetGroupName="db_subnet", | 
					
						
							|  |  |  |         DBSubnetGroupDescription="my db subnet", | 
					
						
							|  |  |  |         SubnetIds=[subnet1["SubnetId"]], | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     conn.modify_db_subnet_group( | 
					
						
							|  |  |  |         DBSubnetGroupName="db_subnet", | 
					
						
							|  |  |  |         DBSubnetGroupDescription="my updated desc", | 
					
						
							|  |  |  |         SubnetIds=[subnet1["SubnetId"], subnet2["SubnetId"]], | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     groups = conn.describe_db_subnet_groups()["DBSubnetGroups"] | 
					
						
							|  |  |  |     # FIXME: Group is deleted atm | 
					
						
							|  |  |  |     # TODO: we should check whether all attrs are persisted | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-30 08:18:15 +11:00
										 |  |  | @mock_ec2 | 
					
						
							|  |  |  | @mock_rds2 | 
					
						
							|  |  |  | def test_create_database_in_subnet_group(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     vpc_conn = boto3.client("ec2", "us-west-2") | 
					
						
							|  |  |  |     vpc = vpc_conn.create_vpc(CidrBlock="10.0.0.0/16")["Vpc"] | 
					
						
							|  |  |  |     subnet = vpc_conn.create_subnet(VpcId=vpc["VpcId"], CidrBlock="10.0.1.0/24")[ | 
					
						
							|  |  |  |         "Subnet" | 
					
						
							|  |  |  |     ] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     conn = boto3.client("rds", region_name="us-west-2") | 
					
						
							|  |  |  |     conn.create_db_subnet_group( | 
					
						
							|  |  |  |         DBSubnetGroupName="db_subnet1", | 
					
						
							|  |  |  |         DBSubnetGroupDescription="my db subnet", | 
					
						
							|  |  |  |         SubnetIds=[subnet["SubnetId"]], | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     conn.create_db_instance( | 
					
						
							|  |  |  |         DBInstanceIdentifier="db-master-1", | 
					
						
							|  |  |  |         AllocatedStorage=10, | 
					
						
							|  |  |  |         Engine="postgres", | 
					
						
							|  |  |  |         DBInstanceClass="db.m1.small", | 
					
						
							|  |  |  |         MasterUsername="root", | 
					
						
							|  |  |  |         MasterUserPassword="hunter2", | 
					
						
							|  |  |  |         Port=1234, | 
					
						
							|  |  |  |         DBSubnetGroupName="db_subnet1", | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     result = conn.describe_db_instances(DBInstanceIdentifier="db-master-1") | 
					
						
							|  |  |  |     result["DBInstances"][0]["DBSubnetGroup"]["DBSubnetGroupName"].should.equal( | 
					
						
							|  |  |  |         "db_subnet1" | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2015-01-29 07:15:03 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-26 15:39:34 -05:00
										 |  |  | @mock_ec2 | 
					
						
							|  |  |  | @mock_rds2 | 
					
						
							|  |  |  | def test_describe_database_subnet_group(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     vpc_conn = boto3.client("ec2", "us-west-2") | 
					
						
							|  |  |  |     vpc = vpc_conn.create_vpc(CidrBlock="10.0.0.0/16")["Vpc"] | 
					
						
							|  |  |  |     subnet = vpc_conn.create_subnet(VpcId=vpc["VpcId"], CidrBlock="10.0.1.0/24")[ | 
					
						
							|  |  |  |         "Subnet" | 
					
						
							|  |  |  |     ] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     conn = boto3.client("rds", region_name="us-west-2") | 
					
						
							|  |  |  |     conn.create_db_subnet_group( | 
					
						
							|  |  |  |         DBSubnetGroupName="db_subnet1", | 
					
						
							|  |  |  |         DBSubnetGroupDescription="my db subnet", | 
					
						
							|  |  |  |         SubnetIds=[subnet["SubnetId"]], | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     conn.create_db_subnet_group( | 
					
						
							|  |  |  |         DBSubnetGroupName="db_subnet2", | 
					
						
							|  |  |  |         DBSubnetGroupDescription="my db subnet", | 
					
						
							|  |  |  |         SubnetIds=[subnet["SubnetId"]], | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2015-01-26 15:39:34 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-11 18:02:51 -08:00
										 |  |  |     resp = conn.describe_db_subnet_groups() | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     resp["DBSubnetGroups"].should.have.length_of(2) | 
					
						
							| 
									
										
										
										
											2015-01-26 15:39:34 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     subnets = resp["DBSubnetGroups"][0]["Subnets"] | 
					
						
							| 
									
										
										
										
											2017-01-11 18:02:51 -08:00
										 |  |  |     subnets.should.have.length_of(1) | 
					
						
							| 
									
										
										
										
											2015-01-26 15:39:34 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     list( | 
					
						
							|  |  |  |         conn.describe_db_subnet_groups(DBSubnetGroupName="db_subnet1")["DBSubnetGroups"] | 
					
						
							|  |  |  |     ).should.have.length_of(1) | 
					
						
							| 
									
										
										
										
											2015-01-26 15:39:34 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     conn.describe_db_subnet_groups.when.called_with( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         DBSubnetGroupName="not-a-subnet" | 
					
						
							|  |  |  |     ).should.throw(ClientError) | 
					
						
							| 
									
										
										
										
											2015-01-29 07:15:03 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-30 08:18:15 +11:00
										 |  |  | @mock_ec2 | 
					
						
							|  |  |  | @mock_rds2 | 
					
						
							|  |  |  | def test_delete_database_subnet_group(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     vpc_conn = boto3.client("ec2", "us-west-2") | 
					
						
							|  |  |  |     vpc = vpc_conn.create_vpc(CidrBlock="10.0.0.0/16")["Vpc"] | 
					
						
							|  |  |  |     subnet = vpc_conn.create_subnet(VpcId=vpc["VpcId"], CidrBlock="10.0.1.0/24")[ | 
					
						
							|  |  |  |         "Subnet" | 
					
						
							|  |  |  |     ] | 
					
						
							| 
									
										
										
										
											2015-01-30 08:18:15 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto3.client("rds", region_name="us-west-2") | 
					
						
							| 
									
										
										
										
											2015-01-30 08:18:15 +11:00
										 |  |  |     result = conn.describe_db_subnet_groups() | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     result["DBSubnetGroups"].should.have.length_of(0) | 
					
						
							| 
									
										
										
										
											2015-01-30 08:18:15 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn.create_db_subnet_group( | 
					
						
							|  |  |  |         DBSubnetGroupName="db_subnet1", | 
					
						
							|  |  |  |         DBSubnetGroupDescription="my db subnet", | 
					
						
							|  |  |  |         SubnetIds=[subnet["SubnetId"]], | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2015-01-30 08:18:15 +11:00
										 |  |  |     result = conn.describe_db_subnet_groups() | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     result["DBSubnetGroups"].should.have.length_of(1) | 
					
						
							| 
									
										
										
										
											2015-01-30 08:18:15 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-11 18:02:51 -08:00
										 |  |  |     conn.delete_db_subnet_group(DBSubnetGroupName="db_subnet1") | 
					
						
							| 
									
										
										
										
											2015-01-30 08:18:15 +11:00
										 |  |  |     result = conn.describe_db_subnet_groups() | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     result["DBSubnetGroups"].should.have.length_of(0) | 
					
						
							| 
									
										
										
										
											2015-01-30 08:18:15 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     conn.delete_db_subnet_group.when.called_with( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         DBSubnetGroupName="db_subnet1" | 
					
						
							|  |  |  |     ).should.throw(ClientError) | 
					
						
							| 
									
										
										
										
											2017-01-11 18:02:51 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_ec2 | 
					
						
							|  |  |  | @mock_rds2 | 
					
						
							|  |  |  | def test_list_tags_database_subnet_group(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     vpc_conn = boto3.client("ec2", "us-west-2") | 
					
						
							|  |  |  |     vpc = vpc_conn.create_vpc(CidrBlock="10.0.0.0/16")["Vpc"] | 
					
						
							|  |  |  |     subnet = vpc_conn.create_subnet(VpcId=vpc["VpcId"], CidrBlock="10.0.1.0/24")[ | 
					
						
							|  |  |  |         "Subnet" | 
					
						
							|  |  |  |     ] | 
					
						
							| 
									
										
										
										
											2017-01-11 18:02:51 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto3.client("rds", region_name="us-west-2") | 
					
						
							| 
									
										
										
										
											2017-01-11 18:02:51 -08:00
										 |  |  |     result = conn.describe_db_subnet_groups() | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     result["DBSubnetGroups"].should.have.length_of(0) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     subnet = conn.create_db_subnet_group( | 
					
						
							|  |  |  |         DBSubnetGroupName="db_subnet1", | 
					
						
							|  |  |  |         DBSubnetGroupDescription="my db subnet", | 
					
						
							|  |  |  |         SubnetIds=[subnet["SubnetId"]], | 
					
						
							|  |  |  |         Tags=[{"Value": "bar", "Key": "foo"}, {"Value": "bar1", "Key": "foo1"}], | 
					
						
							|  |  |  |     )["DBSubnetGroup"]["DBSubnetGroupName"] | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     result = conn.list_tags_for_resource( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         ResourceName="arn:aws:rds:us-west-2:1234567890:subgrp:{0}".format(subnet) | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     result["TagList"].should.equal( | 
					
						
							|  |  |  |         [{"Value": "bar", "Key": "foo"}, {"Value": "bar1", "Key": "foo1"}] | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-11 18:02:51 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | @mock_ec2 | 
					
						
							|  |  |  | @mock_rds2 | 
					
						
							|  |  |  | def test_add_tags_database_subnet_group(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     vpc_conn = boto3.client("ec2", "us-west-2") | 
					
						
							|  |  |  |     vpc = vpc_conn.create_vpc(CidrBlock="10.0.0.0/16")["Vpc"] | 
					
						
							|  |  |  |     subnet = vpc_conn.create_subnet(VpcId=vpc["VpcId"], CidrBlock="10.0.1.0/24")[ | 
					
						
							|  |  |  |         "Subnet" | 
					
						
							|  |  |  |     ] | 
					
						
							| 
									
										
										
										
											2017-01-11 18:02:51 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto3.client("rds", region_name="us-west-2") | 
					
						
							| 
									
										
										
										
											2017-01-11 18:02:51 -08:00
										 |  |  |     result = conn.describe_db_subnet_groups() | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     result["DBSubnetGroups"].should.have.length_of(0) | 
					
						
							| 
									
										
										
										
											2017-01-11 18:02:51 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     subnet = conn.create_db_subnet_group( | 
					
						
							|  |  |  |         DBSubnetGroupName="db_subnet1", | 
					
						
							|  |  |  |         DBSubnetGroupDescription="my db subnet", | 
					
						
							|  |  |  |         SubnetIds=[subnet["SubnetId"]], | 
					
						
							|  |  |  |         Tags=[], | 
					
						
							|  |  |  |     )["DBSubnetGroup"]["DBSubnetGroupName"] | 
					
						
							|  |  |  |     resource = "arn:aws:rds:us-west-2:1234567890:subgrp:{0}".format(subnet) | 
					
						
							| 
									
										
										
										
											2017-01-11 18:02:51 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn.add_tags_to_resource( | 
					
						
							|  |  |  |         ResourceName=resource, | 
					
						
							|  |  |  |         Tags=[{"Value": "bar", "Key": "foo"}, {"Value": "bar1", "Key": "foo1"}], | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2017-01-11 18:02:51 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     result = conn.list_tags_for_resource(ResourceName=resource) | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     result["TagList"].should.equal( | 
					
						
							|  |  |  |         [{"Value": "bar", "Key": "foo"}, {"Value": "bar1", "Key": "foo1"}] | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-11 18:02:51 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | @mock_ec2 | 
					
						
							|  |  |  | @mock_rds2 | 
					
						
							|  |  |  | def test_remove_tags_database_subnet_group(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     vpc_conn = boto3.client("ec2", "us-west-2") | 
					
						
							|  |  |  |     vpc = vpc_conn.create_vpc(CidrBlock="10.0.0.0/16")["Vpc"] | 
					
						
							|  |  |  |     subnet = vpc_conn.create_subnet(VpcId=vpc["VpcId"], CidrBlock="10.0.1.0/24")[ | 
					
						
							|  |  |  |         "Subnet" | 
					
						
							|  |  |  |     ] | 
					
						
							| 
									
										
										
										
											2017-01-11 18:02:51 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto3.client("rds", region_name="us-west-2") | 
					
						
							| 
									
										
										
										
											2017-01-11 18:02:51 -08:00
										 |  |  |     result = conn.describe_db_subnet_groups() | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     result["DBSubnetGroups"].should.have.length_of(0) | 
					
						
							| 
									
										
										
										
											2017-01-11 18:02:51 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     subnet = conn.create_db_subnet_group( | 
					
						
							|  |  |  |         DBSubnetGroupName="db_subnet1", | 
					
						
							|  |  |  |         DBSubnetGroupDescription="my db subnet", | 
					
						
							|  |  |  |         SubnetIds=[subnet["SubnetId"]], | 
					
						
							|  |  |  |         Tags=[{"Value": "bar", "Key": "foo"}, {"Value": "bar1", "Key": "foo1"}], | 
					
						
							|  |  |  |     )["DBSubnetGroup"]["DBSubnetGroupName"] | 
					
						
							|  |  |  |     resource = "arn:aws:rds:us-west-2:1234567890:subgrp:{0}".format(subnet) | 
					
						
							| 
									
										
										
										
											2017-01-11 18:02:51 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn.remove_tags_from_resource(ResourceName=resource, TagKeys=["foo"]) | 
					
						
							| 
									
										
										
										
											2017-01-11 18:02:51 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     result = conn.list_tags_for_resource(ResourceName=resource) | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     result["TagList"].should.equal([{"Value": "bar1", "Key": "foo1"}]) | 
					
						
							| 
									
										
										
										
											2015-01-30 08:18:15 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-30 17:12:51 +11:00
										 |  |  | @mock_rds2 | 
					
						
							|  |  |  | def test_create_database_replica(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto3.client("rds", region_name="us-west-2") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     database = conn.create_db_instance( | 
					
						
							|  |  |  |         DBInstanceIdentifier="db-master-1", | 
					
						
							|  |  |  |         AllocatedStorage=10, | 
					
						
							|  |  |  |         Engine="postgres", | 
					
						
							|  |  |  |         DBInstanceClass="db.m1.small", | 
					
						
							|  |  |  |         MasterUsername="root", | 
					
						
							|  |  |  |         MasterUserPassword="hunter2", | 
					
						
							|  |  |  |         Port=1234, | 
					
						
							|  |  |  |         DBSecurityGroups=["my_sg"], | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     replica = conn.create_db_instance_read_replica( | 
					
						
							|  |  |  |         DBInstanceIdentifier="db-replica-1", | 
					
						
							|  |  |  |         SourceDBInstanceIdentifier="db-master-1", | 
					
						
							|  |  |  |         DBInstanceClass="db.m1.small", | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     replica["DBInstance"]["ReadReplicaSourceDBInstanceIdentifier"].should.equal( | 
					
						
							|  |  |  |         "db-master-1" | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     replica["DBInstance"]["DBInstanceClass"].should.equal("db.m1.small") | 
					
						
							|  |  |  |     replica["DBInstance"]["DBInstanceIdentifier"].should.equal("db-replica-1") | 
					
						
							| 
									
										
										
										
											2015-01-30 17:12:51 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-11 18:02:51 -08:00
										 |  |  |     master = conn.describe_db_instances(DBInstanceIdentifier="db-master-1") | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     master["DBInstances"][0]["ReadReplicaDBInstanceIdentifiers"].should.equal( | 
					
						
							|  |  |  |         ["db-replica-1"] | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2015-01-30 17:12:51 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn.delete_db_instance(DBInstanceIdentifier="db-replica-1", SkipFinalSnapshot=True) | 
					
						
							| 
									
										
										
										
											2015-01-30 17:12:51 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-11 18:02:51 -08:00
										 |  |  |     master = conn.describe_db_instances(DBInstanceIdentifier="db-master-1") | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     master["DBInstances"][0]["ReadReplicaDBInstanceIdentifiers"].should.equal([]) | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-30 17:12:51 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-11 18:02:51 -08:00
										 |  |  | @mock_rds2 | 
					
						
							|  |  |  | @mock_kms | 
					
						
							|  |  |  | def test_create_database_with_encrypted_storage(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     kms_conn = boto3.client("kms", region_name="us-west-2") | 
					
						
							|  |  |  |     key = kms_conn.create_key( | 
					
						
							|  |  |  |         Policy="my RDS encryption policy", | 
					
						
							|  |  |  |         Description="RDS encryption key", | 
					
						
							|  |  |  |         KeyUsage="ENCRYPT_DECRYPT", | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     conn = boto3.client("rds", region_name="us-west-2") | 
					
						
							|  |  |  |     database = conn.create_db_instance( | 
					
						
							|  |  |  |         DBInstanceIdentifier="db-master-1", | 
					
						
							|  |  |  |         AllocatedStorage=10, | 
					
						
							|  |  |  |         Engine="postgres", | 
					
						
							|  |  |  |         DBInstanceClass="db.m1.small", | 
					
						
							|  |  |  |         MasterUsername="root", | 
					
						
							|  |  |  |         MasterUserPassword="hunter2", | 
					
						
							|  |  |  |         Port=1234, | 
					
						
							|  |  |  |         DBSecurityGroups=["my_sg"], | 
					
						
							|  |  |  |         StorageEncrypted=True, | 
					
						
							|  |  |  |         KmsKeyId=key["KeyMetadata"]["KeyId"], | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2017-01-11 18:02:51 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     database["DBInstance"]["StorageEncrypted"].should.equal(True) | 
					
						
							|  |  |  |     database["DBInstance"]["KmsKeyId"].should.equal(key["KeyMetadata"]["KeyId"]) | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-11 18:02:51 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | @mock_rds2 | 
					
						
							|  |  |  | def test_create_db_parameter_group(): | 
					
						
							| 
									
										
										
										
											2020-12-02 01:23:01 +05:30
										 |  |  |     region = "us-west-2" | 
					
						
							|  |  |  |     pg_name = "test" | 
					
						
							|  |  |  |     conn = boto3.client("rds", region_name=region) | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     db_parameter_group = conn.create_db_parameter_group( | 
					
						
							|  |  |  |         DBParameterGroupName="test", | 
					
						
							|  |  |  |         DBParameterGroupFamily="mysql5.6", | 
					
						
							|  |  |  |         Description="test parameter group", | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     db_parameter_group["DBParameterGroup"]["DBParameterGroupName"].should.equal("test") | 
					
						
							|  |  |  |     db_parameter_group["DBParameterGroup"]["DBParameterGroupFamily"].should.equal( | 
					
						
							|  |  |  |         "mysql5.6" | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     db_parameter_group["DBParameterGroup"]["Description"].should.equal( | 
					
						
							|  |  |  |         "test parameter group" | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2020-12-02 01:23:01 +05:30
										 |  |  |     db_parameter_group["DBParameterGroup"]["DBParameterGroupArn"].should.equal( | 
					
						
							|  |  |  |         "arn:aws:rds:{0}:{1}:pg:{2}".format(region, ACCOUNT_ID, pg_name) | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2017-01-11 18:02:51 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_rds2 | 
					
						
							|  |  |  | def test_create_db_instance_with_parameter_group(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto3.client("rds", region_name="us-west-2") | 
					
						
							|  |  |  |     db_parameter_group = conn.create_db_parameter_group( | 
					
						
							|  |  |  |         DBParameterGroupName="test", | 
					
						
							|  |  |  |         DBParameterGroupFamily="mysql5.6", | 
					
						
							|  |  |  |         Description="test parameter group", | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2017-01-11 18:02:51 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     database = conn.create_db_instance( | 
					
						
							|  |  |  |         DBInstanceIdentifier="db-master-1", | 
					
						
							|  |  |  |         AllocatedStorage=10, | 
					
						
							|  |  |  |         Engine="mysql", | 
					
						
							|  |  |  |         DBInstanceClass="db.m1.small", | 
					
						
							|  |  |  |         DBParameterGroupName="test", | 
					
						
							|  |  |  |         MasterUsername="root", | 
					
						
							|  |  |  |         MasterUserPassword="hunter2", | 
					
						
							|  |  |  |         Port=1234, | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2017-01-11 18:02:51 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     len(database["DBInstance"]["DBParameterGroups"]).should.equal(1) | 
					
						
							|  |  |  |     database["DBInstance"]["DBParameterGroups"][0]["DBParameterGroupName"].should.equal( | 
					
						
							|  |  |  |         "test" | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     database["DBInstance"]["DBParameterGroups"][0]["ParameterApplyStatus"].should.equal( | 
					
						
							|  |  |  |         "in-sync" | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-11 18:02:51 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-08 20:05:46 -10:00
										 |  |  | @mock_rds2 | 
					
						
							|  |  |  | def test_create_database_with_default_port(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto3.client("rds", region_name="us-west-2") | 
					
						
							|  |  |  |     database = conn.create_db_instance( | 
					
						
							|  |  |  |         DBInstanceIdentifier="db-master-1", | 
					
						
							|  |  |  |         AllocatedStorage=10, | 
					
						
							|  |  |  |         Engine="postgres", | 
					
						
							|  |  |  |         DBInstanceClass="db.m1.small", | 
					
						
							|  |  |  |         MasterUsername="root", | 
					
						
							|  |  |  |         MasterUserPassword="hunter2", | 
					
						
							|  |  |  |         DBSecurityGroups=["my_sg"], | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     database["DBInstance"]["Endpoint"]["Port"].should.equal(5432) | 
					
						
							| 
									
										
										
										
											2017-05-08 20:05:46 -10:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-11 18:02:51 -08:00
										 |  |  | @mock_rds2 | 
					
						
							|  |  |  | def test_modify_db_instance_with_parameter_group(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto3.client("rds", region_name="us-west-2") | 
					
						
							|  |  |  |     database = conn.create_db_instance( | 
					
						
							|  |  |  |         DBInstanceIdentifier="db-master-1", | 
					
						
							|  |  |  |         AllocatedStorage=10, | 
					
						
							|  |  |  |         Engine="mysql", | 
					
						
							|  |  |  |         DBInstanceClass="db.m1.small", | 
					
						
							|  |  |  |         MasterUsername="root", | 
					
						
							|  |  |  |         MasterUserPassword="hunter2", | 
					
						
							|  |  |  |         Port=1234, | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     len(database["DBInstance"]["DBParameterGroups"]).should.equal(1) | 
					
						
							|  |  |  |     database["DBInstance"]["DBParameterGroups"][0]["DBParameterGroupName"].should.equal( | 
					
						
							|  |  |  |         "default.mysql5.6" | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     database["DBInstance"]["DBParameterGroups"][0]["ParameterApplyStatus"].should.equal( | 
					
						
							|  |  |  |         "in-sync" | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     db_parameter_group = conn.create_db_parameter_group( | 
					
						
							|  |  |  |         DBParameterGroupName="test", | 
					
						
							|  |  |  |         DBParameterGroupFamily="mysql5.6", | 
					
						
							|  |  |  |         Description="test parameter group", | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     conn.modify_db_instance( | 
					
						
							|  |  |  |         DBInstanceIdentifier="db-master-1", | 
					
						
							|  |  |  |         DBParameterGroupName="test", | 
					
						
							|  |  |  |         ApplyImmediately=True, | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     database = conn.describe_db_instances(DBInstanceIdentifier="db-master-1")[ | 
					
						
							|  |  |  |         "DBInstances" | 
					
						
							|  |  |  |     ][0] | 
					
						
							|  |  |  |     len(database["DBParameterGroups"]).should.equal(1) | 
					
						
							|  |  |  |     database["DBParameterGroups"][0]["DBParameterGroupName"].should.equal("test") | 
					
						
							|  |  |  |     database["DBParameterGroups"][0]["ParameterApplyStatus"].should.equal("in-sync") | 
					
						
							| 
									
										
										
										
											2017-01-11 18:02:51 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_rds2 | 
					
						
							|  |  |  | def test_create_db_parameter_group_empty_description(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto3.client("rds", region_name="us-west-2") | 
					
						
							|  |  |  |     conn.create_db_parameter_group.when.called_with( | 
					
						
							|  |  |  |         DBParameterGroupName="test", DBParameterGroupFamily="mysql5.6", Description="" | 
					
						
							|  |  |  |     ).should.throw(ClientError) | 
					
						
							| 
									
										
										
										
											2017-01-11 18:02:51 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_rds2 | 
					
						
							|  |  |  | def test_create_db_parameter_group_duplicate(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto3.client("rds", region_name="us-west-2") | 
					
						
							|  |  |  |     conn.create_db_parameter_group( | 
					
						
							|  |  |  |         DBParameterGroupName="test", | 
					
						
							|  |  |  |         DBParameterGroupFamily="mysql5.6", | 
					
						
							|  |  |  |         Description="test parameter group", | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     conn.create_db_parameter_group.when.called_with( | 
					
						
							|  |  |  |         DBParameterGroupName="test", | 
					
						
							|  |  |  |         DBParameterGroupFamily="mysql5.6", | 
					
						
							|  |  |  |         Description="test parameter group", | 
					
						
							|  |  |  |     ).should.throw(ClientError) | 
					
						
							| 
									
										
										
										
											2017-01-11 18:02:51 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_rds2 | 
					
						
							|  |  |  | def test_describe_db_parameter_group(): | 
					
						
							| 
									
										
										
										
											2020-12-02 01:23:01 +05:30
										 |  |  |     region = "us-west-2" | 
					
						
							|  |  |  |     pg_name = "test" | 
					
						
							|  |  |  |     conn = boto3.client("rds", region_name=region) | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn.create_db_parameter_group( | 
					
						
							| 
									
										
										
										
											2020-12-02 01:23:01 +05:30
										 |  |  |         DBParameterGroupName=pg_name, | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         DBParameterGroupFamily="mysql5.6", | 
					
						
							|  |  |  |         Description="test parameter group", | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     db_parameter_groups = conn.describe_db_parameter_groups(DBParameterGroupName="test") | 
					
						
							|  |  |  |     db_parameter_groups["DBParameterGroups"][0]["DBParameterGroupName"].should.equal( | 
					
						
							|  |  |  |         "test" | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2020-12-02 01:23:01 +05:30
										 |  |  |     db_parameter_groups["DBParameterGroups"][0]["DBParameterGroupArn"].should.equal( | 
					
						
							|  |  |  |         "arn:aws:rds:{0}:{1}:pg:{2}".format(region, ACCOUNT_ID, pg_name) | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2017-01-11 18:02:51 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_rds2 | 
					
						
							| 
									
										
										
										
											2020-01-20 15:21:11 -08:00
										 |  |  | def test_describe_non_existent_db_parameter_group(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto3.client("rds", region_name="us-west-2") | 
					
						
							|  |  |  |     db_parameter_groups = conn.describe_db_parameter_groups(DBParameterGroupName="test") | 
					
						
							|  |  |  |     len(db_parameter_groups["DBParameterGroups"]).should.equal(0) | 
					
						
							| 
									
										
										
										
											2017-01-11 18:02:51 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_rds2 | 
					
						
							|  |  |  | def test_delete_db_parameter_group(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto3.client("rds", region_name="us-west-2") | 
					
						
							|  |  |  |     conn.create_db_parameter_group( | 
					
						
							|  |  |  |         DBParameterGroupName="test", | 
					
						
							|  |  |  |         DBParameterGroupFamily="mysql5.6", | 
					
						
							|  |  |  |         Description="test parameter group", | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     db_parameter_groups = conn.describe_db_parameter_groups(DBParameterGroupName="test") | 
					
						
							|  |  |  |     db_parameter_groups["DBParameterGroups"][0]["DBParameterGroupName"].should.equal( | 
					
						
							|  |  |  |         "test" | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     conn.delete_db_parameter_group(DBParameterGroupName="test") | 
					
						
							|  |  |  |     db_parameter_groups = conn.describe_db_parameter_groups(DBParameterGroupName="test") | 
					
						
							|  |  |  |     len(db_parameter_groups["DBParameterGroups"]).should.equal(0) | 
					
						
							| 
									
										
										
										
											2015-01-30 08:18:15 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-11 18:02:51 -08:00
										 |  |  | @mock_rds2 | 
					
						
							|  |  |  | def test_modify_db_parameter_group(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto3.client("rds", region_name="us-west-2") | 
					
						
							|  |  |  |     conn.create_db_parameter_group( | 
					
						
							|  |  |  |         DBParameterGroupName="test", | 
					
						
							|  |  |  |         DBParameterGroupFamily="mysql5.6", | 
					
						
							|  |  |  |         Description="test parameter group", | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     modify_result = conn.modify_db_parameter_group( | 
					
						
							|  |  |  |         DBParameterGroupName="test", | 
					
						
							|  |  |  |         Parameters=[ | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 "ParameterName": "foo", | 
					
						
							|  |  |  |                 "ParameterValue": "foo_val", | 
					
						
							|  |  |  |                 "Description": "test param", | 
					
						
							|  |  |  |                 "ApplyMethod": "immediate", | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         ], | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2017-01-11 18:02:51 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     modify_result["DBParameterGroupName"].should.equal("test") | 
					
						
							| 
									
										
										
										
											2017-01-11 18:02:51 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     db_parameters = conn.describe_db_parameters(DBParameterGroupName="test") | 
					
						
							|  |  |  |     db_parameters["Parameters"][0]["ParameterName"].should.equal("foo") | 
					
						
							|  |  |  |     db_parameters["Parameters"][0]["ParameterValue"].should.equal("foo_val") | 
					
						
							|  |  |  |     db_parameters["Parameters"][0]["Description"].should.equal("test param") | 
					
						
							|  |  |  |     db_parameters["Parameters"][0]["ApplyMethod"].should.equal("immediate") | 
					
						
							| 
									
										
										
										
											2017-01-11 18:02:51 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_rds2 | 
					
						
							| 
									
										
										
										
											2020-01-20 15:21:11 -08:00
										 |  |  | def test_delete_non_existent_db_parameter_group(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto3.client("rds", region_name="us-west-2") | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     conn.delete_db_parameter_group.when.called_with( | 
					
						
							| 
									
										
										
										
											2020-01-20 15:21:11 -08:00
										 |  |  |         DBParameterGroupName="non-existent" | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     ).should.throw(ClientError) | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-11 18:02:51 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | @mock_rds2 | 
					
						
							|  |  |  | def test_create_parameter_group_with_tags(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto3.client("rds", region_name="us-west-2") | 
					
						
							|  |  |  |     conn.create_db_parameter_group( | 
					
						
							|  |  |  |         DBParameterGroupName="test", | 
					
						
							|  |  |  |         DBParameterGroupFamily="mysql5.6", | 
					
						
							|  |  |  |         Description="test parameter group", | 
					
						
							|  |  |  |         Tags=[{"Key": "foo", "Value": "bar"}], | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     result = conn.list_tags_for_resource( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         ResourceName="arn:aws:rds:us-west-2:1234567890:pg:test" | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     result["TagList"].should.equal([{"Value": "bar", "Key": "foo"}]) | 
					
						
							| 
									
										
										
										
											2020-02-02 12:47:54 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_rds2 | 
					
						
							| 
									
										
										
										
											2020-02-02 13:19:50 -03:00
										 |  |  | def test_create_db_with_iam_authentication(): | 
					
						
							| 
									
										
										
										
											2020-02-02 12:47:54 -03:00
										 |  |  |     conn = boto3.client("rds", region_name="us-west-2") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     database = conn.create_db_instance( | 
					
						
							|  |  |  |         DBInstanceIdentifier="rds", | 
					
						
							|  |  |  |         DBInstanceClass="db.t1.micro", | 
					
						
							|  |  |  |         Engine="postgres", | 
					
						
							|  |  |  |         EnableIAMDatabaseAuthentication=True, | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     db_instance = database["DBInstance"] | 
					
						
							|  |  |  |     db_instance["IAMDatabaseAuthenticationEnabled"].should.equal(True) | 
					
						
							| 
									
										
										
										
											2020-02-02 13:08:13 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_rds2 | 
					
						
							|  |  |  | def test_create_db_snapshot_with_iam_authentication(): | 
					
						
							|  |  |  |     conn = boto3.client("rds", region_name="us-west-2") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     conn.create_db_instance( | 
					
						
							|  |  |  |         DBInstanceIdentifier="rds", | 
					
						
							|  |  |  |         DBInstanceClass="db.t1.micro", | 
					
						
							|  |  |  |         Engine="postgres", | 
					
						
							|  |  |  |         EnableIAMDatabaseAuthentication=True, | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     snapshot = conn.create_db_snapshot( | 
					
						
							|  |  |  |         DBInstanceIdentifier="rds", DBSnapshotIdentifier="snapshot" | 
					
						
							|  |  |  |     ).get("DBSnapshot") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     snapshot.get("IAMDatabaseAuthenticationEnabled").should.equal(True) | 
					
						
							| 
									
										
										
										
											2020-11-16 01:30:53 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_rds2 | 
					
						
							|  |  |  | def test_create_db_instance_with_tags(): | 
					
						
							|  |  |  |     client = boto3.client("rds", region_name="us-west-2") | 
					
						
							|  |  |  |     tags = [{"Key": "foo", "Value": "bar"}, {"Key": "foo1", "Value": "bar1"}] | 
					
						
							|  |  |  |     db_instance_identifier = "test-db-instance" | 
					
						
							|  |  |  |     resp = client.create_db_instance( | 
					
						
							|  |  |  |         DBInstanceIdentifier=db_instance_identifier, | 
					
						
							|  |  |  |         Engine="postgres", | 
					
						
							|  |  |  |         DBName="staging-postgres", | 
					
						
							|  |  |  |         DBInstanceClass="db.m1.small", | 
					
						
							|  |  |  |         Tags=tags, | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     resp["DBInstance"]["TagList"].should.equal(tags) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     resp = client.describe_db_instances(DBInstanceIdentifier=db_instance_identifier) | 
					
						
							|  |  |  |     resp["DBInstances"][0]["TagList"].should.equal(tags) |