summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEndre Karlson <endre.karlson@hp.com>2014-03-05 11:50:07 +0100
committerEndre Karlson <endre.karlson@hp.com>2014-03-05 11:56:56 +0100
commit490d6b36361b6980d29d2a927fa2596602338dcc (patch)
tree3aa2b48a009121d208cc30553041743b6695fd14
parentbd9ae5ad80cf29c9b7c7c36df73a9165f04233cc (diff)
downloaddesignate-490d6b36361b6980d29d2a927fa2596602338dcc.tar.gz
Introduce nameservers endpoint for zones
This adds /zones/<uuid>/nameservers according the the bug report and will later support server-pools in Juno. Closes-Bug: #1281839 Change-Id: If5ba284320e0e72ca25d7b288ddf0f169cc297a1
-rw-r--r--designate/api/v2/controllers/nameservers.py39
-rw-r--r--designate/api/v2/controllers/zones.py2
-rw-r--r--designate/api/v2/views/nameservers.py42
-rw-r--r--designate/tests/test_api/test_v2/test_nameservers.py68
4 files changed, 151 insertions, 0 deletions
diff --git a/designate/api/v2/controllers/nameservers.py b/designate/api/v2/controllers/nameservers.py
new file mode 100644
index 00000000..d3cc449f
--- /dev/null
+++ b/designate/api/v2/controllers/nameservers.py
@@ -0,0 +1,39 @@
+# Copyright 2013 Hewlett-Packard Development Company, L.P.
+#
+# Author: Kiall Mac Innes <kiall@hp.com>
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+import pecan
+from designate import utils
+from designate.central import rpcapi as central_rpcapi
+from designate.openstack.common import log as logging
+from designate.api.v2.controllers import rest
+from designate.api.v2.views import nameservers as nameservers_view
+
+LOG = logging.getLogger(__name__)
+central_api = central_rpcapi.CentralAPI()
+
+
+class NameServersController(rest.RestController):
+ _view = nameservers_view.NameServerView()
+
+ @pecan.expose(template='json:', content_type='application/json')
+ @utils.validate_uuid('zone_id')
+ def get_all(self, zone_id):
+ request = pecan.request
+ context = pecan.request.environ['context']
+
+ servers = central_api.get_domain_servers(context, zone_id)
+
+ return self._view.list(context, request, servers, [zone_id])
diff --git a/designate/api/v2/controllers/zones.py b/designate/api/v2/controllers/zones.py
index 87b07a08..8fcdb0e9 100644
--- a/designate/api/v2/controllers/zones.py
+++ b/designate/api/v2/controllers/zones.py
@@ -21,6 +21,7 @@ from designate import exceptions
from designate import utils
from designate import schema
from designate.api.v2.controllers import rest
+from designate.api.v2.controllers import nameservers
from designate.api.v2.controllers import recordsets
from designate.api.v2.views import zones as zones_view
from designate.central import rpcapi as central_rpcapi
@@ -37,6 +38,7 @@ class ZonesController(rest.RestController):
SORT_KEYS = ['created_at', 'id', 'updated_at', 'name', 'tenant_id',
'serial', 'ttl']
+ nameservers = nameservers.NameServersController()
recordsets = recordsets.RecordSetsController()
@pecan.expose(template=None, content_type='text/dns')
diff --git a/designate/api/v2/views/nameservers.py b/designate/api/v2/views/nameservers.py
new file mode 100644
index 00000000..03c020c0
--- /dev/null
+++ b/designate/api/v2/views/nameservers.py
@@ -0,0 +1,42 @@
+# Copyright 2013 Hewlett-Packard Development Company, L.P.
+#
+# Author: Kiall Mac Innes <kiall@hp.com>
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+from designate.api.v2.views import base as base_view
+from designate.openstack.common import log as logging
+
+
+LOG = logging.getLogger(__name__)
+
+
+class NameServerView(base_view.BaseView):
+ """ Model a NameServer API response as a python dictionary """
+
+ _resource_name = 'nameserver'
+ _collection_name = 'nameservers'
+
+ def _get_base_href(self, parents=None):
+ assert len(parents) == 1
+
+ href = "%s/v2/zones/%s/nameservers" % (self.base_uri, parents[0])
+
+ return href.rstrip('?')
+
+ def show_basic(self, context, request, nameserver):
+ """ Basic view of a nameserver """
+ return {
+ "id": nameserver["id"],
+ "name": nameserver["name"]
+ }
diff --git a/designate/tests/test_api/test_v2/test_nameservers.py b/designate/tests/test_api/test_v2/test_nameservers.py
new file mode 100644
index 00000000..eea70ac6
--- /dev/null
+++ b/designate/tests/test_api/test_v2/test_nameservers.py
@@ -0,0 +1,68 @@
+# Copyright 2013 Hewlett-Packard Development Company, L.P.
+#
+# Author: Kiall Mac Innes <kiall@managedit.ie>
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+from mock import patch
+from designate.central import service as central_service
+from designate.openstack.common.rpc import common as rpc_common
+from designate.tests.test_api.test_v2 import ApiV2TestCase
+
+
+class ApiV2NameServersTest(ApiV2TestCase):
+ def setUp(self):
+ super(ApiV2NameServersTest, self).setUp()
+
+ # Create a domain
+ self.domain = self.create_domain()
+
+ def test_get_nameservers(self):
+ url = '/zones/%s/nameservers' % self.domain['id']
+
+ response = self.client.get(url)
+
+ # Check the headers are what we expect
+ self.assertEqual(200, response.status_int)
+ self.assertEqual('application/json', response.content_type)
+
+ # Check the body structure is what we expect
+ self.assertIn('nameservers', response.json)
+ self.assertIn('links', response.json)
+ self.assertIn('self', response.json['links'])
+
+ # We should start with 0 nameservers
+ self.assertEqual(1, len(response.json['nameservers']))
+
+ servers = self.central_service.get_domain_servers(
+ self.admin_context, self.domain['id'])
+
+ self.assertEqual(servers[0]['id'],
+ response.json['nameservers'][0]['id'])
+ self.assertEqual(servers[0]['name'],
+ response.json['nameservers'][0]['name'])
+
+ self.create_server(name='nsx.mydomain.com.')
+
+ response = self.client.get(url)
+
+ self.assertEqual(2, len(response.json['nameservers']))
+
+ def test_get_nameservers_invalid_id(self):
+ self._assert_invalid_uuid(self.client.get, '/zones/%s/nameservers')
+
+ @patch.object(central_service.Service, 'get_domain_servers',
+ side_effect=rpc_common.Timeout())
+ def test_get_nameservers_timeout(self, _):
+ url = '/zones/ba751950-6193-11e3-949a-0800200c9a66/nameservers'
+
+ self._assert_exception('timeout', 504, self.client.get, url)