1
0
mirror of https://github.com/github/octodns.git synced 2024-05-11 05:55:00 +00:00

filters must be ordered as 'geodns', 'defaults', 'first_n'

This commit is contained in:
Yaroshevich, Denis
2021-08-03 10:46:04 +03:00
parent 006a61e4d8
commit 33d56b8357
3 changed files with 38 additions and 68 deletions

View File

@@ -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"] = [

View File

@@ -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": [

View File

@@ -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."],