From 3afd4e0ea9dd56b4f6a1241acfc58cfd7d31f02d Mon Sep 17 00:00:00 2001 From: Yann Lambret Date: Wed, 2 Mar 2016 00:34:45 +0100 Subject: [PATCH 1/2] Correct a typo in DESCRIBE_ROUTE_TABLES_RESPONSE string (duplicate tagSet) that causes buggy responses --- moto/ec2/responses/route_tables.py | 1 - 1 file changed, 1 deletion(-) diff --git a/moto/ec2/responses/route_tables.py b/moto/ec2/responses/route_tables.py index de0942f7f..04fdf1d25 100644 --- a/moto/ec2/responses/route_tables.py +++ b/moto/ec2/responses/route_tables.py @@ -179,7 +179,6 @@ DESCRIBE_ROUTE_TABLES_RESPONSE = """ {% endfor %} - {% for tag in route_table.get_tags() %} From a06fa082a45367d6b5218c68de4cee653083e865 Mon Sep 17 00:00:00 2001 From: Yann Lambret Date: Wed, 2 Mar 2016 12:15:47 +0100 Subject: [PATCH 2/2] Add two tests for both boto and boto3 as the problem only affects boto3 client --- tests/test_ec2/test_route_tables.py | 40 ++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/tests/test_ec2/test_route_tables.py b/tests/test_ec2/test_route_tables.py index 38ccd09c8..2adec61a6 100644 --- a/tests/test_ec2/test_route_tables.py +++ b/tests/test_ec2/test_route_tables.py @@ -4,6 +4,7 @@ import tests.backport_assert_raises from nose.tools import assert_raises import boto +import boto3 from boto.exception import EC2ResponseError import sure # noqa @@ -288,6 +289,43 @@ def test_route_table_replace_route_table_association(): cm.exception.request_id.should_not.be.none +@mock_ec2 +def test_route_table_get_by_tag(): + conn = boto.connect_vpc('the_key', 'the_secret') + + vpc = conn.create_vpc('10.0.0.0/16') + + route_table = conn.create_route_table(vpc.id) + route_table.add_tag('Name', 'TestRouteTable') + + route_tables = conn.get_all_route_tables(filters={'tag:Name': 'TestRouteTable'}) + + route_tables.should.have.length_of(1) + route_tables[0].vpc_id.should.equal(vpc.id) + route_tables[0].id.should.equal(route_table.id) + route_tables[0].tags.should.have.length_of(1) + route_tables[0].tags['Name'].should.equal('TestRouteTable') + + +@mock_ec2 +def test_route_table_get_by_tag_boto3(): + ec2 = boto3.resource('ec2', region_name='eu-central-1') + + vpc = ec2.create_vpc(CidrBlock='10.0.0.0/16') + + route_table = ec2.create_route_table(VpcId=vpc.id) + route_table.create_tags(Tags=[{'Key': 'Name', 'Value': 'TestRouteTable'}]) + + filters = [{'Name': 'tag:Name', 'Values': ['TestRouteTable']}] + route_tables = list(ec2.route_tables.filter(Filters=filters)) + + route_tables.should.have.length_of(1) + route_tables[0].vpc_id.should.equal(vpc.id) + route_tables[0].id.should.equal(route_table.id) + route_tables[0].tags.should.have.length_of(1) + route_tables[0].tags[0].should.equal({'Key': 'Name', 'Value': 'TestRouteTable'}) + + @mock_ec2 def test_routes_additional(): conn = boto.connect_vpc('the_key', 'the_secret') @@ -459,4 +497,4 @@ def test_network_acl_tagging(): test_route_table = next(na for na in all_route_tables if na.id == route_table.id) test_route_table.tags.should.have.length_of(1) - test_route_table.tags["a key"].should.equal("some value") \ No newline at end of file + test_route_table.tags["a key"].should.equal("some value")