2014-08-27 15:17:06 +00:00
|
|
|
from __future__ import unicode_literals
|
2014-08-25 22:09:38 +00:00
|
|
|
# Ensure 'assert_raises' context manager support for Python 2.6
|
2014-09-30 14:07:09 +00:00
|
|
|
#import tests.backport_assert_raises
|
2014-08-25 22:09:38 +00:00
|
|
|
from nose.tools import assert_raises
|
|
|
|
|
2013-02-22 04:13:01 +00:00
|
|
|
import boto
|
2013-03-06 03:33:41 +00:00
|
|
|
from boto.exception import EC2ResponseError
|
2013-08-03 21:21:25 +00:00
|
|
|
import sure # noqa
|
2013-02-22 04:13:01 +00:00
|
|
|
|
|
|
|
from moto import mock_ec2
|
|
|
|
|
2014-09-30 14:29:50 +00:00
|
|
|
SAMPLE_DOMAIN_NAME = u'example.com'
|
|
|
|
SAMPLE_NAME_SERVERS = [u'10.0.0.6', u'10.0.0.7']
|
|
|
|
|
2013-02-22 04:13:01 +00:00
|
|
|
|
|
|
|
@mock_ec2
|
|
|
|
def test_vpcs():
|
2013-03-06 03:33:41 +00:00
|
|
|
conn = boto.connect_vpc('the_key', 'the_secret')
|
|
|
|
vpc = conn.create_vpc("10.0.0.0/16")
|
|
|
|
vpc.cidr_block.should.equal('10.0.0.0/16')
|
|
|
|
|
|
|
|
all_vpcs = conn.get_all_vpcs()
|
|
|
|
all_vpcs.should.have.length_of(1)
|
|
|
|
|
|
|
|
vpc.delete()
|
|
|
|
|
|
|
|
all_vpcs = conn.get_all_vpcs()
|
|
|
|
all_vpcs.should.have.length_of(0)
|
|
|
|
|
2014-08-25 17:54:47 +00:00
|
|
|
with assert_raises(EC2ResponseError) as cm:
|
|
|
|
conn.delete_vpc("vpc-1234abcd")
|
|
|
|
cm.exception.code.should.equal('InvalidVpcID.NotFound')
|
|
|
|
cm.exception.status.should.equal(400)
|
|
|
|
cm.exception.request_id.should_not.be.none
|
2014-05-11 23:00:28 +00:00
|
|
|
|
|
|
|
|
2014-09-10 18:15:43 +00:00
|
|
|
@mock_ec2
|
|
|
|
def test_vpc_defaults():
|
|
|
|
conn = boto.connect_vpc('the_key', 'the_secret')
|
|
|
|
vpc = conn.create_vpc("10.0.0.0/16")
|
|
|
|
|
|
|
|
conn.get_all_vpcs().should.have.length_of(1)
|
|
|
|
conn.get_all_route_tables().should.have.length_of(1)
|
|
|
|
conn.get_all_security_groups().should.have.length_of(1)
|
|
|
|
|
|
|
|
vpc.delete()
|
|
|
|
|
|
|
|
conn.get_all_vpcs().should.have.length_of(0)
|
|
|
|
conn.get_all_route_tables().should.have.length_of(0)
|
|
|
|
conn.get_all_security_groups().should.have.length_of(0)
|
|
|
|
|
|
|
|
|
2014-05-11 23:00:28 +00:00
|
|
|
@mock_ec2
|
|
|
|
def test_vpc_tagging():
|
|
|
|
conn = boto.connect_vpc()
|
|
|
|
vpc = conn.create_vpc("10.0.0.0/16")
|
|
|
|
|
|
|
|
vpc.add_tag("a key", "some value")
|
|
|
|
|
|
|
|
tag = conn.get_all_tags()[0]
|
|
|
|
tag.name.should.equal("a key")
|
|
|
|
tag.value.should.equal("some value")
|
|
|
|
|
|
|
|
# Refresh the vpc
|
|
|
|
vpc = conn.get_all_vpcs()[0]
|
|
|
|
vpc.tags.should.have.length_of(1)
|
|
|
|
vpc.tags["a key"].should.equal("some value")
|
2014-09-30 14:07:09 +00:00
|
|
|
|
2014-09-30 14:29:50 +00:00
|
|
|
|
2014-09-30 14:07:09 +00:00
|
|
|
@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)
|
2014-09-30 14:29:50 +00:00
|
|
|
vpc_ids = 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 = 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 = map(lambda v: v.id, vpcs)
|
|
|
|
vpc1.id.should.be.within(vpc_ids)
|
|
|
|
vpc2.id.should.be.within(vpc_ids)
|