From 33d56b8357ebde9b513925e929440c581c92c03a Mon Sep 17 00:00:00 2001 From: "Yaroshevich, Denis" Date: Tue, 3 Aug 2021 10:46:04 +0300 Subject: [PATCH] filters must be ordered as 'geodns', 'defaults', 'first_n' --- octodns/provider/gcore.py | 12 ++--- tests/fixtures/gcore-records.json | 26 +++++------ tests/test_octodns_provider_gcore.py | 68 ++++++++-------------------- 3 files changed, 38 insertions(+), 68 deletions(-) diff --git a/octodns/provider/gcore.py b/octodns/provider/gcore.py index 821d109..bbbf81f 100644 --- a/octodns/provider/gcore.py +++ b/octodns/provider/gcore.py @@ -194,10 +194,10 @@ class GCoreProvider(BaseProvider): geo_sets, pool_idx = dict(), 0 pools = defaultdict(lambda: {"values": []}) for rr in record["resource_records"]: - meta = rr.get("meta", {}) + meta = rr.get("meta", {}) or {} value = {"value": value_transform_fn(rr["content"][0])} - countries = meta.get("countries", []) - continents = meta.get("continents", []) + countries = meta.get("countries", []) or [] + continents = meta.get("continents", []) or [] if meta.get("default", False): pools[default_pool_name]["values"].append(value) @@ -432,7 +432,7 @@ class GCoreProvider(BaseProvider): ) return True types = [v.get("type") for v in filters] - for i, want_type in enumerate(["geodns", "first_n", "default"]): + for i, want_type in enumerate(["geodns", "default", "first_n"]): if types[i] != want_type: self.log.info( "ignore %s, filters.%d.type is %s, want %s", @@ -509,12 +509,12 @@ class GCoreProvider(BaseProvider): "resource_records": self._params_for_dymanic(record), "filters": [ {"type": "geodns"}, - {"type": "first_n", "limit": self.records_per_response}, { "type": "default", "limit": self.records_per_response, "strict": False, }, + {"type": "first_n", "limit": self.records_per_response}, ], } @@ -524,12 +524,12 @@ class GCoreProvider(BaseProvider): extra["resource_records"] = self._params_for_dymanic(record) extra["filters"] = [ {"type": "geodns"}, - {"type": "first_n", "limit": self.records_per_response}, { "type": "default", "limit": self.records_per_response, "strict": False, }, + {"type": "first_n", "limit": self.records_per_response}, ] else: extra["resource_records"] = [ diff --git a/tests/fixtures/gcore-records.json b/tests/fixtures/gcore-records.json index 570b358..9bf58d7 100644 --- a/tests/fixtures/gcore-records.json +++ b/tests/fixtures/gcore-records.json @@ -210,12 +210,12 @@ }, { "limit": 1, - "type": "first_n" + "strict": false, + "type": "default" }, { "limit": 1, - "strict": false, - "type": "default" + "type": "first_n" } ], "resource_records": [ @@ -269,12 +269,12 @@ }, { "limit": 1, - "type": "first_n" + "strict": false, + "type": "default" }, { "limit": 1, - "strict": false, - "type": "default" + "type": "first_n" } ], "resource_records": [ @@ -300,12 +300,12 @@ }, { "limit": 1, - "type": "first_n" + "strict": false, + "type": "default" }, { "limit": 1, - "strict": false, - "type": "default" + "type": "first_n" } ], "resource_records": [ @@ -406,14 +406,14 @@ { "type": "geodns" }, - { - "limit": 1, - "type": "first_n" - }, { "limit": 2, "strict": false, "type": "default" + }, + { + "limit": 1, + "type": "first_n" } ], "resource_records": [ diff --git a/tests/test_octodns_provider_gcore.py b/tests/test_octodns_provider_gcore.py index 14c0137..2151440 100644 --- a/tests/test_octodns_provider_gcore.py +++ b/tests/test_octodns_provider_gcore.py @@ -31,6 +31,16 @@ class TestGCoreProvider(TestCase): source = YamlProvider("test", join(dirname(__file__), "config")) source.populate(expected) + default_filters = [ + {"type": "geodns"}, + { + "type": "default", + "limit": 1, + "strict": False, + }, + {"type": "first_n", "limit": 1}, + ] + def test_populate(self): provider = GCoreProvider("test_id", token="token") @@ -170,15 +180,7 @@ class TestGCoreProvider(TestCase): "name": "unit.tests.", "type": "A", "ttl": 300, - "filters": [ - {"type": "geodns"}, - {"limit": 1, "type": "first_n"}, - { - "limit": 1, - "strict": False, - "type": "default", - }, - ], + "filters": self.default_filters, "resource_records": [{"content": ["7.7.7.7"]}], } ] @@ -518,7 +520,7 @@ class TestGCoreProvider(TestCase): wanted.add_record( Record.new( wanted, - "geo-cname-simple", + "cname-smpl", { "ttl": 300, "type": "CNAME", @@ -552,7 +554,7 @@ class TestGCoreProvider(TestCase): wanted.add_record( Record.new( wanted, - "geo-cname-defaults", + "cname-dflt", { "ttl": 300, "type": "CNAME", @@ -585,15 +587,7 @@ class TestGCoreProvider(TestCase): "http://api/zones/unit.tests/geo-simple.unit.tests./A", data={ "ttl": 300, - "filters": [ - {"type": "geodns"}, - {"type": "first_n", "limit": 1}, - { - "type": "default", - "limit": 1, - "strict": False, - }, - ], + "filters": self.default_filters, "resource_records": [ { "content": ["1.1.1.1"], @@ -619,15 +613,7 @@ class TestGCoreProvider(TestCase): "http://api/zones/unit.tests/geo-defaults.unit.tests./A", data={ "ttl": 300, - "filters": [ - {"type": "geodns"}, - {"type": "first_n", "limit": 1}, - { - "type": "default", - "limit": 1, - "strict": False, - }, - ], + "filters": self.default_filters, "resource_records": [ { "content": ["2.2.2.1"], @@ -641,18 +627,10 @@ class TestGCoreProvider(TestCase): ), call( "POST", - "http://api/zones/unit.tests/geo-cname-simple.unit.tests./CNAME", + "http://api/zones/unit.tests/cname-smpl.unit.tests./CNAME", data={ "ttl": 300, - "filters": [ - {"type": "geodns"}, - {"type": "first_n", "limit": 1}, - { - "type": "default", - "limit": 1, - "strict": False, - }, - ], + "filters": self.default_filters, "resource_records": [ { "content": ["ru-1.unit.tests."], @@ -675,18 +653,10 @@ class TestGCoreProvider(TestCase): ), call( "POST", - "http://api/zones/unit.tests/geo-cname-defaults.unit.tests./CNAME", + "http://api/zones/unit.tests/cname-dflt.unit.tests./CNAME", data={ "ttl": 300, - "filters": [ - {"type": "geodns"}, - {"type": "first_n", "limit": 1}, - { - "type": "default", - "limit": 1, - "strict": False, - }, - ], + "filters": self.default_filters, "resource_records": [ { "content": ["eu.unit.tests."],