| 
									
										
										
										
											2014-08-27 11:17:06 -04:00
										 |  |  | from __future__ import unicode_literals | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 08:04:09 +02:00
										 |  |  | # Ensure 'pytest.raises' context manager support for Python 2.6 | 
					
						
							| 
									
										
										
										
											2020-10-06 07:54:49 +02:00
										 |  |  | import pytest | 
					
						
							| 
									
										
										
										
											2014-08-25 15:09:38 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-05 00:12:22 -04:00
										 |  |  | import re | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-21 23:13:01 -05:00
										 |  |  | import boto | 
					
						
							| 
									
										
										
										
											2020-11-02 19:00:02 +05:30
										 |  |  | import boto3 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-23 19:43:48 -05:00
										 |  |  | from boto.exception import EC2ResponseError | 
					
						
							| 
									
										
										
										
											2014-06-05 00:12:22 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-03 17:21:25 -04:00
										 |  |  | import sure  # noqa | 
					
						
							| 
									
										
										
										
											2013-02-21 23:13:01 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-02 19:00:02 +05:30
										 |  |  | from moto import mock_ec2_deprecated, mock_ec2 | 
					
						
							| 
									
										
										
										
											2013-02-21 23:13:01 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  | VPC_CIDR = "10.0.0.0/16" | 
					
						
							|  |  |  | BAD_VPC = "vpc-deadbeef" | 
					
						
							|  |  |  | BAD_IGW = "igw-deadbeef" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-05 00:12:22 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-15 22:35:45 -05:00
										 |  |  | @mock_ec2_deprecated | 
					
						
							| 
									
										
										
										
											2014-06-05 00:12:22 -04:00
										 |  |  | def test_igw_create(): | 
					
						
							|  |  |  |     """ internet gateway create """ | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto.connect_vpc("the_key", "the_secret") | 
					
						
							| 
									
										
										
										
											2014-06-05 00:12:22 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     conn.get_all_internet_gateways().should.have.length_of(0) | 
					
						
							| 
									
										
										
										
											2016-10-15 23:08:44 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 07:54:49 +02:00
										 |  |  |     with pytest.raises(EC2ResponseError) as ex: | 
					
						
							| 
									
										
										
										
											2016-10-15 23:08:44 +10:00
										 |  |  |         igw = conn.create_internet_gateway(dry_run=True) | 
					
						
							| 
									
										
										
										
											2020-10-06 08:04:09 +02:00
										 |  |  |     ex.value.error_code.should.equal("DryRunOperation") | 
					
						
							|  |  |  |     ex.value.status.should.equal(400) | 
					
						
							|  |  |  |     ex.value.message.should.equal( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         "An error occurred (DryRunOperation) when calling the CreateInternetGateway operation: Request would have succeeded, but DryRun flag is set" | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2016-10-15 23:08:44 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-05 00:12:22 -04:00
										 |  |  |     igw = conn.create_internet_gateway() | 
					
						
							|  |  |  |     conn.get_all_internet_gateways().should.have.length_of(1) | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     igw.id.should.match(r"igw-[0-9a-f]+") | 
					
						
							| 
									
										
										
										
											2014-06-05 00:12:22 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     igw = conn.get_all_internet_gateways()[0] | 
					
						
							|  |  |  |     igw.attachments.should.have.length_of(0) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-15 22:35:45 -05:00
										 |  |  | @mock_ec2_deprecated | 
					
						
							| 
									
										
										
										
											2014-06-05 00:12:22 -04:00
										 |  |  | def test_igw_attach(): | 
					
						
							|  |  |  |     """ internet gateway attach """ | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto.connect_vpc("the_key", "the_secret") | 
					
						
							| 
									
										
										
										
											2014-06-05 00:12:22 -04:00
										 |  |  |     igw = conn.create_internet_gateway() | 
					
						
							|  |  |  |     vpc = conn.create_vpc(VPC_CIDR) | 
					
						
							| 
									
										
										
										
											2016-10-15 23:08:44 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 07:54:49 +02:00
										 |  |  |     with pytest.raises(EC2ResponseError) as ex: | 
					
						
							| 
									
										
										
										
											2016-10-15 23:08:44 +10:00
										 |  |  |         conn.attach_internet_gateway(igw.id, vpc.id, dry_run=True) | 
					
						
							| 
									
										
										
										
											2020-10-06 08:04:09 +02:00
										 |  |  |     ex.value.error_code.should.equal("DryRunOperation") | 
					
						
							|  |  |  |     ex.value.status.should.equal(400) | 
					
						
							|  |  |  |     ex.value.message.should.equal( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         "An error occurred (DryRunOperation) when calling the AttachInternetGateway operation: Request would have succeeded, but DryRun flag is set" | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2016-10-15 23:08:44 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-05 00:12:22 -04:00
										 |  |  |     conn.attach_internet_gateway(igw.id, vpc.id) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     igw = conn.get_all_internet_gateways()[0] | 
					
						
							|  |  |  |     igw.attachments[0].vpc_id.should.be.equal(vpc.id) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-15 22:35:45 -05:00
										 |  |  | @mock_ec2_deprecated | 
					
						
							| 
									
										
										
										
											2014-06-05 00:12:22 -04:00
										 |  |  | def test_igw_attach_bad_vpc(): | 
					
						
							|  |  |  |     """ internet gateway fail to attach w/ bad vpc """ | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto.connect_vpc("the_key", "the_secret") | 
					
						
							| 
									
										
										
										
											2014-06-05 00:12:22 -04:00
										 |  |  |     igw = conn.create_internet_gateway() | 
					
						
							| 
									
										
										
										
											2014-08-25 10:54:47 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 07:54:49 +02:00
										 |  |  |     with pytest.raises(EC2ResponseError) as cm: | 
					
						
							| 
									
										
										
										
											2014-08-25 10:54:47 -07:00
										 |  |  |         conn.attach_internet_gateway(igw.id, BAD_VPC) | 
					
						
							| 
									
										
										
										
											2020-10-06 08:04:09 +02:00
										 |  |  |     cm.value.code.should.equal("InvalidVpcID.NotFound") | 
					
						
							|  |  |  |     cm.value.status.should.equal(400) | 
					
						
							|  |  |  |     cm.value.request_id.should_not.be.none | 
					
						
							| 
									
										
										
										
											2014-06-05 00:12:22 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-15 22:35:45 -05:00
										 |  |  | @mock_ec2_deprecated | 
					
						
							| 
									
										
										
										
											2014-06-05 00:12:22 -04:00
										 |  |  | def test_igw_attach_twice(): | 
					
						
							|  |  |  |     """ internet gateway fail to attach twice """ | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto.connect_vpc("the_key", "the_secret") | 
					
						
							| 
									
										
										
										
											2014-06-05 00:12:22 -04:00
										 |  |  |     igw = conn.create_internet_gateway() | 
					
						
							|  |  |  |     vpc1 = conn.create_vpc(VPC_CIDR) | 
					
						
							|  |  |  |     vpc2 = conn.create_vpc(VPC_CIDR) | 
					
						
							|  |  |  |     conn.attach_internet_gateway(igw.id, vpc1.id) | 
					
						
							| 
									
										
										
										
											2014-08-25 10:54:47 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 07:54:49 +02:00
										 |  |  |     with pytest.raises(EC2ResponseError) as cm: | 
					
						
							| 
									
										
										
										
											2014-08-25 10:54:47 -07:00
										 |  |  |         conn.attach_internet_gateway(igw.id, vpc2.id) | 
					
						
							| 
									
										
										
										
											2020-10-06 08:04:09 +02:00
										 |  |  |     cm.value.code.should.equal("Resource.AlreadyAssociated") | 
					
						
							|  |  |  |     cm.value.status.should.equal(400) | 
					
						
							|  |  |  |     cm.value.request_id.should_not.be.none | 
					
						
							| 
									
										
										
										
											2014-06-05 00:12:22 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-15 22:35:45 -05:00
										 |  |  | @mock_ec2_deprecated | 
					
						
							| 
									
										
										
										
											2014-06-05 00:12:22 -04:00
										 |  |  | def test_igw_detach(): | 
					
						
							|  |  |  |     """ internet gateway detach""" | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto.connect_vpc("the_key", "the_secret") | 
					
						
							| 
									
										
										
										
											2014-06-05 00:12:22 -04:00
										 |  |  |     igw = conn.create_internet_gateway() | 
					
						
							|  |  |  |     vpc = conn.create_vpc(VPC_CIDR) | 
					
						
							|  |  |  |     conn.attach_internet_gateway(igw.id, vpc.id) | 
					
						
							| 
									
										
										
										
											2016-10-15 23:08:44 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 07:54:49 +02:00
										 |  |  |     with pytest.raises(EC2ResponseError) as ex: | 
					
						
							| 
									
										
										
										
											2016-10-15 23:08:44 +10:00
										 |  |  |         conn.detach_internet_gateway(igw.id, vpc.id, dry_run=True) | 
					
						
							| 
									
										
										
										
											2020-10-06 08:04:09 +02:00
										 |  |  |     ex.value.error_code.should.equal("DryRunOperation") | 
					
						
							|  |  |  |     ex.value.status.should.equal(400) | 
					
						
							|  |  |  |     ex.value.message.should.equal( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         "An error occurred (DryRunOperation) when calling the DetachInternetGateway operation: Request would have succeeded, but DryRun flag is set" | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2016-10-15 23:08:44 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-05 00:12:22 -04:00
										 |  |  |     conn.detach_internet_gateway(igw.id, vpc.id) | 
					
						
							|  |  |  |     igw = conn.get_all_internet_gateways()[0] | 
					
						
							|  |  |  |     igw.attachments.should.have.length_of(0) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-15 22:35:45 -05:00
										 |  |  | @mock_ec2_deprecated | 
					
						
							| 
									
										
										
										
											2014-08-25 10:54:47 -07:00
										 |  |  | def test_igw_detach_wrong_vpc(): | 
					
						
							|  |  |  |     """ internet gateway fail to detach w/ wrong vpc """ | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto.connect_vpc("the_key", "the_secret") | 
					
						
							| 
									
										
										
										
											2014-08-25 10:54:47 -07:00
										 |  |  |     igw = conn.create_internet_gateway() | 
					
						
							|  |  |  |     vpc1 = conn.create_vpc(VPC_CIDR) | 
					
						
							|  |  |  |     vpc2 = conn.create_vpc(VPC_CIDR) | 
					
						
							|  |  |  |     conn.attach_internet_gateway(igw.id, vpc1.id) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 07:54:49 +02:00
										 |  |  |     with pytest.raises(EC2ResponseError) as cm: | 
					
						
							| 
									
										
										
										
											2014-08-25 10:54:47 -07:00
										 |  |  |         conn.detach_internet_gateway(igw.id, vpc2.id) | 
					
						
							| 
									
										
										
										
											2020-10-06 08:04:09 +02:00
										 |  |  |     cm.value.code.should.equal("Gateway.NotAttached") | 
					
						
							|  |  |  |     cm.value.status.should.equal(400) | 
					
						
							|  |  |  |     cm.value.request_id.should_not.be.none | 
					
						
							| 
									
										
										
										
											2014-08-25 10:54:47 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-15 22:35:45 -05:00
										 |  |  | @mock_ec2_deprecated | 
					
						
							| 
									
										
										
										
											2014-08-25 10:54:47 -07:00
										 |  |  | def test_igw_detach_invalid_vpc(): | 
					
						
							|  |  |  |     """ internet gateway fail to detach w/ invalid vpc """ | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto.connect_vpc("the_key", "the_secret") | 
					
						
							| 
									
										
										
										
											2014-06-05 00:12:22 -04:00
										 |  |  |     igw = conn.create_internet_gateway() | 
					
						
							|  |  |  |     vpc = conn.create_vpc(VPC_CIDR) | 
					
						
							|  |  |  |     conn.attach_internet_gateway(igw.id, vpc.id) | 
					
						
							| 
									
										
										
										
											2014-08-25 10:54:47 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 07:54:49 +02:00
										 |  |  |     with pytest.raises(EC2ResponseError) as cm: | 
					
						
							| 
									
										
										
										
											2014-08-25 10:54:47 -07:00
										 |  |  |         conn.detach_internet_gateway(igw.id, BAD_VPC) | 
					
						
							| 
									
										
										
										
											2020-10-06 08:04:09 +02:00
										 |  |  |     cm.value.code.should.equal("Gateway.NotAttached") | 
					
						
							|  |  |  |     cm.value.status.should.equal(400) | 
					
						
							|  |  |  |     cm.value.request_id.should_not.be.none | 
					
						
							| 
									
										
										
										
											2014-06-05 00:12:22 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-15 22:35:45 -05:00
										 |  |  | @mock_ec2_deprecated | 
					
						
							| 
									
										
										
										
											2014-06-05 00:12:22 -04:00
										 |  |  | def test_igw_detach_unattached(): | 
					
						
							|  |  |  |     """ internet gateway fail to detach unattached """ | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto.connect_vpc("the_key", "the_secret") | 
					
						
							| 
									
										
										
										
											2014-06-05 00:12:22 -04:00
										 |  |  |     igw = conn.create_internet_gateway() | 
					
						
							| 
									
										
										
										
											2014-08-25 10:54:47 -07:00
										 |  |  |     vpc = conn.create_vpc(VPC_CIDR) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 07:54:49 +02:00
										 |  |  |     with pytest.raises(EC2ResponseError) as cm: | 
					
						
							| 
									
										
										
										
											2014-08-25 10:54:47 -07:00
										 |  |  |         conn.detach_internet_gateway(igw.id, vpc.id) | 
					
						
							| 
									
										
										
										
											2020-10-06 08:04:09 +02:00
										 |  |  |     cm.value.code.should.equal("Gateway.NotAttached") | 
					
						
							|  |  |  |     cm.value.status.should.equal(400) | 
					
						
							|  |  |  |     cm.value.request_id.should_not.be.none | 
					
						
							| 
									
										
										
										
											2014-06-05 00:12:22 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-15 22:35:45 -05:00
										 |  |  | @mock_ec2_deprecated | 
					
						
							| 
									
										
										
										
											2014-06-05 00:12:22 -04:00
										 |  |  | def test_igw_delete(): | 
					
						
							|  |  |  |     """ internet gateway delete""" | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto.connect_vpc("the_key", "the_secret") | 
					
						
							| 
									
										
										
										
											2014-06-05 00:12:22 -04:00
										 |  |  |     vpc = conn.create_vpc(VPC_CIDR) | 
					
						
							|  |  |  |     conn.get_all_internet_gateways().should.have.length_of(0) | 
					
						
							|  |  |  |     igw = conn.create_internet_gateway() | 
					
						
							|  |  |  |     conn.get_all_internet_gateways().should.have.length_of(1) | 
					
						
							| 
									
										
										
										
											2016-10-15 23:08:44 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 07:54:49 +02:00
										 |  |  |     with pytest.raises(EC2ResponseError) as ex: | 
					
						
							| 
									
										
										
										
											2016-10-15 23:08:44 +10:00
										 |  |  |         conn.delete_internet_gateway(igw.id, dry_run=True) | 
					
						
							| 
									
										
										
										
											2020-10-06 08:04:09 +02:00
										 |  |  |     ex.value.error_code.should.equal("DryRunOperation") | 
					
						
							|  |  |  |     ex.value.status.should.equal(400) | 
					
						
							|  |  |  |     ex.value.message.should.equal( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         "An error occurred (DryRunOperation) when calling the DeleteInternetGateway operation: Request would have succeeded, but DryRun flag is set" | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2016-10-15 23:08:44 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-05 00:12:22 -04:00
										 |  |  |     conn.delete_internet_gateway(igw.id) | 
					
						
							|  |  |  |     conn.get_all_internet_gateways().should.have.length_of(0) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-15 22:35:45 -05:00
										 |  |  | @mock_ec2_deprecated | 
					
						
							| 
									
										
										
										
											2014-06-05 00:12:22 -04:00
										 |  |  | def test_igw_delete_attached(): | 
					
						
							|  |  |  |     """ internet gateway fail to delete attached """ | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto.connect_vpc("the_key", "the_secret") | 
					
						
							| 
									
										
										
										
											2014-06-05 00:12:22 -04:00
										 |  |  |     igw = conn.create_internet_gateway() | 
					
						
							|  |  |  |     vpc = conn.create_vpc(VPC_CIDR) | 
					
						
							|  |  |  |     conn.attach_internet_gateway(igw.id, vpc.id) | 
					
						
							| 
									
										
										
										
											2014-08-25 10:54:47 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 07:54:49 +02:00
										 |  |  |     with pytest.raises(EC2ResponseError) as cm: | 
					
						
							| 
									
										
										
										
											2014-08-25 10:54:47 -07:00
										 |  |  |         conn.delete_internet_gateway(igw.id) | 
					
						
							| 
									
										
										
										
											2020-10-06 08:04:09 +02:00
										 |  |  |     cm.value.code.should.equal("DependencyViolation") | 
					
						
							|  |  |  |     cm.value.status.should.equal(400) | 
					
						
							|  |  |  |     cm.value.request_id.should_not.be.none | 
					
						
							| 
									
										
										
										
											2014-06-05 00:12:22 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-15 22:35:45 -05:00
										 |  |  | @mock_ec2_deprecated | 
					
						
							| 
									
										
										
										
											2014-06-05 00:12:22 -04:00
										 |  |  | def test_igw_desribe(): | 
					
						
							|  |  |  |     """ internet gateway fetch by id """ | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto.connect_vpc("the_key", "the_secret") | 
					
						
							| 
									
										
										
										
											2014-06-05 00:12:22 -04:00
										 |  |  |     igw = conn.create_internet_gateway() | 
					
						
							|  |  |  |     igw_by_search = conn.get_all_internet_gateways([igw.id])[0] | 
					
						
							|  |  |  |     igw.id.should.equal(igw_by_search.id) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-15 22:35:45 -05:00
										 |  |  | @mock_ec2_deprecated | 
					
						
							| 
									
										
										
										
											2018-07-25 08:11:04 +10:00
										 |  |  | def test_igw_describe_bad_id(): | 
					
						
							| 
									
										
										
										
											2014-06-05 00:12:22 -04:00
										 |  |  |     """ internet gateway fail to fetch by bad id """ | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto.connect_vpc("the_key", "the_secret") | 
					
						
							| 
									
										
										
										
											2020-10-06 07:54:49 +02:00
										 |  |  |     with pytest.raises(EC2ResponseError) as cm: | 
					
						
							| 
									
										
										
										
											2014-08-25 10:54:47 -07:00
										 |  |  |         conn.get_all_internet_gateways([BAD_IGW]) | 
					
						
							| 
									
										
										
										
											2020-10-06 08:04:09 +02:00
										 |  |  |     cm.value.code.should.equal("InvalidInternetGatewayID.NotFound") | 
					
						
							|  |  |  |     cm.value.status.should.equal(400) | 
					
						
							|  |  |  |     cm.value.request_id.should_not.be.none | 
					
						
							| 
									
										
										
										
											2014-11-05 12:11:56 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-15 22:35:45 -05:00
										 |  |  | @mock_ec2_deprecated | 
					
						
							| 
									
										
										
										
											2014-11-05 12:11:56 -05:00
										 |  |  | def test_igw_filter_by_vpc_id(): | 
					
						
							|  |  |  |     """ internet gateway filter by vpc id """ | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto.connect_vpc("the_key", "the_secret") | 
					
						
							| 
									
										
										
										
											2014-11-05 12:11:56 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     igw1 = conn.create_internet_gateway() | 
					
						
							|  |  |  |     igw2 = conn.create_internet_gateway() | 
					
						
							|  |  |  |     vpc = conn.create_vpc(VPC_CIDR) | 
					
						
							|  |  |  |     conn.attach_internet_gateway(igw1.id, vpc.id) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     result = conn.get_all_internet_gateways(filters={"attachment.vpc-id": vpc.id}) | 
					
						
							| 
									
										
										
										
											2014-11-05 12:11:56 -05:00
										 |  |  |     result.should.have.length_of(1) | 
					
						
							|  |  |  |     result[0].id.should.equal(igw1.id) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-15 22:35:45 -05:00
										 |  |  | @mock_ec2_deprecated | 
					
						
							| 
									
										
										
										
											2014-11-05 12:11:56 -05:00
										 |  |  | def test_igw_filter_by_tags(): | 
					
						
							|  |  |  |     """ internet gateway filter by vpc id """ | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto.connect_vpc("the_key", "the_secret") | 
					
						
							| 
									
										
										
										
											2014-11-05 12:11:56 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     igw1 = conn.create_internet_gateway() | 
					
						
							|  |  |  |     igw2 = conn.create_internet_gateway() | 
					
						
							|  |  |  |     igw1.add_tag("tests", "yes") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     result = conn.get_all_internet_gateways(filters={"tag:tests": "yes"}) | 
					
						
							|  |  |  |     result.should.have.length_of(1) | 
					
						
							|  |  |  |     result[0].id.should.equal(igw1.id) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-15 22:35:45 -05:00
										 |  |  | @mock_ec2_deprecated | 
					
						
							| 
									
										
										
										
											2014-11-05 12:11:56 -05:00
										 |  |  | def test_igw_filter_by_internet_gateway_id(): | 
					
						
							|  |  |  |     """ internet gateway filter by internet gateway id """ | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto.connect_vpc("the_key", "the_secret") | 
					
						
							| 
									
										
										
										
											2014-11-05 12:11:56 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     igw1 = conn.create_internet_gateway() | 
					
						
							|  |  |  |     igw2 = conn.create_internet_gateway() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     result = conn.get_all_internet_gateways(filters={"internet-gateway-id": igw1.id}) | 
					
						
							| 
									
										
										
										
											2014-11-05 12:11:56 -05:00
										 |  |  |     result.should.have.length_of(1) | 
					
						
							|  |  |  |     result[0].id.should.equal(igw1.id) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-15 22:35:45 -05:00
										 |  |  | @mock_ec2_deprecated | 
					
						
							| 
									
										
										
										
											2014-11-05 12:11:56 -05:00
										 |  |  | def test_igw_filter_by_attachment_state(): | 
					
						
							|  |  |  |     """ internet gateway filter by attachment state """ | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto.connect_vpc("the_key", "the_secret") | 
					
						
							| 
									
										
										
										
											2014-11-05 12:11:56 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     igw1 = conn.create_internet_gateway() | 
					
						
							|  |  |  |     igw2 = conn.create_internet_gateway() | 
					
						
							|  |  |  |     vpc = conn.create_vpc(VPC_CIDR) | 
					
						
							|  |  |  |     conn.attach_internet_gateway(igw1.id, vpc.id) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     result = conn.get_all_internet_gateways(filters={"attachment.state": "available"}) | 
					
						
							| 
									
										
										
										
											2014-11-05 12:11:56 -05:00
										 |  |  |     result.should.have.length_of(1) | 
					
						
							|  |  |  |     result[0].id.should.equal(igw1.id) | 
					
						
							| 
									
										
										
										
											2020-11-02 19:00:02 +05:30
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_ec2 | 
					
						
							|  |  |  | def test_create_internet_gateway_with_tags(): | 
					
						
							|  |  |  |     ec2 = boto3.resource("ec2", region_name="eu-central-1") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     igw = ec2.create_internet_gateway( | 
					
						
							|  |  |  |         TagSpecifications=[ | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 "ResourceType": "internet-gateway", | 
					
						
							|  |  |  |                 "Tags": [{"Key": "test", "Value": "TestRouteTable"}], | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         ], | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     igw.tags.should.have.length_of(1) | 
					
						
							|  |  |  |     igw.tags.should.equal([{"Key": "test", "Value": "TestRouteTable"}]) |