Route Tables: Added support for associate/disassociate subnets.
This commit is contained in:
parent
68d2db55d4
commit
5d046c76e5
4 changed files with 164 additions and 19 deletions
|
|
@ -77,7 +77,7 @@ def test_route_tables_additional():
|
|||
|
||||
|
||||
@mock_ec2
|
||||
def test_route_tables_filters():
|
||||
def test_route_tables_filters_standard():
|
||||
conn = boto.connect_vpc('the_key', 'the_secret')
|
||||
|
||||
vpc1 = conn.create_vpc("10.0.0.0/16")
|
||||
|
|
@ -114,6 +114,106 @@ def test_route_tables_filters():
|
|||
conn.get_all_route_tables.when.called_with(filters={'not-implemented-filter': 'foobar'}).should.throw(NotImplementedError)
|
||||
|
||||
|
||||
@mock_ec2
|
||||
def test_route_tables_filters_associations():
|
||||
conn = boto.connect_vpc('the_key', 'the_secret')
|
||||
|
||||
vpc = conn.create_vpc("10.0.0.0/16")
|
||||
subnet1 = conn.create_subnet(vpc.id, "10.0.0.0/18")
|
||||
subnet2 = conn.create_subnet(vpc.id, "10.0.1.0/18")
|
||||
subnet3 = conn.create_subnet(vpc.id, "10.0.2.0/18")
|
||||
route_table1 = conn.create_route_table(vpc.id)
|
||||
route_table2 = conn.create_route_table(vpc.id)
|
||||
|
||||
association_id1 = conn.associate_route_table(route_table1.id, subnet1.id)
|
||||
association_id2 = conn.associate_route_table(route_table1.id, subnet2.id)
|
||||
association_id3 = conn.associate_route_table(route_table2.id, subnet3.id)
|
||||
|
||||
all_route_tables = conn.get_all_route_tables()
|
||||
all_route_tables.should.have.length_of(3)
|
||||
|
||||
# Filter by association ID
|
||||
association1_route_tables = conn.get_all_route_tables(filters={'association.route-table-association-id':association_id1})
|
||||
association1_route_tables.should.have.length_of(1)
|
||||
association1_route_tables[0].id.should.equal(route_table1.id)
|
||||
association1_route_tables[0].associations.should.have.length_of(2)
|
||||
|
||||
# Filter by route table ID
|
||||
route_table2_route_tables = conn.get_all_route_tables(filters={'association.route-table-id':route_table2.id})
|
||||
route_table2_route_tables.should.have.length_of(1)
|
||||
route_table2_route_tables[0].id.should.equal(route_table2.id)
|
||||
route_table2_route_tables[0].associations.should.have.length_of(1)
|
||||
|
||||
# Filter by subnet ID
|
||||
subnet_route_tables = conn.get_all_route_tables(filters={'association.subnet-id':subnet1.id})
|
||||
subnet_route_tables.should.have.length_of(1)
|
||||
subnet_route_tables[0].id.should.equal(route_table1.id)
|
||||
association1_route_tables[0].associations.should.have.length_of(2)
|
||||
|
||||
|
||||
@mock_ec2
|
||||
def test_route_table_associations():
|
||||
conn = boto.connect_vpc('the_key', 'the_secret')
|
||||
vpc = conn.create_vpc("10.0.0.0/16")
|
||||
subnet = conn.create_subnet(vpc.id, "10.0.0.0/18")
|
||||
route_table = conn.create_route_table(vpc.id)
|
||||
|
||||
all_route_tables = conn.get_all_route_tables()
|
||||
all_route_tables.should.have.length_of(2)
|
||||
|
||||
# Refresh
|
||||
route_table = conn.get_all_route_tables(route_table.id)[0]
|
||||
print route_table.__dict__
|
||||
route_table.associations.should.have.length_of(0)
|
||||
|
||||
# Associate
|
||||
association_id = conn.associate_route_table(route_table.id, subnet.id)
|
||||
|
||||
# Refresh
|
||||
route_table = conn.get_all_route_tables(route_table.id)[0]
|
||||
route_table.associations.should.have.length_of(1)
|
||||
|
||||
route_table.associations[0].id.should.equal(association_id)
|
||||
route_table.associations[0].main.should.equal(False)
|
||||
route_table.associations[0].route_table_id.should.equal(route_table.id)
|
||||
route_table.associations[0].subnet_id.should.equal(subnet.id)
|
||||
|
||||
# Error: Attempt delete associated route table.
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
conn.delete_route_table(route_table.id)
|
||||
cm.exception.code.should.equal('DependencyViolation')
|
||||
cm.exception.status.should.equal(400)
|
||||
cm.exception.request_id.should_not.be.none
|
||||
|
||||
# Disassociate
|
||||
conn.disassociate_route_table(association_id)
|
||||
|
||||
# Refresh
|
||||
route_table = conn.get_all_route_tables(route_table.id)[0]
|
||||
route_table.associations.should.have.length_of(0)
|
||||
|
||||
# Error: Disassociate with invalid association ID
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
conn.disassociate_route_table(association_id)
|
||||
cm.exception.code.should.equal('InvalidAssociationID.NotFound')
|
||||
cm.exception.status.should.equal(400)
|
||||
cm.exception.request_id.should_not.be.none
|
||||
|
||||
# Error: Associate with invalid subnet ID
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
conn.associate_route_table(route_table.id, "subnet-1234abcd")
|
||||
cm.exception.code.should.equal('InvalidSubnetID.NotFound')
|
||||
cm.exception.status.should.equal(400)
|
||||
cm.exception.request_id.should_not.be.none
|
||||
|
||||
# Error: Associate with invalid route table ID
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
conn.associate_route_table("rtb-1234abcd", subnet.id)
|
||||
cm.exception.code.should.equal('InvalidRouteTableID.NotFound')
|
||||
cm.exception.status.should.equal(400)
|
||||
cm.exception.request_id.should_not.be.none
|
||||
|
||||
|
||||
@mock_ec2
|
||||
def test_routes_additional():
|
||||
conn = boto.connect_vpc('the_key', 'the_secret')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue