From e1d262a3013942e2a614622ce6d819deab3909c9 Mon Sep 17 00:00:00 2001 From: Ross McFarland Date: Mon, 17 May 2021 17:06:40 -0700 Subject: [PATCH] Add a validation requiring single value weight=1 --- octodns/record/__init__.py | 4 ++++ tests/test_octodns_record.py | 29 ++++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/octodns/record/__init__.py b/octodns/record/__init__.py index 135baf8..f960998 100644 --- a/octodns/record/__init__.py +++ b/octodns/record/__init__.py @@ -573,6 +573,10 @@ class _DynamicMixin(object): reasons.append('missing value in pool "{}" ' 'value {}'.format(_id, value_num)) + if len(values) == 1 and values[0].get('weight', 1) != 1: + reasons.append('pool "{}" has single value with ' + 'weight!=1'.format(_id)) + fallback = pool.get('fallback', None) if fallback is not None: if fallback in pools: diff --git a/tests/test_octodns_record.py b/tests/test_octodns_record.py index ce40b9b..5a4704a 100644 --- a/tests/test_octodns_record.py +++ b/tests/test_octodns_record.py @@ -3412,7 +3412,7 @@ class TestDynamicRecords(TestCase): self.assertEquals(['pool "one" is missing values'], ctx.exception.reasons) - # pool valu not a dict + # pool value not a dict a_data = { 'dynamic': { 'pools': { @@ -3596,6 +3596,33 @@ class TestDynamicRecords(TestCase): self.assertEquals(['invalid weight "foo" in pool "three" value 2'], ctx.exception.reasons) + # single value with weight!=1 + a_data = { + 'dynamic': { + 'pools': { + 'one': { + 'values': [{ + 'weight': 12, + 'value': '6.6.6.6', + }], + }, + }, + 'rules': [{ + 'pool': 'one', + }], + }, + 'ttl': 60, + 'type': 'A', + 'values': [ + '1.1.1.1', + '2.2.2.2', + ], + } + with self.assertRaises(ValidationError) as ctx: + Record.new(self.zone, 'bad', a_data) + self.assertEquals(['pool "one" has single value with weight!=1'], + ctx.exception.reasons) + # invalid fallback a_data = { 'dynamic': {