From 5011cd28b65a3edf145374fb6a9bec1a5c92c257 Mon Sep 17 00:00:00 2001 From: Jack Danger Date: Wed, 2 Aug 2017 11:45:27 -0700 Subject: [PATCH] Allow boto3 redshift cluster subnet group creation Boto3 deviates from the AWS docs in the way subnets are described when creating a Redshift cluster subnet group. This entry in botocore nests the SubnetIds under SubnetIdentifier tags: https://github.com/boto/botocore/blob/develop/botocore/data/redshift/2012-12-01/service-2.json#L5423-L5429 referenced here: https://github.com/boto/botocore/blob/develop/botocore/data/redshift/2012-12-01/service-2.json#L2296 And the AWS docs do not nest them that way: https://docs.aws.amazon.com/redshift/latest/APIReference/API_CreateClusterSubnetGroup.html Fixes #1029 --- moto/redshift/responses.py | 4 ++++ tests/test_redshift/test_redshift.py | 31 +++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/moto/redshift/responses.py b/moto/redshift/responses.py index ba28b1343..48f113cf2 100644 --- a/moto/redshift/responses.py +++ b/moto/redshift/responses.py @@ -122,6 +122,10 @@ class RedshiftResponse(BaseResponse): cluster_subnet_group_name = self._get_param('ClusterSubnetGroupName') description = self._get_param('Description') subnet_ids = self._get_multi_param('SubnetIds.member') + # There's a bug in boto3 where the subnet ids are not passed + # according to the AWS documentation + if not subnet_ids: + subnet_ids = self._get_multi_param('SubnetIds.SubnetIdentifier') subnet_group = self.redshift_backend.create_cluster_subnet_group( cluster_subnet_group_name=cluster_subnet_group_name, diff --git a/tests/test_redshift/test_redshift.py b/tests/test_redshift/test_redshift.py index 045e30246..aff3e8bed 100644 --- a/tests/test_redshift/test_redshift.py +++ b/tests/test_redshift/test_redshift.py @@ -11,7 +11,10 @@ from boto.redshift.exceptions import ( ) import sure # noqa -from moto import mock_ec2_deprecated, mock_redshift_deprecated, mock_redshift +from moto import mock_ec2 +from moto import mock_ec2_deprecated +from moto import mock_redshift +from moto import mock_redshift_deprecated @mock_redshift @@ -153,6 +156,32 @@ def test_create_cluster_in_subnet_group(): cluster['ClusterSubnetGroupName'].should.equal('my_subnet_group') +@mock_redshift +@mock_ec2 +def test_create_cluster_in_subnet_group_boto3(): + ec2 = boto3.resource('ec2', region_name='us-east-1') + vpc = ec2.create_vpc(CidrBlock='10.0.0.0/16') + subnet = ec2.create_subnet(VpcId=vpc.id, CidrBlock='10.0.0.0/24') + client = boto3.client('redshift', region_name='us-east-1') + client.create_cluster_subnet_group( + ClusterSubnetGroupName='my_subnet_group', + Description='This is my subnet group', + SubnetIds=[subnet.id] + ) + + client.create_cluster( + ClusterIdentifier="my_cluster", + NodeType="dw.hs1.xlarge", + MasterUsername="username", + MasterUserPassword="password", + ClusterSubnetGroupName='my_subnet_group', + ) + + cluster_response = client.describe_clusters(ClusterIdentifier="my_cluster") + cluster = cluster_response['Clusters'][0] + cluster['ClusterSubnetGroupName'].should.equal('my_subnet_group') + + @mock_redshift_deprecated def test_create_cluster_with_security_group(): conn = boto.redshift.connect_to_region("us-east-1")