review 'print' statements - make sure to use PLC.Debug.log that gets redirected to...
authorThierry Parmentelat <thierry.parmentelat@inria.fr>
Mon, 2 Mar 2015 16:18:37 +0000 (17:18 +0100)
committerThierry Parmentelat <thierry.parmentelat@inria.fr>
Mon, 2 Mar 2015 16:18:37 +0000 (17:18 +0100)
especially for GetBootMedium that tends to become very long

PLC/Accessor.py
PLC/Filter.py
PLC/LeaseFilter.py
PLC/Methods/AddPersonToSite.py
PLC/Methods/AddSlice.py
PLC/Methods/GetBootMedium.py
PLC/Methods/GetNodeFlavour.py
PLC/Methods/RefreshPeer.py
PLC/Methods/UpdateLeases.py
PLC/Peers.py

index e02d29e..e8a69f5 100644 (file)
@@ -74,7 +74,7 @@ This is implemented as a singleton, so we can cache results over time"""
                     tag_type.add_role(role_obj)
                 except:
                     # xxx todo find a more appropriate way of notifying this
-                    print "Accessor.locate_or_create_tag: Could not add role %r to tag_type %s"%(role,tagname)
+                    print >> log, "Accessor.locate_or_create_tag: Could not add role %r to tag_type %s"%(role,tagname)
         self.set_cache(tagname,tag_type)
         return tag_type
 
index c7e28e3..a991f78 100644 (file)
@@ -265,5 +265,6 @@ class Filter(Parameter, dict):
             clip_part += " ORDER BY " + ",".join(sorts)
         if clips:
             clip_part += " " + " ".join(clips)
-        if Filter.debug: print 'Filter.sql: where_part=',where_part,'clip_part',clip_part
+        if Filter.debug:
+            print >> log, 'Filter.sql: where_part=',where_part,'clip_part',clip_part
         return (where_part,clip_part)
index 938f81d..86948ff 100644 (file)
@@ -110,7 +110,8 @@ class LeaseFilter (Filter):
                 where_part += " %s %s(%s)" %(self.join_with,self.negation[k],method(self,self.local[k]))
             except Exception,e:
                 raise PLCInvalidArgument,"LeaseFilter: something wrong with filter key %s, val was %r -- %r"%(k,v,e)
-        if Filter.debug: print 'LeaseFilter.sql: where_part=',where_part,'clip_part',clip_part
+        if Filter.debug:
+            print >> log, 'LeaseFilter.sql: where_part=',where_part,'clip_part',clip_part
         return (where_part,clip_part)
 
 ######## xxx not sure where this belongs yet
index 487892c..17c3c99 100644 (file)
@@ -8,6 +8,8 @@ from PLC.PersonTags import PersonTags, PersonTag
 from PLC.Namespace import email_to_hrn
 from PLC.TagTypes import TagTypes
 
+from PLC.Debug import log
+
 class AddPersonToSite(Method):
     """
     Adds the specified person to the specified site. If the person is
@@ -81,10 +83,10 @@ class AddPersonToSite(Method):
                     person_tag['value'] = hrn
                     person_tag.sync() 
         except Exception,e:
-            print "BEG Warning, cannot maintain person's hrn, %s"%e
+            print >> log, "BEG Warning, cannot maintain person's hrn, %s"%e
             import traceback
-            traceback.print_exc()
-            print "END Warning, cannot maintain person's hrn, %s"%e
+            traceback.print_exc(file=log)
+            print >> log, "END Warning, cannot maintain person's hrn, %s"%e
                 
 
         return 1
index bcae122..0d6c1c6 100644 (file)
@@ -13,6 +13,8 @@ from PLC.SliceTags import SliceTags
 from PLC.Methods.AddSliceTag import AddSliceTag
 from PLC.Methods.UpdateSliceTag import UpdateSliceTag
 
+from PLC.Debug import log
+
 can_update = ['name', 'instantiation', 'url', 'description', 'max_nodes']
 
 class AddSlice(Method):
@@ -110,9 +112,9 @@ class AddSlice(Method):
             for value in values:
                 AddSliceTag(self.api).__call__(auth,slice['slice_id'],'vsys',value)
         except:
-            print "Could not set vsys tags as configured in PLC_VSYS_DEFAULTS"
+            print >> log, "Could not set vsys tags as configured in PLC_VSYS_DEFAULTS"
             import traceback
-            traceback.print_exc()
+            traceback.print_exc(file=log)
         self.event_objects = {'Slice': [slice['slice_id']]}
         self.message = "Slice %d created" % slice['slice_id']
 
index 7225b12..90d65e1 100644 (file)
@@ -14,6 +14,8 @@ from PLC.Interfaces import Interface, Interfaces
 from PLC.InterfaceTags import InterfaceTag, InterfaceTags
 from PLC.NodeTags import NodeTag, NodeTags
 
+from PLC.Debug import log
+
 from PLC.Accessors.Accessors_standard import *                  # import node accessors
 
 # could not define this in the class..
@@ -282,7 +284,7 @@ class GetBootMedium(Method):
     def cleantrash (self):
         for file in self.trash:
             if self.DEBUG:
-                print 'DEBUG -- preserving',file
+                print >> log, 'DEBUG -- preserving',file
             else:
                 os.unlink(file)
 
@@ -367,7 +369,7 @@ class GetBootMedium(Method):
                                                                  log_file)
 
         if self.DEBUG:
-            print "The build command line is %s" % command
+            print >> log, "The build command line is %s" % command
 
         return command
 
@@ -392,7 +394,8 @@ class GetBootMedium(Method):
             raise PLCInvalidArgument, "No such node %r"%node_id_or_hostname
         node = nodes[0]
 
-        if self.DEBUG: print "%s required on node %s. Node type is: %s" \
+        if self.DEBUG:
+            print >> log, "%s requested on node %s. Node type is: %s" \
                 % (action, node['node_id'], node['node_type'])
 
         # check the required action against the node type
@@ -573,7 +576,11 @@ class GetBootMedium(Method):
                     result = file(node_image).read()
                     self.trash.append(node_image)
                     self.cleantrash()
-                    return base64.b64encode(result)
+                    print >> log, "GetBootMedium - done with build.sh"
+                    encoded_result = base64.b64encode(result)
+                    print >> log, "GetBootMedium - done with base64 encoding - lengths=%s - %s"\
+                        %(len(result),len(encoded_result))
+                    return encoded_result
             except:
                 self.cleantrash()
                 raise
index 8e8381d..30a7b8f 100644 (file)
@@ -59,14 +59,14 @@ class GetNodeFlavour(Method):
             for assign in assigns:
                 (left,right)=[x.strip() for x in assign.split(':')]
                 if right not in GetNodeFlavour.known_virts:
-                    print "GetNodeFlavour, unknown 'virt' %s - ignored" % right
+                    print >> log, "GetNodeFlavour, unknown 'virt' %s - ignored" % right
                     continue
                 for fcdistro in [ x.strip() for x in left.split(',')]:
                     map[fcdistro]=right
         except:
-            print "GetNodeFlavour, issue with parsing PLC_FLAVOUR_VIRT_MAP=%s - returning '%s'"%\
+            print >> log, "GetNodeFlavour, issue with parsing PLC_FLAVOUR_VIRT_MAP=%s - returning '%s'"%\
                 (self.api.config.PLC_FLAVOUR_VIRT_MAP,GetNodeFlavour.default_virt)
-            traceback.print_exc()
+            traceback.print_exc(file=log)
             return GetNodeFlavour.default_virt
 #        print 'virt_from_virt_map, using map',map
         if node_fcdistro in map:  return map[node_fcdistro]
index 75b3a87..90a0b70 100644 (file)
@@ -137,7 +137,7 @@ class RefreshPeer(Method):
             file_lock.unlock()
             message("RefreshPeer caught exception - BEG")
             import traceback
-            traceback.print_exc()
+            traceback.print_exc(file=log)
             message("RefreshPeer caught exception - END")
             raise Exception, e
         file_lock.unlock()
@@ -250,12 +250,12 @@ class RefreshPeer(Method):
                     return True
                 else:
                     result=True
-                    print 'COMPARING ',
+#                    print >> log, 'COMPARING ',
                     for column in columns:
                         test= object[column] == peer_object[column]
-                        print column,test,
+#                        print >> log, column,test,
                         if not test: result=False
-                    print '=>',result
+#                    print >> log, '=>',result
                     return result
 
             # Add/update new/existing objects
index bc1d736..28dffb0 100644 (file)
@@ -98,7 +98,8 @@ class UpdateLeases(Method):
                 if UpdateLeases.debug:
                     print 'lease_fields',lease_fields
                     for k in [ 't_from', 't_until'] :
-                        if k in lease_fields: print k,'aka',Timestamp.sql_validate_utc(lease_fields[k])
+                        if k in lease_fields:
+                            print k,'aka',Timestamp.sql_validate_utc(lease_fields[k])
 
                 lease.update(lease_fields)
                 lease.sync()
index 1fa515a..bab43f6 100644 (file)
@@ -175,9 +175,9 @@ class Peer(Row):
             tags = {'hrn': hrn}
             Node(self.api, node).update_tags(tags)
         except:
-            print >>log, "WARNING: (beg) could not find out hrn on hostname=%s"%node['hostname']
-            traceback.print_exc(5,log)
-            print >>log, "WARNING: (end) could not find out hrn on hostname=%s"%node['hostname']
+            print >> log, "WARNING: (beg) could not find out hrn on hostname=%s"%node['hostname']
+            traceback.print_exc(5,file=log)
+            print >> log, "WARNING: (end) could not find out hrn on hostname=%s"%node['hostname']
 
     def remove_node(self, node, commit = True):
         """