Browse Source

session initialization raises SessionError instead of socket.error
catch that error in bind-cfgd.py


git-svn-id: svn://bind10.isc.org/svn/bind10/branches/f2f200910@134 e5f2f494-b856-4b98-b285-d166d9295462

Jelte Jansen 15 years ago
parent
commit
da4e68a21e
2 changed files with 13 additions and 9 deletions
  1. 1 1
      src/lib/bind-cfgd/bind-cfgd.py
  2. 12 8
      src/lib/cc/python/ISC/CC/session.py

+ 1 - 1
src/lib/bind-cfgd/bind-cfgd.py

@@ -19,6 +19,6 @@ if __name__ == "__main__":
     try:
         cm = ConfigManager()
         cm.run()
-    except socket.error:
+    except ISC.CC.SessionError, se:
         print "Error creating config manager, "\
               "is the command channel daemon running?"

+ 12 - 8
src/lib/cc/python/ISC/CC/session.py

@@ -20,6 +20,7 @@ import struct
 import Message
 
 class ProtocolError(Exception): pass
+class SessionError(Exception): pass
 
 class Session:
     def __init__(self):
@@ -30,14 +31,17 @@ class Session:
         self._sendbuffer = ""
         self._sequence = 1
 
-        self._socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
-        self._socket.connect(tuple(['127.0.0.1', 9912]))
-
-        self.sendmsg({ "type": "getlname" })
-        msg = self.recvmsg(False)
-        self._lname = msg["lname"]
-        if not self._lname:
-            raise ProtocolError("Could not get local name")
+        try:
+            self._socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+            self._socket.connect(tuple(['127.0.0.1', 9912]))
+
+            self.sendmsg({ "type": "getlname" })
+            msg = self.recvmsg(False)
+            self._lname = msg["lname"]
+            if not self._lname:
+                raise ProtocolError("Could not get local name")
+        except socket.error, se:
+                raise SessionError(se)
 
     @property
     def lname(self):