From 9fdeaca589956d7911e8b05491e3e15f7a9bcfad Mon Sep 17 00:00:00 2001 From: Jon Nangle Date: Mon, 2 Mar 2020 12:46:15 +0000 Subject: [PATCH 1/2] Support GeoLocation and Failover on Route 53 --- moto/route53/models.py | 12 +++++ tests/test_route53/test_route53.py | 82 ++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+) diff --git a/moto/route53/models.py b/moto/route53/models.py index 2ae03e54d..0bdefd25b 100644 --- a/moto/route53/models.py +++ b/moto/route53/models.py @@ -88,6 +88,8 @@ class RecordSet(BaseModel): self.hosted_zone_name = kwargs.get("HostedZoneName") self.hosted_zone_id = kwargs.get("HostedZoneId") self.alias_target = kwargs.get("AliasTarget") + self.failover = kwargs.get("Failover") + self.geo_location = kwargs.get("GeoLocation") @classmethod def create_from_cloudformation_json( @@ -154,6 +156,16 @@ class RecordSet(BaseModel): {% if record_set.ttl %} {{ record_set.ttl }} {% endif %} + {% if record_set.failover %} + {{ record_set.failover }} + {% endif %} + {% if record_set.geo_location %} + + {% for geo_key in ['ContinentCode','CountryCode','SubdivisionCode'] %} + {% if record_set.geo_location[geo_key] %}<{{ geo_key }}>{{ record_set.geo_location[geo_key] }}{% endif %} + {% endfor %} + + {% endif %} {% if record_set.alias_target %} {{ record_set.alias_target['HostedZoneId'] }} diff --git a/tests/test_route53/test_route53.py b/tests/test_route53/test_route53.py index 746c78719..8cf148c14 100644 --- a/tests/test_route53/test_route53.py +++ b/tests/test_route53/test_route53.py @@ -753,6 +753,88 @@ def test_change_weighted_resource_record_sets(): record["Weight"].should.equal(10) +@mock_route53 +def test_failover_record_sets(): + conn = boto3.client("route53", region_name="us-east-2") + conn.create_hosted_zone( + Name="test.zone.", CallerReference=str(hash("test")) + ) + 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"}], + "Failover": "PRIMARY" + } + } + ] + } + ) + + 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") + conn.create_hosted_zone( + Name="test.zone.", CallerReference=str(hash("test")) + ) + 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"}], + "GeoLocation": { + "ContinentCode": "EU" + } + } + }, + { + "Action": "CREATE", + "ResourceRecordSet": { + "Name": "georecord2.test.zone.", + "Type": "A", + "TTL": 10, + "ResourceRecords": [{"Value": "127.0.0.2"}], + "GeoLocation": { + "CountryCode": "US", + "SubdivisionCode": "NY" + } + } + } + ] + } + ) + + 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"}) + + @mock_route53 def test_change_resource_record_invalid(): conn = boto3.client("route53", region_name="us-east-1") From bebcf52851e5dd094dd8b670f1ff4b65d6599f9d Mon Sep 17 00:00:00 2001 From: Jon Nangle Date: Mon, 2 Mar 2020 13:07:34 +0000 Subject: [PATCH 2/2] Formatting --- tests/test_route53/test_route53.py | 31 +++++++++++------------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/tests/test_route53/test_route53.py b/tests/test_route53/test_route53.py index 8cf148c14..8c036441c 100644 --- a/tests/test_route53/test_route53.py +++ b/tests/test_route53/test_route53.py @@ -756,9 +756,7 @@ def test_change_weighted_resource_record_sets(): @mock_route53 def test_failover_record_sets(): conn = boto3.client("route53", region_name="us-east-2") - conn.create_hosted_zone( - Name="test.zone.", CallerReference=str(hash("test")) - ) + conn.create_hosted_zone(Name="test.zone.", CallerReference=str(hash("test"))) zones = conn.list_hosted_zones_by_name(DNSName="test.zone.") hosted_zone_id = zones["HostedZones"][0]["Id"] @@ -774,11 +772,11 @@ def test_failover_record_sets(): "Type": "A", "TTL": 10, "ResourceRecords": [{"Value": "127.0.0.1"}], - "Failover": "PRIMARY" - } + "Failover": "PRIMARY", + }, } ] - } + }, ) response = conn.list_resource_record_sets(HostedZoneId=hosted_zone_id) @@ -789,9 +787,7 @@ def test_failover_record_sets(): @mock_route53 def test_geolocation_record_sets(): conn = boto3.client("route53", region_name="us-east-2") - conn.create_hosted_zone( - Name="test.zone.", CallerReference=str(hash("test")) - ) + conn.create_hosted_zone(Name="test.zone.", CallerReference=str(hash("test"))) zones = conn.list_hosted_zones_by_name(DNSName="test.zone.") hosted_zone_id = zones["HostedZones"][0]["Id"] @@ -807,10 +803,8 @@ def test_geolocation_record_sets(): "Type": "A", "TTL": 10, "ResourceRecords": [{"Value": "127.0.0.1"}], - "GeoLocation": { - "ContinentCode": "EU" - } - } + "GeoLocation": {"ContinentCode": "EU"}, + }, }, { "Action": "CREATE", @@ -819,14 +813,11 @@ def test_geolocation_record_sets(): "Type": "A", "TTL": 10, "ResourceRecords": [{"Value": "127.0.0.2"}], - "GeoLocation": { - "CountryCode": "US", - "SubdivisionCode": "NY" - } - } - } + "GeoLocation": {"CountryCode": "US", "SubdivisionCode": "NY"}, + }, + }, ] - } + }, ) response = conn.list_resource_record_sets(HostedZoneId=hosted_zone_id)