Move DNS OPCODEs/Classes into private_codes.py
Change-Id: I32d0a3a5fb0c3ff0ea0596befb53badf9c46a4af
This commit is contained in:
@@ -27,23 +27,11 @@ from designate import dnsutils
|
||||
from designate.backend import agent_backend
|
||||
from designate.i18n import _LW
|
||||
from designate.i18n import _LI
|
||||
|
||||
import designate.backend.private_codes as pcodes
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
CONF = cfg.CONF
|
||||
|
||||
# Command and Control OPCODE
|
||||
CC = 14
|
||||
|
||||
# Private DNS CLASS Uses
|
||||
ClassCC = 65280
|
||||
|
||||
# Private RR Code Uses
|
||||
SUCCESS = 65280
|
||||
FAILURE = 65281
|
||||
CREATE = 65282
|
||||
DELETE = 65283
|
||||
|
||||
|
||||
class RequestHandler(object):
|
||||
def __init__(self):
|
||||
@@ -72,11 +60,11 @@ class RequestHandler(object):
|
||||
opcode = request.opcode()
|
||||
if opcode == dns.opcode.NOTIFY:
|
||||
response = self._handle_notify(request)
|
||||
elif opcode == CC:
|
||||
if rdclass == ClassCC:
|
||||
if rdtype == CREATE:
|
||||
elif opcode == pcodes.CC:
|
||||
if rdclass == pcodes.CLASSCC:
|
||||
if rdtype == pcodes.CREATE:
|
||||
response = self._handle_create(request)
|
||||
elif rdtype == DELETE:
|
||||
elif rdtype == pcodes.DELETE:
|
||||
response = self._handle_delete(request)
|
||||
else:
|
||||
response = self._handle_query_error(request,
|
||||
|
||||
@@ -30,25 +30,13 @@ from designate.i18n import _LW
|
||||
from designate.backend import base
|
||||
from designate import exceptions
|
||||
from designate.mdns import rpcapi as mdns_api
|
||||
|
||||
import designate.backend.private_codes as pcodes
|
||||
|
||||
dns_query = eventlet.import_patched('dns.query')
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
CONF = cfg.CONF
|
||||
|
||||
# Command and Control OPCODE
|
||||
CC = 14
|
||||
|
||||
# Private DNS CLASS Uses
|
||||
CLASSCC = 65280
|
||||
|
||||
# Private RR Code Uses
|
||||
SUCCESS = 65280
|
||||
FAILURE = 65281
|
||||
CREATE = 65282
|
||||
DELETE = 65283
|
||||
|
||||
|
||||
class AgentPoolBackend(base.Backend):
|
||||
__plugin_name__ = 'agent'
|
||||
@@ -72,9 +60,9 @@ class AgentPoolBackend(base.Backend):
|
||||
response, retry = self._make_and_send_dns_message(
|
||||
zone.name,
|
||||
self.timeout,
|
||||
CC,
|
||||
CREATE,
|
||||
CLASSCC,
|
||||
pcodes.CC,
|
||||
pcodes.CREATE,
|
||||
pcodes.CLASSCC,
|
||||
self.host,
|
||||
self.port
|
||||
)
|
||||
@@ -100,9 +88,9 @@ class AgentPoolBackend(base.Backend):
|
||||
response, retry = self._make_and_send_dns_message(
|
||||
zone.name,
|
||||
self.timeout,
|
||||
CC,
|
||||
DELETE,
|
||||
CLASSCC,
|
||||
pcodes.CC,
|
||||
pcodes.DELETE,
|
||||
pcodes.CLASSCC,
|
||||
self.host,
|
||||
self.port
|
||||
)
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
# Copyright 2016 Hewlett Packard Enterprise Development Company LP
|
||||
#
|
||||
# Author: Federico Ceratto <federico.ceratto@hpe.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.
|
||||
|
||||
|
||||
"""
|
||||
backend.private_codes
|
||||
~~~~~~~~~~~~~~~~~~~~~~
|
||||
Private DNS opcodes, classes, RR codes for communication between the
|
||||
agent and its backends
|
||||
"""
|
||||
|
||||
# Command and Control OPCODE
|
||||
CC = 14
|
||||
|
||||
# Private DNS CLASS Uses
|
||||
CLASSCC = 65280
|
||||
|
||||
# Private RR Code Uses
|
||||
SUCCESS = 65280
|
||||
FAILURE = 65281
|
||||
CREATE = 65282
|
||||
DELETE = 65283
|
||||
@@ -30,6 +30,7 @@ import testtools
|
||||
from designate import exceptions
|
||||
from designate.tests.unit import RoObject
|
||||
import designate.backend.agent as agent
|
||||
import designate.backend.private_codes as pcodes
|
||||
|
||||
|
||||
class SCAgentPoolBackend(agent.AgentPoolBackend):
|
||||
@@ -63,7 +64,7 @@ class BackendAgentTest(base.BaseTestCase):
|
||||
out = self.agent.create_zone('ctx', RoObject(name='zn'))
|
||||
|
||||
self.agent._make_and_send_dns_message.assert_called_with(
|
||||
'zn', 1, 14, agent.CREATE, agent.SUCCESS, 2, 3)
|
||||
'zn', 1, 14, pcodes.CREATE, pcodes.SUCCESS, 2, 3)
|
||||
self.assertEqual(None, out)
|
||||
|
||||
def test_create_zone_exception(self, *mock):
|
||||
@@ -73,7 +74,7 @@ class BackendAgentTest(base.BaseTestCase):
|
||||
self.agent.create_zone('ctx', RoObject(name='zn'))
|
||||
|
||||
self.agent._make_and_send_dns_message.assert_called_with(
|
||||
'zn', 1, 14, agent.CREATE, agent.SUCCESS, 2, 3)
|
||||
'zn', 1, 14, pcodes.CREATE, pcodes.SUCCESS, 2, 3)
|
||||
|
||||
def test_update_zone(self, *mock):
|
||||
self.agent.mdns_api.notify_zone_changed = Mock()
|
||||
@@ -91,7 +92,7 @@ class BackendAgentTest(base.BaseTestCase):
|
||||
out = self.agent.delete_zone('ctx', RoObject(name='zn'))
|
||||
|
||||
self.agent._make_and_send_dns_message.assert_called_with(
|
||||
'zn', 1, 14, agent.DELETE, agent.SUCCESS, 2, 3)
|
||||
'zn', 1, 14, pcodes.DELETE, pcodes.SUCCESS, 2, 3)
|
||||
self.assertEqual(None, out)
|
||||
|
||||
def test_delete_zone_exception(self, *mock):
|
||||
@@ -101,7 +102,7 @@ class BackendAgentTest(base.BaseTestCase):
|
||||
self.agent.delete_zone('ctx', RoObject(name='zn'))
|
||||
|
||||
self.agent._make_and_send_dns_message.assert_called_with(
|
||||
'zn', 1, 14, agent.DELETE, agent.SUCCESS, 2, 3)
|
||||
'zn', 1, 14, pcodes.DELETE, pcodes.SUCCESS, 2, 3)
|
||||
|
||||
def test_make_and_send_dns_message_timeout(self, *mocks):
|
||||
self.agent._make_dns_message = Mock(return_value='')
|
||||
|
||||
Reference in New Issue
Block a user