BIND 10 trac2737, updated. 660990cbc4df062e7814f86040f7cf87662190c2 [2737] Use constants in isc.config.ccsession
BIND 10 source code commits
bind10-changes at lists.isc.org
Tue Mar 19 11:46:15 UTC 2013
The branch, trac2737 has been updated
via 660990cbc4df062e7814f86040f7cf87662190c2 (commit)
via 8c4c6e96fb6289bbacc2e4d15b8a7b131c8fadd8 (commit)
from 191f569b711f30366f584045e4cefd9211929ad8 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 660990cbc4df062e7814f86040f7cf87662190c2
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Tue Mar 19 12:44:47 2013 +0100
[2737] Use constants in isc.config.ccsession
commit 8c4c6e96fb6289bbacc2e4d15b8a7b131c8fadd8
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Tue Mar 19 12:42:42 2013 +0100
[2737] Use constants in cfgmgr
-----------------------------------------------------------------------
Summary of changes:
src/lib/cc/proto_defs.cc | 4 +++-
src/lib/python/isc/config/ccsession.py | 33 ++++++++++++++++----------------
src/lib/python/isc/config/cfgmgr.py | 3 ++-
3 files changed, 22 insertions(+), 18 deletions(-)
-----------------------------------------------------------------------
diff --git a/src/lib/cc/proto_defs.cc b/src/lib/cc/proto_defs.cc
index 5509e81..8f7fb91 100644
--- a/src/lib/cc/proto_defs.cc
+++ b/src/lib/cc/proto_defs.cc
@@ -46,8 +46,10 @@ const char* const CC_INSTANCE_WILDCARD = "*";
// Reply codes
const int CC_REPLY_NO_RECPT = -1;
const int CC_REPLY_SUCCESS = 0;
-// Others
+// Payload in the message
const char *const CC_PAYLOAD_LNAME = "lname";
+const char *const CC_PAYLOAD_RESULT = "result";
+const char *const CC_PAYLOAD_COMMAND = "command";
}
}
diff --git a/src/lib/python/isc/config/ccsession.py b/src/lib/python/isc/config/ccsession.py
index b592d8d..6687b5f 100644
--- a/src/lib/python/isc/config/ccsession.py
+++ b/src/lib/python/isc/config/ccsession.py
@@ -84,20 +84,20 @@ def parse_answer(msg):
raise ModuleCCSessionError("Answer message is not a dict: " + str(msg))
if 'result' not in msg:
raise ModuleCCSessionError("answer message does not contain 'result' element")
- elif type(msg['result']) != list:
+ elif type(msg[CC_PAYLOAD_RESULT]) != list:
raise ModuleCCSessionError("wrong result type in answer message")
- elif len(msg['result']) < 1:
+ elif len(msg[CC_PAYLOAD_RESULT]) < 1:
raise ModuleCCSessionError("empty result list in answer message")
- elif type(msg['result'][0]) != int:
+ elif type(msg[CC_PAYLOAD_RESULT][0]) != int:
raise ModuleCCSessionError("wrong rcode type in answer message")
else:
- if len(msg['result']) > 1:
- if (msg['result'][0] != CC_REPLY_SUCCESS and
- type(msg['result'][1]) != str):
+ if len(msg[CC_PAYLOAD_RESULT]) > 1:
+ if (msg[CC_PAYLOAD_RESULT][0] != CC_REPLY_SUCCESS and
+ type(msg[CC_PAYLOAD_RESULT][1]) != str):
raise ModuleCCSessionError("rcode in answer message is non-zero, value is not a string")
- return msg['result'][0], msg['result'][1]
+ return msg[CC_PAYLOAD_RESULT][0], msg[CC_PAYLOAD_RESULT][1]
else:
- return msg['result'][0], None
+ return msg[CC_PAYLOAD_RESULT][0], None
def create_answer(rcode, arg = None):
"""Creates an answer packet for config&commands. rcode must be an
@@ -109,9 +109,9 @@ def create_answer(rcode, arg = None):
if rcode != CC_REPLY_SUCCESS and type(arg) != str:
raise ModuleCCSessionError("arg in create_answer for rcode != 0 must be a string describing the error")
if arg != None:
- return { 'result': [ rcode, arg ] }
+ return { CC_PAYLOAD_RESULT: [ rcode, arg ] }
else:
- return { 'result': [ rcode ] }
+ return { CC_PAYLOAD_RESULT: [ rcode ] }
# 'fixed' commands
"""Fixed names for command and configuration messages"""
@@ -133,7 +133,7 @@ def parse_command(msg):
string. If it is not, this function returns None, None"""
if type(msg) == dict and len(msg.items()) == 1:
cmd, value = msg.popitem()
- if cmd == "command" and type(value) == list:
+ if cmd == CC_PAYLOAD_COMMAND and type(value) == list:
if len(value) == 1 and type(value[0]) == str:
return value[0], None
elif len(value) > 1 and type(value[0]) == str:
@@ -150,7 +150,7 @@ def create_command(command_name, params = None):
cmd = [ command_name ]
if params:
cmd.append(params)
- msg = { 'command': cmd }
+ msg = { CC_PAYLOAD_COMMAND: cmd }
return msg
def default_logconfig_handler(new_config, config_data):
@@ -215,7 +215,7 @@ class ModuleCCSession(ConfigData):
self._session = Session(socket_file)
else:
self._session = cc_session
- self._session.group_subscribe(self._module_name, "*")
+ self._session.group_subscribe(self._module_name, CC_INSTANCE_WILDCARD)
self._remote_module_configs = {}
self._remote_module_callbacks = {}
@@ -228,7 +228,8 @@ class ModuleCCSession(ConfigData):
# If the CC Session obejct has been closed, it returns
# immediately.
if self._session._closed: return
- self._session.group_unsubscribe(self._module_name, "*")
+ self._session.group_unsubscribe(self._module_name,
+ CC_INSTANCE_WILDCARD)
for module_name in self._remote_module_configs:
self._session.group_unsubscribe(module_name)
@@ -294,10 +295,10 @@ class ModuleCCSession(ConfigData):
functions if present. Responds on the channel if the
handler returns a message."""
# should we default to an answer? success-by-default? unhandled error?
- if msg is not None and not 'result' in msg:
+ if msg is not None and not CC_PAYLOAD_RESULT in msg:
answer = None
try:
- module_name = env['group']
+ module_name = env[CC_HEADER_GROUP]
cmd, arg = isc.config.ccsession.parse_command(msg)
if cmd == COMMAND_CONFIG_UPDATE:
new_config = arg
diff --git a/src/lib/python/isc/config/cfgmgr.py b/src/lib/python/isc/config/cfgmgr.py
index 82c8e6c..fe4924c 100644
--- a/src/lib/python/isc/config/cfgmgr.py
+++ b/src/lib/python/isc/config/cfgmgr.py
@@ -28,6 +28,7 @@ import tempfile
import json
import errno
from isc.cc import data
+from isc.cc.proto_defs import *
from isc.config import ccsession, config_data, module_spec
from isc.util.file import path_search
import bind10_config
@@ -603,7 +604,7 @@ class ConfigManager:
# ignore 'None' value (even though they should not occur)
# and messages that are answers to questions we did
# not ask
- if msg is not None and not 'result' in msg:
+ if msg is not None and not CC_PAYLOAD_RESULT in msg:
answer = self.handle_msg(msg);
# Only respond if there actually is something to respond with
if answer is not None:
More information about the bind10-changes
mailing list