From 756f017854648da12d27a80f3e2dcd028c88985e Mon Sep 17 00:00:00 2001 From: Ross McFarland Date: Sat, 3 Jun 2017 08:47:01 -0700 Subject: [PATCH] Go back to simple/standard ALIAS value --- octodns/record.py | 42 +++++--------------------------- tests/test_octodns_record.py | 47 ++++++------------------------------ 2 files changed, 13 insertions(+), 76 deletions(-) diff --git a/octodns/record.py b/octodns/record.py index 8394782..34e4bb9 100644 --- a/octodns/record.py +++ b/octodns/record.py @@ -313,29 +313,7 @@ class _ValueMixin(object): self.fqdn, self.value) -class AliasValue(object): - - def __init__(self, value): - self.name = value['name'].lower() - self._type = value['type'] - - @property - def data(self): - return { - 'name': self.name, - 'type': self._type, - } - - def __cmp__(self, other): - if self.name == other.name: - return cmp(self._type, other._type) - return cmp(self.name, other.name) - - def __repr__(self): - return "'{} {}'".format(self.name, self._type) - - -class AliasRecord(_ValuesMixin, Record): +class AliasRecord(_ValueMixin, Record): _type = 'ALIAS' def __init__(self, zone, name, data, source=None): @@ -344,19 +322,11 @@ class AliasRecord(_ValuesMixin, Record): data['ttl'] = 0 super(AliasRecord, self).__init__(zone, name, data, source) - def _process_values(self, values): - ret = [] - for value in values: - try: - value = AliasValue(value) - except KeyError as e: - raise Exception('Invalid value in record {}, missing {}' - .format(self.fqdn, e.args[0])) - if not value.name.endswith(self.zone.name): - raise Exception('Invalid value in record {}, name must be in ' - 'same zone.'.format(self.fqdn)) - ret.append(value) - return ret + def _process_value(self, value): + if not value.endswith('.'): + raise Exception('Invalid record {}, value ({}) missing trailing .' + .format(self.fqdn, value)) + return value class CnameRecord(_ValueMixin, Record): diff --git a/tests/test_octodns_record.py b/tests/test_octodns_record.py index 80d4253..52505cb 100644 --- a/tests/test_octodns_record.py +++ b/tests/test_octodns_record.py @@ -243,62 +243,29 @@ class TestRecord(TestCase): a.__repr__() def test_alias(self): - a_values = [{ - 'name': 'www.unit.tests.', - 'type': 'A' - }, { - 'name': 'www.unit.tests.', - 'type': 'AAAA' - }] - a_data = {'ttl': 0, 'values': a_values} + a_data = {'ttl': 0, 'value': 'www.unit.tests.'} a = AliasRecord(self.zone, '', a_data) self.assertEquals('', a.name) self.assertEquals('unit.tests.', a.fqdn) self.assertEquals(0, a.ttl) - self.assertEquals(a_values[0]['name'], a.values[0].name) - self.assertEquals(a_values[0]['type'], a.values[0]._type) - self.assertEquals(a_values[1]['name'], a.values[1].name) - self.assertEquals(a_values[1]['type'], a.values[1]._type) + self.assertEquals(a_data['value'], a.value) self.assertEquals(a_data, a.data) - b_value = { - 'name': 'www.unit.tests.', - 'type': 'A', - } - b_data = {'ttl': 0, 'value': b_value} - b = AliasRecord(self.zone, 'b', b_data) - self.assertEquals(b_value['name'], b.values[0].name) - self.assertEquals(b_value['type'], b.values[0]._type) - self.assertEquals(b_data, b.data) - # missing value with self.assertRaises(Exception) as ctx: AliasRecord(self.zone, None, {'ttl': 0}) - self.assertTrue('missing value(s)' in ctx.exception.message) - # invalid value - with self.assertRaises(Exception) as ctx: - AliasRecord(self.zone, None, {'ttl': 0, 'value': {}}) - self.assertTrue('Invalid value' in ctx.exception.message) + self.assertTrue('missing value' in ctx.exception.message) # bad name with self.assertRaises(Exception) as ctx: - AliasRecord(self.zone, None, {'ttl': 0, 'value': { - 'name': 'foo.bar.com.', - 'type': 'A' - }}) - self.assertTrue('Invalid value' in ctx.exception.message) + AliasRecord(self.zone, None, {'ttl': 0, 'value': 'www.unit.tests'}) + self.assertTrue('missing trailing .' in ctx.exception.message) target = SimpleProvider() # No changes with self self.assertFalse(a.changes(a, target)) - # Diff in priority causes change - other = AliasRecord(self.zone, 'a', {'ttl': 30, 'values': a_values}) - other.values[0].name = 'foo.unit.tests.' - change = a.changes(other, target) - self.assertEqual(change.existing, a) - self.assertEqual(change.new, other) # Diff in value causes change - other.values[0].name = a.values[0].name - other.values[0]._type = 'MX' + other = AliasRecord(self.zone, 'a', a_data) + other.value = 'foo.unit.tests.' change = a.changes(other, target) self.assertEqual(change.existing, a) self.assertEqual(change.new, other)