| 
									
										
										
										
											2014-08-27 11:17:06 -04:00
										 |  |  | from __future__ import unicode_literals | 
					
						
							| 
									
										
										
										
											2013-02-23 14:51:19 -05:00
										 |  |  | import boto | 
					
						
							| 
									
										
										
										
											2017-01-11 17:37:57 -08:00
										 |  |  | import boto.ec2 | 
					
						
							|  |  |  | import boto3 | 
					
						
							| 
									
										
										
										
											2013-08-03 17:21:25 -04:00
										 |  |  | import sure  # noqa | 
					
						
							| 
									
										
										
										
											2013-02-23 14:51:19 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-15 22:35:45 -05:00
										 |  |  | from moto import mock_ec2, mock_ec2_deprecated | 
					
						
							| 
									
										
										
										
											2013-02-23 14:51:19 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-15 22:35:45 -05:00
										 |  |  | @mock_ec2_deprecated | 
					
						
							| 
									
										
										
										
											2013-02-23 14:51:19 -05:00
										 |  |  | def test_describe_regions(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto.connect_ec2("the_key", "the_secret") | 
					
						
							| 
									
										
										
										
											2013-02-23 14:51:19 -05:00
										 |  |  |     regions = conn.get_all_regions() | 
					
						
							| 
									
										
										
										
											2019-12-28 21:22:16 +01:00
										 |  |  |     len(regions).should.be.greater_than(1) | 
					
						
							| 
									
										
										
										
											2017-01-11 17:37:57 -08:00
										 |  |  |     for region in regions: | 
					
						
							|  |  |  |         region.endpoint.should.contain(region.name) | 
					
						
							| 
									
										
										
										
											2013-02-23 14:51:19 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-15 22:35:45 -05:00
										 |  |  | @mock_ec2_deprecated | 
					
						
							| 
									
										
										
										
											2013-02-23 14:51:19 -05:00
										 |  |  | def test_availability_zones(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto.connect_ec2("the_key", "the_secret") | 
					
						
							| 
									
										
										
										
											2017-01-11 17:37:57 -08:00
										 |  |  |     regions = conn.get_all_regions() | 
					
						
							|  |  |  |     for region in regions: | 
					
						
							|  |  |  |         conn = boto.ec2.connect_to_region(region.name) | 
					
						
							|  |  |  |         if conn is None: | 
					
						
							|  |  |  |             continue | 
					
						
							|  |  |  |         for zone in conn.get_all_zones(): | 
					
						
							|  |  |  |             zone.name.should.contain(region.name) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_ec2 | 
					
						
							|  |  |  | def test_boto3_describe_regions(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     ec2 = boto3.client("ec2", "us-east-1") | 
					
						
							| 
									
										
										
										
											2017-01-11 17:37:57 -08:00
										 |  |  |     resp = ec2.describe_regions() | 
					
						
							| 
									
										
										
										
											2019-12-28 21:22:16 +01:00
										 |  |  |     len(resp["Regions"]).should.be.greater_than(1) | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     for rec in resp["Regions"]: | 
					
						
							|  |  |  |         rec["Endpoint"].should.contain(rec["RegionName"]) | 
					
						
							| 
									
										
										
										
											2017-01-11 17:37:57 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     test_region = "us-east-1" | 
					
						
							| 
									
										
										
										
											2017-12-28 21:02:58 +00:00
										 |  |  |     resp = ec2.describe_regions(RegionNames=[test_region]) | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     resp["Regions"].should.have.length_of(1) | 
					
						
							|  |  |  |     resp["Regions"][0].should.have.key("RegionName").which.should.equal(test_region) | 
					
						
							| 
									
										
										
										
											2020-04-24 14:20:58 -04:00
										 |  |  |     resp["Regions"][0].should.have.key("OptInStatus").which.should.equal( | 
					
						
							|  |  |  |         "opt-in-not-required" | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2020-04-24 14:15:22 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     test_region = "ap-east-1" | 
					
						
							|  |  |  |     resp = ec2.describe_regions(RegionNames=[test_region]) | 
					
						
							|  |  |  |     resp["Regions"].should.have.length_of(1) | 
					
						
							|  |  |  |     resp["Regions"][0].should.have.key("RegionName").which.should.equal(test_region) | 
					
						
							|  |  |  |     resp["Regions"][0].should.have.key("OptInStatus").which.should.equal("not-opted-in") | 
					
						
							| 
									
										
										
										
											2017-12-28 21:02:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-11 17:37:57 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | @mock_ec2 | 
					
						
							|  |  |  | def test_boto3_availability_zones(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     ec2 = boto3.client("ec2", "us-east-1") | 
					
						
							| 
									
										
										
										
											2017-01-11 17:37:57 -08:00
										 |  |  |     resp = ec2.describe_regions() | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     regions = [r["RegionName"] for r in resp["Regions"]] | 
					
						
							| 
									
										
										
										
											2017-01-11 17:37:57 -08:00
										 |  |  |     for region in regions: | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         conn = boto3.client("ec2", region) | 
					
						
							| 
									
										
										
										
											2017-01-11 17:37:57 -08:00
										 |  |  |         resp = conn.describe_availability_zones() | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         for rec in resp["AvailabilityZones"]: | 
					
						
							|  |  |  |             rec["ZoneName"].should.contain(region) | 
					
						
							| 
									
										
										
										
											2020-04-11 08:37:00 +05:30
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_ec2 | 
					
						
							|  |  |  | def test_boto3_zoneId_in_availability_zones(): | 
					
						
							|  |  |  |     conn = boto3.client("ec2", "us-east-1") | 
					
						
							|  |  |  |     resp = conn.describe_availability_zones() | 
					
						
							|  |  |  |     for rec in resp["AvailabilityZones"]: | 
					
						
							|  |  |  |         rec.get("ZoneId").should.contain("use1") | 
					
						
							|  |  |  |     conn = boto3.client("ec2", "us-west-1") | 
					
						
							|  |  |  |     resp = conn.describe_availability_zones() | 
					
						
							|  |  |  |     for rec in resp["AvailabilityZones"]: | 
					
						
							|  |  |  |         rec.get("ZoneId").should.contain("usw1") |