def dispose_db_cluster(self, db_cluster: RDSDBCluster): region_db_clusters = self.get_region_db_clusters(db_cluster.region) for region_db_cluster in region_db_clusters: if db_cluster.id == region_db_cluster.id: db_cluster.update_from_raw_response(region_db_cluster.dict_src) break else: return filters_req = [{ 'Name': 'db-cluster-id', 'Values': [ db_cluster.id, ] }] db_instances = self.get_region_db_instances(region=db_cluster.region, filters=filters_req) for db_instance in db_instances: db_instance.region = db_cluster.region db_instance.skip_final_snapshot = db_cluster.skip_final_snapshot self.dispose_db_instance(db_instance) AWSAccount.set_aws_region(db_cluster.region) response = self.dispose_db_cluster_raw( db_cluster.generate_dispose_request()) db_cluster.update_from_raw_response(response) try: self.wait_for_status( db_cluster, self.update_db_cluster_information, [], [db_cluster.Status.DELETING, db_cluster.Status.AVAILABLE], [], timeout=20 * 60) except self.ResourceNotFoundError: pass
def test_dispose_db_cluster(): client = RDSClient() cluster = RDSDBCluster({}) cluster.region = AWSAccount.get_aws_region() cluster.skip_final_snapshot = True cluster.id = "cluster-db-test" client.dispose_db_cluster(cluster)
def modify_db_cluster(self, db_cluster: RDSDBCluster): AWSAccount.set_aws_region(db_cluster.region) request = db_cluster.generate_modify_request() response = self.modify_db_cluster_raw(request) db_cluster.update_from_raw_response(response) if "MasterUserPassword" in request: self.wait_for_status( db_cluster, self.update_db_cluster_information, [db_cluster.Status.RESETTING_MASTER_CREDENTIALS], [db_cluster.Status.AVAILABLE], [], sleep_time=2) self.wait_for_status( db_cluster, self.update_db_cluster_information, [db_cluster.Status.AVAILABLE], [db_cluster.Status.RESETTING_MASTER_CREDENTIALS], [])
def provision_db_cluster(self, db_cluster: RDSDBCluster, snapshot_id=None): if snapshot_id is not None: return self.restore_db_cluster_from_snapshot( db_cluster, snapshot_id) region_db_clusters = self.get_region_db_clusters(db_cluster.region) for region_db_cluster in region_db_clusters: if db_cluster.id == region_db_cluster.id: db_cluster.update_from_raw_response(region_db_cluster.dict_src) return AWSAccount.set_aws_region(db_cluster.region) response = self.provision_db_cluster_raw( db_cluster.generate_create_request()) db_cluster.update_from_raw_response(response) self.wait_for_status( db_cluster, self.update_db_cluster_information, [db_cluster.Status.AVAILABLE], [db_cluster.Status.CREATING], [db_cluster.Status.FAILED, db_cluster.Status.DELETING])
def get_region_db_clusters(self, region, filters=None, update_tags=True): final_result = list() if filters is not None: filters = {"Filters": filters} AWSAccount.set_aws_region(region) for response in self.execute(self.client.describe_db_clusters, "DBClusters", filters_req=filters): obj = RDSDBCluster(response) final_result.append(obj) if update_tags: self.update_tags(final_result) return final_result
def modify_db_instance(self, db_instance: RDSDBCluster): AWSAccount.set_aws_region(db_instance.region) response = self.modify_db_instance_raw( db_instance.generate_modify_request()) db_instance.update_from_raw_response(response)
def test_provision_cluster_from_snapshot(): client = RDSClient() cluster = RDSDBCluster({}) cluster.region = AWSAccount.get_aws_region() cluster.db_subnet_group_name = "db_subnet-test" cluster.db_cluster_parameter_group_name = "cluster-param-group-test" cluster.backup_retention_period = 35 cluster.database_name = "db_test" cluster.id = "cluster-db-test" cluster.vpc_security_group_ids = [ mock_values["cluster.vpc_security_group_ids"] ] cluster.engine = "aurora-mysql" cluster.engine_version = "5.7.mysql_aurora.2.09.2" cluster.port = 3306 cluster.master_username = "******" cluster.master_user_password = "******" cluster.preferred_backup_window = "09:23-09:53" cluster.preferred_maintenance_window = "sun:03:30-sun:04:00" cluster.storage_encrypted = True #cluster.kms_key_id = True cluster.engine_mode = "provisioned" cluster.deletion_protection = False cluster.copy_tags_to_snapshot = True cluster.enable_cloudwatch_logs_exports = [ "audit", "error", "general", "slowquery" ] cluster.tags = [{ 'Key': 'lvl', 'Value': "tst" }, { 'Key': 'name', 'Value': cluster.id }] client.provision_db_cluster(cluster, snapshot_id="horey-test-snapshot-id") assert cluster.arn is not None