rename str to a name that doesn't conflict with builtin func, error report if unable...
smbaker [Tue, 11 Dec 2012 04:27:37 +0000 (20:27 -0800)]
scripts/mpi-copy.py

index 83b223d..164005a 100755 (executable)
@@ -57,6 +57,24 @@ def fetch_output_nofail(inpath,outpath):
 
     return output
 
+def write_hostnamefile(wholestring, hostfile_pathname):
+    for eachline in wholestring:
+      if eachline == "\n" or eachline == "":
+        continue
+      line = eachline.split()
+      if line[0] == "vsys_ipList:":
+        print "writing", hostfile_pathname
+        g = open(hostfile_pathname, "w+")
+        nodeNames = line[1]
+        nodes = nodeNames.split(",")
+        for i in nodes:
+          g.write(i + "\n")
+        g.close()
+        return
+    print "failed to parse vsys_iplist. no hostnamefile created. aborting"
+    print "dump wholestring: ", str(wholestring)
+    sys.exit(-1)
+
 parser = OptionParser()
 (options, args) = parser.parse_args()
 hostfileName = "hostfile"
@@ -68,8 +86,8 @@ f = open("/etc/slicename", "r")
 sliceName = f.read()
 homedir = "/home/" + sliceName
 
-str = "sudo chown -R " + sliceName + " /vsys"
-os.system(str)
+cmd = "sudo chown -R " + sliceName + " /vsys"
+os.system(cmd)
 
 outpath = '/vsys/slice_config.out'
 inpath = '/vsys/slice_config.in'
@@ -108,20 +126,10 @@ while (True):
                 break
 
 wholestring = output.split("\n")
-pathname = homedir + "/" + hostfileName
-for eachline in wholestring:
-  if eachline == "\n" or eachline == "":
-    continue
-  line = eachline.split()
-  if line[0] == "vsys_ipList:":
-    g = open(hostfileName, "w+")
-    nodeNames = line[1]
-    nodes = nodeNames.split(",")
-    for i in nodes:
-      g.write(i + "\n")
-    g.close()
-
-nodes = open(hostfileName, "r")
+hostfile_pathname = homedir + "/" + hostfileName
+write_hostnamefile(wholestring, hostfile_pathname)
+
+nodes = open(hostfile_pathname, "r")
 
 username = getpass.getuser()
 wholefile = nodes.readlines()
@@ -130,14 +138,14 @@ for n in wholefile[1:]:
   node = n.rstrip()
   # wait until node is alive
   while (True):
-    str = "ssh -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no " + username + "@" + node + " true"
-    x = os.system(str)
+    cmd = "ssh -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no " + username + "@" + node + " true"
+    x = os.system(cmd)
     if x == 0:
       break
     else:
       os.system("sleep 10")
-  str = "ssh -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no " + username + "@" + node + " \"if [ ! -d " + directory + " ]; then mkdir " + directory + "; fi\""
-  os.system(str)
+  cmd = "ssh -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no " + username + "@" + node + " \"if [ ! -d " + directory + " ]; then mkdir " + directory + "; fi\""
+  os.system(cmd)
   for eachfile in fileList:
-     str = "scp -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no " + eachfile + " " + username + "@" + node + ":" + directory
-     os.system(str)
+     cmd = "scp -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no " + eachfile + " " + username + "@" + node + ":" + directory
+     os.system(cmd)