From 706868c7f8ae3445a4fa55596f42e3b79aaf1847 Mon Sep 17 00:00:00 2001 From: Paul Cieslar Date: Thu, 23 Jun 2016 11:59:58 +0100 Subject: [PATCH 1/3] describe_security_groups() support for Boto3 Support for list of filters --- moto/ec2/models.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/moto/ec2/models.py b/moto/ec2/models.py index 40277a660..5c7c35e2f 100644 --- a/moto/ec2/models.py +++ b/moto/ec2/models.py @@ -1226,6 +1226,8 @@ class SecurityGroup(TaggedEC2Resource): return True elif is_tag_filter(key): tag_value = self.get_filter_value(key) + if isinstance(filter_value, list): + return any(v in tag_value for v in filter_value) return tag_value in filter_value else: attr_name = to_attr(key) From 35d200c420c50dab37cc308d3ac1e8e2c375bf91 Mon Sep 17 00:00:00 2001 From: Paul Cieslar Date: Thu, 23 Jun 2016 12:03:29 +0100 Subject: [PATCH 2/3] Update to test for security group tagging Support for describe_security_groups() in boto3 --- tests/test_ec2/test_security_groups.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/test_ec2/test_security_groups.py b/tests/test_ec2/test_security_groups.py index 99d8f5595..8bdebf5b3 100644 --- a/tests/test_ec2/test_security_groups.py +++ b/tests/test_ec2/test_security_groups.py @@ -326,3 +326,19 @@ def test_authorize_all_protocols_with_no_port_specification(): sg = conn.get_all_security_groups('test')[0] sg.rules[0].from_port.should.equal(None) sg.rules[0].to_port.should.equal(None) + + +''' +Boto3 +''' + + +@mock_ec2 +def test_security_group_tagging_boto3(): + conn = boto3.client('ec2') + sg = conn.create_security_group(GroupName="test-sg", Description="Test SG") + conn.create_tags(Resources=[sg['GroupId']], Tags=[{'Key': 'Test', 'Value': 'Tag'}]) + describe = conn.describe_security_groups(Filters=[{'Name': 'tag-value', 'Values': ['Tag']}]) + tag = describe["SecurityGroups"][0]['Tags'][0] + tag['Value'].should.equal("Tag") + tag['Key'].should.equal("Test") From 8e6dd137383db43a668de31176a829b407d5ec63 Mon Sep 17 00:00:00 2001 From: Paul Cieslar Date: Thu, 23 Jun 2016 12:38:17 +0100 Subject: [PATCH 3/3] Addition of region to test_security_group_tagging_boto3 --- tests/test_ec2/test_security_groups.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_ec2/test_security_groups.py b/tests/test_ec2/test_security_groups.py index 8bdebf5b3..bacbc3d18 100644 --- a/tests/test_ec2/test_security_groups.py +++ b/tests/test_ec2/test_security_groups.py @@ -335,7 +335,7 @@ Boto3 @mock_ec2 def test_security_group_tagging_boto3(): - conn = boto3.client('ec2') + conn = boto3.client('ec2', region_name='us-east-1') sg = conn.create_security_group(GroupName="test-sg", Description="Test SG") conn.create_tags(Resources=[sg['GroupId']], Tags=[{'Key': 'Test', 'Value': 'Tag'}]) describe = conn.describe_security_groups(Filters=[{'Name': 'tag-value', 'Values': ['Tag']}])