diff --git a/moto/redshift/models.py b/moto/redshift/models.py index 6f1a89675..d40ea0871 100644 --- a/moto/redshift/models.py +++ b/moto/redshift/models.py @@ -25,7 +25,6 @@ class Cluster(object): self.master_username = master_username self.master_user_password = master_user_password self.db_name = db_name if db_name else "dev" - self.cluster_security_groups = cluster_security_groups self.vpc_security_group_ids = vpc_security_group_ids self.cluster_subnet_group_name = cluster_subnet_group_name self.cluster_parameter_group_name = cluster_parameter_group_name @@ -38,6 +37,11 @@ class Cluster(object): self.automated_snapshot_retention_period = automated_snapshot_retention_period if automated_snapshot_retention_period else 1 self.preferred_maintenance_window = preferred_maintenance_window if preferred_maintenance_window else "Mon:03:00-Mon:03:30" + if cluster_security_groups: + self.cluster_security_groups = cluster_security_groups + else: + self.cluster_security_groups = ["Default"] + if availability_zone: self.availability_zone = availability_zone else: @@ -140,7 +144,9 @@ class RedshiftBackend(BaseBackend): def __init__(self, ec2_backend): self.clusters = {} self.subnet_groups = {} - self.security_groups = {} + self.security_groups = { + "Default": SecurityGroup("Default", "Default Redshift Security Group") + } self.ec2_backend = ec2_backend def reset(self): diff --git a/tests/test_redshift/test_redshift.py b/tests/test_redshift/test_redshift.py index ba5e30065..881c65504 100644 --- a/tests/test_redshift/test_redshift.py +++ b/tests/test_redshift/test_redshift.py @@ -41,7 +41,7 @@ def test_create_cluster(): cluster['NodeType'].should.equal("dw.hs1.xlarge") cluster['MasterUsername'].should.equal("username") cluster['DBName'].should.equal("my_db") - cluster['ClusterSecurityGroups'].should.equal([]) + cluster['ClusterSecurityGroups'][0]['ClusterSecurityGroupName'].should.equal("Default") cluster['VpcSecurityGroups'].should.equal([]) cluster['ClusterSubnetGroupName'].should.equal(None) cluster['AvailabilityZone'].should.equal("us-east-1d") @@ -94,7 +94,6 @@ def test_default_cluster_attibutes(): cluster = cluster_response['DescribeClustersResponse']['DescribeClustersResult']['Clusters'][0] cluster['DBName'].should.equal("dev") - # cluster['ClusterSecurityGroups'].should.equal([]) # cluster['VpcSecurityGroups'].should.equal([]) cluster['ClusterSubnetGroupName'].should.equal(None) assert "us-east-" in cluster['AvailabilityZone'] @@ -326,13 +325,13 @@ def test_delete_cluster_security_group(): groups_response = conn.describe_cluster_security_groups() groups = groups_response['DescribeClusterSecurityGroupsResponse']['DescribeClusterSecurityGroupsResult']['ClusterSecurityGroups'] - groups.should.have.length_of(1) + groups.should.have.length_of(2) # The default group already exists conn.delete_cluster_security_group("my_security_group") groups_response = conn.describe_cluster_security_groups() groups = groups_response['DescribeClusterSecurityGroupsResponse']['DescribeClusterSecurityGroupsResult']['ClusterSecurityGroups'] - groups.should.have.length_of(0) + groups.should.have.length_of(1) # Delete invalid id conn.delete_cluster_security_group.when.called_with("not-a-security-group").should.throw(ClusterSecurityGroupNotFound)