files pushed to the client are written to files under directories named after udid 59/15359/1
authorUlas Kozat <ulas.kozat@gmail.com>
Thu, 9 Jun 2016 23:43:16 +0000 (16:43 -0700)
committerUlas Kozat <ulas.kozat@gmail.com>
Thu, 9 Jun 2016 23:43:16 +0000 (16:43 -0700)
Change-Id: I28b5dd6ce3bcc9592108ffecbd325b4290ddeddf
Signed-off-by: Ulas Kozat <ulas.kozat@gmail.com>
DominoClient.py
DominoServer.py
domino_conf.py

index 067b090..a31e074 100755 (executable)
@@ -12,9 +12,9 @@
 #   limitations under the License.
 
 
-import sys, glob, threading
+import sys, os, glob, threading
 import getopt, socket
-import logging
+import logging, errno
 
 #sys.path.append('gen-py')
 #sys.path.insert(0, glob.glob('./lib/py/build/lib.*')[0])
@@ -66,10 +66,25 @@ class CommunicationHandler:
   def d_push(self, push_msg):
     logging.info('%d Received Template File', self.dominoClient.UDID)
     # Retrieve the template file
-
-    ## End of retrieval
-    # Any inspection code goes here
+    try:
+      os.makedirs(TOSCA_RX_DIR+str(self.dominoClient.UDID))
+    except OSError as exception:
+      if exception.errno == errno.EEXIST:
+        logging.debug('IGNORING error: ERRNO %d; %s exists.', exception.errno, TOSCA_RX_DIR+str(self.dominoClient.UDID))
+      else:
+        logging.error('IGNORING error in creating %s. Err no: %d', exception.errno)
+
+    try:  
+      miscutil.write_templatefile(TOSCA_RX_DIR+str(self.dominoClient.UDID)+'/'+str(push_msg.seq_no)+'.yaml' , push_msg.template)
+    except:    
+      logging.error('FAILED to write the pushed file: %s', sys.exc_info()[0])
+      push_r = PushResponseMessage()
+      # Fill response message fields
+      push_r.domino_udid = self.dominoClient.UDID
+      push_r.seq_no = self.dominoClient.seqno
+      push_r.responseCode = FAILED
+      self.dominoClient.seqno = self.dominoClient.seqno + 1
+      return push_r# Any inspection code goes here
 
     ## End of inspection
 
index cebdc78..98a67e3 100755 (executable)
@@ -237,28 +237,35 @@ class CommunicationHandler:
       if exception.errno == errno.EEXIST:
         logging.debug('ERRNO %d; %s exists. Creating: %s', exception.errno, TOSCADIR,  TOSCADIR+TOSCA_DEFAULT_FNAME)
       else:
-        logging.error('Error occurred in creating %s. Err no: %d', exception.errno)
+        logging.error('IGNORING error occurred in creating %s. Err no: %d', exception.errno)
 
     #Risking a race condition if another process is attempting to write to same file
-#    f = open(TOSCADIR+TOSCA_DEFAULT_FNAME, 'w')  
-#    for item in pub_msg.template:
-#      print>>f, item
-#    f.close()
     try:
       miscutil.write_templatefile(TOSCADIR+TOSCA_DEFAULT_FNAME , pub_msg.template)
     except:
       #Some sort of race condition should have occured that prevented the write operation
       #treat as failure
+      logging.error('FAILED to write the published file: %s', sys.exc_info()[0])
       pub_r = PublishResponseMessage()
       pub_r.domino_udid = SERVER_UDID
       pub_r.seq_no = self.seqno
-      pub_r.responseCode = FAILURE
+      pub_r.responseCode = FAILED
       self.seqno = self.seqno + 1
       return pub_r
 
     # Load tosca object from file into memory
-    tosca = ToscaTemplate( TOSCADIR+TOSCA_DEFAULT_FNAME )
-    
+    try:
+      tosca = ToscaTemplate( TOSCADIR+TOSCA_DEFAULT_FNAME )
+    except:
+      logging.error('Tosca Parser error: %s', sys.exc_info()[0])
+      #tosca file could not be read
+      pub_r = PublishResponseMessage()
+      pub_r.domino_udid = SERVER_UDID
+      pub_r.seq_no = self.seqno
+      pub_r.responseCode = FAILED
+      self.seqno = self.seqno + 1 
+      return pub_r 
+
     # Extract Labels
     node_labels = label.extract_labels( tosca )
     logging.debug('Node Labels: %s', node_labels)
index 4f03212..56ccf58 100644 (file)
@@ -14,6 +14,7 @@ DOMINO_CLI_PORT = 9100
 UDID_DESIRED = 12467
 LIST_SUPPORTED_TEMPLATES = ['tosca-nfv-v1.0']
 DEFAULT_TOSCA_PUBFILE = './tosca-templates/tosca_helloworld_nfv.yaml'
+TOSCA_RX_DIR = './toscafiles/'
 
 #Server Parameters
 SERVER_UDID = 0