Browse Source

[2853] Handle exceptions from getSegmentType()

Mukund Sivaraman 12 years ago
parent
commit
3ffa4a979d

+ 2 - 0
src/lib/python/isc/datasrc/configurableclientlist_inc.cc

@@ -92,6 +92,8 @@ The tuples contain (name, segment_type, segment_state):\n\
   name              The name of the data source.\n\
   segment_type      A string indicating the type of memory segment in use.\n\
   segment_state     The state of the memory segment.\n\
+\n\
+If segment_state is SEGMENT_UNUSED, None is returned for the segment_type.\n\
 ";
 
 const char* const ConfigurableClientList_find_doc = "\

+ 16 - 2
src/lib/python/isc/datasrc/configurableclientlist_python.cc

@@ -210,10 +210,24 @@ ConfigurableClientList_getStatus(PyObject* po_self, PyObject*) {
         }
 
         for (size_t i = 0; i < status.size(); ++i) {
-            PyObject *tup = Py_BuildValue("(ssI)",
+            PyObject *segment_type = NULL;
+            try {
+                segment_type = Py_BuildValue(
+                    "s", status[i].getSegmentType().c_str());
+            } catch (const isc::InvalidOperation& e) {
+                Py_INCREF(Py_None);
+                segment_type = Py_None;
+            }
+
+            PyObject *tup = Py_BuildValue("(sOI)",
                                           status[i].getName().c_str(),
-                                          status[i].getSegmentType().c_str(),
+                                          segment_type,
                                           status[i].getSegmentState());
+            if (segment_type) {
+                // The Py_BuildValue() above increments its refcount,
+                // so we drop our reference.
+                Py_DECREF(segment_type);
+            }
             if (!tup) {
                 Py_DECREF(slist);
                 return (NULL);