[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Cluster-devel] conga/luci cluster/resource_form_handlers.js h ...



CVSROOT:	/cvs/cluster
Module name:	conga
Changes by:	rmccabe sourceware org	2006-09-29 21:41:43

Modified files:
	luci/cluster   : resource_form_handlers.js 
	luci/homebase  : index_html 
	luci/site/luci/Extensions: ricci_bridge.py ricci_communicator.py 

Log message:
	improve the robustness of the ssl socket code

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/cluster/resource_form_handlers.js.diff?cvsroot=cluster&r1=1.15&r2=1.16
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/homebase/index_html.diff?cvsroot=cluster&r1=1.16&r2=1.17
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/site/luci/Extensions/ricci_bridge.py.diff?cvsroot=cluster&r1=1.19&r2=1.20
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/site/luci/Extensions/ricci_communicator.py.diff?cvsroot=cluster&r1=1.5&r2=1.6

--- conga/luci/cluster/resource_form_handlers.js	2006/09/27 22:24:11	1.15
+++ conga/luci/cluster/resource_form_handlers.js	2006/09/29 21:41:43	1.16
@@ -106,7 +106,7 @@
 	} else
 		clr_form_error(form.mountpoint);
 
-	if (!form.host || str_is_blank(form.host.value))
+	if (!form.host || str_is_blank(form.host.value)) {
 		errors.push('No NFS server host was given.');
 		set_form_error(form.host);
 	} else
--- conga/luci/homebase/index_html	2006/09/27 22:49:09	1.16
+++ conga/luci/homebase/index_html	2006/09/29 21:41:43	1.17
@@ -15,7 +15,7 @@
 					xml:lang language">
 
 <tal:comment replace="nothing">
-	$Id: index_html,v 1.16 2006/09/27 22:49:09 rmccabe Exp $
+	$Id: index_html,v 1.17 2006/09/29 21:41:43 rmccabe Exp $
 </tal:comment>
 
 <head metal:use-macro="here/header/macros/html_header">
@@ -66,6 +66,7 @@
 
 <body tal:attributes="class here/getSectionFromURL;
 						dir python:test(isRTL, 'rtl', 'ltr')">
+
 	<div id="visual-portal-wrapper">
 
 	<div id="portal-top" i18n:domain="plone">
--- conga/luci/site/luci/Extensions/ricci_bridge.py	2006/09/25 22:59:15	1.19
+++ conga/luci/site/luci/Extensions/ricci_bridge.py	2006/09/29 21:41:43	1.20
@@ -19,10 +19,14 @@
   def process(self, xml_out):
     CLUSTER_STR='<?xml version="1.0" ?><ricci async="false" function="process_batch" version="1.0"><batch><module name="cluster"><request API_version="1.0"><function_call name="get_cluster.conf"/></request></module></batch></ricci>'
         
-    doc = self.makeConnection(CLUSTER_STR)
-        
-    if doc == None:
-      print "Sorry, doc is None"
+    docc = None
+    try:
+      doc = self.makeConnection(CLUSTER_STR)
+    except RicciReceiveError, r:
+      return None
+
+    #if doc == None:
+    #  print "Sorry, doc is None"
     if doc != None:
       bt_node = None
       for node in doc.firstChild.childNodes:
@@ -30,7 +34,7 @@
           if node.nodeName == 'batch':
             bt_node = node
       if bt_node == None:
-        print "bt_node == None"
+        #print "bt_node == None"
         doc = None
       else:
         #print doc.toxml()
@@ -40,7 +44,7 @@
                 if node.nodeName == 'module':
                     mod_node = node
         if mod_node == None:
-            print "mod_node == None"
+            #print "mod_node == None"
             doc = None
         else:
             resp_node = None
@@ -48,7 +52,7 @@
                 if node.nodeType == xml.dom.Node.ELEMENT_NODE:
                     resp_node = node
             if resp_node == None:
-                print "resp_node == None"
+                #print "resp_node == None"
                 doc = None
             else:
                 fr_node = None
@@ -56,7 +60,7 @@
                     if node.nodeType == xml.dom.Node.ELEMENT_NODE:
                       fr_node = node
                 if fr_node == None:
-                    print "fr_node == None"
+                    #print "fr_node == None"
                     doc = None
                 else:
                     varnode = None
@@ -65,7 +69,7 @@
                           varnode = node
                           break
                     if varnode == None:
-                       print "varnode == None"
+                       #print "varnode == None"
                        doc = None
                     else:
                       cl_node = None
@@ -74,7 +78,7 @@
                               cl_node = node
                               break
                       if cl_node == None:
-                        print "cl_node == None"
+                        #print "cl_node == None"
                         doc = None
                       else:
                           docc = minidom.Document()
@@ -83,7 +87,7 @@
     return docc
     
   def __sendall(self, str, ssl_sock):
-    print str
+    #print str
     s = str
     while len(s) != 0:
         pos = ssl_sock.write(s)
@@ -119,29 +123,41 @@
     CLUSTER_STR='<?xml version="1.0" ?><ricci async="false" function="process_batch" version="1.0"><batch><module name="cluster"><request API_version="1.0"><function_call name="status"/></request></module></batch></ricci>'
     # socket
     sock = socket(AF_INET, SOCK_STREAM)
-    sock.connect((self.__hostname, self.__port))
-    ss = ssl(sock, PATH_TO_PRIVKEY, PATH_TO_CACERT)
+    try:
+      sock.connect((self.__hostname, self.__port))
+    except:
+      sock.close()
+      return ''
+
+    ss = 0
+    try:
+        ss = ssl(sock, PATH_TO_PRIVKEY, PATH_TO_CACERT)
+    except sslerror, e:
+        if ss:
+           del ss
+        sock.close()
+        return ''
 
     # receive ricci header
     hello = self.__receive(ss)
     if hello != None:
         pass
         #print hello.toxml()
+
     try:
         self.__sendall(CLUSTER_STR, ss)
+        doc = self.__receive(ss)
     except sslerror, e:
-        sock.close()
-        return ''
+        doc = None
 
-    # receive response
-    doc = self.__receive(ss)
-    if doc == None:
-      print "Sorry, doc is None"
-    else:
-      payload = self.extractPayload(doc)
-    sock.shutdown(2)
+    del ss
     sock.close()
 
+    if doc == None:
+      return ''
+      #print "Sorry, doc is None"
+
+    payload = self.extractPayload(doc)
     return payload
 
   def startService(self,servicename, preferrednode = None):
@@ -204,25 +220,29 @@
   def makeConnection(self,query_str):
     # socket
     sock = socket(AF_INET, SOCK_STREAM)
-    sock.connect((self.__hostname, self.__port))
-    ss = ssl(sock, PATH_TO_PRIVKEY, PATH_TO_CACERT)
+    try:
+        sock.connect((self.__hostname, self.__port))
+    except:
+        sock.close()
+        return None
 
-    # receive ricci header
-    hello = self.__receive(ss)
-    print >> sys.stderr, hello.toxml()
-    if hello != None:
-        pass
-        #print hello.toxml()
-    self.__sendall(query_str, ss)
-    
-    
-    # receive response
-    payload = self.__receive(ss)
-    if payload == None:
-      raise RicciReceiveError('FATAL',"Unable to receive ricci data for %s" % self.__hostname)
-    sock.shutdown(2)
+    ss = 0
+    try:
+        ss = ssl(sock, PATH_TO_PRIVKEY, PATH_TO_CACERT)
+        hello = self.__receive(ss)
+        #print >> sys.stderr, hello.toxml()
+        self.__sendall(query_str, ss)
+        # receive response
+        payload = self.__receive(ss)
+    except sslerror, e:
+        payload = None
+
+    if ss: 
+        del ss
     sock.close()
 
+    if payload == None:
+      raise RicciReceiveError('FATAL',"Unable to receive ricci data for %s" % self.__hostname)
     return payload
 
 
@@ -341,7 +361,7 @@
         if node.nodeName == 'batch':
           bt_node = node
     if bt_node == None:
-      print "bt_node == None"
+      #print "bt_node == None"
       doc = None
     else:
       #print doc.toxml()
@@ -351,7 +371,7 @@
               if node.nodeName == 'module':
                   mod_node = node
       if mod_node == None:
-          print "mod_node == None"
+          #print "mod_node == None"
           doc = None
       else:
           resp_node = None
@@ -359,7 +379,7 @@
               if node.nodeType == xml.dom.Node.ELEMENT_NODE:
                   resp_node = node
           if resp_node == None:
-              print "resp_node == None"
+              #print "resp_node == None"
               doc = None
           else:
               fr_node = None
@@ -367,7 +387,7 @@
                   if node.nodeType == xml.dom.Node.ELEMENT_NODE:
                     fr_node = node
               if fr_node == None:
-                  print "fr_node == None"
+                  #print "fr_node == None"
                   doc = None
               else:
                   varnode = None
@@ -376,7 +396,7 @@
                         varnode = node
                         break
                   if varnode == None:
-                     print "varnode == None"
+                     #print "varnode == None"
                      doc = None
                   else:
                     cl_node = None
@@ -385,7 +405,7 @@
                             cl_node = node
                             break
                     if cl_node == None:
-                      print "cl_node == None"
+                      #print "cl_node == None"
                       doc = None
                     else:
                         docc = minidom.Document()
@@ -402,7 +422,7 @@
         if node.nodeName == 'batch':
           bt_node = node
     if bt_node == None:
-      print "bt_node == None"
+      #print "bt_node == None"
       doc = None
     else:
       #print doc.toxml()
@@ -412,7 +432,7 @@
               if node.nodeName == 'module':
                   mod_node = node
       if mod_node == None:
-          print "mod_node == None"
+          #print "mod_node == None"
           doc = None
       else:
           resp_node = None
@@ -420,7 +440,7 @@
               if node.nodeType == xml.dom.Node.ELEMENT_NODE:
                   resp_node = node
           if resp_node == None:
-              print "resp_node == None"
+              #print "resp_node == None"
               doc = None
           else:
               fr_node = None
@@ -428,7 +448,7 @@
                   if node.nodeType == xml.dom.Node.ELEMENT_NODE:
                     fr_node = node
               if fr_node == None:
-                  print "fr_node == None"
+                  #print "fr_node == None"
                   doc = None
               else:
                   varnode = None
@@ -437,7 +457,7 @@
                         varnode = node
                         break
                   if varnode == None:
-                     print "varnode == None"
+                     #print "varnode == None"
                      doc = None
                   else:
                     svc_node = None
@@ -462,20 +482,41 @@
                 result = node.getAttribute('status')
                 return (batch_number, result)
             else:
-                print "RETURNING NONE!!!"
+                #print "RETURNING NONE!!!"
                 return (None, None )
 
 
         
   def getRicciResponse(self):
     sock = socket(AF_INET, SOCK_STREAM)
+    sock.settimeout(2.0)
     try:
       sock.connect((self.__hostname, self.__port))
     except:
+      sock.close()
       return False
-    ss = ssl(sock, PATH_TO_PRIVKEY, PATH_TO_CACERT)
+
+    ss = 0
+    try:
+        ss = ssl(sock, PATH_TO_PRIVKEY, PATH_TO_CACERT)
+    except sslerror, e:
+        if ss:
+           del ss
+        sock.close()
+        return False
+    sock.settimeout(600.0) # 10 minutes
+    # TODO: data transfer timeout should be much less, 
+    # leave until all calls are async ricci calls
+
     # receive ricci header
-    hello = self.__receive(ss)
+    try:
+      hello = self.__receive(ss)
+    except sslerror, e:
+      hello = None
+
+    del ss
+    sock.close()
+
     if hello != None:
       return True
     else:
--- conga/luci/site/luci/Extensions/ricci_communicator.py	2006/09/26 21:04:47	1.5
+++ conga/luci/site/luci/Extensions/ricci_communicator.py	2006/09/29 21:41:43	1.6
@@ -164,7 +164,7 @@
     
     def __send(self, xml_doc):
         buff = xml_doc.toxml() + '\n'
-        print buff
+        #print buff
         while len(buff) != 0:
             pos = self.ss.write(buff)
             buff = buff[pos:]


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]