Best Python code snippet using localstack_python
test_redshift.py
Source:test_redshift.py
...347 iam_roles_arn.should.equal(iam_roles)348@mock_redshift_deprecated349def test_create_cluster_with_parameter_group():350 conn = boto.connect_redshift()351 conn.create_cluster_parameter_group(352 "my_parameter_group", "redshift-1.0", "This is my parameter group"353 )354 conn.create_cluster(355 "my_cluster",356 node_type="dw.hs1.xlarge",357 master_username="username",358 master_user_password="password",359 cluster_parameter_group_name="my_parameter_group",360 )361 cluster_response = conn.describe_clusters("my_cluster")362 cluster = cluster_response["DescribeClustersResponse"]["DescribeClustersResult"][363 "Clusters"364 ][0]365 cluster["ClusterParameterGroups"][0]["ParameterGroupName"].should.equal(366 "my_parameter_group"367 )368@mock_redshift_deprecated369def test_describe_non_existent_cluster():370 conn = boto.redshift.connect_to_region("us-east-1")371 conn.describe_clusters.when.called_with("not-a-cluster").should.throw(372 ClusterNotFound373 )374@mock_redshift_deprecated375def test_delete_cluster():376 conn = boto.connect_redshift()377 cluster_identifier = "my_cluster"378 snapshot_identifier = "my_snapshot"379 conn.create_cluster(380 cluster_identifier,381 node_type="single-node",382 master_username="username",383 master_user_password="password",384 )385 conn.delete_cluster.when.called_with(cluster_identifier, False).should.throw(386 boto.exception.JSONResponseError387 )388 clusters = conn.describe_clusters()["DescribeClustersResponse"][389 "DescribeClustersResult"390 ]["Clusters"]391 list(clusters).should.have.length_of(1)392 conn.delete_cluster(393 cluster_identifier=cluster_identifier,394 skip_final_cluster_snapshot=False,395 final_cluster_snapshot_identifier=snapshot_identifier,396 )397 clusters = conn.describe_clusters()["DescribeClustersResponse"][398 "DescribeClustersResult"399 ]["Clusters"]400 list(clusters).should.have.length_of(0)401 snapshots = conn.describe_cluster_snapshots()["DescribeClusterSnapshotsResponse"][402 "DescribeClusterSnapshotsResult"403 ]["Snapshots"]404 list(snapshots).should.have.length_of(1)405 assert snapshot_identifier in snapshots[0]["SnapshotIdentifier"]406 # Delete invalid id407 conn.delete_cluster.when.called_with("not-a-cluster").should.throw(ClusterNotFound)408@mock_redshift409def test_modify_cluster_vpc_routing():410 iam_roles_arn = ["arn:aws:iam:::role/my-iam-role"]411 client = boto3.client("redshift", region_name="us-east-1")412 cluster_identifier = "my_cluster"413 client.create_cluster(414 ClusterIdentifier=cluster_identifier,415 NodeType="single-node",416 MasterUsername="username",417 MasterUserPassword="password",418 IamRoles=iam_roles_arn,419 )420 cluster_response = client.describe_clusters(ClusterIdentifier=cluster_identifier)421 cluster = cluster_response["Clusters"][0]422 cluster["EnhancedVpcRouting"].should.equal(False)423 client.create_cluster_security_group(424 ClusterSecurityGroupName="security_group", Description="security_group"425 )426 client.create_cluster_parameter_group(427 ParameterGroupName="my_parameter_group",428 ParameterGroupFamily="redshift-1.0",429 Description="my_parameter_group",430 )431 client.modify_cluster(432 ClusterIdentifier=cluster_identifier,433 ClusterType="multi-node",434 NodeType="ds2.8xlarge",435 NumberOfNodes=3,436 ClusterSecurityGroups=["security_group"],437 MasterUserPassword="new_password",438 ClusterParameterGroupName="my_parameter_group",439 AutomatedSnapshotRetentionPeriod=7,440 PreferredMaintenanceWindow="Tue:03:00-Tue:11:00",441 AllowVersionUpgrade=False,442 NewClusterIdentifier=cluster_identifier,443 EnhancedVpcRouting=True,444 )445 cluster_response = client.describe_clusters(ClusterIdentifier=cluster_identifier)446 cluster = cluster_response["Clusters"][0]447 cluster["ClusterIdentifier"].should.equal(cluster_identifier)448 cluster["NodeType"].should.equal("ds2.8xlarge")449 cluster["PreferredMaintenanceWindow"].should.equal("Tue:03:00-Tue:11:00")450 cluster["AutomatedSnapshotRetentionPeriod"].should.equal(7)451 cluster["AllowVersionUpgrade"].should.equal(False)452 # This one should remain unmodified.453 cluster["NumberOfNodes"].should.equal(3)454 cluster["EnhancedVpcRouting"].should.equal(True)455@mock_redshift_deprecated456def test_modify_cluster():457 conn = boto.connect_redshift()458 cluster_identifier = "my_cluster"459 conn.create_cluster_security_group("security_group", "This is my security group")460 conn.create_cluster_parameter_group(461 "my_parameter_group", "redshift-1.0", "This is my parameter group"462 )463 conn.create_cluster(464 cluster_identifier,465 node_type="single-node",466 master_username="username",467 master_user_password="password",468 )469 cluster_response = conn.describe_clusters(cluster_identifier)470 cluster = cluster_response["DescribeClustersResponse"]["DescribeClustersResult"][471 "Clusters"472 ][0]473 cluster["EnhancedVpcRouting"].should.equal(False)474 conn.modify_cluster(475 cluster_identifier,476 cluster_type="multi-node",477 number_of_nodes=4,478 node_type="dw.hs1.xlarge",479 cluster_security_groups="security_group",480 master_user_password="new_password",481 cluster_parameter_group_name="my_parameter_group",482 automated_snapshot_retention_period=7,483 preferred_maintenance_window="Tue:03:00-Tue:11:00",484 allow_version_upgrade=False,485 new_cluster_identifier=cluster_identifier,486 )487 cluster_response = conn.describe_clusters(cluster_identifier)488 cluster = cluster_response["DescribeClustersResponse"]["DescribeClustersResult"][489 "Clusters"490 ][0]491 cluster["ClusterIdentifier"].should.equal(cluster_identifier)492 cluster["NodeType"].should.equal("dw.hs1.xlarge")493 cluster["ClusterSecurityGroups"][0]["ClusterSecurityGroupName"].should.equal(494 "security_group"495 )496 cluster["PreferredMaintenanceWindow"].should.equal("Tue:03:00-Tue:11:00")497 cluster["ClusterParameterGroups"][0]["ParameterGroupName"].should.equal(498 "my_parameter_group"499 )500 cluster["AutomatedSnapshotRetentionPeriod"].should.equal(7)501 cluster["AllowVersionUpgrade"].should.equal(False)502 cluster["NumberOfNodes"].should.equal(4)503@mock_redshift504@mock_ec2505def test_create_cluster_subnet_group():506 ec2 = boto3.resource("ec2", region_name="us-east-1")507 vpc = ec2.create_vpc(CidrBlock="10.0.0.0/16")508 subnet1 = ec2.create_subnet(VpcId=vpc.id, CidrBlock="10.0.0.0/24")509 subnet2 = ec2.create_subnet(VpcId=vpc.id, CidrBlock="10.0.1.0/24")510 client = boto3.client("redshift", region_name="us-east-1")511 client.create_cluster_subnet_group(512 ClusterSubnetGroupName="my_subnet_group",513 Description="This is my subnet group",514 SubnetIds=[subnet1.id, subnet2.id],515 )516 subnets_response = client.describe_cluster_subnet_groups(517 ClusterSubnetGroupName="my_subnet_group"518 )519 my_subnet = subnets_response["ClusterSubnetGroups"][0]520 my_subnet["ClusterSubnetGroupName"].should.equal("my_subnet_group")521 my_subnet["Description"].should.equal("This is my subnet group")522 subnet_ids = [subnet["SubnetIdentifier"] for subnet in my_subnet["Subnets"]]523 set(subnet_ids).should.equal(set([subnet1.id, subnet2.id]))524@mock_redshift525def test_authorize_security_group_ingress():526 iam_roles_arn = ["arn:aws:iam:::role/my-iam-role"]527 client = boto3.client("redshift", region_name="us-east-1")528 cluster_identifier = "my_cluster"529 client.create_cluster(530 ClusterIdentifier=cluster_identifier,531 NodeType="single-node",532 MasterUsername="username",533 MasterUserPassword="password",534 IamRoles=iam_roles_arn,535 )536 client.create_cluster_security_group(537 ClusterSecurityGroupName="security_group",538 Description="security_group_description",539 )540 response = client.authorize_cluster_security_group_ingress(541 ClusterSecurityGroupName="security_group", CIDRIP="192.168.10.0/28"542 )543 assert (544 response.get("ClusterSecurityGroup").get("ClusterSecurityGroupName")545 == "security_group"546 )547 assert (548 response.get("ClusterSecurityGroup").get("Description")549 == "security_group_description"550 )551 assert (552 response.get("ClusterSecurityGroup").get("IPRanges")[0].get("Status")553 == "authorized"554 )555 assert (556 response.get("ClusterSecurityGroup").get("IPRanges")[0].get("CIDRIP")557 == "192.168.10.0/28"558 )559 with pytest.raises(ClientError) as ex:560 client.authorize_cluster_security_group_ingress(561 ClusterSecurityGroupName="invalid_security_group", CIDRIP="192.168.10.0/28"562 )563 assert ex.value.response["Error"]["Code"] == "ClusterSecurityGroupNotFoundFault"564 assert (565 ex.value.response["Error"]["Message"]566 == "The cluster security group name does not refer to an existing cluster security group."567 )568@mock_redshift_deprecated569@mock_ec2_deprecated570def test_create_invalid_cluster_subnet_group():571 redshift_conn = boto.connect_redshift()572 redshift_conn.create_cluster_subnet_group.when.called_with(573 "my_subnet", "This is my subnet group", subnet_ids=["subnet-1234"]574 ).should.throw(InvalidSubnet)575@mock_redshift_deprecated576def test_describe_non_existent_subnet_group():577 conn = boto.redshift.connect_to_region("us-east-1")578 conn.describe_cluster_subnet_groups.when.called_with(579 "not-a-subnet-group"580 ).should.throw(ClusterSubnetGroupNotFound)581@mock_redshift582@mock_ec2583def test_delete_cluster_subnet_group():584 ec2 = boto3.resource("ec2", region_name="us-east-1")585 vpc = ec2.create_vpc(CidrBlock="10.0.0.0/16")586 subnet = ec2.create_subnet(VpcId=vpc.id, CidrBlock="10.0.0.0/24")587 client = boto3.client("redshift", region_name="us-east-1")588 client.create_cluster_subnet_group(589 ClusterSubnetGroupName="my_subnet_group",590 Description="This is my subnet group",591 SubnetIds=[subnet.id],592 )593 subnets_response = client.describe_cluster_subnet_groups()594 subnets = subnets_response["ClusterSubnetGroups"]595 subnets.should.have.length_of(1)596 client.delete_cluster_subnet_group(ClusterSubnetGroupName="my_subnet_group")597 subnets_response = client.describe_cluster_subnet_groups()598 subnets = subnets_response["ClusterSubnetGroups"]599 subnets.should.have.length_of(0)600 # Delete invalid id601 client.delete_cluster_subnet_group.when.called_with(602 ClusterSubnetGroupName="not-a-subnet-group"603 ).should.throw(ClientError)604@mock_redshift_deprecated605def test_create_cluster_security_group():606 conn = boto.connect_redshift()607 conn.create_cluster_security_group("my_security_group", "This is my security group")608 groups_response = conn.describe_cluster_security_groups("my_security_group")609 my_group = groups_response["DescribeClusterSecurityGroupsResponse"][610 "DescribeClusterSecurityGroupsResult"611 ]["ClusterSecurityGroups"][0]612 my_group["ClusterSecurityGroupName"].should.equal("my_security_group")613 my_group["Description"].should.equal("This is my security group")614 list(my_group["IPRanges"]).should.equal([])615@mock_redshift_deprecated616def test_describe_non_existent_security_group():617 conn = boto.redshift.connect_to_region("us-east-1")618 conn.describe_cluster_security_groups.when.called_with(619 "not-a-security-group"620 ).should.throw(ClusterSecurityGroupNotFound)621@mock_redshift_deprecated622def test_delete_cluster_security_group():623 conn = boto.connect_redshift()624 conn.create_cluster_security_group("my_security_group", "This is my security group")625 groups_response = conn.describe_cluster_security_groups()626 groups = groups_response["DescribeClusterSecurityGroupsResponse"][627 "DescribeClusterSecurityGroupsResult"628 ]["ClusterSecurityGroups"]629 groups.should.have.length_of(2) # The default group already exists630 conn.delete_cluster_security_group("my_security_group")631 groups_response = conn.describe_cluster_security_groups()632 groups = groups_response["DescribeClusterSecurityGroupsResponse"][633 "DescribeClusterSecurityGroupsResult"634 ]["ClusterSecurityGroups"]635 groups.should.have.length_of(1)636 # Delete invalid id637 conn.delete_cluster_security_group.when.called_with(638 "not-a-security-group"639 ).should.throw(ClusterSecurityGroupNotFound)640@mock_redshift_deprecated641def test_create_cluster_parameter_group():642 conn = boto.connect_redshift()643 conn.create_cluster_parameter_group(644 "my_parameter_group", "redshift-1.0", "This is my parameter group"645 )646 groups_response = conn.describe_cluster_parameter_groups("my_parameter_group")647 my_group = groups_response["DescribeClusterParameterGroupsResponse"][648 "DescribeClusterParameterGroupsResult"649 ]["ParameterGroups"][0]650 my_group["ParameterGroupName"].should.equal("my_parameter_group")651 my_group["ParameterGroupFamily"].should.equal("redshift-1.0")652 my_group["Description"].should.equal("This is my parameter group")653@mock_redshift_deprecated654def test_describe_non_existent_parameter_group():655 conn = boto.redshift.connect_to_region("us-east-1")656 conn.describe_cluster_parameter_groups.when.called_with(657 "not-a-parameter-group"658 ).should.throw(ClusterParameterGroupNotFound)659@mock_redshift_deprecated660def test_delete_cluster_parameter_group():661 conn = boto.connect_redshift()662 conn.create_cluster_parameter_group(663 "my_parameter_group", "redshift-1.0", "This is my parameter group"664 )665 groups_response = conn.describe_cluster_parameter_groups()666 groups = groups_response["DescribeClusterParameterGroupsResponse"][667 "DescribeClusterParameterGroupsResult"668 ]["ParameterGroups"]669 groups.should.have.length_of(2) # The default group already exists670 conn.delete_cluster_parameter_group("my_parameter_group")671 groups_response = conn.describe_cluster_parameter_groups()672 groups = groups_response["DescribeClusterParameterGroupsResponse"][673 "DescribeClusterParameterGroupsResult"674 ]["ParameterGroups"]675 groups.should.have.length_of(1)676 # Delete invalid id677 conn.delete_cluster_parameter_group.when.called_with(678 "not-a-parameter-group"679 ).should.throw(ClusterParameterGroupNotFound)680@mock_redshift681def test_create_cluster_snapshot_of_non_existent_cluster():682 client = boto3.client("redshift", region_name="us-east-1")683 cluster_identifier = "non-existent-cluster-id"684 client.create_cluster_snapshot.when.called_with(685 SnapshotIdentifier="snapshot-id", ClusterIdentifier=cluster_identifier686 ).should.throw(ClientError, "Cluster {} not found.".format(cluster_identifier))687@mock_redshift688def test_create_cluster_snapshot():689 client = boto3.client("redshift", region_name="us-east-1")690 cluster_identifier = "my_cluster"691 snapshot_identifier = "my_snapshot"692 cluster_response = client.create_cluster(693 DBName="test-db",694 ClusterIdentifier=cluster_identifier,695 ClusterType="single-node",696 NodeType="ds2.xlarge",697 MasterUsername="username",698 MasterUserPassword="password",699 EnhancedVpcRouting=True,700 )701 cluster_response["Cluster"]["NodeType"].should.equal("ds2.xlarge")702 snapshot_response = client.create_cluster_snapshot(703 SnapshotIdentifier=snapshot_identifier,704 ClusterIdentifier=cluster_identifier,705 Tags=[{"Key": "test-tag-key", "Value": "test-tag-value"}],706 )707 snapshot = snapshot_response["Snapshot"]708 snapshot["SnapshotIdentifier"].should.equal(snapshot_identifier)709 snapshot["ClusterIdentifier"].should.equal(cluster_identifier)710 snapshot["NumberOfNodes"].should.equal(1)711 snapshot["NodeType"].should.equal("ds2.xlarge")712 snapshot["MasterUsername"].should.equal("username")713@mock_redshift714def test_describe_cluster_snapshots():715 client = boto3.client("redshift", region_name="us-east-1")716 cluster_identifier = "my_cluster"717 snapshot_identifier_1 = "my_snapshot_1"718 snapshot_identifier_2 = "my_snapshot_2"719 client.create_cluster(720 DBName="test-db",721 ClusterIdentifier=cluster_identifier,722 ClusterType="single-node",723 NodeType="ds2.xlarge",724 MasterUsername="username",725 MasterUserPassword="password",726 )727 client.create_cluster_snapshot(728 SnapshotIdentifier=snapshot_identifier_1, ClusterIdentifier=cluster_identifier729 )730 client.create_cluster_snapshot(731 SnapshotIdentifier=snapshot_identifier_2, ClusterIdentifier=cluster_identifier732 )733 resp_snap_1 = client.describe_cluster_snapshots(734 SnapshotIdentifier=snapshot_identifier_1735 )736 snapshot_1 = resp_snap_1["Snapshots"][0]737 snapshot_1["SnapshotIdentifier"].should.equal(snapshot_identifier_1)738 snapshot_1["ClusterIdentifier"].should.equal(cluster_identifier)739 snapshot_1["NumberOfNodes"].should.equal(1)740 snapshot_1["NodeType"].should.equal("ds2.xlarge")741 snapshot_1["MasterUsername"].should.equal("username")742 resp_snap_2 = client.describe_cluster_snapshots(743 SnapshotIdentifier=snapshot_identifier_2744 )745 snapshot_2 = resp_snap_2["Snapshots"][0]746 snapshot_2["SnapshotIdentifier"].should.equal(snapshot_identifier_2)747 snapshot_2["ClusterIdentifier"].should.equal(cluster_identifier)748 snapshot_2["NumberOfNodes"].should.equal(1)749 snapshot_2["NodeType"].should.equal("ds2.xlarge")750 snapshot_2["MasterUsername"].should.equal("username")751 resp_clust = client.describe_cluster_snapshots(ClusterIdentifier=cluster_identifier)752 resp_clust["Snapshots"][0].should.equal(resp_snap_1["Snapshots"][0])753 resp_clust["Snapshots"][1].should.equal(resp_snap_2["Snapshots"][0])754@mock_redshift755def test_describe_cluster_snapshots_not_found_error():756 client = boto3.client("redshift", region_name="us-east-1")757 cluster_identifier = "non-existent-cluster-id"758 snapshot_identifier = "non-existent-snapshot-id"759 resp = client.describe_cluster_snapshots(ClusterIdentifier=cluster_identifier)760 resp["Snapshots"].should.have.length_of(0)761 client.describe_cluster_snapshots.when.called_with(762 SnapshotIdentifier=snapshot_identifier763 ).should.throw(ClientError, "Snapshot {} not found.".format(snapshot_identifier))764@mock_redshift765def test_delete_cluster_snapshot():766 client = boto3.client("redshift", region_name="us-east-1")767 cluster_identifier = "my_cluster"768 snapshot_identifier = "my_snapshot"769 client.create_cluster(770 ClusterIdentifier=cluster_identifier,771 ClusterType="single-node",772 NodeType="ds2.xlarge",773 MasterUsername="username",774 MasterUserPassword="password",775 )776 client.create_cluster_snapshot(777 SnapshotIdentifier=snapshot_identifier, ClusterIdentifier=cluster_identifier778 )779 snapshots = client.describe_cluster_snapshots()["Snapshots"]780 list(snapshots).should.have.length_of(1)781 client.delete_cluster_snapshot(SnapshotIdentifier=snapshot_identifier)["Snapshot"][782 "Status"783 ].should.equal("deleted")784 snapshots = client.describe_cluster_snapshots()["Snapshots"]785 list(snapshots).should.have.length_of(0)786 # Delete invalid id787 client.delete_cluster_snapshot.when.called_with(788 SnapshotIdentifier="non-existent"789 ).should.throw(ClientError, "Snapshot non-existent not found.")790@mock_redshift791def test_cluster_snapshot_already_exists():792 client = boto3.client("redshift", region_name="us-east-1")793 cluster_identifier = "my_cluster"794 snapshot_identifier = "my_snapshot"795 client.create_cluster(796 DBName="test-db",797 ClusterIdentifier=cluster_identifier,798 ClusterType="single-node",799 NodeType="ds2.xlarge",800 MasterUsername="username",801 MasterUserPassword="password",802 )803 client.create_cluster_snapshot(804 SnapshotIdentifier=snapshot_identifier, ClusterIdentifier=cluster_identifier805 )806 client.create_cluster_snapshot.when.called_with(807 SnapshotIdentifier=snapshot_identifier, ClusterIdentifier=cluster_identifier808 ).should.throw(ClientError, "{} already exists".format(snapshot_identifier))809@mock_redshift810def test_create_cluster_from_snapshot():811 client = boto3.client("redshift", region_name="us-east-1")812 original_cluster_identifier = "original-cluster"813 original_snapshot_identifier = "original-snapshot"814 new_cluster_identifier = "new-cluster"815 client.create_cluster(816 ClusterIdentifier=original_cluster_identifier,817 ClusterType="single-node",818 NodeType="ds2.xlarge",819 MasterUsername="username",820 MasterUserPassword="password",821 EnhancedVpcRouting=True,822 )823 client.create_cluster_snapshot(824 SnapshotIdentifier=original_snapshot_identifier,825 ClusterIdentifier=original_cluster_identifier,826 )827 client.restore_from_cluster_snapshot.when.called_with(828 ClusterIdentifier=original_cluster_identifier,829 SnapshotIdentifier=original_snapshot_identifier,830 ).should.throw(ClientError, "ClusterAlreadyExists")831 response = client.restore_from_cluster_snapshot(832 ClusterIdentifier=new_cluster_identifier,833 SnapshotIdentifier=original_snapshot_identifier,834 Port=1234,835 )836 response["Cluster"]["ClusterStatus"].should.equal("creating")837 response = client.describe_clusters(ClusterIdentifier=new_cluster_identifier)838 new_cluster = response["Clusters"][0]839 new_cluster["NodeType"].should.equal("ds2.xlarge")840 new_cluster["MasterUsername"].should.equal("username")841 new_cluster["Endpoint"]["Port"].should.equal(1234)842 new_cluster["EnhancedVpcRouting"].should.equal(True)843@mock_redshift844def test_create_cluster_from_snapshot_with_waiter():845 client = boto3.client("redshift", region_name="us-east-1")846 original_cluster_identifier = "original-cluster"847 original_snapshot_identifier = "original-snapshot"848 new_cluster_identifier = "new-cluster"849 client.create_cluster(850 ClusterIdentifier=original_cluster_identifier,851 ClusterType="single-node",852 NodeType="ds2.xlarge",853 MasterUsername="username",854 MasterUserPassword="password",855 EnhancedVpcRouting=True,856 )857 client.create_cluster_snapshot(858 SnapshotIdentifier=original_snapshot_identifier,859 ClusterIdentifier=original_cluster_identifier,860 )861 response = client.restore_from_cluster_snapshot(862 ClusterIdentifier=new_cluster_identifier,863 SnapshotIdentifier=original_snapshot_identifier,864 Port=1234,865 )866 response["Cluster"]["ClusterStatus"].should.equal("creating")867 client.get_waiter("cluster_restored").wait(868 ClusterIdentifier=new_cluster_identifier,869 WaiterConfig={"Delay": 1, "MaxAttempts": 2},870 )871 response = client.describe_clusters(ClusterIdentifier=new_cluster_identifier)872 new_cluster = response["Clusters"][0]873 new_cluster["NodeType"].should.equal("ds2.xlarge")874 new_cluster["MasterUsername"].should.equal("username")875 new_cluster["EnhancedVpcRouting"].should.equal(True)876 new_cluster["Endpoint"]["Port"].should.equal(1234)877@mock_redshift878def test_create_cluster_from_non_existent_snapshot():879 client = boto3.client("redshift", region_name="us-east-1")880 client.restore_from_cluster_snapshot.when.called_with(881 ClusterIdentifier="cluster-id", SnapshotIdentifier="non-existent-snapshot"882 ).should.throw(ClientError, "Snapshot non-existent-snapshot not found.")883@mock_redshift884def test_create_cluster_status_update():885 client = boto3.client("redshift", region_name="us-east-1")886 cluster_identifier = "test-cluster"887 response = client.create_cluster(888 ClusterIdentifier=cluster_identifier,889 ClusterType="single-node",890 NodeType="ds2.xlarge",891 MasterUsername="username",892 MasterUserPassword="password",893 )894 response["Cluster"]["ClusterStatus"].should.equal("creating")895 response = client.describe_clusters(ClusterIdentifier=cluster_identifier)896 response["Clusters"][0]["ClusterStatus"].should.equal("available")897@mock_redshift898def test_describe_tags_with_resource_type():899 client = boto3.client("redshift", region_name="us-east-1")900 cluster_identifier = "my_cluster"901 cluster_arn = "arn:aws:redshift:us-east-1:{}:" "cluster:{}".format(902 ACCOUNT_ID, cluster_identifier903 )904 snapshot_identifier = "my_snapshot"905 snapshot_arn = "arn:aws:redshift:us-east-1:{}:" "snapshot:{}/{}".format(906 ACCOUNT_ID, cluster_identifier, snapshot_identifier907 )908 tag_key = "test-tag-key"909 tag_value = "test-tag-value"910 client.create_cluster(911 DBName="test-db",912 ClusterIdentifier=cluster_identifier,913 ClusterType="single-node",914 NodeType="ds2.xlarge",915 MasterUsername="username",916 MasterUserPassword="password",917 Tags=[{"Key": tag_key, "Value": tag_value}],918 )919 tags_response = client.describe_tags(ResourceType="cluster")920 tagged_resources = tags_response["TaggedResources"]921 list(tagged_resources).should.have.length_of(1)922 tagged_resources[0]["ResourceType"].should.equal("cluster")923 tagged_resources[0]["ResourceName"].should.equal(cluster_arn)924 tag = tagged_resources[0]["Tag"]925 tag["Key"].should.equal(tag_key)926 tag["Value"].should.equal(tag_value)927 client.create_cluster_snapshot(928 SnapshotIdentifier=snapshot_identifier,929 ClusterIdentifier=cluster_identifier,930 Tags=[{"Key": tag_key, "Value": tag_value}],931 )932 tags_response = client.describe_tags(ResourceType="snapshot")933 tagged_resources = tags_response["TaggedResources"]934 list(tagged_resources).should.have.length_of(1)935 tagged_resources[0]["ResourceType"].should.equal("snapshot")936 tagged_resources[0]["ResourceName"].should.equal(snapshot_arn)937 tag = tagged_resources[0]["Tag"]938 tag["Key"].should.equal(tag_key)939 tag["Value"].should.equal(tag_value)940@mock_redshift941def test_describe_tags_cannot_specify_resource_type_and_resource_name():942 client = boto3.client("redshift", region_name="us-east-1")943 resource_name = "arn:aws:redshift:us-east-1:{}:cluster:cluster-id".format(944 ACCOUNT_ID945 )946 resource_type = "cluster"947 client.describe_tags.when.called_with(948 ResourceName=resource_name, ResourceType=resource_type949 ).should.throw(ClientError, "using either an ARN or a resource type")950@mock_redshift951def test_describe_tags_with_resource_name():952 client = boto3.client("redshift", region_name="us-east-1")953 cluster_identifier = "cluster-id"954 cluster_arn = "arn:aws:redshift:us-east-1:{}:" "cluster:{}".format(955 ACCOUNT_ID, cluster_identifier956 )957 snapshot_identifier = "snapshot-id"958 snapshot_arn = "arn:aws:redshift:us-east-1:{}:" "snapshot:{}/{}".format(959 ACCOUNT_ID, cluster_identifier, snapshot_identifier960 )961 tag_key = "test-tag-key"962 tag_value = "test-tag-value"963 client.create_cluster(964 DBName="test-db",965 ClusterIdentifier=cluster_identifier,966 ClusterType="single-node",967 NodeType="ds2.xlarge",968 MasterUsername="username",969 MasterUserPassword="password",970 Tags=[{"Key": tag_key, "Value": tag_value}],971 )972 tags_response = client.describe_tags(ResourceName=cluster_arn)973 tagged_resources = tags_response["TaggedResources"]974 list(tagged_resources).should.have.length_of(1)975 tagged_resources[0]["ResourceType"].should.equal("cluster")976 tagged_resources[0]["ResourceName"].should.equal(cluster_arn)977 tag = tagged_resources[0]["Tag"]978 tag["Key"].should.equal(tag_key)979 tag["Value"].should.equal(tag_value)980 client.create_cluster_snapshot(981 SnapshotIdentifier=snapshot_identifier,982 ClusterIdentifier=cluster_identifier,983 Tags=[{"Key": tag_key, "Value": tag_value}],984 )985 tags_response = client.describe_tags(ResourceName=snapshot_arn)986 tagged_resources = tags_response["TaggedResources"]987 list(tagged_resources).should.have.length_of(1)988 tagged_resources[0]["ResourceType"].should.equal("snapshot")989 tagged_resources[0]["ResourceName"].should.equal(snapshot_arn)990 tag = tagged_resources[0]["Tag"]991 tag["Key"].should.equal(tag_key)992 tag["Value"].should.equal(tag_value)993@mock_redshift994def test_create_tags():995 client = boto3.client("redshift", region_name="us-east-1")996 cluster_identifier = "cluster-id"997 cluster_arn = "arn:aws:redshift:us-east-1:{}:" "cluster:{}".format(998 ACCOUNT_ID, cluster_identifier999 )1000 tag_key = "test-tag-key"1001 tag_value = "test-tag-value"1002 num_tags = 51003 tags = []1004 for i in range(0, num_tags):1005 tag = {"Key": "{}-{}".format(tag_key, i), "Value": "{}-{}".format(tag_value, i)}1006 tags.append(tag)1007 client.create_cluster(1008 DBName="test-db",1009 ClusterIdentifier=cluster_identifier,1010 ClusterType="single-node",1011 NodeType="ds2.xlarge",1012 MasterUsername="username",1013 MasterUserPassword="password",1014 )1015 client.create_tags(ResourceName=cluster_arn, Tags=tags)1016 response = client.describe_clusters(ClusterIdentifier=cluster_identifier)1017 cluster = response["Clusters"][0]1018 list(cluster["Tags"]).should.have.length_of(num_tags)1019 response = client.describe_tags(ResourceName=cluster_arn)1020 list(response["TaggedResources"]).should.have.length_of(num_tags)1021@mock_redshift1022def test_delete_tags():1023 client = boto3.client("redshift", region_name="us-east-1")1024 cluster_identifier = "cluster-id"1025 cluster_arn = "arn:aws:redshift:us-east-1:{}:" "cluster:{}".format(1026 ACCOUNT_ID, cluster_identifier1027 )1028 tag_key = "test-tag-key"1029 tag_value = "test-tag-value"1030 tags = []1031 for i in range(1, 2):1032 tag = {"Key": "{}-{}".format(tag_key, i), "Value": "{}-{}".format(tag_value, i)}1033 tags.append(tag)1034 client.create_cluster(1035 DBName="test-db",1036 ClusterIdentifier=cluster_identifier,1037 ClusterType="single-node",1038 NodeType="ds2.xlarge",1039 MasterUsername="username",1040 MasterUserPassword="password",1041 Tags=tags,1042 )1043 client.delete_tags(1044 ResourceName=cluster_arn,1045 TagKeys=[tag["Key"] for tag in tags if tag["Key"] != "{}-1".format(tag_key)],1046 )1047 response = client.describe_clusters(ClusterIdentifier=cluster_identifier)1048 cluster = response["Clusters"][0]1049 list(cluster["Tags"]).should.have.length_of(1)1050 response = client.describe_tags(ResourceName=cluster_arn)1051 list(response["TaggedResources"]).should.have.length_of(1)1052@mock_ec21053@mock_redshift1054def test_describe_tags_all_resource_types():1055 ec2 = boto3.resource("ec2", region_name="us-east-1")1056 vpc = ec2.create_vpc(CidrBlock="10.0.0.0/16")1057 subnet = ec2.create_subnet(VpcId=vpc.id, CidrBlock="10.0.0.0/24")1058 client = boto3.client("redshift", region_name="us-east-1")1059 response = client.describe_tags()1060 list(response["TaggedResources"]).should.have.length_of(0)1061 client.create_cluster_subnet_group(1062 ClusterSubnetGroupName="my_subnet_group",1063 Description="This is my subnet group",1064 SubnetIds=[subnet.id],1065 Tags=[{"Key": "tag_key", "Value": "tag_value"}],1066 )1067 client.create_cluster_security_group(1068 ClusterSecurityGroupName="security_group1",1069 Description="This is my security group",1070 Tags=[{"Key": "tag_key", "Value": "tag_value"}],1071 )1072 client.create_cluster(1073 DBName="test",1074 ClusterIdentifier="my_cluster",1075 ClusterType="single-node",1076 NodeType="ds2.xlarge",1077 MasterUsername="user",1078 MasterUserPassword="password",1079 Tags=[{"Key": "tag_key", "Value": "tag_value"}],1080 )1081 client.create_cluster_snapshot(1082 SnapshotIdentifier="my_snapshot",1083 ClusterIdentifier="my_cluster",1084 Tags=[{"Key": "tag_key", "Value": "tag_value"}],1085 )1086 client.create_cluster_parameter_group(1087 ParameterGroupName="my_parameter_group",1088 ParameterGroupFamily="redshift-1.0",1089 Description="This is my parameter group",1090 Tags=[{"Key": "tag_key", "Value": "tag_value"}],1091 )1092 response = client.describe_tags()1093 expected_types = [1094 "cluster",1095 "parametergroup",1096 "securitygroup",1097 "snapshot",1098 "subnetgroup",1099 ]1100 tagged_resources = response["TaggedResources"]...
test_mocked_redshift_infra.py
Source:test_mocked_redshift_infra.py
...342 @classmethod343 @mock_redshift_deprecated344 def test_create_cluster_with_parameter_group(cls):345 conn = boto.connect_redshift()346 conn.create_cluster_parameter_group(347 "my_parameter_group", "redshift-1.0", "This is my parameter group"348 )349 conn.create_cluster(350 "my_cluster",351 node_type="dw.hs1.xlarge",352 master_username="username",353 master_user_password="password",354 cluster_parameter_group_name="my_parameter_group",355 )356 cluster_response = conn.describe_clusters("my_cluster")357 cluster = cluster_response["DescribeClustersResponse"]["DescribeClustersResult"][358 "Clusters"359 ][0]360 cluster["ClusterParameterGroups"][0]["ParameterGroupName"].should.equal(361 "my_parameter_group"362 )363 @classmethod364 @mock_redshift_deprecated365 def test_describe_non_existent_cluster(cls):366 conn = boto.redshift.connect_to_region("us-east-1")367 conn.describe_clusters.when.called_with("not-a-cluster").should.throw(368 ClusterNotFound369 )370 @classmethod371 @mock_redshift_deprecated372 def test_delete_cluster(cls):373 conn = boto.connect_redshift()374 cluster_identifier = "my_cluster"375 snapshot_identifier = "my_snapshot"376 conn.create_cluster(377 cluster_identifier,378 node_type="single-node",379 master_username="username",380 master_user_password="password",381 )382 conn.delete_cluster.when.called_with(cluster_identifier, False).should.throw(383 AttributeError384 )385 clusters = conn.describe_clusters()["DescribeClustersResponse"][386 "DescribeClustersResult"387 ]["Clusters"]388 list(clusters).should.have.length_of(1)389 conn.delete_cluster(390 cluster_identifier=cluster_identifier,391 skip_final_cluster_snapshot=False,392 final_cluster_snapshot_identifier=snapshot_identifier,393 )394 clusters = conn.describe_clusters()["DescribeClustersResponse"][395 "DescribeClustersResult"396 ]["Clusters"]397 list(clusters).should.have.length_of(0)398 snapshots = conn.describe_cluster_snapshots()["DescribeClusterSnapshotsResponse"][399 "DescribeClusterSnapshotsResult"400 ]["Snapshots"]401 list(snapshots).should.have.length_of(1)402 assert snapshot_identifier in snapshots[0]["SnapshotIdentifier"]403 # Delete invalid id404 conn.delete_cluster.when.called_with("not-a-cluster").should.throw(ClusterNotFound)405 @classmethod406 @mock_redshift407 def test_modify_cluster_vpc_routing(cls):408 iam_roles_arn = ["arn:aws:iam:::role/my-iam-role"]409 client = boto3.client("redshift", region_name="us-east-1")410 cluster_identifier = "my_cluster"411 client.create_cluster(412 ClusterIdentifier=cluster_identifier,413 NodeType="single-node",414 MasterUsername="username",415 MasterUserPassword="password",416 IamRoles=iam_roles_arn,417 )418 cluster_response = client.describe_clusters(ClusterIdentifier=cluster_identifier)419 cluster = cluster_response["Clusters"][0]420 cluster["EnhancedVpcRouting"].should.equal(False)421 client.create_cluster_security_group(422 ClusterSecurityGroupName="security_group", Description="security_group"423 )424 client.create_cluster_parameter_group(425 ParameterGroupName="my_parameter_group",426 ParameterGroupFamily="redshift-1.0",427 Description="my_parameter_group",428 )429 client.modify_cluster(430 ClusterIdentifier=cluster_identifier,431 ClusterType="multi-node",432 NodeType="ds2.8xlarge",433 NumberOfNodes=3,434 ClusterSecurityGroups=["security_group"],435 MasterUserPassword="new_password",436 ClusterParameterGroupName="my_parameter_group",437 AutomatedSnapshotRetentionPeriod=7,438 PreferredMaintenanceWindow="Tue:03:00-Tue:11:00",439 AllowVersionUpgrade=False,440 NewClusterIdentifier=cluster_identifier,441 EnhancedVpcRouting=True,442 )443 cluster_response = client.describe_clusters(ClusterIdentifier=cluster_identifier)444 cluster = cluster_response["Clusters"][0]445 cluster["ClusterIdentifier"].should.equal(cluster_identifier)446 cluster["NodeType"].should.equal("ds2.8xlarge")447 cluster["PreferredMaintenanceWindow"].should.equal("Tue:03:00-Tue:11:00")448 cluster["AutomatedSnapshotRetentionPeriod"].should.equal(7)449 cluster["AllowVersionUpgrade"].should.equal(False)450 # This one should remain unmodified.451 cluster["NumberOfNodes"].should.equal(3)452 cluster["EnhancedVpcRouting"].should.equal(True)453 @classmethod454 @mock_redshift_deprecated455 def test_modify_cluster(cls):456 conn = boto.connect_redshift()457 cluster_identifier = "my_cluster"458 conn.create_cluster_security_group("security_group", "This is my security group")459 conn.create_cluster_parameter_group(460 "my_parameter_group", "redshift-1.0", "This is my parameter group"461 )462 conn.create_cluster(463 cluster_identifier,464 node_type="single-node",465 master_username="username",466 master_user_password="password",467 )468 cluster_response = conn.describe_clusters(cluster_identifier)469 cluster = cluster_response["DescribeClustersResponse"]["DescribeClustersResult"][470 "Clusters"471 ][0]472 cluster["EnhancedVpcRouting"].should.equal(False)473 conn.modify_cluster(474 cluster_identifier,475 cluster_type="multi-node",476 node_type="dw.hs1.xlarge",477 cluster_security_groups="security_group",478 master_user_password="new_password",479 cluster_parameter_group_name="my_parameter_group",480 automated_snapshot_retention_period=7,481 preferred_maintenance_window="Tue:03:00-Tue:11:00",482 allow_version_upgrade=False,483 new_cluster_identifier=cluster_identifier,484 )485 cluster_response = conn.describe_clusters(cluster_identifier)486 cluster = cluster_response["DescribeClustersResponse"]["DescribeClustersResult"][487 "Clusters"488 ][0]489 cluster["ClusterIdentifier"].should.equal(cluster_identifier)490 cluster["NodeType"].should.equal("dw.hs1.xlarge")491 cluster["ClusterSecurityGroups"][0]["ClusterSecurityGroupName"].should.equal(492 "security_group"493 )494 cluster["PreferredMaintenanceWindow"].should.equal("Tue:03:00-Tue:11:00")495 cluster["ClusterParameterGroups"][0]["ParameterGroupName"].should.equal(496 "my_parameter_group"497 )498 cluster["AutomatedSnapshotRetentionPeriod"].should.equal(7)499 cluster["AllowVersionUpgrade"].should.equal(False)500 # This one should remain unmodified.501 cluster["NumberOfNodes"].should.equal(1)502 @classmethod503 @mock_redshift504 @mock_ec2505 def test_create_cluster_subnet_group(cls):506 ec2 = boto3.resource("ec2", region_name="us-east-1")507 vpc = ec2.create_vpc(CidrBlock="10.0.0.0/16")508 subnet1 = ec2.create_subnet(VpcId=vpc.id, CidrBlock="10.0.0.0/24")509 subnet2 = ec2.create_subnet(VpcId=vpc.id, CidrBlock="10.0.1.0/24")510 client = boto3.client("redshift", region_name="us-east-1")511 client.create_cluster_subnet_group(512 ClusterSubnetGroupName="my_subnet_group",513 Description="This is my subnet group",514 SubnetIds=[subnet1.id, subnet2.id],515 )516 subnets_response = client.describe_cluster_subnet_groups(517 ClusterSubnetGroupName="my_subnet_group"518 )519 my_subnet = subnets_response["ClusterSubnetGroups"][0]520 my_subnet["ClusterSubnetGroupName"].should.equal("my_subnet_group")521 my_subnet["Description"].should.equal("This is my subnet group")522 subnet_ids = [subnet["SubnetIdentifier"] for subnet in my_subnet["Subnets"]]523 set(subnet_ids).should.equal(set([subnet1.id, subnet2.id]))524 @classmethod525 @mock_redshift_deprecated526 @mock_ec2_deprecated527 def test_create_invalid_cluster_subnet_group(cls):528 redshift_conn = boto.connect_redshift()529 redshift_conn.create_cluster_subnet_group.when.called_with(530 "my_subnet", "This is my subnet group", subnet_ids=["subnet-1234"]531 ).should.throw(InvalidSubnet)532 @classmethod533 @mock_redshift_deprecated534 def test_describe_non_existent_subnet_group(cls):535 conn = boto.redshift.connect_to_region("us-east-1")536 conn.describe_cluster_subnet_groups.when.called_with(537 "not-a-subnet-group"538 ).should.throw(ClusterSubnetGroupNotFound)539 @classmethod540 @mock_redshift541 @mock_ec2542 def test_delete_cluster_subnet_group(cls):543 ec2 = boto3.resource("ec2", region_name="us-east-1")544 vpc = ec2.create_vpc(CidrBlock="10.0.0.0/16")545 subnet = ec2.create_subnet(VpcId=vpc.id, CidrBlock="10.0.0.0/24")546 client = boto3.client("redshift", region_name="us-east-1")547 client.create_cluster_subnet_group(548 ClusterSubnetGroupName="my_subnet_group",549 Description="This is my subnet group",550 SubnetIds=[subnet.id],551 )552 subnets_response = client.describe_cluster_subnet_groups()553 subnets = subnets_response["ClusterSubnetGroups"]554 subnets.should.have.length_of(1)555 client.delete_cluster_subnet_group(ClusterSubnetGroupName="my_subnet_group")556 subnets_response = client.describe_cluster_subnet_groups()557 subnets = subnets_response["ClusterSubnetGroups"]558 subnets.should.have.length_of(0)559 # Delete invalid id560 client.delete_cluster_subnet_group.when.called_with(561 ClusterSubnetGroupName="not-a-subnet-group"562 ).should.throw(ClientError)563 @classmethod564 @mock_redshift_deprecated565 def test_create_cluster_security_group(cls):566 conn = boto.connect_redshift()567 conn.create_cluster_security_group("my_security_group", "This is my security group")568 groups_response = conn.describe_cluster_security_groups("my_security_group")569 my_group = groups_response["DescribeClusterSecurityGroupsResponse"][570 "DescribeClusterSecurityGroupsResult"571 ]["ClusterSecurityGroups"][0]572 my_group["ClusterSecurityGroupName"].should.equal("my_security_group")573 my_group["Description"].should.equal("This is my security group")574 list(my_group["IPRanges"]).should.equal([])575 @classmethod576 @mock_redshift_deprecated577 def test_describe_non_existent_security_group(cls):578 conn = boto.redshift.connect_to_region("us-east-1")579 conn.describe_cluster_security_groups.when.called_with(580 "not-a-security-group"581 ).should.throw(ClusterSecurityGroupNotFound)582 @classmethod583 @mock_redshift_deprecated584 def test_delete_cluster_security_group(cls):585 conn = boto.connect_redshift()586 conn.create_cluster_security_group("my_security_group", "This is my security group")587 groups_response = conn.describe_cluster_security_groups()588 groups = groups_response["DescribeClusterSecurityGroupsResponse"][589 "DescribeClusterSecurityGroupsResult"590 ]["ClusterSecurityGroups"]591 groups.should.have.length_of(2) # The default group already exists592 conn.delete_cluster_security_group("my_security_group")593 groups_response = conn.describe_cluster_security_groups()594 groups = groups_response["DescribeClusterSecurityGroupsResponse"][595 "DescribeClusterSecurityGroupsResult"596 ]["ClusterSecurityGroups"]597 groups.should.have.length_of(1)598 # Delete invalid id599 conn.delete_cluster_security_group.when.called_with(600 "not-a-security-group"601 ).should.throw(ClusterSecurityGroupNotFound)602 @classmethod603 @mock_redshift_deprecated604 def test_create_cluster_parameter_group(cls):605 conn = boto.connect_redshift()606 conn.create_cluster_parameter_group(607 "my_parameter_group", "redshift-1.0", "This is my parameter group"608 )609 groups_response = conn.describe_cluster_parameter_groups("my_parameter_group")610 my_group = groups_response["DescribeClusterParameterGroupsResponse"][611 "DescribeClusterParameterGroupsResult"612 ]["ParameterGroups"][0]613 my_group["ParameterGroupName"].should.equal("my_parameter_group")614 my_group["ParameterGroupFamily"].should.equal("redshift-1.0")615 my_group["Description"].should.equal("This is my parameter group")616 @classmethod617 @mock_redshift_deprecated618 def test_describe_non_existent_parameter_group(cls):619 conn = boto.redshift.connect_to_region("us-east-1")620 conn.describe_cluster_parameter_groups.when.called_with(621 "not-a-parameter-group"622 ).should.throw(ClusterParameterGroupNotFound)623 @classmethod624 @mock_redshift_deprecated625 def test_delete_cluster_parameter_group(cls):626 conn = boto.connect_redshift()627 conn.create_cluster_parameter_group(628 "my_parameter_group", "redshift-1.0", "This is my parameter group"629 )630 groups_response = conn.describe_cluster_parameter_groups()631 groups = groups_response["DescribeClusterParameterGroupsResponse"][632 "DescribeClusterParameterGroupsResult"633 ]["ParameterGroups"]634 groups.should.have.length_of(2) # The default group already exists635 conn.delete_cluster_parameter_group("my_parameter_group")636 groups_response = conn.describe_cluster_parameter_groups()637 groups = groups_response["DescribeClusterParameterGroupsResponse"][638 "DescribeClusterParameterGroupsResult"639 ]["ParameterGroups"]640 groups.should.have.length_of(1)641 # Delete invalid id642 conn.delete_cluster_parameter_group.when.called_with(643 "not-a-parameter-group"644 ).should.throw(ClusterParameterGroupNotFound)645 @classmethod646 @mock_redshift647 def test_create_cluster_snapshot_of_non_existent_cluster(cls):648 client = boto3.client("redshift", region_name="us-east-1")649 cluster_identifier = "non-existent-cluster-id"650 client.create_cluster_snapshot.when.called_with(651 SnapshotIdentifier="snapshot-id", ClusterIdentifier=cluster_identifier652 ).should.throw(ClientError, "Cluster {} not found.".format(cluster_identifier))653 @classmethod654 @mock_redshift655 def test_create_cluster_snapshot(cls):656 client = boto3.client("redshift", region_name="us-east-1")657 cluster_identifier = "my_cluster"658 snapshot_identifier = "my_snapshot"659 cluster_response = client.create_cluster(660 DBName="test-db",661 ClusterIdentifier=cluster_identifier,662 ClusterType="single-node",663 NodeType="ds2.xlarge",664 MasterUsername="username",665 MasterUserPassword="password",666 EnhancedVpcRouting=True,667 )668 cluster_response["Cluster"]["NodeType"].should.equal("ds2.xlarge")669 snapshot_response = client.create_cluster_snapshot(670 SnapshotIdentifier=snapshot_identifier,671 ClusterIdentifier=cluster_identifier,672 Tags=[{"Key": "test-tag-key", "Value": "test-tag-value"}],673 )674 snapshot = snapshot_response["Snapshot"]675 snapshot["SnapshotIdentifier"].should.equal(snapshot_identifier)676 snapshot["ClusterIdentifier"].should.equal(cluster_identifier)677 snapshot["NumberOfNodes"].should.equal(1)678 snapshot["NodeType"].should.equal("ds2.xlarge")679 snapshot["MasterUsername"].should.equal("username")680 @classmethod681 @mock_redshift682 def test_describe_cluster_snapshots(cls):683 client = boto3.client("redshift", region_name="us-east-1")684 cluster_identifier = "my_cluster"685 snapshot_identifier_1 = "my_snapshot_1"686 snapshot_identifier_2 = "my_snapshot_2"687 client.create_cluster(688 DBName="test-db",689 ClusterIdentifier=cluster_identifier,690 ClusterType="single-node",691 NodeType="ds2.xlarge",692 MasterUsername="username",693 MasterUserPassword="password",694 )695 client.create_cluster_snapshot(696 SnapshotIdentifier=snapshot_identifier_1, ClusterIdentifier=cluster_identifier697 )698 client.create_cluster_snapshot(699 SnapshotIdentifier=snapshot_identifier_2, ClusterIdentifier=cluster_identifier700 )701 resp_snap_1 = client.describe_cluster_snapshots(702 SnapshotIdentifier=snapshot_identifier_1703 )704 snapshot_1 = resp_snap_1["Snapshots"][0]705 snapshot_1["SnapshotIdentifier"].should.equal(snapshot_identifier_1)706 snapshot_1["ClusterIdentifier"].should.equal(cluster_identifier)707 snapshot_1["NumberOfNodes"].should.equal(1)708 snapshot_1["NodeType"].should.equal("ds2.xlarge")709 snapshot_1["MasterUsername"].should.equal("username")710 resp_snap_2 = client.describe_cluster_snapshots(711 SnapshotIdentifier=snapshot_identifier_2712 )713 snapshot_2 = resp_snap_2["Snapshots"][0]714 snapshot_2["SnapshotIdentifier"].should.equal(snapshot_identifier_2)715 snapshot_2["ClusterIdentifier"].should.equal(cluster_identifier)716 snapshot_2["NumberOfNodes"].should.equal(1)717 snapshot_2["NodeType"].should.equal("ds2.xlarge")718 snapshot_2["MasterUsername"].should.equal("username")719 resp_clust = client.describe_cluster_snapshots(ClusterIdentifier=cluster_identifier)720 resp_clust["Snapshots"][0].should.equal(resp_snap_1["Snapshots"][0])721 resp_clust["Snapshots"][1].should.equal(resp_snap_2["Snapshots"][0])722 @classmethod723 @mock_redshift724 def test_describe_cluster_snapshots_not_found_error(cls):725 client = boto3.client("redshift", region_name="us-east-1")726 cluster_identifier = "my_cluster"727 snapshot_identifier = "my_snapshot"728 client.describe_cluster_snapshots.when.called_with(729 ClusterIdentifier=cluster_identifier730 ).should.throw(ClientError, "Cluster {} not found.".format(cluster_identifier))731 client.describe_cluster_snapshots.when.called_with(732 SnapshotIdentifier=snapshot_identifier733 ).should.throw(ClientError, "Snapshot {} not found.".format(snapshot_identifier))734 @classmethod735 @mock_redshift736 def test_delete_cluster_snapshot(cls):737 client = boto3.client("redshift", region_name="us-east-1")738 cluster_identifier = "my_cluster"739 snapshot_identifier = "my_snapshot"740 client.create_cluster(741 ClusterIdentifier=cluster_identifier,742 ClusterType="single-node",743 NodeType="ds2.xlarge",744 MasterUsername="username",745 MasterUserPassword="password",746 )747 client.create_cluster_snapshot(748 SnapshotIdentifier=snapshot_identifier, ClusterIdentifier=cluster_identifier749 )750 snapshots = client.describe_cluster_snapshots()["Snapshots"]751 list(snapshots).should.have.length_of(1)752 client.delete_cluster_snapshot(SnapshotIdentifier=snapshot_identifier)["Snapshot"][753 "Status"754 ].should.equal("deleted")755 snapshots = client.describe_cluster_snapshots()["Snapshots"]756 list(snapshots).should.have.length_of(0)757 # Delete invalid id758 client.delete_cluster_snapshot.when.called_with(759 SnapshotIdentifier="not-a-snapshot"760 ).should.throw(ClientError)761 @classmethod762 @mock_redshift763 def test_cluster_snapshot_already_exists(cls):764 client = boto3.client("redshift", region_name="us-east-1")765 cluster_identifier = "my_cluster"766 snapshot_identifier = "my_snapshot"767 client.create_cluster(768 DBName="test-db",769 ClusterIdentifier=cluster_identifier,770 ClusterType="single-node",771 NodeType="ds2.xlarge",772 MasterUsername="username",773 MasterUserPassword="password",774 )775 client.create_cluster_snapshot(776 SnapshotIdentifier=snapshot_identifier, ClusterIdentifier=cluster_identifier777 )778 client.create_cluster_snapshot.when.called_with(779 SnapshotIdentifier=snapshot_identifier, ClusterIdentifier=cluster_identifier780 ).should.throw(ClientError)781 @classmethod782 @mock_redshift783 def test_create_cluster_from_snapshot(cls):784 client = boto3.client("redshift", region_name="us-east-1")785 original_cluster_identifier = "original-cluster"786 original_snapshot_identifier = "original-snapshot"787 new_cluster_identifier = "new-cluster"788 client.create_cluster(789 ClusterIdentifier=original_cluster_identifier,790 ClusterType="single-node",791 NodeType="ds2.xlarge",792 MasterUsername="username",793 MasterUserPassword="password",794 EnhancedVpcRouting=True,795 )796 client.create_cluster_snapshot(797 SnapshotIdentifier=original_snapshot_identifier,798 ClusterIdentifier=original_cluster_identifier,799 )800 response = client.restore_from_cluster_snapshot(801 ClusterIdentifier=new_cluster_identifier,802 SnapshotIdentifier=original_snapshot_identifier,803 Port=1234,804 )805 response["Cluster"]["ClusterStatus"].should.equal("creating")806 response = client.describe_clusters(ClusterIdentifier=new_cluster_identifier)807 new_cluster = response["Clusters"][0]808 new_cluster["NodeType"].should.equal("ds2.xlarge")809 new_cluster["MasterUsername"].should.equal("username")810 new_cluster["Endpoint"]["Port"].should.equal(1234)811 new_cluster["EnhancedVpcRouting"].should.equal(True)812 @classmethod813 @mock_redshift814 def test_create_cluster_from_snapshot_with_waiter(cls):815 client = boto3.client("redshift", region_name="us-east-1")816 original_cluster_identifier = "original-cluster"817 original_snapshot_identifier = "original-snapshot"818 new_cluster_identifier = "new-cluster"819 client.create_cluster(820 ClusterIdentifier=original_cluster_identifier,821 ClusterType="single-node",822 NodeType="ds2.xlarge",823 MasterUsername="username",824 MasterUserPassword="password",825 EnhancedVpcRouting=True,826 )827 client.create_cluster_snapshot(828 SnapshotIdentifier=original_snapshot_identifier,829 ClusterIdentifier=original_cluster_identifier,830 )831 response = client.restore_from_cluster_snapshot(832 ClusterIdentifier=new_cluster_identifier,833 SnapshotIdentifier=original_snapshot_identifier,834 Port=1234,835 )836 response["Cluster"]["ClusterStatus"].should.equal("creating")837 client.get_waiter("cluster_restored").wait(838 ClusterIdentifier=new_cluster_identifier,839 WaiterConfig={"Delay": 1, "MaxAttempts": 2},840 )841 response = client.describe_clusters(ClusterIdentifier=new_cluster_identifier)842 new_cluster = response["Clusters"][0]843 new_cluster["NodeType"].should.equal("ds2.xlarge")844 new_cluster["MasterUsername"].should.equal("username")845 new_cluster["EnhancedVpcRouting"].should.equal(True)846 new_cluster["Endpoint"]["Port"].should.equal(1234)847 @classmethod848 @mock_redshift849 def test_create_cluster_from_non_existent_snapshot(cls):850 client = boto3.client("redshift", region_name="us-east-1")851 client.restore_from_cluster_snapshot.when.called_with(852 ClusterIdentifier="cluster-id", SnapshotIdentifier="non-existent-snapshot"853 ).should.throw(ClientError, "Snapshot non-existent-snapshot not found.")854 @classmethod855 @mock_redshift856 def test_create_cluster_status_update(cls):857 client = boto3.client("redshift", region_name="us-east-1")858 cluster_identifier = "test-cluster"859 response = client.create_cluster(860 ClusterIdentifier=cluster_identifier,861 ClusterType="single-node",862 NodeType="ds2.xlarge",863 MasterUsername="username",864 MasterUserPassword="password",865 )866 response["Cluster"]["ClusterStatus"].should.equal("creating")867 response = client.describe_clusters(ClusterIdentifier=cluster_identifier)868 response["Clusters"][0]["ClusterStatus"].should.equal("available")869 @classmethod870 @mock_redshift871 def test_describe_tags_with_resource_type(cls):872 client = boto3.client("redshift", region_name="us-east-1")873 cluster_identifier = "my_cluster"874 cluster_arn = "arn:aws:redshift:us-east-1:{}:" "cluster:{}".format(875 ACCOUNT_ID, cluster_identifier876 )877 snapshot_identifier = "my_snapshot"878 snapshot_arn = "arn:aws:redshift:us-east-1:{}:" "snapshot:{}/{}".format(879 ACCOUNT_ID, cluster_identifier, snapshot_identifier880 )881 tag_key = "test-tag-key"882 tag_value = "test-tag-value"883 client.create_cluster(884 DBName="test-db",885 ClusterIdentifier=cluster_identifier,886 ClusterType="single-node",887 NodeType="ds2.xlarge",888 MasterUsername="username",889 MasterUserPassword="password",890 Tags=[{"Key": tag_key, "Value": tag_value}],891 )892 tags_response = client.describe_tags(ResourceType="cluster")893 tagged_resources = tags_response["TaggedResources"]894 list(tagged_resources).should.have.length_of(1)895 tagged_resources[0]["ResourceType"].should.equal("cluster")896 tagged_resources[0]["ResourceName"].should.equal(cluster_arn)897 tag = tagged_resources[0]["Tag"]898 tag["Key"].should.equal(tag_key)899 tag["Value"].should.equal(tag_value)900 client.create_cluster_snapshot(901 SnapshotIdentifier=snapshot_identifier,902 ClusterIdentifier=cluster_identifier,903 Tags=[{"Key": tag_key, "Value": tag_value}],904 )905 tags_response = client.describe_tags(ResourceType="snapshot")906 tagged_resources = tags_response["TaggedResources"]907 list(tagged_resources).should.have.length_of(1)908 tagged_resources[0]["ResourceType"].should.equal("snapshot")909 tagged_resources[0]["ResourceName"].should.equal(snapshot_arn)910 tag = tagged_resources[0]["Tag"]911 tag["Key"].should.equal(tag_key)912 tag["Value"].should.equal(tag_value)913 @classmethod914 @mock_redshift915 def test_describe_tags_cannot_specify_resource_type_and_resource_name(cls):916 client = boto3.client("redshift", region_name="us-east-1")917 resource_name = "arn:aws:redshift:us-east-1:{}:cluster:cluster-id".format(918 ACCOUNT_ID919 )920 resource_type = "cluster"921 client.describe_tags.when.called_with(922 ResourceName=resource_name, ResourceType=resource_type923 ).should.throw(ClientError, "using either an ARN or a resource type")924 @classmethod925 @mock_redshift926 def test_describe_tags_with_resource_name(cls):927 client = boto3.client("redshift", region_name="us-east-1")928 cluster_identifier = "cluster-id"929 cluster_arn = "arn:aws:redshift:us-east-1:{}:" "cluster:{}".format(930 ACCOUNT_ID, cluster_identifier931 )932 snapshot_identifier = "snapshot-id"933 snapshot_arn = "arn:aws:redshift:us-east-1:{}:" "snapshot:{}/{}".format(934 ACCOUNT_ID, cluster_identifier, snapshot_identifier935 )936 tag_key = "test-tag-key"937 tag_value = "test-tag-value"938 client.create_cluster(939 DBName="test-db",940 ClusterIdentifier=cluster_identifier,941 ClusterType="single-node",942 NodeType="ds2.xlarge",943 MasterUsername="username",944 MasterUserPassword="password",945 Tags=[{"Key": tag_key, "Value": tag_value}],946 )947 tags_response = client.describe_tags(ResourceName=cluster_arn)948 tagged_resources = tags_response["TaggedResources"]949 list(tagged_resources).should.have.length_of(1)950 tagged_resources[0]["ResourceType"].should.equal("cluster")951 tagged_resources[0]["ResourceName"].should.equal(cluster_arn)952 tag = tagged_resources[0]["Tag"]953 tag["Key"].should.equal(tag_key)954 tag["Value"].should.equal(tag_value)955 client.create_cluster_snapshot(956 SnapshotIdentifier=snapshot_identifier,957 ClusterIdentifier=cluster_identifier,958 Tags=[{"Key": tag_key, "Value": tag_value}],959 )960 tags_response = client.describe_tags(ResourceName=snapshot_arn)961 tagged_resources = tags_response["TaggedResources"]962 list(tagged_resources).should.have.length_of(1)963 tagged_resources[0]["ResourceType"].should.equal("snapshot")964 tagged_resources[0]["ResourceName"].should.equal(snapshot_arn)965 tag = tagged_resources[0]["Tag"]966 tag["Key"].should.equal(tag_key)967 tag["Value"].should.equal(tag_value)968 @classmethod969 @mock_redshift970 def test_create_tags(cls):971 client = boto3.client("redshift", region_name="us-east-1")972 cluster_identifier = "cluster-id"973 cluster_arn = "arn:aws:redshift:us-east-1:{}:" "cluster:{}".format(974 ACCOUNT_ID, cluster_identifier975 )976 tag_key = "test-tag-key"977 tag_value = "test-tag-value"978 num_tags = 5979 tags = []980 for i in range(0, num_tags):981 tag = {"Key": "{}-{}".format(tag_key, i), "Value": "{}-{}".format(tag_value, i)}982 tags.append(tag)983 client.create_cluster(984 DBName="test-db",985 ClusterIdentifier=cluster_identifier,986 ClusterType="single-node",987 NodeType="ds2.xlarge",988 MasterUsername="username",989 MasterUserPassword="password",990 )991 client.create_tags(ResourceName=cluster_arn, Tags=tags)992 response = client.describe_clusters(ClusterIdentifier=cluster_identifier)993 cluster = response["Clusters"][0]994 list(cluster["Tags"]).should.have.length_of(num_tags)995 response = client.describe_tags(ResourceName=cluster_arn)996 list(response["TaggedResources"]).should.have.length_of(num_tags)997 @classmethod998 @mock_redshift999 def test_delete_tags(cls):1000 client = boto3.client("redshift", region_name="us-east-1")1001 cluster_identifier = "cluster-id"1002 cluster_arn = "arn:aws:redshift:us-east-1:{}:" "cluster:{}".format(1003 ACCOUNT_ID, cluster_identifier1004 )1005 tag_key = "test-tag-key"1006 tag_value = "test-tag-value"1007 tags = []1008 for i in range(1, 2):1009 tag = {"Key": "{}-{}".format(tag_key, i), "Value": "{}-{}".format(tag_value, i)}1010 tags.append(tag)1011 client.create_cluster(1012 DBName="test-db",1013 ClusterIdentifier=cluster_identifier,1014 ClusterType="single-node",1015 NodeType="ds2.xlarge",1016 MasterUsername="username",1017 MasterUserPassword="password",1018 Tags=tags,1019 )1020 client.delete_tags(1021 ResourceName=cluster_arn,1022 TagKeys=[tag["Key"] for tag in tags if tag["Key"] != "{}-1".format(tag_key)],1023 )1024 response = client.describe_clusters(ClusterIdentifier=cluster_identifier)1025 cluster = response["Clusters"][0]1026 list(cluster["Tags"]).should.have.length_of(1)1027 response = client.describe_tags(ResourceName=cluster_arn)1028 list(response["TaggedResources"]).should.have.length_of(1)1029 @classmethod1030 @mock_ec21031 @mock_redshift1032 def test_describe_tags_all_resource_types(cls):1033 ec2 = boto3.resource("ec2", region_name="us-east-1")1034 vpc = ec2.create_vpc(CidrBlock="10.0.0.0/16")1035 subnet = ec2.create_subnet(VpcId=vpc.id, CidrBlock="10.0.0.0/24")1036 client = boto3.client("redshift", region_name="us-east-1")1037 response = client.describe_tags()1038 list(response["TaggedResources"]).should.have.length_of(0)1039 client.create_cluster_subnet_group(1040 ClusterSubnetGroupName="my_subnet_group",1041 Description="This is my subnet group",1042 SubnetIds=[subnet.id],1043 Tags=[{"Key": "tag_key", "Value": "tag_value"}],1044 )1045 client.create_cluster_security_group(1046 ClusterSecurityGroupName="security_group1",1047 Description="This is my security group",1048 Tags=[{"Key": "tag_key", "Value": "tag_value"}],1049 )1050 client.create_cluster(1051 DBName="test",1052 ClusterIdentifier="my_cluster",1053 ClusterType="single-node",1054 NodeType="ds2.xlarge",1055 MasterUsername="user",1056 MasterUserPassword="password",1057 Tags=[{"Key": "tag_key", "Value": "tag_value"}],1058 )1059 client.create_cluster_snapshot(1060 SnapshotIdentifier="my_snapshot",1061 ClusterIdentifier="my_cluster",1062 Tags=[{"Key": "tag_key", "Value": "tag_value"}],1063 )1064 client.create_cluster_parameter_group(1065 ParameterGroupName="my_parameter_group",1066 ParameterGroupFamily="redshift-1.0",1067 Description="This is my parameter group",1068 Tags=[{"Key": "tag_key", "Value": "tag_value"}],1069 )1070 response = client.describe_tags()1071 expected_types = [1072 "cluster",1073 "parametergroup",1074 "securitygroup",1075 "snapshot",1076 "subnetgroup",1077 ]1078 tagged_resources = response["TaggedResources"]...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!