mirror of
https://github.com/github/octodns.git
synced 2024-05-11 05:55:00 +00:00
Clean up and simplification of tests and command generation, bug fix for multiple sub domain NS records and handling of creation/deletion
This commit is contained in:
@@ -366,10 +366,9 @@ class MythicBeastsProvider(BaseProvider):
|
||||
|
||||
return exists
|
||||
|
||||
def _compile_commands(self, action, change):
|
||||
def _compile_commands(self, action, record):
|
||||
commands = []
|
||||
|
||||
record = change.record
|
||||
hostname = remove_trailing_dot(record.fqdn)
|
||||
ttl = record.ttl
|
||||
_type = record._type
|
||||
@@ -384,11 +383,7 @@ class MythicBeastsProvider(BaseProvider):
|
||||
|
||||
base = '{} {} {} {}'.format(action, hostname, ttl, _type)
|
||||
|
||||
if _type in ('A', 'AAAA'):
|
||||
for value in values:
|
||||
commands.append('{} {}'.format(base, value))
|
||||
|
||||
elif _type == 'SSHFP':
|
||||
if _type == 'SSHFP':
|
||||
data = values[0].data
|
||||
commands.append('{} {} {} {}'.format(
|
||||
base,
|
||||
@@ -417,8 +412,8 @@ class MythicBeastsProvider(BaseProvider):
|
||||
|
||||
else:
|
||||
if hasattr(self, '_data_for_{}'.format(_type)):
|
||||
commands.append('{} {}'.format(
|
||||
base, values[0]))
|
||||
for value in values:
|
||||
commands.append('{} {}'.format(base, value))
|
||||
else:
|
||||
self.log.debug('skipping %s as not supported', _type)
|
||||
|
||||
@@ -426,7 +421,7 @@ class MythicBeastsProvider(BaseProvider):
|
||||
|
||||
def _apply_Create(self, change):
|
||||
zone = change.new.zone
|
||||
commands = self._compile_commands('ADD', change)
|
||||
commands = self._compile_commands('ADD', change.new)
|
||||
|
||||
for command in commands:
|
||||
self._post({
|
||||
@@ -443,7 +438,7 @@ class MythicBeastsProvider(BaseProvider):
|
||||
|
||||
def _apply_Delete(self, change):
|
||||
zone = change.existing.zone
|
||||
commands = self._compile_commands('DELETE', change)
|
||||
commands = self._compile_commands('DELETE', change.existing)
|
||||
|
||||
for command in commands:
|
||||
self._post({
|
||||
|
||||
@@ -156,32 +156,39 @@ class TestMythicBeastsProvider(TestCase):
|
||||
self.assertEquals('Unable to parse CAA data',
|
||||
err.exception.message)
|
||||
|
||||
def test_alias_command_generation(self):
|
||||
def test_command_generation(self):
|
||||
zone = Zone('unit.tests.', [])
|
||||
zone.add_record(Record.new(zone, 'prawf', {
|
||||
zone.add_record(Record.new(zone, 'prawf-alias', {
|
||||
'ttl': 60,
|
||||
'type': 'ALIAS',
|
||||
'value': 'alias.unit.tests.',
|
||||
}))
|
||||
with requests_mock() as mock:
|
||||
mock.post(ANY, status_code=200, text='')
|
||||
|
||||
provider = MythicBeastsProvider('test', {
|
||||
'unit.tests.': 'mypassword'
|
||||
})
|
||||
|
||||
plan = provider.plan(zone)
|
||||
change = plan.changes[0]
|
||||
|
||||
command = provider._compile_commands('ADD', change)
|
||||
self.assertEquals(
|
||||
['ADD prawf.unit.tests 60 ANAME alias.unit.tests.'],
|
||||
command
|
||||
)
|
||||
|
||||
def test_txt_command_generation(self):
|
||||
zone = Zone('unit.tests.', [])
|
||||
zone.add_record(Record.new(zone, 'prawf', {
|
||||
zone.add_record(Record.new(zone, 'prawf-ns', {
|
||||
'ttl': 300,
|
||||
'type': 'NS',
|
||||
'values': [
|
||||
'alias.unit.tests.',
|
||||
'alias2.unit.tests.',
|
||||
],
|
||||
}))
|
||||
zone.add_record(Record.new(zone, 'prawf-a', {
|
||||
'ttl': 60,
|
||||
'type': 'A',
|
||||
'values': [
|
||||
'1.2.3.4',
|
||||
'5.6.7.8',
|
||||
],
|
||||
}))
|
||||
zone.add_record(Record.new(zone, 'prawf-aaaa', {
|
||||
'ttl': 60,
|
||||
'type': 'AAAA',
|
||||
'values': [
|
||||
'a:a::a',
|
||||
'b:b::b',
|
||||
'c:c::c:c',
|
||||
],
|
||||
}))
|
||||
zone.add_record(Record.new(zone, 'prawf-txt', {
|
||||
'ttl': 60,
|
||||
'type': 'TXT',
|
||||
'value': 'prawf prawf dyma prawf',
|
||||
@@ -194,15 +201,35 @@ class TestMythicBeastsProvider(TestCase):
|
||||
})
|
||||
|
||||
plan = provider.plan(zone)
|
||||
change = plan.changes[0]
|
||||
changes = plan.changes
|
||||
generated_commands = []
|
||||
|
||||
for change in changes:
|
||||
generated_commands.extend(
|
||||
provider._compile_commands('ADD', change.new)
|
||||
)
|
||||
|
||||
expected_commands = [
|
||||
'ADD prawf-alias.unit.tests 60 ANAME alias.unit.tests.',
|
||||
'ADD prawf-ns.unit.tests 300 NS alias.unit.tests.',
|
||||
'ADD prawf-ns.unit.tests 300 NS alias2.unit.tests.',
|
||||
'ADD prawf-a.unit.tests 60 A 1.2.3.4',
|
||||
'ADD prawf-a.unit.tests 60 A 5.6.7.8',
|
||||
'ADD prawf-aaaa.unit.tests 60 AAAA a:a::a',
|
||||
'ADD prawf-aaaa.unit.tests 60 AAAA b:b::b',
|
||||
'ADD prawf-aaaa.unit.tests 60 AAAA c:c::c:c',
|
||||
'ADD prawf-txt.unit.tests 60 TXT prawf prawf dyma prawf',
|
||||
]
|
||||
|
||||
generated_commands.sort()
|
||||
expected_commands.sort()
|
||||
|
||||
command = provider._compile_commands('ADD', change)
|
||||
self.assertEquals(
|
||||
['ADD prawf.unit.tests 60 TXT prawf prawf dyma prawf'],
|
||||
command
|
||||
generated_commands,
|
||||
expected_commands
|
||||
)
|
||||
|
||||
def test_command_generation(self):
|
||||
def test_fake_command_generation(self):
|
||||
class FakeChangeRecord(object):
|
||||
def __init__(self):
|
||||
self.__fqdn = 'prawf.unit.tests.'
|
||||
|
||||
Reference in New Issue
Block a user