| 
									
										
										
										
											2013-11-14 11:14:14 -08:00
										 |  |  | import boto | 
					
						
							| 
									
										
										
										
											2016-06-03 09:57:33 -04:00
										 |  |  | import boto3 | 
					
						
							| 
									
										
										
										
											2015-01-17 19:06:43 -05:00
										 |  |  | from boto.route53.healthcheck import HealthCheck | 
					
						
							| 
									
										
										
										
											2013-11-14 11:14:14 -08:00
										 |  |  | from boto.route53.record import ResourceRecordSets | 
					
						
							| 
									
										
										
										
											2021-09-23 10:27:09 +00:00
										 |  |  | from botocore.exceptions import ClientError | 
					
						
							| 
									
										
										
										
											2013-11-14 11:14:14 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-18 19:44:29 +00:00
										 |  |  | import sure  # noqa # pylint: disable=unused-import | 
					
						
							| 
									
										
										
										
											2016-09-20 17:41:23 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-28 21:26:32 +05:30
										 |  |  | import botocore | 
					
						
							| 
									
										
										
										
											2020-10-06 07:54:49 +02:00
										 |  |  | import pytest | 
					
						
							| 
									
										
										
										
											2017-04-28 21:26:32 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-15 22:35:45 -05:00
										 |  |  | from moto import mock_route53, mock_route53_deprecated | 
					
						
							| 
									
										
										
										
											2013-11-14 11:14:14 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-23 10:27:09 +00:00
										 |  |  | # Has boto3 equivalent | 
					
						
							| 
									
										
										
										
											2017-02-15 22:35:45 -05:00
										 |  |  | @mock_route53_deprecated | 
					
						
							| 
									
										
										
										
											2013-11-14 11:14:14 -08:00
										 |  |  | def test_hosted_zone(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto.connect_route53("the_key", "the_secret") | 
					
						
							| 
									
										
										
										
											2013-11-14 11:14:14 -08:00
										 |  |  |     firstzone = conn.create_hosted_zone("testdns.aws.com") | 
					
						
							|  |  |  |     zones = conn.get_all_hosted_zones() | 
					
						
							|  |  |  |     len(zones["ListHostedZonesResponse"]["HostedZones"]).should.equal(1) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-08 22:00:55 -04:00
										 |  |  |     conn.create_hosted_zone("testdns1.aws.com") | 
					
						
							| 
									
										
										
										
											2013-11-14 11:14:14 -08:00
										 |  |  |     zones = conn.get_all_hosted_zones() | 
					
						
							|  |  |  |     len(zones["ListHostedZonesResponse"]["HostedZones"]).should.equal(2) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     id1 = firstzone["CreateHostedZoneResponse"]["HostedZone"]["Id"].split("/")[-1] | 
					
						
							| 
									
										
										
										
											2013-11-14 11:14:14 -08:00
										 |  |  |     zone = conn.get_hosted_zone(id1) | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     zone["GetHostedZoneResponse"]["HostedZone"]["Name"].should.equal("testdns.aws.com.") | 
					
						
							| 
									
										
										
										
											2013-11-14 11:14:14 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     conn.delete_hosted_zone(id1) | 
					
						
							|  |  |  |     zones = conn.get_all_hosted_zones() | 
					
						
							|  |  |  |     len(zones["ListHostedZonesResponse"]["HostedZones"]).should.equal(1) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     conn.get_hosted_zone.when.called_with("abcd").should.throw( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         boto.route53.exception.DNSServerError, "404 Not Found" | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2013-11-14 11:14:14 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-23 10:27:09 +00:00
										 |  |  | @mock_route53 | 
					
						
							|  |  |  | def test_create_hosted_zone_boto3(): | 
					
						
							|  |  |  |     conn = boto3.client("route53", region_name="us-east-1") | 
					
						
							|  |  |  |     response = conn.create_hosted_zone( | 
					
						
							|  |  |  |         Name="testdns.aws.com.", CallerReference=str(hash("foo")) | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     firstzone = response["HostedZone"] | 
					
						
							|  |  |  |     firstzone.should.have.key("Id").match(r"/hostedzone/[A-Z0-9]+") | 
					
						
							|  |  |  |     firstzone.should.have.key("Name").equal("testdns.aws.com.") | 
					
						
							|  |  |  |     firstzone.should.have.key("Config").equal({"PrivateZone": False}) | 
					
						
							|  |  |  |     firstzone.should.have.key("ResourceRecordSetCount").equal(0) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     delegation = response["DelegationSet"] | 
					
						
							|  |  |  |     delegation.should.equal({"NameServers": ["moto.test.com"]}) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_route53 | 
					
						
							|  |  |  | def test_list_hosted_zones(): | 
					
						
							|  |  |  |     conn = boto3.client("route53", region_name="us-east-1") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     res = conn.list_hosted_zones()["HostedZones"] | 
					
						
							|  |  |  |     res.should.have.length_of(0) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     zone1 = conn.create_hosted_zone( | 
					
						
							|  |  |  |         Name="testdns1.aws.com.", CallerReference=str(hash("foo")) | 
					
						
							|  |  |  |     )["HostedZone"] | 
					
						
							|  |  |  |     zone2 = conn.create_hosted_zone( | 
					
						
							|  |  |  |         Name="testdns2.aws.com.", CallerReference=str(hash("foo")) | 
					
						
							|  |  |  |     )["HostedZone"] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     res = conn.list_hosted_zones()["HostedZones"] | 
					
						
							|  |  |  |     res.should.have.length_of(2) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     res.should.contain(zone1) | 
					
						
							|  |  |  |     res.should.contain(zone2) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_route53 | 
					
						
							|  |  |  | def test_delete_hosted_zone(): | 
					
						
							|  |  |  |     conn = boto3.client("route53", region_name="us-east-1") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     zone1 = conn.create_hosted_zone( | 
					
						
							|  |  |  |         Name="testdns1.aws.com.", CallerReference=str(hash("foo")) | 
					
						
							|  |  |  |     )["HostedZone"] | 
					
						
							|  |  |  |     conn.create_hosted_zone(Name="testdns2.aws.com.", CallerReference=str(hash("foo"))) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     conn.delete_hosted_zone(Id=zone1["Id"]) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     res = conn.list_hosted_zones()["HostedZones"] | 
					
						
							|  |  |  |     res.should.have.length_of(1) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_route53 | 
					
						
							|  |  |  | def test_get_unknown_hosted_zone(): | 
					
						
							|  |  |  |     conn = boto3.client("route53", region_name="us-east-1") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     with pytest.raises(ClientError) as ex: | 
					
						
							|  |  |  |         conn.get_hosted_zone(Id="unknown") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     err = ex.value.response["Error"] | 
					
						
							|  |  |  |     err["Code"].should.equal("NoSuchHostedZone") | 
					
						
							|  |  |  |     err["Message"].should.equal("Zone unknown Not Found") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # Has boto3 equivalent | 
					
						
							| 
									
										
										
										
											2017-02-15 22:35:45 -05:00
										 |  |  | @mock_route53_deprecated | 
					
						
							| 
									
										
										
										
											2013-11-14 11:14:14 -08:00
										 |  |  | def test_rrset(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto.connect_route53("the_key", "the_secret") | 
					
						
							| 
									
										
										
										
											2013-11-15 16:20:25 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-20 14:50:05 +03:00
										 |  |  |     conn.get_all_rrsets.when.called_with("abcd").should.throw( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         boto.route53.exception.DNSServerError, "404 Not Found" | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2013-11-15 16:20:25 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-14 11:14:14 -08:00
										 |  |  |     zone = conn.create_hosted_zone("testdns.aws.com") | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     zoneid = zone["CreateHostedZoneResponse"]["HostedZone"]["Id"].split("/")[-1] | 
					
						
							| 
									
										
										
										
											2013-11-14 11:14:14 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-20 14:50:05 +03:00
										 |  |  |     conn.get_all_rrsets.when.called_with(zoneid, type="A").should.throw( | 
					
						
							|  |  |  |         boto.route53.exception.DNSServerError, "400 Bad Request" | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-14 11:14:14 -08:00
										 |  |  |     changes = ResourceRecordSets(conn, zoneid) | 
					
						
							|  |  |  |     change = changes.add_change("CREATE", "foo.bar.testdns.aws.com", "A") | 
					
						
							|  |  |  |     change.add_value("1.2.3.4") | 
					
						
							|  |  |  |     changes.commit() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-20 14:50:05 +03:00
										 |  |  |     rrsets = conn.get_all_rrsets(zoneid) | 
					
						
							| 
									
										
										
										
											2013-11-14 11:14:14 -08:00
										 |  |  |     rrsets.should.have.length_of(1) | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     rrsets[0].resource_records[0].should.equal("1.2.3.4") | 
					
						
							| 
									
										
										
										
											2013-11-14 11:14:14 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-20 14:50:05 +03:00
										 |  |  |     rrsets = conn.get_all_rrsets(zoneid, name="foo.bar.testdns.aws.com.", type="CNAME") | 
					
						
							| 
									
										
										
										
											2013-11-14 11:14:14 -08:00
										 |  |  |     rrsets.should.have.length_of(0) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-03 12:37:57 -05:00
										 |  |  |     changes = ResourceRecordSets(conn, zoneid) | 
					
						
							|  |  |  |     changes.add_change("DELETE", "foo.bar.testdns.aws.com", "A") | 
					
						
							|  |  |  |     change = changes.add_change("CREATE", "foo.bar.testdns.aws.com", "A") | 
					
						
							|  |  |  |     change.add_value("5.6.7.8") | 
					
						
							|  |  |  |     changes.commit() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-20 14:50:05 +03:00
										 |  |  |     rrsets = conn.get_all_rrsets(zoneid) | 
					
						
							| 
									
										
										
										
											2014-02-03 12:37:57 -05:00
										 |  |  |     rrsets.should.have.length_of(1) | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     rrsets[0].resource_records[0].should.equal("5.6.7.8") | 
					
						
							| 
									
										
										
										
											2014-02-03 12:37:57 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-14 11:14:14 -08:00
										 |  |  |     changes = ResourceRecordSets(conn, zoneid) | 
					
						
							|  |  |  |     changes.add_change("DELETE", "foo.bar.testdns.aws.com", "A") | 
					
						
							|  |  |  |     changes.commit() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     rrsets = conn.get_all_rrsets(zoneid) | 
					
						
							|  |  |  |     rrsets.should.have.length_of(0) | 
					
						
							| 
									
										
										
										
											2014-07-13 19:48:20 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     changes = ResourceRecordSets(conn, zoneid) | 
					
						
							| 
									
										
										
										
											2016-04-12 10:37:01 -07:00
										 |  |  |     change = changes.add_change("UPSERT", "foo.bar.testdns.aws.com", "A") | 
					
						
							|  |  |  |     change.add_value("1.2.3.4") | 
					
						
							|  |  |  |     changes.commit() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-20 14:50:05 +03:00
										 |  |  |     rrsets = conn.get_all_rrsets(zoneid) | 
					
						
							| 
									
										
										
										
											2016-04-12 10:37:01 -07:00
										 |  |  |     rrsets.should.have.length_of(1) | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     rrsets[0].resource_records[0].should.equal("1.2.3.4") | 
					
						
							| 
									
										
										
										
											2016-04-12 10:37:01 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     changes = ResourceRecordSets(conn, zoneid) | 
					
						
							|  |  |  |     change = changes.add_change("UPSERT", "foo.bar.testdns.aws.com", "A") | 
					
						
							|  |  |  |     change.add_value("5.6.7.8") | 
					
						
							|  |  |  |     changes.commit() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-20 14:50:05 +03:00
										 |  |  |     rrsets = conn.get_all_rrsets(zoneid) | 
					
						
							| 
									
										
										
										
											2016-04-12 10:37:01 -07:00
										 |  |  |     rrsets.should.have.length_of(1) | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     rrsets[0].resource_records[0].should.equal("5.6.7.8") | 
					
						
							| 
									
										
										
										
											2016-04-12 10:37:01 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-27 10:54:55 +00:00
										 |  |  |     changes = ResourceRecordSets(conn, zoneid) | 
					
						
							|  |  |  |     change = changes.add_change("UPSERT", "foo.bar.testdns.aws.com", "TXT") | 
					
						
							|  |  |  |     change.add_value("foo") | 
					
						
							|  |  |  |     changes.commit() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     rrsets = conn.get_all_rrsets(zoneid) | 
					
						
							|  |  |  |     rrsets.should.have.length_of(2) | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     rrsets[0].resource_records[0].should.equal("5.6.7.8") | 
					
						
							|  |  |  |     rrsets[1].resource_records[0].should.equal("foo") | 
					
						
							| 
									
										
										
										
											2019-02-27 10:54:55 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-12 10:37:01 -07:00
										 |  |  |     changes = ResourceRecordSets(conn, zoneid) | 
					
						
							|  |  |  |     changes.add_change("DELETE", "foo.bar.testdns.aws.com", "A") | 
					
						
							| 
									
										
										
										
											2019-06-17 15:53:32 +02:00
										 |  |  |     changes.add_change("DELETE", "foo.bar.testdns.aws.com", "TXT") | 
					
						
							| 
									
										
										
										
											2016-04-12 10:37:01 -07:00
										 |  |  |     changes.commit() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     changes = ResourceRecordSets(conn, zoneid) | 
					
						
							| 
									
										
										
										
											2021-04-20 14:50:05 +03:00
										 |  |  |     change = changes.add_change("CREATE", "bar.foo.testdns.aws.com", "TXT") | 
					
						
							|  |  |  |     change.add_value("bar") | 
					
						
							| 
									
										
										
										
											2014-07-13 19:48:20 +02:00
										 |  |  |     change = changes.add_change("CREATE", "foo.bar.testdns.aws.com", "A") | 
					
						
							|  |  |  |     change.add_value("1.2.3.4") | 
					
						
							|  |  |  |     change = changes.add_change("CREATE", "bar.foo.testdns.aws.com", "A") | 
					
						
							|  |  |  |     change.add_value("5.6.7.8") | 
					
						
							|  |  |  |     changes.commit() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-20 14:50:05 +03:00
										 |  |  |     rrsets = conn.get_all_rrsets(zoneid) | 
					
						
							|  |  |  |     rrsets.should.have.length_of(3) | 
					
						
							|  |  |  |     rrsets[0].resource_records[0].should.equal("1.2.3.4") | 
					
						
							|  |  |  |     rrsets[1].resource_records[0].should.equal("5.6.7.8") | 
					
						
							|  |  |  |     rrsets[2].resource_records[0].should.equal("bar") | 
					
						
							| 
									
										
										
										
											2014-07-13 19:48:20 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     rrsets = conn.get_all_rrsets(zoneid, name="foo.bar.testdns.aws.com", type="A") | 
					
						
							| 
									
										
										
										
											2021-04-20 14:50:05 +03:00
										 |  |  |     rrsets.should.have.length_of(3) | 
					
						
							| 
									
										
										
										
											2017-10-23 17:25:40 +02:00
										 |  |  |     resource_records = [rr for rr_set in rrsets for rr in rr_set.resource_records] | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     resource_records.should.contain("1.2.3.4") | 
					
						
							|  |  |  |     resource_records.should.contain("5.6.7.8") | 
					
						
							| 
									
										
										
										
											2021-04-20 14:50:05 +03:00
										 |  |  |     resource_records.should.contain("bar") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     rrsets = conn.get_all_rrsets(zoneid, name="foo.testdns.aws.com", type="A") | 
					
						
							|  |  |  |     rrsets.should.have.length_of(2) | 
					
						
							|  |  |  |     rrsets[0].resource_records[0].should.equal("5.6.7.8") | 
					
						
							|  |  |  |     rrsets[1].resource_records[0].should.equal("bar") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     rrsets = conn.get_all_rrsets(zoneid, name="foo.bar.testdns.aws.com", type="TXT") | 
					
						
							|  |  |  |     rrsets.should.have.length_of(2) | 
					
						
							|  |  |  |     rrsets[0].resource_records[0].should.equal("5.6.7.8") | 
					
						
							|  |  |  |     rrsets[1].resource_records[0].should.equal("bar") | 
					
						
							| 
									
										
										
										
											2014-07-13 19:48:20 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     rrsets = conn.get_all_rrsets(zoneid, name="foo.foo.testdns.aws.com", type="A") | 
					
						
							| 
									
										
										
										
											2014-07-13 19:48:20 +02:00
										 |  |  |     rrsets.should.have.length_of(0) | 
					
						
							| 
									
										
										
										
											2015-01-17 19:06:43 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-23 10:27:09 +00:00
										 |  |  | @mock_route53 | 
					
						
							|  |  |  | def test_list_resource_record_set_unknown_zone(): | 
					
						
							|  |  |  |     conn = boto3.client("route53", region_name="us-east-1") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     with pytest.raises(ClientError) as ex: | 
					
						
							|  |  |  |         conn.list_resource_record_sets(HostedZoneId="abcd") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     err = ex.value.response["Error"] | 
					
						
							|  |  |  |     err["Code"].should.equal("NoSuchHostedZone") | 
					
						
							|  |  |  |     err["Message"].should.equal("Zone abcd Not Found") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_route53 | 
					
						
							|  |  |  | def test_list_resource_record_set_unknown_type(): | 
					
						
							|  |  |  |     conn = boto3.client("route53", region_name="us-east-1") | 
					
						
							|  |  |  |     zone = conn.create_hosted_zone( | 
					
						
							|  |  |  |         Name="testdns1.aws.com.", CallerReference=str(hash("foo")) | 
					
						
							|  |  |  |     )["HostedZone"] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     with pytest.raises(ClientError) as ex: | 
					
						
							|  |  |  |         conn.list_resource_record_sets(HostedZoneId=zone["Id"], StartRecordType="A") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     err = ex.value.response["Error"] | 
					
						
							|  |  |  |     err["Code"].should.equal("400") | 
					
						
							|  |  |  |     err["Message"].should.equal("Bad Request") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # Has boto3 equivalent | 
					
						
							| 
									
										
										
										
											2017-02-15 22:35:45 -05:00
										 |  |  | @mock_route53_deprecated | 
					
						
							| 
									
										
										
										
											2015-06-05 21:29:20 -04:00
										 |  |  | def test_rrset_with_multiple_values(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto.connect_route53("the_key", "the_secret") | 
					
						
							| 
									
										
										
										
											2015-06-05 21:29:20 -04:00
										 |  |  |     zone = conn.create_hosted_zone("testdns.aws.com") | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     zoneid = zone["CreateHostedZoneResponse"]["HostedZone"]["Id"].split("/")[-1] | 
					
						
							| 
									
										
										
										
											2015-06-05 21:29:20 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     changes = ResourceRecordSets(conn, zoneid) | 
					
						
							|  |  |  |     change = changes.add_change("CREATE", "foo.bar.testdns.aws.com", "A") | 
					
						
							|  |  |  |     change.add_value("1.2.3.4") | 
					
						
							|  |  |  |     change.add_value("5.6.7.8") | 
					
						
							|  |  |  |     changes.commit() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-20 14:50:05 +03:00
										 |  |  |     rrsets = conn.get_all_rrsets(zoneid) | 
					
						
							| 
									
										
										
										
											2015-06-05 21:29:20 -04:00
										 |  |  |     rrsets.should.have.length_of(1) | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     set(rrsets[0].resource_records).should.equal(set(["1.2.3.4", "5.6.7.8"])) | 
					
						
							| 
									
										
										
										
											2015-06-05 21:29:20 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-23 10:27:09 +00:00
										 |  |  | # Has boto3 equivalent | 
					
						
							| 
									
										
										
										
											2017-02-15 22:35:45 -05:00
										 |  |  | @mock_route53_deprecated | 
					
						
							| 
									
										
										
										
											2015-06-28 17:27:24 +02:00
										 |  |  | def test_alias_rrset(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto.connect_route53("the_key", "the_secret") | 
					
						
							| 
									
										
										
										
											2015-06-28 17:27:24 +02:00
										 |  |  |     zone = conn.create_hosted_zone("testdns.aws.com") | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     zoneid = zone["CreateHostedZoneResponse"]["HostedZone"]["Id"].split("/")[-1] | 
					
						
							| 
									
										
										
										
											2015-06-28 17:27:24 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     changes = ResourceRecordSets(conn, zoneid) | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     changes.add_change( | 
					
						
							|  |  |  |         "CREATE", | 
					
						
							|  |  |  |         "foo.alias.testdns.aws.com", | 
					
						
							|  |  |  |         "A", | 
					
						
							|  |  |  |         alias_hosted_zone_id="Z3DG6IL3SJCGPX", | 
					
						
							|  |  |  |         alias_dns_name="foo.testdns.aws.com", | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     changes.add_change( | 
					
						
							|  |  |  |         "CREATE", | 
					
						
							|  |  |  |         "bar.alias.testdns.aws.com", | 
					
						
							|  |  |  |         "CNAME", | 
					
						
							|  |  |  |         alias_hosted_zone_id="Z3DG6IL3SJCGPX", | 
					
						
							|  |  |  |         alias_dns_name="bar.testdns.aws.com", | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2015-06-28 17:27:24 +02:00
										 |  |  |     changes.commit() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-20 14:50:05 +03:00
										 |  |  |     rrsets = conn.get_all_rrsets(zoneid, name="alias.testdns.aws.com") | 
					
						
							| 
									
										
										
										
											2018-06-21 21:09:04 -05:00
										 |  |  |     alias_targets = [rr_set.alias_dns_name for rr_set in rrsets] | 
					
						
							|  |  |  |     alias_targets.should.have.length_of(2) | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     alias_targets.should.contain("foo.testdns.aws.com") | 
					
						
							|  |  |  |     alias_targets.should.contain("bar.testdns.aws.com") | 
					
						
							| 
									
										
										
										
											2021-04-20 14:50:05 +03:00
										 |  |  |     rrsets[0].alias_dns_name.should.equal("bar.testdns.aws.com") | 
					
						
							| 
									
										
										
										
											2018-06-21 21:09:04 -05:00
										 |  |  |     rrsets[0].resource_records.should.have.length_of(0) | 
					
						
							| 
									
										
										
										
											2021-04-20 14:50:05 +03:00
										 |  |  |     rrsets = conn.get_all_rrsets(zoneid, name="foo.alias.testdns.aws.com", type="A") | 
					
						
							| 
									
										
										
										
											2015-06-28 17:27:24 +02:00
										 |  |  |     rrsets.should.have.length_of(1) | 
					
						
							| 
									
										
										
										
											2021-04-20 14:50:05 +03:00
										 |  |  |     rrsets[0].alias_dns_name.should.equal("foo.testdns.aws.com") | 
					
						
							| 
									
										
										
										
											2018-06-21 21:09:04 -05:00
										 |  |  |     rrsets[0].resource_records.should.have.length_of(0) | 
					
						
							| 
									
										
										
										
											2015-06-28 17:27:24 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-23 10:27:09 +00:00
										 |  |  | # Has boto3 equivalent | 
					
						
							| 
									
										
										
										
											2017-02-15 22:35:45 -05:00
										 |  |  | @mock_route53_deprecated | 
					
						
							| 
									
										
										
										
											2015-01-17 19:06:43 -05:00
										 |  |  | def test_create_health_check(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto.connect_route53("the_key", "the_secret") | 
					
						
							| 
									
										
										
										
											2015-01-17 19:06:43 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     check = HealthCheck( | 
					
						
							|  |  |  |         ip_addr="10.0.0.25", | 
					
						
							|  |  |  |         port=80, | 
					
						
							|  |  |  |         hc_type="HTTP", | 
					
						
							|  |  |  |         resource_path="/", | 
					
						
							|  |  |  |         fqdn="example.com", | 
					
						
							|  |  |  |         string_match="a good response", | 
					
						
							|  |  |  |         request_interval=10, | 
					
						
							|  |  |  |         failure_threshold=2, | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     conn.create_health_check(check) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     checks = conn.get_list_health_checks()["ListHealthChecksResponse"]["HealthChecks"] | 
					
						
							| 
									
										
										
										
											2015-01-17 19:06:43 -05:00
										 |  |  |     list(checks).should.have.length_of(1) | 
					
						
							|  |  |  |     check = checks[0] | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     config = check["HealthCheckConfig"] | 
					
						
							|  |  |  |     config["IPAddress"].should.equal("10.0.0.25") | 
					
						
							|  |  |  |     config["Port"].should.equal("80") | 
					
						
							|  |  |  |     config["Type"].should.equal("HTTP") | 
					
						
							|  |  |  |     config["ResourcePath"].should.equal("/") | 
					
						
							|  |  |  |     config["FullyQualifiedDomainName"].should.equal("example.com") | 
					
						
							|  |  |  |     config["SearchString"].should.equal("a good response") | 
					
						
							|  |  |  |     config["RequestInterval"].should.equal("10") | 
					
						
							|  |  |  |     config["FailureThreshold"].should.equal("2") | 
					
						
							| 
									
										
										
										
											2015-01-17 19:06:43 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-23 10:27:09 +00:00
										 |  |  | @mock_route53 | 
					
						
							|  |  |  | def test_create_health_check_boto3(): | 
					
						
							|  |  |  |     conn = boto3.client("route53", region_name="us-east-1") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     check = conn.create_health_check( | 
					
						
							|  |  |  |         CallerReference="?", | 
					
						
							|  |  |  |         HealthCheckConfig={ | 
					
						
							|  |  |  |             "IPAddress": "10.0.0.25", | 
					
						
							|  |  |  |             "Port": 80, | 
					
						
							|  |  |  |             "Type": "HTTP", | 
					
						
							|  |  |  |             "ResourcePath": "/", | 
					
						
							|  |  |  |             "FullyQualifiedDomainName": "example.com", | 
					
						
							|  |  |  |             "SearchString": "a good response", | 
					
						
							|  |  |  |             "RequestInterval": 10, | 
					
						
							|  |  |  |             "FailureThreshold": 2, | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |     )["HealthCheck"] | 
					
						
							|  |  |  |     check.should.have.key("Id").match("[a-z0-9-]+") | 
					
						
							|  |  |  |     check.should.have.key("CallerReference") | 
					
						
							|  |  |  |     check.should.have.key("HealthCheckConfig") | 
					
						
							|  |  |  |     check["HealthCheckConfig"].should.have.key("IPAddress").equal("10.0.0.25") | 
					
						
							|  |  |  |     check["HealthCheckConfig"].should.have.key("Port").equal(80) | 
					
						
							|  |  |  |     check["HealthCheckConfig"].should.have.key("Type").equal("HTTP") | 
					
						
							|  |  |  |     check["HealthCheckConfig"].should.have.key("ResourcePath").equal("/") | 
					
						
							|  |  |  |     check["HealthCheckConfig"].should.have.key("FullyQualifiedDomainName").equal( | 
					
						
							|  |  |  |         "example.com" | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     check["HealthCheckConfig"].should.have.key("SearchString").equal("a good response") | 
					
						
							|  |  |  |     check["HealthCheckConfig"].should.have.key("RequestInterval").equal(10) | 
					
						
							|  |  |  |     check["HealthCheckConfig"].should.have.key("FailureThreshold").equal(2) | 
					
						
							|  |  |  |     check.should.have.key("HealthCheckVersion").equal(1) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_route53 | 
					
						
							|  |  |  | def test_list_health_checks_boto3(): | 
					
						
							|  |  |  |     conn = boto3.client("route53", region_name="us-east-1") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     conn.list_health_checks()["HealthChecks"].should.have.length_of(0) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     check = conn.create_health_check( | 
					
						
							|  |  |  |         CallerReference="?", | 
					
						
							|  |  |  |         HealthCheckConfig={ | 
					
						
							|  |  |  |             "IPAddress": "10.0.0.25", | 
					
						
							|  |  |  |             "Port": 80, | 
					
						
							|  |  |  |             "Type": "HTTP", | 
					
						
							|  |  |  |             "ResourcePath": "/", | 
					
						
							|  |  |  |             "FullyQualifiedDomainName": "example.com", | 
					
						
							|  |  |  |             "SearchString": "a good response", | 
					
						
							|  |  |  |             "RequestInterval": 10, | 
					
						
							|  |  |  |             "FailureThreshold": 2, | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |     )["HealthCheck"] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     checks = conn.list_health_checks()["HealthChecks"] | 
					
						
							|  |  |  |     checks.should.have.length_of(1) | 
					
						
							|  |  |  |     checks.should.contain(check) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # Has boto3 equivalent | 
					
						
							| 
									
										
										
										
											2017-02-15 22:35:45 -05:00
										 |  |  | @mock_route53_deprecated | 
					
						
							| 
									
										
										
										
											2015-01-17 19:06:43 -05:00
										 |  |  | def test_delete_health_check(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto.connect_route53("the_key", "the_secret") | 
					
						
							| 
									
										
										
										
											2015-01-17 19:06:43 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     check = HealthCheck(ip_addr="10.0.0.25", port=80, hc_type="HTTP", resource_path="/") | 
					
						
							| 
									
										
										
										
											2015-01-17 19:06:43 -05:00
										 |  |  |     conn.create_health_check(check) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     checks = conn.get_list_health_checks()["ListHealthChecksResponse"]["HealthChecks"] | 
					
						
							| 
									
										
										
										
											2015-01-17 19:06:43 -05:00
										 |  |  |     list(checks).should.have.length_of(1) | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     health_check_id = checks[0]["Id"] | 
					
						
							| 
									
										
										
										
											2015-01-17 19:06:43 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     conn.delete_health_check(health_check_id) | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     checks = conn.get_list_health_checks()["ListHealthChecksResponse"]["HealthChecks"] | 
					
						
							| 
									
										
										
										
											2015-01-17 19:06:43 -05:00
										 |  |  |     list(checks).should.have.length_of(0) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-23 10:27:09 +00:00
										 |  |  | @mock_route53 | 
					
						
							|  |  |  | def test_delete_health_checks_boto3(): | 
					
						
							|  |  |  |     conn = boto3.client("route53", region_name="us-east-1") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     conn.list_health_checks()["HealthChecks"].should.have.length_of(0) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     check = conn.create_health_check( | 
					
						
							|  |  |  |         CallerReference="?", | 
					
						
							|  |  |  |         HealthCheckConfig={ | 
					
						
							|  |  |  |             "IPAddress": "10.0.0.25", | 
					
						
							|  |  |  |             "Port": 80, | 
					
						
							|  |  |  |             "Type": "HTTP", | 
					
						
							|  |  |  |             "ResourcePath": "/", | 
					
						
							|  |  |  |             "FullyQualifiedDomainName": "example.com", | 
					
						
							|  |  |  |             "SearchString": "a good response", | 
					
						
							|  |  |  |             "RequestInterval": 10, | 
					
						
							|  |  |  |             "FailureThreshold": 2, | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |     )["HealthCheck"] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     conn.delete_health_check(HealthCheckId=check["Id"]) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     checks = conn.list_health_checks()["HealthChecks"] | 
					
						
							|  |  |  |     checks.should.have.length_of(0) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # Has boto3 equivalent | 
					
						
							| 
									
										
										
										
											2017-02-15 22:35:45 -05:00
										 |  |  | @mock_route53_deprecated | 
					
						
							| 
									
										
										
										
											2015-01-17 19:06:43 -05:00
										 |  |  | def test_use_health_check_in_resource_record_set(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto.connect_route53("the_key", "the_secret") | 
					
						
							| 
									
										
										
										
											2015-01-17 19:06:43 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     check = HealthCheck(ip_addr="10.0.0.25", port=80, hc_type="HTTP", resource_path="/") | 
					
						
							|  |  |  |     check = conn.create_health_check(check)["CreateHealthCheckResponse"]["HealthCheck"] | 
					
						
							|  |  |  |     check_id = check["Id"] | 
					
						
							| 
									
										
										
										
											2015-01-17 19:06:43 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     zone = conn.create_hosted_zone("testdns.aws.com") | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     zone_id = zone["CreateHostedZoneResponse"]["HostedZone"]["Id"].split("/")[-1] | 
					
						
							| 
									
										
										
										
											2015-01-17 19:06:43 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     changes = ResourceRecordSets(conn, zone_id) | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     change = changes.add_change( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         "CREATE", "foo.bar.testdns.aws.com", "A", health_check=check_id | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2015-01-17 19:06:43 -05:00
										 |  |  |     change.add_value("1.2.3.4") | 
					
						
							|  |  |  |     changes.commit() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     record_sets = conn.get_all_rrsets(zone_id) | 
					
						
							|  |  |  |     record_sets[0].health_check.should.equal(check_id) | 
					
						
							| 
									
										
										
										
											2015-04-23 19:01:20 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-30 18:51:01 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-23 10:27:09 +00:00
										 |  |  | @mock_route53 | 
					
						
							|  |  |  | def test_use_health_check_in_resource_record_set_boto3(): | 
					
						
							|  |  |  |     conn = boto3.client("route53", region_name="us-east-1") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     check = conn.create_health_check( | 
					
						
							|  |  |  |         CallerReference="?", | 
					
						
							|  |  |  |         HealthCheckConfig={ | 
					
						
							|  |  |  |             "IPAddress": "10.0.0.25", | 
					
						
							|  |  |  |             "Port": 80, | 
					
						
							|  |  |  |             "Type": "HTTP", | 
					
						
							|  |  |  |             "ResourcePath": "/", | 
					
						
							|  |  |  |             "RequestInterval": 10, | 
					
						
							|  |  |  |             "FailureThreshold": 2, | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |     )["HealthCheck"] | 
					
						
							|  |  |  |     check_id = check["Id"] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     zone = conn.create_hosted_zone( | 
					
						
							|  |  |  |         Name="testdns.aws.com", CallerReference=str(hash("foo")) | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     zone_id = zone["HostedZone"]["Id"] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     conn.change_resource_record_sets( | 
					
						
							|  |  |  |         HostedZoneId=zone_id, | 
					
						
							|  |  |  |         ChangeBatch={ | 
					
						
							|  |  |  |             "Changes": [ | 
					
						
							|  |  |  |                 { | 
					
						
							|  |  |  |                     "Action": "CREATE", | 
					
						
							|  |  |  |                     "ResourceRecordSet": { | 
					
						
							|  |  |  |                         "Name": "foo.bar.testdns.aws.com", | 
					
						
							|  |  |  |                         "Type": "A", | 
					
						
							|  |  |  |                         "HealthCheckId": check_id, | 
					
						
							|  |  |  |                         "ResourceRecords": [{"Value": "1.2.3.4"}], | 
					
						
							|  |  |  |                     }, | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             ] | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     record_sets = conn.list_resource_record_sets(HostedZoneId=zone_id)[ | 
					
						
							|  |  |  |         "ResourceRecordSets" | 
					
						
							|  |  |  |     ] | 
					
						
							|  |  |  |     record_sets[0]["Name"].should.equal("foo.bar.testdns.aws.com.") | 
					
						
							|  |  |  |     record_sets[0]["HealthCheckId"].should.equal(check_id) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # Has boto3 equivalent | 
					
						
							| 
									
										
										
										
											2017-02-15 22:35:45 -05:00
										 |  |  | @mock_route53_deprecated | 
					
						
							| 
									
										
										
										
											2015-04-23 19:01:20 +00:00
										 |  |  | def test_hosted_zone_comment_preserved(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto.connect_route53("the_key", "the_secret") | 
					
						
							| 
									
										
										
										
											2015-04-23 19:01:20 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     firstzone = conn.create_hosted_zone("testdns.aws.com.", comment="test comment") | 
					
						
							|  |  |  |     zone_id = firstzone["CreateHostedZoneResponse"]["HostedZone"]["Id"].split("/")[-1] | 
					
						
							| 
									
										
										
										
											2015-04-23 19:01:20 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     hosted_zone = conn.get_hosted_zone(zone_id) | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     hosted_zone["GetHostedZoneResponse"]["HostedZone"]["Config"][ | 
					
						
							|  |  |  |         "Comment" | 
					
						
							|  |  |  |     ].should.equal("test comment") | 
					
						
							| 
									
										
										
										
											2015-04-23 19:01:20 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     hosted_zones = conn.get_all_hosted_zones() | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     hosted_zones["ListHostedZonesResponse"]["HostedZones"][0]["Config"][ | 
					
						
							|  |  |  |         "Comment" | 
					
						
							|  |  |  |     ].should.equal("test comment") | 
					
						
							| 
									
										
										
										
											2015-04-23 19:01:20 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     zone = conn.get_zone("testdns.aws.com.") | 
					
						
							|  |  |  |     zone.config["Comment"].should.equal("test comment") | 
					
						
							| 
									
										
										
										
											2015-04-30 18:51:01 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-23 10:27:09 +00:00
										 |  |  | @mock_route53 | 
					
						
							|  |  |  | def test_hosted_zone_comment_preserved_boto3(): | 
					
						
							|  |  |  |     conn = boto3.client("route53", region_name="us-east-1") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     firstzone = conn.create_hosted_zone( | 
					
						
							|  |  |  |         Name="testdns.aws.com", | 
					
						
							|  |  |  |         CallerReference=str(hash("foo")), | 
					
						
							|  |  |  |         HostedZoneConfig={"Comment": "test comment"}, | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     zone_id = firstzone["HostedZone"]["Id"] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     hosted_zone = conn.get_hosted_zone(Id=zone_id) | 
					
						
							|  |  |  |     hosted_zone["HostedZone"]["Config"]["Comment"].should.equal("test comment") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     hosted_zones = conn.list_hosted_zones() | 
					
						
							|  |  |  |     hosted_zones["HostedZones"][0]["Config"]["Comment"].should.equal("test comment") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # Has boto3 equivalent | 
					
						
							| 
									
										
										
										
											2017-02-15 22:35:45 -05:00
										 |  |  | @mock_route53_deprecated | 
					
						
							| 
									
										
										
										
											2015-04-30 18:51:01 -04:00
										 |  |  | def test_deleting_weighted_route(): | 
					
						
							|  |  |  |     conn = boto.connect_route53() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     conn.create_hosted_zone("testdns.aws.com.") | 
					
						
							|  |  |  |     zone = conn.get_zone("testdns.aws.com.") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     zone.add_cname( | 
					
						
							|  |  |  |         "cname.testdns.aws.com", "example.com", identifier=("success-test-foo", "50") | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     zone.add_cname( | 
					
						
							|  |  |  |         "cname.testdns.aws.com", "example.com", identifier=("success-test-bar", "50") | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2015-04-30 18:51:01 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     cnames = zone.get_cname("cname.testdns.aws.com.", all=True) | 
					
						
							| 
									
										
										
										
											2015-04-30 18:51:01 -04:00
										 |  |  |     cnames.should.have.length_of(2) | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     foo_cname = [cname for cname in cnames if cname.identifier == "success-test-foo"][0] | 
					
						
							| 
									
										
										
										
											2015-04-30 18:51:01 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     zone.delete_record(foo_cname) | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     cname = zone.get_cname("cname.testdns.aws.com.", all=True) | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     # When get_cname only had one result, it returns just that result instead | 
					
						
							|  |  |  |     # of a list. | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     cname.identifier.should.equal("success-test-bar") | 
					
						
							| 
									
										
										
										
											2015-09-08 21:36:32 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-23 10:27:09 +00:00
										 |  |  | @mock_route53 | 
					
						
							|  |  |  | def test_deleting_weighted_route_boto3(): | 
					
						
							|  |  |  |     conn = boto3.client("route53", region_name="us-east-1") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     zone = conn.create_hosted_zone( | 
					
						
							|  |  |  |         Name="testdns.aws.com", CallerReference=str(hash("foo")) | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     zone_id = zone["HostedZone"]["Id"] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     for identifier in ["success-test-foo", "success-test-bar"]: | 
					
						
							|  |  |  |         conn.change_resource_record_sets( | 
					
						
							|  |  |  |             HostedZoneId=zone_id, | 
					
						
							|  |  |  |             ChangeBatch={ | 
					
						
							|  |  |  |                 "Changes": [ | 
					
						
							|  |  |  |                     { | 
					
						
							|  |  |  |                         "Action": "CREATE", | 
					
						
							|  |  |  |                         "ResourceRecordSet": { | 
					
						
							|  |  |  |                             "Name": "cname.testdns.aws.com", | 
					
						
							|  |  |  |                             "Type": "CNAME", | 
					
						
							|  |  |  |                             "SetIdentifier": identifier, | 
					
						
							|  |  |  |                             "Weight": 50, | 
					
						
							|  |  |  |                         }, | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                 ] | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     cnames = conn.list_resource_record_sets( | 
					
						
							|  |  |  |         HostedZoneId=zone_id, StartRecordName="cname", StartRecordType="CNAME" | 
					
						
							|  |  |  |     )["ResourceRecordSets"] | 
					
						
							|  |  |  |     cnames.should.have.length_of(2) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     conn.change_resource_record_sets( | 
					
						
							|  |  |  |         HostedZoneId=zone_id, | 
					
						
							|  |  |  |         ChangeBatch={ | 
					
						
							|  |  |  |             "Changes": [ | 
					
						
							|  |  |  |                 { | 
					
						
							|  |  |  |                     "Action": "DELETE", | 
					
						
							|  |  |  |                     "ResourceRecordSet": { | 
					
						
							|  |  |  |                         "Name": "cname.testdns.aws.com", | 
					
						
							|  |  |  |                         "Type": "CNAME", | 
					
						
							|  |  |  |                         "SetIdentifier": "success-test-foo", | 
					
						
							|  |  |  |                     }, | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             ] | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     cnames = conn.list_resource_record_sets( | 
					
						
							|  |  |  |         HostedZoneId=zone_id, StartRecordName="cname", StartRecordType="CNAME" | 
					
						
							|  |  |  |     )["ResourceRecordSets"] | 
					
						
							|  |  |  |     cnames.should.have.length_of(1) | 
					
						
							|  |  |  |     cnames[0]["Name"].should.equal("cname.testdns.aws.com.") | 
					
						
							|  |  |  |     cnames[0]["SetIdentifier"].should.equal("success-test-bar") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # Has boto3 equivalent | 
					
						
							| 
									
										
										
										
											2017-02-15 22:35:45 -05:00
										 |  |  | @mock_route53_deprecated | 
					
						
							| 
									
										
										
										
											2015-09-08 21:36:32 +00:00
										 |  |  | def test_deleting_latency_route(): | 
					
						
							|  |  |  |     conn = boto.connect_route53() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     conn.create_hosted_zone("testdns.aws.com.") | 
					
						
							|  |  |  |     zone = conn.get_zone("testdns.aws.com.") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     zone.add_cname( | 
					
						
							|  |  |  |         "cname.testdns.aws.com", | 
					
						
							|  |  |  |         "example.com", | 
					
						
							|  |  |  |         identifier=("success-test-foo", "us-west-2"), | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     zone.add_cname( | 
					
						
							|  |  |  |         "cname.testdns.aws.com", | 
					
						
							|  |  |  |         "example.com", | 
					
						
							|  |  |  |         identifier=("success-test-bar", "us-west-1"), | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2015-09-08 21:36:32 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     cnames = zone.get_cname("cname.testdns.aws.com.", all=True) | 
					
						
							| 
									
										
										
										
											2015-09-08 21:36:32 +00:00
										 |  |  |     cnames.should.have.length_of(2) | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     foo_cname = [cname for cname in cnames if cname.identifier == "success-test-foo"][0] | 
					
						
							|  |  |  |     foo_cname.region.should.equal("us-west-2") | 
					
						
							| 
									
										
										
										
											2015-09-08 21:36:32 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     zone.delete_record(foo_cname) | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     cname = zone.get_cname("cname.testdns.aws.com.", all=True) | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     # When get_cname only had one result, it returns just that result instead | 
					
						
							|  |  |  |     # of a list. | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     cname.identifier.should.equal("success-test-bar") | 
					
						
							|  |  |  |     cname.region.should.equal("us-west-1") | 
					
						
							| 
									
										
										
										
											2016-06-03 09:57:33 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-23 10:27:09 +00:00
										 |  |  | @mock_route53 | 
					
						
							|  |  |  | def test_deleting_latency_route_boto3(): | 
					
						
							|  |  |  |     conn = boto3.client("route53", region_name="us-east-1") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     zone = conn.create_hosted_zone( | 
					
						
							|  |  |  |         Name="testdns.aws.com", CallerReference=str(hash("foo")) | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     zone_id = zone["HostedZone"]["Id"] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     for _id, region in [ | 
					
						
							|  |  |  |         ("success-test-foo", "us-west-2"), | 
					
						
							|  |  |  |         ("success-test-bar", "us-west-1"), | 
					
						
							|  |  |  |     ]: | 
					
						
							|  |  |  |         conn.change_resource_record_sets( | 
					
						
							|  |  |  |             HostedZoneId=zone_id, | 
					
						
							|  |  |  |             ChangeBatch={ | 
					
						
							|  |  |  |                 "Changes": [ | 
					
						
							|  |  |  |                     { | 
					
						
							|  |  |  |                         "Action": "CREATE", | 
					
						
							|  |  |  |                         "ResourceRecordSet": { | 
					
						
							|  |  |  |                             "Name": "cname.testdns.aws.com", | 
					
						
							|  |  |  |                             "Type": "CNAME", | 
					
						
							|  |  |  |                             "SetIdentifier": _id, | 
					
						
							|  |  |  |                             "Region": region, | 
					
						
							|  |  |  |                             "ResourceRecords": [{"Value": "example.com"}], | 
					
						
							|  |  |  |                         }, | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                 ] | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     cnames = conn.list_resource_record_sets( | 
					
						
							|  |  |  |         HostedZoneId=zone_id, StartRecordName="cname", StartRecordType="CNAME" | 
					
						
							|  |  |  |     )["ResourceRecordSets"] | 
					
						
							|  |  |  |     cnames.should.have.length_of(2) | 
					
						
							|  |  |  |     foo_cname = [ | 
					
						
							|  |  |  |         cname for cname in cnames if cname["SetIdentifier"] == "success-test-foo" | 
					
						
							|  |  |  |     ][0] | 
					
						
							|  |  |  |     foo_cname["Region"].should.equal("us-west-2") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     conn.change_resource_record_sets( | 
					
						
							|  |  |  |         HostedZoneId=zone_id, | 
					
						
							|  |  |  |         ChangeBatch={ | 
					
						
							|  |  |  |             "Changes": [ | 
					
						
							|  |  |  |                 { | 
					
						
							|  |  |  |                     "Action": "DELETE", | 
					
						
							|  |  |  |                     "ResourceRecordSet": { | 
					
						
							|  |  |  |                         "Name": "cname.testdns.aws.com", | 
					
						
							|  |  |  |                         "Type": "CNAME", | 
					
						
							|  |  |  |                         "SetIdentifier": "success-test-foo", | 
					
						
							|  |  |  |                     }, | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             ] | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     cnames = conn.list_resource_record_sets( | 
					
						
							|  |  |  |         HostedZoneId=zone_id, StartRecordName="cname", StartRecordType="CNAME" | 
					
						
							|  |  |  |     )["ResourceRecordSets"] | 
					
						
							|  |  |  |     cnames.should.have.length_of(1) | 
					
						
							|  |  |  |     cnames[0]["SetIdentifier"].should.equal("success-test-bar") | 
					
						
							|  |  |  |     cnames[0]["Region"].should.equal("us-west-1") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # Has boto3 equivalent | 
					
						
							| 
									
										
										
										
											2017-02-15 22:35:45 -05:00
										 |  |  | @mock_route53_deprecated | 
					
						
							| 
									
										
										
										
											2016-06-03 09:57:33 -04:00
										 |  |  | def test_hosted_zone_private_zone_preserved(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto.connect_route53("the_key", "the_secret") | 
					
						
							| 
									
										
										
										
											2016-06-03 09:57:33 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     firstzone = conn.create_hosted_zone( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         "testdns.aws.com.", private_zone=True, vpc_id="vpc-fake", vpc_region="us-east-1" | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     zone_id = firstzone["CreateHostedZoneResponse"]["HostedZone"]["Id"].split("/")[-1] | 
					
						
							| 
									
										
										
										
											2016-06-03 09:57:33 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     hosted_zone = conn.get_hosted_zone(zone_id) | 
					
						
							|  |  |  |     # in (original) boto, these bools returned as strings. | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     hosted_zone["GetHostedZoneResponse"]["HostedZone"]["Config"][ | 
					
						
							|  |  |  |         "PrivateZone" | 
					
						
							|  |  |  |     ].should.equal("True") | 
					
						
							| 
									
										
										
										
											2016-06-03 09:57:33 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     hosted_zones = conn.get_all_hosted_zones() | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     hosted_zones["ListHostedZonesResponse"]["HostedZones"][0]["Config"][ | 
					
						
							|  |  |  |         "PrivateZone" | 
					
						
							|  |  |  |     ].should.equal("True") | 
					
						
							| 
									
										
										
										
											2016-06-03 09:57:33 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     zone = conn.get_zone("testdns.aws.com.") | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     zone.config["PrivateZone"].should.equal("True") | 
					
						
							| 
									
										
										
										
											2016-06-03 09:57:33 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_route53 | 
					
						
							|  |  |  | def test_hosted_zone_private_zone_preserved_boto3(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto3.client("route53", region_name="us-east-1") | 
					
						
							| 
									
										
										
										
											2016-06-03 09:57:33 -04:00
										 |  |  |     # TODO: actually create_hosted_zone statements with PrivateZone=True, but without | 
					
						
							|  |  |  |     # a _valid_ vpc-id should fail. | 
					
						
							|  |  |  |     firstzone = conn.create_hosted_zone( | 
					
						
							|  |  |  |         Name="testdns.aws.com.", | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         CallerReference=str(hash("foo")), | 
					
						
							|  |  |  |         HostedZoneConfig=dict(PrivateZone=True, Comment="Test"), | 
					
						
							| 
									
										
										
										
											2016-06-03 09:57:33 -04:00
										 |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     zone_id = firstzone["HostedZone"]["Id"].split("/")[-1] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     hosted_zone = conn.get_hosted_zone(Id=zone_id) | 
					
						
							|  |  |  |     hosted_zone["HostedZone"]["Config"]["PrivateZone"].should.equal(True) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     hosted_zones = conn.list_hosted_zones() | 
					
						
							|  |  |  |     hosted_zones["HostedZones"][0]["Config"]["PrivateZone"].should.equal(True) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-13 14:09:51 +00:00
										 |  |  |     hosted_zones = conn.list_hosted_zones_by_name(DNSName="testdns.aws.com.") | 
					
						
							|  |  |  |     len(hosted_zones["HostedZones"]).should.equal(1) | 
					
						
							|  |  |  |     hosted_zones["HostedZones"][0]["Config"]["PrivateZone"].should.equal(True) | 
					
						
							| 
									
										
										
										
											2016-09-20 17:41:23 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-20 17:41:23 -07:00
										 |  |  | @mock_route53 | 
					
						
							|  |  |  | def test_list_or_change_tags_for_resource_request(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto3.client("route53", region_name="us-east-1") | 
					
						
							| 
									
										
										
										
											2017-02-23 19:43:48 -05:00
										 |  |  |     health_check = conn.create_health_check( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         CallerReference="foobar", | 
					
						
							| 
									
										
										
										
											2017-02-23 19:43:48 -05:00
										 |  |  |         HealthCheckConfig={ | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |             "IPAddress": "192.0.2.44", | 
					
						
							|  |  |  |             "Port": 123, | 
					
						
							|  |  |  |             "Type": "HTTP", | 
					
						
							|  |  |  |             "ResourcePath": "/", | 
					
						
							|  |  |  |             "RequestInterval": 30, | 
					
						
							|  |  |  |             "FailureThreshold": 123, | 
					
						
							|  |  |  |             "HealthThreshold": 123, | 
					
						
							|  |  |  |         }, | 
					
						
							| 
									
										
										
										
											2017-02-23 19:43:48 -05:00
										 |  |  |     ) | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     healthcheck_id = health_check["HealthCheck"]["Id"] | 
					
						
							| 
									
										
										
										
											2016-09-20 17:41:23 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-28 13:55:19 -05:00
										 |  |  |     # confirm this works for resources with zero tags | 
					
						
							|  |  |  |     response = conn.list_tags_for_resource( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         ResourceType="healthcheck", ResourceId=healthcheck_id | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2019-08-28 13:55:19 -05:00
										 |  |  |     response["ResourceTagSet"]["Tags"].should.be.empty | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-20 17:41:23 -07:00
										 |  |  |     tag1 = {"Key": "Deploy", "Value": "True"} | 
					
						
							|  |  |  |     tag2 = {"Key": "Name", "Value": "UnitTest"} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Test adding a tag for a resource id | 
					
						
							|  |  |  |     conn.change_tags_for_resource( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         ResourceType="healthcheck", ResourceId=healthcheck_id, AddTags=[tag1, tag2] | 
					
						
							| 
									
										
										
										
											2016-09-20 17:41:23 -07:00
										 |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Check to make sure that the response has the 'ResourceTagSet' key | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     response = conn.list_tags_for_resource( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         ResourceType="healthcheck", ResourceId=healthcheck_id | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     response.should.contain("ResourceTagSet") | 
					
						
							| 
									
										
										
										
											2016-09-20 17:41:23 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # Validate that each key was added | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     response["ResourceTagSet"]["Tags"].should.contain(tag1) | 
					
						
							|  |  |  |     response["ResourceTagSet"]["Tags"].should.contain(tag2) | 
					
						
							| 
									
										
										
										
											2016-09-20 17:41:23 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     len(response["ResourceTagSet"]["Tags"]).should.equal(2) | 
					
						
							| 
									
										
										
										
											2016-09-22 18:44:07 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-20 17:41:23 -07:00
										 |  |  |     # Try to remove the tags | 
					
						
							|  |  |  |     conn.change_tags_for_resource( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         ResourceType="healthcheck", | 
					
						
							| 
									
										
										
										
											2016-09-20 17:41:23 -07:00
										 |  |  |         ResourceId=healthcheck_id, | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         RemoveTagKeys=[tag1["Key"]], | 
					
						
							| 
									
										
										
										
											2016-09-20 17:41:23 -07:00
										 |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Check to make sure that the response has the 'ResourceTagSet' key | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     response = conn.list_tags_for_resource( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         ResourceType="healthcheck", ResourceId=healthcheck_id | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     response.should.contain("ResourceTagSet") | 
					
						
							|  |  |  |     response["ResourceTagSet"]["Tags"].should_not.contain(tag1) | 
					
						
							|  |  |  |     response["ResourceTagSet"]["Tags"].should.contain(tag2) | 
					
						
							| 
									
										
										
										
											2016-09-20 17:41:23 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # Remove the second tag | 
					
						
							|  |  |  |     conn.change_tags_for_resource( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         ResourceType="healthcheck", | 
					
						
							| 
									
										
										
										
											2016-09-20 17:41:23 -07:00
										 |  |  |         ResourceId=healthcheck_id, | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         RemoveTagKeys=[tag2["Key"]], | 
					
						
							| 
									
										
										
										
											2016-09-20 17:41:23 -07:00
										 |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     response = conn.list_tags_for_resource( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         ResourceType="healthcheck", ResourceId=healthcheck_id | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     response["ResourceTagSet"]["Tags"].should_not.contain(tag2) | 
					
						
							| 
									
										
										
										
											2016-09-20 17:41:23 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # Re-add the tags | 
					
						
							|  |  |  |     conn.change_tags_for_resource( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         ResourceType="healthcheck", ResourceId=healthcheck_id, AddTags=[tag1, tag2] | 
					
						
							| 
									
										
										
										
											2016-09-20 17:41:23 -07:00
										 |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Remove both | 
					
						
							|  |  |  |     conn.change_tags_for_resource( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         ResourceType="healthcheck", | 
					
						
							| 
									
										
										
										
											2016-09-20 17:41:23 -07:00
										 |  |  |         ResourceId=healthcheck_id, | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         RemoveTagKeys=[tag1["Key"], tag2["Key"]], | 
					
						
							| 
									
										
										
										
											2016-09-20 17:41:23 -07:00
										 |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     response = conn.list_tags_for_resource( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         ResourceType="healthcheck", ResourceId=healthcheck_id | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     response["ResourceTagSet"]["Tags"].should.be.empty | 
					
						
							| 
									
										
										
										
											2017-03-13 14:09:51 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_route53 | 
					
						
							|  |  |  | def test_list_hosted_zones_by_name(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto3.client("route53", region_name="us-east-1") | 
					
						
							| 
									
										
										
										
											2017-03-13 14:09:51 +00:00
										 |  |  |     conn.create_hosted_zone( | 
					
						
							|  |  |  |         Name="test.b.com.", | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         CallerReference=str(hash("foo")), | 
					
						
							|  |  |  |         HostedZoneConfig=dict(PrivateZone=True, Comment="test com"), | 
					
						
							| 
									
										
										
										
											2017-03-13 14:09:51 +00:00
										 |  |  |     ) | 
					
						
							|  |  |  |     conn.create_hosted_zone( | 
					
						
							|  |  |  |         Name="test.a.org.", | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         CallerReference=str(hash("bar")), | 
					
						
							|  |  |  |         HostedZoneConfig=dict(PrivateZone=True, Comment="test org"), | 
					
						
							| 
									
										
										
										
											2017-03-13 14:09:51 +00:00
										 |  |  |     ) | 
					
						
							|  |  |  |     conn.create_hosted_zone( | 
					
						
							|  |  |  |         Name="test.a.org.", | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         CallerReference=str(hash("bar")), | 
					
						
							|  |  |  |         HostedZoneConfig=dict(PrivateZone=True, Comment="test org 2"), | 
					
						
							| 
									
										
										
										
											2017-03-13 14:09:51 +00:00
										 |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # test lookup | 
					
						
							|  |  |  |     zones = conn.list_hosted_zones_by_name(DNSName="test.b.com.") | 
					
						
							|  |  |  |     len(zones["HostedZones"]).should.equal(1) | 
					
						
							|  |  |  |     zones["HostedZones"][0]["Name"].should.equal("test.b.com.") | 
					
						
							|  |  |  |     zones = conn.list_hosted_zones_by_name(DNSName="test.a.org.") | 
					
						
							|  |  |  |     len(zones["HostedZones"]).should.equal(2) | 
					
						
							|  |  |  |     zones["HostedZones"][0]["Name"].should.equal("test.a.org.") | 
					
						
							|  |  |  |     zones["HostedZones"][1]["Name"].should.equal("test.a.org.") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # test sort order | 
					
						
							|  |  |  |     zones = conn.list_hosted_zones_by_name() | 
					
						
							|  |  |  |     len(zones["HostedZones"]).should.equal(3) | 
					
						
							|  |  |  |     zones["HostedZones"][0]["Name"].should.equal("test.b.com.") | 
					
						
							|  |  |  |     zones["HostedZones"][1]["Name"].should.equal("test.a.org.") | 
					
						
							|  |  |  |     zones["HostedZones"][2]["Name"].should.equal("test.a.org.") | 
					
						
							| 
									
										
										
										
											2017-04-28 21:26:32 +05:30
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-16 06:58:16 -06:00
										 |  |  | @mock_route53 | 
					
						
							|  |  |  | def test_list_hosted_zones_by_dns_name(): | 
					
						
							|  |  |  |     conn = boto3.client("route53", region_name="us-east-1") | 
					
						
							|  |  |  |     conn.create_hosted_zone( | 
					
						
							|  |  |  |         Name="test.b.com.", | 
					
						
							|  |  |  |         CallerReference=str(hash("foo")), | 
					
						
							|  |  |  |         HostedZoneConfig=dict(PrivateZone=True, Comment="test com"), | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     conn.create_hosted_zone( | 
					
						
							|  |  |  |         Name="test.a.org.", | 
					
						
							|  |  |  |         CallerReference=str(hash("bar")), | 
					
						
							|  |  |  |         HostedZoneConfig=dict(PrivateZone=True, Comment="test org"), | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     conn.create_hosted_zone( | 
					
						
							|  |  |  |         Name="test.a.org.", | 
					
						
							|  |  |  |         CallerReference=str(hash("bar")), | 
					
						
							|  |  |  |         HostedZoneConfig=dict(PrivateZone=True, Comment="test org 2"), | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     conn.create_hosted_zone( | 
					
						
							|  |  |  |         Name="my.test.net.", | 
					
						
							|  |  |  |         CallerReference=str(hash("baz")), | 
					
						
							|  |  |  |         HostedZoneConfig=dict(PrivateZone=False, Comment="test net"), | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # test lookup | 
					
						
							|  |  |  |     zones = conn.list_hosted_zones_by_name(DNSName="test.b.com.") | 
					
						
							|  |  |  |     len(zones["HostedZones"]).should.equal(1) | 
					
						
							|  |  |  |     zones["DNSName"].should.equal("test.b.com.") | 
					
						
							|  |  |  |     zones = conn.list_hosted_zones_by_name(DNSName="test.a.org.") | 
					
						
							|  |  |  |     len(zones["HostedZones"]).should.equal(2) | 
					
						
							|  |  |  |     zones["DNSName"].should.equal("test.a.org.") | 
					
						
							|  |  |  |     zones["DNSName"].should.equal("test.a.org.") | 
					
						
							|  |  |  |     zones = conn.list_hosted_zones_by_name(DNSName="my.test.net.") | 
					
						
							|  |  |  |     len(zones["HostedZones"]).should.equal(1) | 
					
						
							|  |  |  |     zones["DNSName"].should.equal("my.test.net.") | 
					
						
							|  |  |  |     zones = conn.list_hosted_zones_by_name(DNSName="my.test.net") | 
					
						
							|  |  |  |     len(zones["HostedZones"]).should.equal(1) | 
					
						
							|  |  |  |     zones["DNSName"].should.equal("my.test.net.") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # test sort order | 
					
						
							|  |  |  |     zones = conn.list_hosted_zones_by_name() | 
					
						
							|  |  |  |     len(zones["HostedZones"]).should.equal(4) | 
					
						
							|  |  |  |     zones["HostedZones"][0]["Name"].should.equal("test.b.com.") | 
					
						
							|  |  |  |     zones["HostedZones"][1]["Name"].should.equal("my.test.net.") | 
					
						
							|  |  |  |     zones["HostedZones"][2]["Name"].should.equal("test.a.org.") | 
					
						
							|  |  |  |     zones["HostedZones"][3]["Name"].should.equal("test.a.org.") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-28 21:26:32 +05:30
										 |  |  | @mock_route53 | 
					
						
							|  |  |  | def test_change_resource_record_sets_crud_valid(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto3.client("route53", region_name="us-east-1") | 
					
						
							| 
									
										
										
										
											2017-04-28 21:26:32 +05:30
										 |  |  |     conn.create_hosted_zone( | 
					
						
							|  |  |  |         Name="db.", | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         CallerReference=str(hash("foo")), | 
					
						
							|  |  |  |         HostedZoneConfig=dict(PrivateZone=True, Comment="db"), | 
					
						
							| 
									
										
										
										
											2017-04-28 21:26:32 +05:30
										 |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     zones = conn.list_hosted_zones_by_name(DNSName="db.") | 
					
						
							|  |  |  |     len(zones["HostedZones"]).should.equal(1) | 
					
						
							|  |  |  |     zones["HostedZones"][0]["Name"].should.equal("db.") | 
					
						
							|  |  |  |     hosted_zone_id = zones["HostedZones"][0]["Id"] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Create A Record. | 
					
						
							|  |  |  |     a_record_endpoint_payload = { | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         "Comment": "Create A record prod.redis.db", | 
					
						
							|  |  |  |         "Changes": [ | 
					
						
							| 
									
										
										
										
											2017-04-28 21:26:32 +05:30
										 |  |  |             { | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |                 "Action": "CREATE", | 
					
						
							|  |  |  |                 "ResourceRecordSet": { | 
					
						
							|  |  |  |                     "Name": "prod.redis.db.", | 
					
						
							|  |  |  |                     "Type": "A", | 
					
						
							|  |  |  |                     "TTL": 10, | 
					
						
							|  |  |  |                     "ResourceRecords": [{"Value": "127.0.0.1"}], | 
					
						
							|  |  |  |                 }, | 
					
						
							| 
									
										
										
										
											2017-04-28 21:26:32 +05:30
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         ], | 
					
						
							| 
									
										
										
										
											2017-04-28 21:26:32 +05:30
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn.change_resource_record_sets( | 
					
						
							|  |  |  |         HostedZoneId=hosted_zone_id, ChangeBatch=a_record_endpoint_payload | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2017-04-28 21:26:32 +05:30
										 |  |  | 
 | 
					
						
							|  |  |  |     response = conn.list_resource_record_sets(HostedZoneId=hosted_zone_id) | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     len(response["ResourceRecordSets"]).should.equal(1) | 
					
						
							|  |  |  |     a_record_detail = response["ResourceRecordSets"][0] | 
					
						
							|  |  |  |     a_record_detail["Name"].should.equal("prod.redis.db.") | 
					
						
							|  |  |  |     a_record_detail["Type"].should.equal("A") | 
					
						
							|  |  |  |     a_record_detail["TTL"].should.equal(10) | 
					
						
							|  |  |  |     a_record_detail["ResourceRecords"].should.equal([{"Value": "127.0.0.1"}]) | 
					
						
							| 
									
										
										
										
											2017-04-28 21:26:32 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-27 10:54:55 +00:00
										 |  |  |     # Update A Record. | 
					
						
							| 
									
										
										
										
											2017-04-28 21:26:32 +05:30
										 |  |  |     cname_record_endpoint_payload = { | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         "Comment": "Update A record prod.redis.db", | 
					
						
							|  |  |  |         "Changes": [ | 
					
						
							| 
									
										
										
										
											2017-04-28 21:26:32 +05:30
										 |  |  |             { | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |                 "Action": "UPSERT", | 
					
						
							|  |  |  |                 "ResourceRecordSet": { | 
					
						
							|  |  |  |                     "Name": "prod.redis.db.", | 
					
						
							|  |  |  |                     "Type": "A", | 
					
						
							|  |  |  |                     "TTL": 60, | 
					
						
							|  |  |  |                     "ResourceRecords": [{"Value": "192.168.1.1"}], | 
					
						
							|  |  |  |                 }, | 
					
						
							| 
									
										
										
										
											2017-04-28 21:26:32 +05:30
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         ], | 
					
						
							| 
									
										
										
										
											2017-04-28 21:26:32 +05:30
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn.change_resource_record_sets( | 
					
						
							|  |  |  |         HostedZoneId=hosted_zone_id, ChangeBatch=cname_record_endpoint_payload | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2017-04-28 21:26:32 +05:30
										 |  |  | 
 | 
					
						
							|  |  |  |     response = conn.list_resource_record_sets(HostedZoneId=hosted_zone_id) | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     len(response["ResourceRecordSets"]).should.equal(1) | 
					
						
							|  |  |  |     cname_record_detail = response["ResourceRecordSets"][0] | 
					
						
							|  |  |  |     cname_record_detail["Name"].should.equal("prod.redis.db.") | 
					
						
							|  |  |  |     cname_record_detail["Type"].should.equal("A") | 
					
						
							|  |  |  |     cname_record_detail["TTL"].should.equal(60) | 
					
						
							|  |  |  |     cname_record_detail["ResourceRecords"].should.equal([{"Value": "192.168.1.1"}]) | 
					
						
							| 
									
										
										
										
											2017-04-28 21:26:32 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-21 21:09:04 -05:00
										 |  |  |     # Update to add Alias. | 
					
						
							|  |  |  |     cname_alias_record_endpoint_payload = { | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         "Comment": "Update to Alias prod.redis.db", | 
					
						
							|  |  |  |         "Changes": [ | 
					
						
							| 
									
										
										
										
											2018-06-21 21:09:04 -05:00
										 |  |  |             { | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |                 "Action": "UPSERT", | 
					
						
							|  |  |  |                 "ResourceRecordSet": { | 
					
						
							|  |  |  |                     "Name": "prod.redis.db.", | 
					
						
							|  |  |  |                     "Type": "A", | 
					
						
							|  |  |  |                     "TTL": 60, | 
					
						
							|  |  |  |                     "AliasTarget": { | 
					
						
							|  |  |  |                         "HostedZoneId": hosted_zone_id, | 
					
						
							|  |  |  |                         "DNSName": "prod.redis.alias.", | 
					
						
							|  |  |  |                         "EvaluateTargetHealth": False, | 
					
						
							|  |  |  |                     }, | 
					
						
							|  |  |  |                 }, | 
					
						
							| 
									
										
										
										
											2018-06-21 21:09:04 -05:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         ], | 
					
						
							| 
									
										
										
										
											2018-06-21 21:09:04 -05:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn.change_resource_record_sets( | 
					
						
							|  |  |  |         HostedZoneId=hosted_zone_id, ChangeBatch=cname_alias_record_endpoint_payload | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2018-06-21 21:09:04 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     response = conn.list_resource_record_sets(HostedZoneId=hosted_zone_id) | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     cname_alias_record_detail = response["ResourceRecordSets"][0] | 
					
						
							|  |  |  |     cname_alias_record_detail["Name"].should.equal("prod.redis.db.") | 
					
						
							|  |  |  |     cname_alias_record_detail["Type"].should.equal("A") | 
					
						
							|  |  |  |     cname_alias_record_detail["TTL"].should.equal(60) | 
					
						
							|  |  |  |     cname_alias_record_detail["AliasTarget"].should.equal( | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             "HostedZoneId": hosted_zone_id, | 
					
						
							|  |  |  |             "DNSName": "prod.redis.alias.", | 
					
						
							|  |  |  |             "EvaluateTargetHealth": False, | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     cname_alias_record_detail.should_not.contain("ResourceRecords") | 
					
						
							| 
									
										
										
										
											2018-06-21 21:09:04 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-17 15:53:32 +02:00
										 |  |  |     # Delete record with wrong type. | 
					
						
							| 
									
										
										
										
											2017-04-28 21:26:32 +05:30
										 |  |  |     delete_payload = { | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         "Comment": "delete prod.redis.db", | 
					
						
							|  |  |  |         "Changes": [ | 
					
						
							| 
									
										
										
										
											2017-04-28 21:26:32 +05:30
										 |  |  |             { | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |                 "Action": "DELETE", | 
					
						
							|  |  |  |                 "ResourceRecordSet": {"Name": "prod.redis.db", "Type": "CNAME"}, | 
					
						
							| 
									
										
										
										
											2017-04-28 21:26:32 +05:30
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         ], | 
					
						
							| 
									
										
										
										
											2017-04-28 21:26:32 +05:30
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn.change_resource_record_sets( | 
					
						
							|  |  |  |         HostedZoneId=hosted_zone_id, ChangeBatch=delete_payload | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2017-04-28 21:26:32 +05:30
										 |  |  |     response = conn.list_resource_record_sets(HostedZoneId=hosted_zone_id) | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     len(response["ResourceRecordSets"]).should.equal(1) | 
					
						
							| 
									
										
										
										
											2019-06-17 15:53:32 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # Delete record. | 
					
						
							|  |  |  |     delete_payload = { | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         "Comment": "delete prod.redis.db", | 
					
						
							|  |  |  |         "Changes": [ | 
					
						
							| 
									
										
										
										
											2019-06-17 15:53:32 +02:00
										 |  |  |             { | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |                 "Action": "DELETE", | 
					
						
							|  |  |  |                 "ResourceRecordSet": {"Name": "prod.redis.db", "Type": "A"}, | 
					
						
							| 
									
										
										
										
											2019-06-17 15:53:32 +02:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         ], | 
					
						
							| 
									
										
										
										
											2019-06-17 15:53:32 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn.change_resource_record_sets( | 
					
						
							|  |  |  |         HostedZoneId=hosted_zone_id, ChangeBatch=delete_payload | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2019-06-17 15:53:32 +02:00
										 |  |  |     response = conn.list_resource_record_sets(HostedZoneId=hosted_zone_id) | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     len(response["ResourceRecordSets"]).should.equal(0) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-28 21:26:32 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-18 02:23:49 -05:00
										 |  |  | @mock_route53 | 
					
						
							|  |  |  | def test_change_resource_record_sets_crud_valid_with_special_xml_chars(): | 
					
						
							|  |  |  |     conn = boto3.client("route53", region_name="us-east-1") | 
					
						
							|  |  |  |     conn.create_hosted_zone( | 
					
						
							|  |  |  |         Name="db.", | 
					
						
							|  |  |  |         CallerReference=str(hash("foo")), | 
					
						
							|  |  |  |         HostedZoneConfig=dict(PrivateZone=True, Comment="db"), | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     zones = conn.list_hosted_zones_by_name(DNSName="db.") | 
					
						
							|  |  |  |     len(zones["HostedZones"]).should.equal(1) | 
					
						
							|  |  |  |     zones["HostedZones"][0]["Name"].should.equal("db.") | 
					
						
							|  |  |  |     hosted_zone_id = zones["HostedZones"][0]["Id"] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Create TXT Record. | 
					
						
							|  |  |  |     txt_record_endpoint_payload = { | 
					
						
							|  |  |  |         "Comment": "Create TXT record prod.redis.db", | 
					
						
							|  |  |  |         "Changes": [ | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 "Action": "CREATE", | 
					
						
							|  |  |  |                 "ResourceRecordSet": { | 
					
						
							|  |  |  |                     "Name": "prod.redis.db.", | 
					
						
							|  |  |  |                     "Type": "TXT", | 
					
						
							|  |  |  |                     "TTL": 10, | 
					
						
							|  |  |  |                     "ResourceRecords": [{"Value": "SomeInitialValue"}], | 
					
						
							|  |  |  |                 }, | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         ], | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     conn.change_resource_record_sets( | 
					
						
							|  |  |  |         HostedZoneId=hosted_zone_id, ChangeBatch=txt_record_endpoint_payload | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = conn.list_resource_record_sets(HostedZoneId=hosted_zone_id) | 
					
						
							|  |  |  |     len(response["ResourceRecordSets"]).should.equal(1) | 
					
						
							|  |  |  |     a_record_detail = response["ResourceRecordSets"][0] | 
					
						
							|  |  |  |     a_record_detail["Name"].should.equal("prod.redis.db.") | 
					
						
							|  |  |  |     a_record_detail["Type"].should.equal("TXT") | 
					
						
							|  |  |  |     a_record_detail["TTL"].should.equal(10) | 
					
						
							|  |  |  |     a_record_detail["ResourceRecords"].should.equal([{"Value": "SomeInitialValue"}]) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Update TXT Record with XML Special Character &. | 
					
						
							|  |  |  |     txt_record_with_special_char_endpoint_payload = { | 
					
						
							|  |  |  |         "Comment": "Update TXT record prod.redis.db", | 
					
						
							|  |  |  |         "Changes": [ | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 "Action": "UPSERT", | 
					
						
							|  |  |  |                 "ResourceRecordSet": { | 
					
						
							|  |  |  |                     "Name": "prod.redis.db.", | 
					
						
							|  |  |  |                     "Type": "TXT", | 
					
						
							|  |  |  |                     "TTL": 60, | 
					
						
							|  |  |  |                     "ResourceRecords": [{"Value": "SomeInitialValue&NewValue"}], | 
					
						
							|  |  |  |                 }, | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         ], | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     conn.change_resource_record_sets( | 
					
						
							|  |  |  |         HostedZoneId=hosted_zone_id, | 
					
						
							|  |  |  |         ChangeBatch=txt_record_with_special_char_endpoint_payload, | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = conn.list_resource_record_sets(HostedZoneId=hosted_zone_id) | 
					
						
							|  |  |  |     len(response["ResourceRecordSets"]).should.equal(1) | 
					
						
							|  |  |  |     cname_record_detail = response["ResourceRecordSets"][0] | 
					
						
							|  |  |  |     cname_record_detail["Name"].should.equal("prod.redis.db.") | 
					
						
							|  |  |  |     cname_record_detail["Type"].should.equal("TXT") | 
					
						
							|  |  |  |     cname_record_detail["TTL"].should.equal(60) | 
					
						
							|  |  |  |     cname_record_detail["ResourceRecords"].should.equal( | 
					
						
							|  |  |  |         [{"Value": "SomeInitialValue&NewValue"}] | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Delete record. | 
					
						
							|  |  |  |     delete_payload = { | 
					
						
							|  |  |  |         "Comment": "delete prod.redis.db", | 
					
						
							|  |  |  |         "Changes": [ | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 "Action": "DELETE", | 
					
						
							|  |  |  |                 "ResourceRecordSet": {"Name": "prod.redis.db", "Type": "TXT"}, | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         ], | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     conn.change_resource_record_sets( | 
					
						
							|  |  |  |         HostedZoneId=hosted_zone_id, ChangeBatch=delete_payload | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     response = conn.list_resource_record_sets(HostedZoneId=hosted_zone_id) | 
					
						
							|  |  |  |     len(response["ResourceRecordSets"]).should.equal(0) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-17 16:37:47 -07:00
										 |  |  | @mock_route53 | 
					
						
							|  |  |  | def test_change_weighted_resource_record_sets(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto3.client("route53", region_name="us-east-2") | 
					
						
							| 
									
										
										
										
											2019-07-17 16:37:47 -07:00
										 |  |  |     conn.create_hosted_zone( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         Name="test.vpc.internal.", CallerReference=str(hash("test")) | 
					
						
							| 
									
										
										
										
											2019-07-17 16:37:47 -07:00
										 |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     zones = conn.list_hosted_zones_by_name(DNSName="test.vpc.internal.") | 
					
						
							| 
									
										
										
										
											2019-07-17 16:37:47 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     hosted_zone_id = zones["HostedZones"][0]["Id"] | 
					
						
							| 
									
										
										
										
											2019-07-17 16:37:47 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     # Create 2 weighted records | 
					
						
							| 
									
										
										
										
											2019-07-17 16:37:47 -07:00
										 |  |  |     conn.change_resource_record_sets( | 
					
						
							|  |  |  |         HostedZoneId=hosted_zone_id, | 
					
						
							|  |  |  |         ChangeBatch={ | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |             "Changes": [ | 
					
						
							| 
									
										
										
										
											2019-07-17 16:37:47 -07:00
										 |  |  |                 { | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |                     "Action": "CREATE", | 
					
						
							|  |  |  |                     "ResourceRecordSet": { | 
					
						
							|  |  |  |                         "Name": "test.vpc.internal", | 
					
						
							|  |  |  |                         "Type": "A", | 
					
						
							|  |  |  |                         "SetIdentifier": "test1", | 
					
						
							|  |  |  |                         "Weight": 50, | 
					
						
							|  |  |  |                         "AliasTarget": { | 
					
						
							|  |  |  |                             "HostedZoneId": "Z3AADJGX6KTTL2", | 
					
						
							|  |  |  |                             "DNSName": "internal-test1lb-447688172.us-east-2.elb.amazonaws.com.", | 
					
						
							|  |  |  |                             "EvaluateTargetHealth": True, | 
					
						
							|  |  |  |                         }, | 
					
						
							|  |  |  |                     }, | 
					
						
							| 
									
										
										
										
											2019-07-17 16:37:47 -07:00
										 |  |  |                 }, | 
					
						
							|  |  |  |                 { | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |                     "Action": "CREATE", | 
					
						
							|  |  |  |                     "ResourceRecordSet": { | 
					
						
							|  |  |  |                         "Name": "test.vpc.internal", | 
					
						
							|  |  |  |                         "Type": "A", | 
					
						
							|  |  |  |                         "SetIdentifier": "test2", | 
					
						
							|  |  |  |                         "Weight": 50, | 
					
						
							|  |  |  |                         "AliasTarget": { | 
					
						
							|  |  |  |                             "HostedZoneId": "Z3AADJGX6KTTL2", | 
					
						
							|  |  |  |                             "DNSName": "internal-testlb2-1116641781.us-east-2.elb.amazonaws.com.", | 
					
						
							|  |  |  |                             "EvaluateTargetHealth": True, | 
					
						
							|  |  |  |                         }, | 
					
						
							|  |  |  |                     }, | 
					
						
							|  |  |  |                 }, | 
					
						
							| 
									
										
										
										
											2019-07-17 16:37:47 -07:00
										 |  |  |             ] | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         }, | 
					
						
							| 
									
										
										
										
											2019-07-17 16:37:47 -07:00
										 |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = conn.list_resource_record_sets(HostedZoneId=hosted_zone_id) | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     record = response["ResourceRecordSets"][0] | 
					
						
							|  |  |  |     # Update the first record to have a weight of 90 | 
					
						
							| 
									
										
										
										
											2019-07-17 16:37:47 -07:00
										 |  |  |     conn.change_resource_record_sets( | 
					
						
							|  |  |  |         HostedZoneId=hosted_zone_id, | 
					
						
							|  |  |  |         ChangeBatch={ | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |             "Changes": [ | 
					
						
							| 
									
										
										
										
											2019-07-17 16:37:47 -07:00
										 |  |  |                 { | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |                     "Action": "UPSERT", | 
					
						
							|  |  |  |                     "ResourceRecordSet": { | 
					
						
							|  |  |  |                         "Name": record["Name"], | 
					
						
							|  |  |  |                         "Type": record["Type"], | 
					
						
							|  |  |  |                         "SetIdentifier": record["SetIdentifier"], | 
					
						
							|  |  |  |                         "Weight": 90, | 
					
						
							|  |  |  |                         "AliasTarget": { | 
					
						
							|  |  |  |                             "HostedZoneId": record["AliasTarget"]["HostedZoneId"], | 
					
						
							|  |  |  |                             "DNSName": record["AliasTarget"]["DNSName"], | 
					
						
							|  |  |  |                             "EvaluateTargetHealth": record["AliasTarget"][ | 
					
						
							|  |  |  |                                 "EvaluateTargetHealth" | 
					
						
							|  |  |  |                             ], | 
					
						
							|  |  |  |                         }, | 
					
						
							|  |  |  |                     }, | 
					
						
							|  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2019-07-17 16:37:47 -07:00
										 |  |  |             ] | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         }, | 
					
						
							| 
									
										
										
										
											2019-07-17 16:37:47 -07:00
										 |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     record = response["ResourceRecordSets"][1] | 
					
						
							|  |  |  |     # Update the second record to have a weight of 10 | 
					
						
							| 
									
										
										
										
											2019-07-17 16:37:47 -07:00
										 |  |  |     conn.change_resource_record_sets( | 
					
						
							|  |  |  |         HostedZoneId=hosted_zone_id, | 
					
						
							|  |  |  |         ChangeBatch={ | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |             "Changes": [ | 
					
						
							| 
									
										
										
										
											2019-07-17 16:37:47 -07:00
										 |  |  |                 { | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |                     "Action": "UPSERT", | 
					
						
							|  |  |  |                     "ResourceRecordSet": { | 
					
						
							|  |  |  |                         "Name": record["Name"], | 
					
						
							|  |  |  |                         "Type": record["Type"], | 
					
						
							|  |  |  |                         "SetIdentifier": record["SetIdentifier"], | 
					
						
							|  |  |  |                         "Weight": 10, | 
					
						
							|  |  |  |                         "AliasTarget": { | 
					
						
							|  |  |  |                             "HostedZoneId": record["AliasTarget"]["HostedZoneId"], | 
					
						
							|  |  |  |                             "DNSName": record["AliasTarget"]["DNSName"], | 
					
						
							|  |  |  |                             "EvaluateTargetHealth": record["AliasTarget"][ | 
					
						
							|  |  |  |                                 "EvaluateTargetHealth" | 
					
						
							|  |  |  |                             ], | 
					
						
							|  |  |  |                         }, | 
					
						
							|  |  |  |                     }, | 
					
						
							|  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2019-07-17 16:37:47 -07:00
										 |  |  |             ] | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         }, | 
					
						
							| 
									
										
										
										
											2019-07-17 16:37:47 -07:00
										 |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = conn.list_resource_record_sets(HostedZoneId=hosted_zone_id) | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     for record in response["ResourceRecordSets"]: | 
					
						
							|  |  |  |         if record["SetIdentifier"] == "test1": | 
					
						
							|  |  |  |             record["Weight"].should.equal(90) | 
					
						
							|  |  |  |         if record["SetIdentifier"] == "test2": | 
					
						
							|  |  |  |             record["Weight"].should.equal(10) | 
					
						
							| 
									
										
										
										
											2019-07-17 16:37:47 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-28 21:26:32 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-02 12:46:15 +00:00
										 |  |  | @mock_route53 | 
					
						
							|  |  |  | def test_failover_record_sets(): | 
					
						
							|  |  |  |     conn = boto3.client("route53", region_name="us-east-2") | 
					
						
							| 
									
										
										
										
											2020-03-02 13:07:34 +00:00
										 |  |  |     conn.create_hosted_zone(Name="test.zone.", CallerReference=str(hash("test"))) | 
					
						
							| 
									
										
										
										
											2020-03-02 12:46:15 +00:00
										 |  |  |     zones = conn.list_hosted_zones_by_name(DNSName="test.zone.") | 
					
						
							|  |  |  |     hosted_zone_id = zones["HostedZones"][0]["Id"] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Create geolocation record | 
					
						
							|  |  |  |     conn.change_resource_record_sets( | 
					
						
							|  |  |  |         HostedZoneId=hosted_zone_id, | 
					
						
							|  |  |  |         ChangeBatch={ | 
					
						
							|  |  |  |             "Changes": [ | 
					
						
							|  |  |  |                 { | 
					
						
							|  |  |  |                     "Action": "CREATE", | 
					
						
							|  |  |  |                     "ResourceRecordSet": { | 
					
						
							|  |  |  |                         "Name": "failover.test.zone.", | 
					
						
							|  |  |  |                         "Type": "A", | 
					
						
							|  |  |  |                         "TTL": 10, | 
					
						
							|  |  |  |                         "ResourceRecords": [{"Value": "127.0.0.1"}], | 
					
						
							| 
									
										
										
										
											2020-03-02 13:07:34 +00:00
										 |  |  |                         "Failover": "PRIMARY", | 
					
						
							|  |  |  |                     }, | 
					
						
							| 
									
										
										
										
											2020-03-02 12:46:15 +00:00
										 |  |  |                 } | 
					
						
							|  |  |  |             ] | 
					
						
							| 
									
										
										
										
											2020-03-02 13:07:34 +00:00
										 |  |  |         }, | 
					
						
							| 
									
										
										
										
											2020-03-02 12:46:15 +00:00
										 |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = conn.list_resource_record_sets(HostedZoneId=hosted_zone_id) | 
					
						
							|  |  |  |     record = response["ResourceRecordSets"][0] | 
					
						
							|  |  |  |     record["Failover"].should.equal("PRIMARY") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_route53 | 
					
						
							|  |  |  | def test_geolocation_record_sets(): | 
					
						
							|  |  |  |     conn = boto3.client("route53", region_name="us-east-2") | 
					
						
							| 
									
										
										
										
											2020-03-02 13:07:34 +00:00
										 |  |  |     conn.create_hosted_zone(Name="test.zone.", CallerReference=str(hash("test"))) | 
					
						
							| 
									
										
										
										
											2020-03-02 12:46:15 +00:00
										 |  |  |     zones = conn.list_hosted_zones_by_name(DNSName="test.zone.") | 
					
						
							|  |  |  |     hosted_zone_id = zones["HostedZones"][0]["Id"] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Create geolocation record | 
					
						
							|  |  |  |     conn.change_resource_record_sets( | 
					
						
							|  |  |  |         HostedZoneId=hosted_zone_id, | 
					
						
							|  |  |  |         ChangeBatch={ | 
					
						
							|  |  |  |             "Changes": [ | 
					
						
							|  |  |  |                 { | 
					
						
							|  |  |  |                     "Action": "CREATE", | 
					
						
							|  |  |  |                     "ResourceRecordSet": { | 
					
						
							|  |  |  |                         "Name": "georecord1.test.zone.", | 
					
						
							|  |  |  |                         "Type": "A", | 
					
						
							|  |  |  |                         "TTL": 10, | 
					
						
							|  |  |  |                         "ResourceRecords": [{"Value": "127.0.0.1"}], | 
					
						
							| 
									
										
										
										
											2020-03-02 13:07:34 +00:00
										 |  |  |                         "GeoLocation": {"ContinentCode": "EU"}, | 
					
						
							|  |  |  |                     }, | 
					
						
							| 
									
										
										
										
											2020-03-02 12:46:15 +00:00
										 |  |  |                 }, | 
					
						
							|  |  |  |                 { | 
					
						
							|  |  |  |                     "Action": "CREATE", | 
					
						
							|  |  |  |                     "ResourceRecordSet": { | 
					
						
							|  |  |  |                         "Name": "georecord2.test.zone.", | 
					
						
							|  |  |  |                         "Type": "A", | 
					
						
							|  |  |  |                         "TTL": 10, | 
					
						
							|  |  |  |                         "ResourceRecords": [{"Value": "127.0.0.2"}], | 
					
						
							| 
									
										
										
										
											2020-03-02 13:07:34 +00:00
										 |  |  |                         "GeoLocation": {"CountryCode": "US", "SubdivisionCode": "NY"}, | 
					
						
							|  |  |  |                     }, | 
					
						
							|  |  |  |                 }, | 
					
						
							| 
									
										
										
										
											2020-03-02 12:46:15 +00:00
										 |  |  |             ] | 
					
						
							| 
									
										
										
										
											2020-03-02 13:07:34 +00:00
										 |  |  |         }, | 
					
						
							| 
									
										
										
										
											2020-03-02 12:46:15 +00:00
										 |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = conn.list_resource_record_sets(HostedZoneId=hosted_zone_id) | 
					
						
							|  |  |  |     rrs = response["ResourceRecordSets"] | 
					
						
							|  |  |  |     rrs[0]["GeoLocation"].should.equal({"ContinentCode": "EU"}) | 
					
						
							|  |  |  |     rrs[1]["GeoLocation"].should.equal({"CountryCode": "US", "SubdivisionCode": "NY"}) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-28 21:26:32 +05:30
										 |  |  | @mock_route53 | 
					
						
							|  |  |  | def test_change_resource_record_invalid(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto3.client("route53", region_name="us-east-1") | 
					
						
							| 
									
										
										
										
											2017-04-28 21:26:32 +05:30
										 |  |  |     conn.create_hosted_zone( | 
					
						
							|  |  |  |         Name="db.", | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         CallerReference=str(hash("foo")), | 
					
						
							|  |  |  |         HostedZoneConfig=dict(PrivateZone=True, Comment="db"), | 
					
						
							| 
									
										
										
										
											2017-04-28 21:26:32 +05:30
										 |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     zones = conn.list_hosted_zones_by_name(DNSName="db.") | 
					
						
							|  |  |  |     len(zones["HostedZones"]).should.equal(1) | 
					
						
							|  |  |  |     zones["HostedZones"][0]["Name"].should.equal("db.") | 
					
						
							|  |  |  |     hosted_zone_id = zones["HostedZones"][0]["Id"] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     invalid_a_record_payload = { | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         "Comment": "this should fail", | 
					
						
							|  |  |  |         "Changes": [ | 
					
						
							| 
									
										
										
										
											2017-04-28 21:26:32 +05:30
										 |  |  |             { | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |                 "Action": "CREATE", | 
					
						
							|  |  |  |                 "ResourceRecordSet": { | 
					
						
							|  |  |  |                     "Name": "prod.scooby.doo", | 
					
						
							|  |  |  |                     "Type": "A", | 
					
						
							|  |  |  |                     "TTL": 10, | 
					
						
							|  |  |  |                     "ResourceRecords": [{"Value": "127.0.0.1"}], | 
					
						
							|  |  |  |                 }, | 
					
						
							| 
									
										
										
										
											2017-04-28 21:26:32 +05:30
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         ], | 
					
						
							| 
									
										
										
										
											2017-04-28 21:26:32 +05:30
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 07:54:49 +02:00
										 |  |  |     with pytest.raises(botocore.exceptions.ClientError): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         conn.change_resource_record_sets( | 
					
						
							|  |  |  |             HostedZoneId=hosted_zone_id, ChangeBatch=invalid_a_record_payload | 
					
						
							|  |  |  |         ) | 
					
						
							| 
									
										
										
										
											2017-04-28 21:26:32 +05:30
										 |  |  | 
 | 
					
						
							|  |  |  |     response = conn.list_resource_record_sets(HostedZoneId=hosted_zone_id) | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     len(response["ResourceRecordSets"]).should.equal(0) | 
					
						
							| 
									
										
										
										
											2017-04-28 21:26:32 +05:30
										 |  |  | 
 | 
					
						
							|  |  |  |     invalid_cname_record_payload = { | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         "Comment": "this should also fail", | 
					
						
							|  |  |  |         "Changes": [ | 
					
						
							| 
									
										
										
										
											2017-04-28 21:26:32 +05:30
										 |  |  |             { | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |                 "Action": "UPSERT", | 
					
						
							|  |  |  |                 "ResourceRecordSet": { | 
					
						
							|  |  |  |                     "Name": "prod.scooby.doo", | 
					
						
							|  |  |  |                     "Type": "CNAME", | 
					
						
							|  |  |  |                     "TTL": 10, | 
					
						
							|  |  |  |                     "ResourceRecords": [{"Value": "127.0.0.1"}], | 
					
						
							|  |  |  |                 }, | 
					
						
							| 
									
										
										
										
											2017-04-28 21:26:32 +05:30
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         ], | 
					
						
							| 
									
										
										
										
											2017-04-28 21:26:32 +05:30
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 07:54:49 +02:00
										 |  |  |     with pytest.raises(botocore.exceptions.ClientError): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         conn.change_resource_record_sets( | 
					
						
							|  |  |  |             HostedZoneId=hosted_zone_id, ChangeBatch=invalid_cname_record_payload | 
					
						
							|  |  |  |         ) | 
					
						
							| 
									
										
										
										
											2017-04-28 21:26:32 +05:30
										 |  |  | 
 | 
					
						
							|  |  |  |     response = conn.list_resource_record_sets(HostedZoneId=hosted_zone_id) | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     len(response["ResourceRecordSets"]).should.equal(0) | 
					
						
							| 
									
										
										
										
											2017-10-23 17:25:40 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_route53 | 
					
						
							|  |  |  | def test_list_resource_record_sets_name_type_filters(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto3.client("route53", region_name="us-east-1") | 
					
						
							| 
									
										
										
										
											2017-10-23 17:25:40 +02:00
										 |  |  |     create_hosted_zone_response = conn.create_hosted_zone( | 
					
						
							|  |  |  |         Name="db.", | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         CallerReference=str(hash("foo")), | 
					
						
							|  |  |  |         HostedZoneConfig=dict(PrivateZone=True, Comment="db"), | 
					
						
							| 
									
										
										
										
											2017-10-23 17:25:40 +02:00
										 |  |  |     ) | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     hosted_zone_id = create_hosted_zone_response["HostedZone"]["Id"] | 
					
						
							| 
									
										
										
										
											2017-10-23 17:25:40 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def create_resource_record_set(rec_type, rec_name): | 
					
						
							|  |  |  |         payload = { | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |             "Comment": "create {} record {}".format(rec_type, rec_name), | 
					
						
							|  |  |  |             "Changes": [ | 
					
						
							| 
									
										
										
										
											2017-10-23 17:25:40 +02:00
										 |  |  |                 { | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |                     "Action": "CREATE", | 
					
						
							|  |  |  |                     "ResourceRecordSet": { | 
					
						
							|  |  |  |                         "Name": rec_name, | 
					
						
							|  |  |  |                         "Type": rec_type, | 
					
						
							|  |  |  |                         "TTL": 10, | 
					
						
							|  |  |  |                         "ResourceRecords": [{"Value": "127.0.0.1"}], | 
					
						
							|  |  |  |                     }, | 
					
						
							| 
									
										
										
										
											2017-10-23 17:25:40 +02:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |             ], | 
					
						
							| 
									
										
										
										
											2017-10-23 17:25:40 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         conn.change_resource_record_sets( | 
					
						
							|  |  |  |             HostedZoneId=hosted_zone_id, ChangeBatch=payload | 
					
						
							|  |  |  |         ) | 
					
						
							| 
									
										
										
										
											2017-10-23 17:25:40 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # record_type, record_name | 
					
						
							|  |  |  |     all_records = [ | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         ("A", "a.a.db."), | 
					
						
							|  |  |  |         ("A", "a.b.db."), | 
					
						
							|  |  |  |         ("A", "b.b.db."), | 
					
						
							|  |  |  |         ("CNAME", "b.b.db."), | 
					
						
							|  |  |  |         ("CNAME", "b.c.db."), | 
					
						
							|  |  |  |         ("CNAME", "c.c.db."), | 
					
						
							| 
									
										
										
										
											2017-10-23 17:25:40 +02:00
										 |  |  |     ] | 
					
						
							|  |  |  |     for record_type, record_name in all_records: | 
					
						
							|  |  |  |         create_resource_record_set(record_type, record_name) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     start_with = 2 | 
					
						
							|  |  |  |     response = conn.list_resource_record_sets( | 
					
						
							|  |  |  |         HostedZoneId=hosted_zone_id, | 
					
						
							|  |  |  |         StartRecordType=all_records[start_with][0], | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         StartRecordName=all_records[start_with][1], | 
					
						
							| 
									
										
										
										
											2017-10-23 17:25:40 +02:00
										 |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-27 18:53:14 +01:00
										 |  |  |     response["IsTruncated"].should.equal(False) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     returned_records = [ | 
					
						
							|  |  |  |         (record["Type"], record["Name"]) for record in response["ResourceRecordSets"] | 
					
						
							|  |  |  |     ] | 
					
						
							| 
									
										
										
										
											2017-10-23 17:25:40 +02:00
										 |  |  |     len(returned_records).should.equal(len(all_records) - start_with) | 
					
						
							|  |  |  |     for desired_record in all_records[start_with:]: | 
					
						
							|  |  |  |         returned_records.should.contain(desired_record) | 
					
						
							| 
									
										
										
										
											2020-11-20 07:21:05 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_route53 | 
					
						
							|  |  |  | def test_get_change(): | 
					
						
							|  |  |  |     conn = boto3.client("route53", region_name="us-east-2") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     change_id = "123456" | 
					
						
							|  |  |  |     response = conn.get_change(Id=change_id) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response["ChangeInfo"]["Id"].should.equal(change_id) | 
					
						
							|  |  |  |     response["ChangeInfo"]["Status"].should.equal("INSYNC") |