BIND 10 trac2853, updated. fae036eecd789c8815f8f52f5954835ef9fcfa82 [2853] Add Python binding for getStatus() method
BIND 10 source code commits
bind10-changes at lists.isc.org
Fri Jun 7 07:56:21 UTC 2013
The branch, trac2853 has been updated
via fae036eecd789c8815f8f52f5954835ef9fcfa82 (commit)
from efea64180e770421ac70e4a607e0b5587433b55a (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 fae036eecd789c8815f8f52f5954835ef9fcfa82
Author: Mukund Sivaraman <muks at isc.org>
Date: Fri Jun 7 13:15:28 2013 +0530
[2853] Add Python binding for getStatus() method
-----------------------------------------------------------------------
Summary of changes:
.../isc/datasrc/configurableclientlist_python.cc | 56 ++++++++++++++++++++
.../python/isc/datasrc/tests/clientlist_test.py | 23 ++++++++
2 files changed, 79 insertions(+)
-----------------------------------------------------------------------
diff --git a/src/lib/python/isc/datasrc/configurableclientlist_python.cc b/src/lib/python/isc/datasrc/configurableclientlist_python.cc
index 36b6cf9..b33d043 100644
--- a/src/lib/python/isc/datasrc/configurableclientlist_python.cc
+++ b/src/lib/python/isc/datasrc/configurableclientlist_python.cc
@@ -196,6 +196,44 @@ ConfigurableClientList_getCachedZoneWriter(PyObject* po_self, PyObject* args) {
}
PyObject*
+ConfigurableClientList_getStatus(PyObject* po_self, PyObject*) {
+ s_ConfigurableClientList* self =
+ static_cast<s_ConfigurableClientList*>(po_self);
+ try {
+ const std::vector<DataSourceStatus> status = self->cppobj->getStatus();
+ if (status.empty()) {
+ Py_RETURN_NONE;
+ }
+
+ PyObject *slist = PyList_New(status.size());
+ if (!slist) {
+ return (NULL);
+ }
+
+ for (size_t i = 0; i < status.size(); ++i) {
+ PyObject *tup = Py_BuildValue("(ssI)",
+ status[i].getName().c_str(),
+ status[i].getSegmentType().c_str(),
+ status[i].getSegmentState());
+ if (!tup) {
+ Py_DECREF(slist);
+ return (NULL);
+ }
+ PyList_SET_ITEM(slist, i, tup);
+ }
+
+ return (slist);
+ } catch (const std::exception& exc) {
+ PyErr_SetString(getDataSourceException("Error"), exc.what());
+ return (NULL);
+ } catch (...) {
+ PyErr_SetString(getDataSourceException("Error"),
+ "Unknown C++ exception");
+ return (NULL);
+ }
+}
+
+PyObject*
ConfigurableClientList_find(PyObject* po_self, PyObject* args) {
s_ConfigurableClientList* self =
static_cast<s_ConfigurableClientList*>(po_self);
@@ -295,6 +333,13 @@ This returns a ZoneWriter that can be used to (re)load a zone.\n\
Parameters:\n\
zone The name of the zone to (re)load.\
datasrc_name The name of the data source where the zone is to be loaded." },
+ { "get_status", ConfigurableClientList_getStatus,
+ METH_NOARGS,
+ "get_status() -> list\n\
+\n\
+Wrapper around C++ ConfigurableClientList::getStatus\n\
+\n\
+This returns a list of tuples, each containing the status of a data source client." },
{ "find", ConfigurableClientList_find, METH_VARARGS,
"find(zone, want_exact_match=False, want_finder=True) -> datasrc_client,\
zone_finder, exact_match\n\
@@ -425,6 +470,17 @@ initModulePart_ConfigurableClientList(PyObject* mod) {
"CACHE_STATUS_ZONE_SUCCESS",
Py_BuildValue("I", ConfigurableClientList::ZONE_SUCCESS));
+ // MemorySegmentState enum
+ installClassVariable(configurableclientlist_type,
+ "SEGMENT_UNUSED",
+ Py_BuildValue("I", SEGMENT_UNUSED));
+ installClassVariable(configurableclientlist_type,
+ "SEGMENT_WAITING",
+ Py_BuildValue("I", SEGMENT_WAITING));
+ installClassVariable(configurableclientlist_type,
+ "SEGMENT_INUSE",
+ Py_BuildValue("I", SEGMENT_INUSE));
+
// FIXME: These should eventually be moved to the
// ZoneTableSegment class when we add Python bindings for the
// memory data source specific bits. But for now, we add these
diff --git a/src/lib/python/isc/datasrc/tests/clientlist_test.py b/src/lib/python/isc/datasrc/tests/clientlist_test.py
index 499e012..c24a10b 100644
--- a/src/lib/python/isc/datasrc/tests/clientlist_test.py
+++ b/src/lib/python/isc/datasrc/tests/clientlist_test.py
@@ -205,6 +205,29 @@ class ClientListTest(unittest.TestCase):
# The segment is still in READ_ONLY mode.
self.find_helper()
+ def test_get_status(self):
+ """
+ Test getting status of various data sources.
+ """
+
+ self.clist = isc.datasrc.ConfigurableClientList(isc.dns.RRClass.IN)
+
+ status = self.clist.get_status()
+ self.assertIsNone(status)
+
+ self.clist.configure('''[{
+ "type": "MasterFiles",
+ "params": {
+ "example.org": "''' + TESTDATA_PATH + '''example.org.zone"
+ },
+ "cache-enable": true
+ }]''', True)
+
+ status = self.clist.get_status()
+ self.assertEqual(1, len(status))
+ self.assertTupleEqual(('MasterFiles', 'local', isc.datasrc.ConfigurableClientList.SEGMENT_INUSE),
+ status[0])
+
if __name__ == "__main__":
isc.log.init("bind10")
isc.log.resetUnitTestRootLogger()
More information about the bind10-changes
mailing list