Merge pull request #218 from thedrow/feature/vpc-filters
Added the cider block, dhcp options id and tag filter to the VPC backend
This commit is contained in:
commit
27ef345b64
4 changed files with 128 additions and 9 deletions
|
|
@ -1,6 +1,6 @@
|
|||
from __future__ import unicode_literals
|
||||
# Ensure 'assert_raises' context manager support for Python 2.6
|
||||
import tests.backport_assert_raises
|
||||
#import tests.backport_assert_raises
|
||||
from nose.tools import assert_raises
|
||||
|
||||
import boto
|
||||
|
|
@ -9,6 +9,9 @@ import sure # noqa
|
|||
|
||||
from moto import mock_ec2
|
||||
|
||||
SAMPLE_DOMAIN_NAME = u'example.com'
|
||||
SAMPLE_NAME_SERVERS = [u'10.0.0.6', u'10.0.0.7']
|
||||
|
||||
|
||||
@mock_ec2
|
||||
def test_vpcs():
|
||||
|
|
@ -62,3 +65,67 @@ def test_vpc_tagging():
|
|||
vpc = conn.get_all_vpcs()[0]
|
||||
vpc.tags.should.have.length_of(1)
|
||||
vpc.tags["a key"].should.equal("some value")
|
||||
|
||||
|
||||
@mock_ec2
|
||||
def test_vpc_get_by_id():
|
||||
conn = boto.connect_vpc()
|
||||
vpc1 = conn.create_vpc("10.0.0.0/16")
|
||||
vpc2 = conn.create_vpc("10.0.0.0/16")
|
||||
vpc3 = conn.create_vpc("10.0.0.0/16")
|
||||
|
||||
vpcs = conn.get_all_vpcs(vpc_ids=[vpc1.id, vpc2.id])
|
||||
vpcs.should.have.length_of(2)
|
||||
vpc_ids = tuple(map(lambda v: v.id, vpcs))
|
||||
vpc1.id.should.be.within(vpc_ids)
|
||||
vpc2.id.should.be.within(vpc_ids)
|
||||
|
||||
|
||||
@mock_ec2
|
||||
def test_vpc_get_by_cidr_block():
|
||||
conn = boto.connect_vpc()
|
||||
vpc1 = conn.create_vpc("10.0.0.0/16")
|
||||
vpc2 = conn.create_vpc("10.0.0.0/16")
|
||||
vpc3 = conn.create_vpc("10.0.0.0/24")
|
||||
|
||||
vpcs = conn.get_all_vpcs(filters={'cidr': '10.0.0.0/16'})
|
||||
vpcs.should.have.length_of(2)
|
||||
vpc_ids = tuple(map(lambda v: v.id, vpcs))
|
||||
vpc1.id.should.be.within(vpc_ids)
|
||||
vpc2.id.should.be.within(vpc_ids)
|
||||
|
||||
|
||||
@mock_ec2
|
||||
def test_vpc_get_by_dhcp_options_id():
|
||||
conn = boto.connect_vpc()
|
||||
dhcp_options = conn.create_dhcp_options(SAMPLE_DOMAIN_NAME, SAMPLE_NAME_SERVERS)
|
||||
vpc1 = conn.create_vpc("10.0.0.0/16")
|
||||
vpc2 = conn.create_vpc("10.0.0.0/16")
|
||||
vpc3 = conn.create_vpc("10.0.0.0/24")
|
||||
|
||||
conn.associate_dhcp_options(dhcp_options.id, vpc1.id)
|
||||
conn.associate_dhcp_options(dhcp_options.id, vpc2.id)
|
||||
|
||||
vpcs = conn.get_all_vpcs(filters={'dhcp-options-id': dhcp_options.id})
|
||||
vpcs.should.have.length_of(2)
|
||||
vpc_ids = tuple(map(lambda v: v.id, vpcs))
|
||||
vpc1.id.should.be.within(vpc_ids)
|
||||
vpc2.id.should.be.within(vpc_ids)
|
||||
|
||||
|
||||
@mock_ec2
|
||||
def test_vpc_get_by_tag():
|
||||
conn = boto.connect_vpc()
|
||||
vpc1 = conn.create_vpc("10.0.0.0/16")
|
||||
vpc2 = conn.create_vpc("10.0.0.0/16")
|
||||
vpc3 = conn.create_vpc("10.0.0.0/24")
|
||||
|
||||
vpc1.add_tag('Name', 'TestVPC')
|
||||
vpc2.add_tag('Name', 'TestVPC')
|
||||
vpc3.add_tag('Name', 'TestVPC2')
|
||||
|
||||
vpcs = conn.get_all_vpcs(filters={'tag:Name': 'TestVPC'})
|
||||
vpcs.should.have.length_of(2)
|
||||
vpc_ids = tuple(map(lambda v: v.id, vpcs))
|
||||
vpc1.id.should.be.within(vpc_ids)
|
||||
vpc2.id.should.be.within(vpc_ids)
|
||||
Loading…
Add table
Add a link
Reference in a new issue