moto/tests/test_ec2/test_virtual_private_gateways.py

97 lines
3.0 KiB
Python
Raw Normal View History

from __future__ import unicode_literals
2013-02-22 04:13:01 +00:00
import boto
2013-08-03 21:21:25 +00:00
import sure # noqa
2013-02-22 04:13:01 +00:00
2017-02-16 03:35:45 +00:00
from moto import mock_ec2_deprecated
2013-02-22 04:13:01 +00:00
2017-02-16 03:35:45 +00:00
@mock_ec2_deprecated
2013-02-22 04:13:01 +00:00
def test_virtual_private_gateways():
2019-10-31 15:44:26 +00:00
conn = boto.connect_vpc("the_key", "the_secret")
2014-12-02 16:28:09 +00:00
2019-10-31 15:44:26 +00:00
vpn_gateway = conn.create_vpn_gateway("ipsec.1", "us-east-1a")
2014-12-02 16:28:09 +00:00
vpn_gateway.should_not.be.none
2019-10-31 15:44:26 +00:00
vpn_gateway.id.should.match(r"vgw-\w+")
vpn_gateway.type.should.equal("ipsec.1")
vpn_gateway.state.should.equal("available")
vpn_gateway.availability_zone.should.equal("us-east-1a")
2014-12-02 16:28:09 +00:00
2017-02-24 02:37:43 +00:00
2017-02-16 03:35:45 +00:00
@mock_ec2_deprecated
2014-12-02 16:28:09 +00:00
def test_describe_vpn_gateway():
2019-10-31 15:44:26 +00:00
conn = boto.connect_vpc("the_key", "the_secret")
vpn_gateway = conn.create_vpn_gateway("ipsec.1", "us-east-1a")
2014-12-02 16:28:09 +00:00
vgws = conn.get_all_vpn_gateways()
vgws.should.have.length_of(1)
gateway = vgws[0]
2019-10-31 15:44:26 +00:00
gateway.id.should.match(r"vgw-\w+")
2014-12-02 16:28:09 +00:00
gateway.id.should.equal(vpn_gateway.id)
2019-10-31 15:44:26 +00:00
vpn_gateway.type.should.equal("ipsec.1")
vpn_gateway.state.should.equal("available")
vpn_gateway.availability_zone.should.equal("us-east-1a")
2014-12-02 16:28:09 +00:00
2017-02-16 03:35:45 +00:00
@mock_ec2_deprecated
2014-12-02 16:28:09 +00:00
def test_vpn_gateway_vpc_attachment():
2019-10-31 15:44:26 +00:00
conn = boto.connect_vpc("the_key", "the_secret")
2014-12-02 16:28:09 +00:00
vpc = conn.create_vpc("10.0.0.0/16")
2019-10-31 15:44:26 +00:00
vpn_gateway = conn.create_vpn_gateway("ipsec.1", "us-east-1a")
2014-12-02 16:28:09 +00:00
2019-10-31 15:44:26 +00:00
conn.attach_vpn_gateway(vpn_gateway_id=vpn_gateway.id, vpc_id=vpc.id)
2014-12-02 16:28:09 +00:00
gateway = conn.get_all_vpn_gateways()[0]
attachments = gateway.attachments
attachments.should.have.length_of(1)
attachments[0].vpc_id.should.equal(vpc.id)
2019-10-31 15:44:26 +00:00
attachments[0].state.should.equal("attached")
2014-12-02 16:28:09 +00:00
2017-02-16 03:35:45 +00:00
@mock_ec2_deprecated
2014-12-02 16:28:09 +00:00
def test_delete_vpn_gateway():
2019-10-31 15:44:26 +00:00
conn = boto.connect_vpc("the_key", "the_secret")
vpn_gateway = conn.create_vpn_gateway("ipsec.1", "us-east-1a")
2014-12-02 16:28:09 +00:00
conn.delete_vpn_gateway(vpn_gateway.id)
vgws = conn.get_all_vpn_gateways()
vgws.should.have.length_of(0)
2017-02-16 03:35:45 +00:00
@mock_ec2_deprecated
2014-12-02 16:28:09 +00:00
def test_vpn_gateway_tagging():
2019-10-31 15:44:26 +00:00
conn = boto.connect_vpc("the_key", "the_secret")
vpn_gateway = conn.create_vpn_gateway("ipsec.1", "us-east-1a")
2014-12-02 16:28:09 +00:00
vpn_gateway.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 subnet
vpn_gateway = conn.get_all_vpn_gateways()[0]
vpn_gateway.tags.should.have.length_of(1)
vpn_gateway.tags["a key"].should.equal("some value")
2014-12-02 16:40:05 +00:00
2017-02-16 03:35:45 +00:00
@mock_ec2_deprecated
2014-12-02 16:40:05 +00:00
def test_detach_vpn_gateway():
2019-10-31 15:44:26 +00:00
conn = boto.connect_vpc("the_key", "the_secret")
2014-12-02 16:40:05 +00:00
vpc = conn.create_vpc("10.0.0.0/16")
2019-10-31 15:44:26 +00:00
vpn_gateway = conn.create_vpn_gateway("ipsec.1", "us-east-1a")
2014-12-02 16:40:05 +00:00
2019-10-31 15:44:26 +00:00
conn.attach_vpn_gateway(vpn_gateway_id=vpn_gateway.id, vpc_id=vpc.id)
2014-12-02 16:40:05 +00:00
gateway = conn.get_all_vpn_gateways()[0]
attachments = gateway.attachments
attachments.should.have.length_of(1)
attachments[0].vpc_id.should.equal(vpc.id)
2019-10-31 15:44:26 +00:00
attachments[0].state.should.equal("attached")
2014-12-02 16:40:05 +00:00
2019-10-31 15:44:26 +00:00
conn.detach_vpn_gateway(vpn_gateway_id=vpn_gateway.id, vpc_id=vpc.id)
2014-12-02 16:40:05 +00:00
gateway = conn.get_all_vpn_gateways()[0]
attachments = gateway.attachments
attachments.should.have.length_of(0)