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

ContellixProvider: zone creation and records in one run

This commit is contained in:
Adam Smith
2020-01-18 20:24:15 -08:00
parent d51c3111c1
commit 08af9aaab3
2 changed files with 22 additions and 17 deletions

View File

@@ -88,7 +88,7 @@ class ConstellixClient(object):
if self._domains is None:
zones = []
resp = self._request('GET', '/').json()
resp = self._request('GET', '').json()
zones += resp
self._domains = {'{}.'.format(z['name']): z['id'] for z in zones}
@@ -96,11 +96,16 @@ class ConstellixClient(object):
return self._domains
def domain(self, name):
path = '/{}'.format(self.domains.get(name))
zone_id = self.domains.get(name, False)
if not zone_id:
raise ConstellixClientNotFound()
path = '/{}'.format(zone_id)
return self._request('GET', path).json()
def domain_create(self, name):
self._request('POST', '/', data={'names': [name]})
resp = self._request('POST', '/', data={'names': [name]})
# Add newly created zone to domain cache
self._domains['{}.'.format(name)] = resp.json()[0]['id']
def _absolutize_value(self, value, zone_name):
if value == '':
@@ -112,6 +117,8 @@ class ConstellixClient(object):
def records(self, zone_name):
zone_id = self.domains.get(zone_name, False)
if not zone_id:
raise ConstellixClientNotFound()
path = '/{}/records'.format(zone_id)
resp = self._request('GET', path).json()

View File

@@ -14,13 +14,11 @@ from six import text_type
from unittest import TestCase
from octodns.record import Record
from octodns.provider.constellix import ConstellixClientNotFound, \
from octodns.provider.constellix import \
ConstellixProvider
from octodns.provider.yaml import YamlProvider
from octodns.zone import Zone
import json
class TestConstellixProvider(TestCase):
expected = Zone('unit.tests.', [])
@@ -102,7 +100,7 @@ class TestConstellixProvider(TestCase):
with requests_mock() as mock:
base = 'https://api.dns.constellix.com/v1/domains'
with open('tests/fixtures/constellix-domains.json') as fh:
mock.get('{}{}'.format(base, '/'), text=fh.read())
mock.get('{}{}'.format(base, ''), text=fh.read())
with open('tests/fixtures/constellix-records.json') as fh:
mock.get('{}{}'.format(base, '/123123/records'),
text=fh.read())
@@ -128,15 +126,15 @@ class TestConstellixProvider(TestCase):
resp.json = Mock()
provider._client._request = Mock(return_value=resp)
with open('tests/fixtures/constellix-domains.json') as fh:
domains = json.load(fh)
# non-existent domain, create everything
resp.json.side_effect = [
ConstellixClientNotFound, # no zone in populate
ConstellixClientNotFound, # no domain during apply
domains
[], # no domains returned during populate
[{
'id': 123123,
'name': 'unit.tests'
}], # domain created in apply
]
plan = provider.plan(self.expected)
# No root NS, no ignored, no excluded, no unsupported
@@ -145,10 +143,10 @@ class TestConstellixProvider(TestCase):
self.assertEquals(n, provider.apply(plan))
provider._client._request.assert_has_calls([
# created the domain
call('POST', '/', data={'names': ['unit.tests']}),
# get all domains to build the cache
call('GET', '/'),
call('GET', ''),
# created the domain
call('POST', '/', data={'names': ['unit.tests']})
])
# These two checks are broken up so that ordering doesn't break things.
# Python3 doesn't make the calls in a consistent order so different
@@ -171,7 +169,7 @@ class TestConstellixProvider(TestCase):
}),
])
self.assertEquals(20, provider._client._request.call_count)
self.assertEquals(18, provider._client._request.call_count)
provider._client._request.reset_mock()