more prettifying
authorThierry Parmentelat <thierry.parmentelat@inria.fr>
Tue, 28 Apr 2015 09:53:12 +0000 (11:53 +0200)
committerThierry Parmentelat <thierry.parmentelat@inria.fr>
Tue, 28 Apr 2015 09:53:12 +0000 (11:53 +0200)
source/steps/InstallUninitHardware.py
source/steps/MakeInitrd.py
source/steps/ReadNodeConfiguration.py
source/steps/SendHardwareConfigToPLC.py
source/steps/StartDebug.py

index 6497081..a2f6086 100644 (file)
@@ -14,7 +14,7 @@ import utils
 
 
 
-def Run( vars, log ):
+def Run(vars, log):
     """
     Unitializes hardware:
     - unmount everything mounted during install, except the
@@ -33,26 +33,26 @@ def Run( vars, log ):
     
     """
 
-    log.write( "\n\nStep: Install: Shutting down installer.\n" )
+    log.write("\n\nStep: Install: Shutting down installer.\n")
 
     # make sure we have the variables we need
     try:
         TEMP_PATH= vars["TEMP_PATH"]
         if TEMP_PATH == "":
-            raise ValueError, "TEMP_PATH"
+            raise ValueError("TEMP_PATH")
 
         SYSIMG_PATH= vars["SYSIMG_PATH"]
         if SYSIMG_PATH == "":
-            raise ValueError, "SYSIMG_PATH"
+            raise ValueError("SYSIMG_PATH")
 
         PARTITIONS= vars["PARTITIONS"]
         if PARTITIONS == None:
-            raise ValueError, "PARTITIONS"
+            raise ValueError("PARTITIONS")
 
-    except KeyError, var:
-        raise BootManagerException, "Missing variable in vars: %s\n" % var
-    except ValueError, var:
-        raise BootManagerException, "Variable in vars, shouldn't be: %s\n" % var
+    except KeyError as var:
+        raise BootManagerException("Missing variable in vars: {}\n".format(var))
+    except ValueError as var:
+        raise BootManagerException("Variable in vars, shouldn't be: {}\n".format(var))
 
 
     try:
@@ -60,17 +60,17 @@ def Run( vars, log ):
         val= PARTITIONS["root"]
         val= PARTITIONS["swap"]
         val= PARTITIONS["vservers"]
-    except KeyError, part:
-        raise BootManagerException, "Missing partition in PARTITIONS: %s\n" % part
+    except KeyError as part:
+        raise BootManagerException("Missing partition in PARTITIONS: {}\n".format(part))
 
     try:
         # backwards compat, though, we should never hit this case post PL 3.2
-        os.stat("%s/rcfs/taskclass"%SYSIMG_PATH)
-        utils.sysexec_chroot_noerr( SYSIMG_PATH, "umount /rcfs", log )
-    except OSError, e:
+        os.stat("{}/rcfs/taskclass".format(SYSIMG_PATH))
+        utils.sysexec_chroot_noerr(SYSIMG_PATH, "umount /rcfs", log)
+    except OSError as e:
         pass
             
-    log.write( "Shutting down swap\n" )
-    utils.sysexec( "swapoff %s" % PARTITIONS["swap"], log )
+    log.write("Shutting down swap\n")
+    utils.sysexec("swapoff {}".format(PARTITIONS["swap"]), log)
 
     return 1
index 4564dfe..0ba815c 100644 (file)
@@ -6,6 +6,8 @@
 # Copyright (c) 2004-2006 The Trustees of Princeton University
 # All rights reserved.
 
+from __future__ import print_function
+
 import os
 
 from Exceptions import *
@@ -17,38 +19,42 @@ import systeminfo
 # http://kbase.redhat.com/faq/docs/DOC-16528;jsessionid=7E984A99DE8DB094D9FB08181C71717C.ab46478d
 def bypassRaidIfNeeded(sysimg_path, log):
     try:
-        [ a,b,c,d]=file('%s/etc/redhat-release'%sysimg_path).readlines()[0].strip().split()
-        if a !='CentOS': return
-        [major,minor]=[int(x) for x in c.split('.')]
+        a, b, c, d = file('{}/etc/redhat-release'.format(sysimg_path))\
+            .readlines()[0].strip().split()
+        if a != 'CentOS':
+            return
+        major, minor = [ int(x) for x in c.split('.') ]
         if minor >= 3:
-            utils.sysexec_noerr('echo "DMRAID=no" >> %s/etc/sysconfig/mkinitrd/noraid' % sysimg_path , log )
-            utils.sysexec_noerr('chmod 755 %s/etc/sysconfig/mkinitrd/noraid' % sysimg_path, log )
+            utils.sysexec_noerr('echo "DMRAID=no" >> {}/etc/sysconfig/mkinitrd/noraid'
+                                .format(sysimg_path), log)
+            utils.sysexec_noerr('chmod 755 {}/etc/sysconfig/mkinitrd/noraid'
+                                .format(sysimg_path), log)
     except:
         pass
             
         
-def Run( vars, log ):
+def Run(vars, log):
     """
     Rebuilds the system initrd, on first install or in case the
     hardware changed.
     """
 
-    log.write( "\n\nStep: Rebuilding initrd\n" )
+    log.write("\n\nStep: Rebuilding initrd\n")
     
     # make sure we have the variables we need
     try:
-        SYSIMG_PATH= vars["SYSIMG_PATH"]
+        SYSIMG_PATH = vars["SYSIMG_PATH"]
         if SYSIMG_PATH == "":
-            raise ValueError, "SYSIMG_PATH"
+            raise ValueError("SYSIMG_PATH")
 
-        PARTITIONS= vars["PARTITIONS"]
+        PARTITIONS = vars["PARTITIONS"]
         if PARTITIONS == None:
-            raise ValueError, "PARTITIONS"
+            raise ValueError("PARTITIONS")
 
-    except KeyError, var:
-        raise BootManagerException, "Missing variable in vars: %s\n" % var
-    except ValueError, var:
-        raise BootManagerException, "Variable in vars, shouldn't be: %s\n" % var
+    except KeyError as var:
+        raise BootManagerException("Missing variable in vars: {}\n".format(var))
+    except ValueError as var:
+        raise BootManagerException("Variable in vars, shouldn't be: {}\n".format(var))
 
     # mkinitrd needs /dev and /proc to do the right thing.
     # /proc is already mounted, so bind-mount /dev here
@@ -57,21 +63,22 @@ def Run( vars, log ):
     # tmp - sysexec_noerr not returning what one would expect
     # if utils.sysexec_noerr ("grep devtmpfs /proc/mounts") != 0:
     utils.sysexec_noerr("mount -t devtmpfs none /dev")
-    utils.sysexec("mount -o bind /dev %s/dev" % SYSIMG_PATH)
-    utils.sysexec("mount -t sysfs none %s/sys" % SYSIMG_PATH)
+    utils.sysexec("mount -o bind /dev {}/dev".format(SYSIMG_PATH))
+    utils.sysexec("mount -t sysfs none {}/sys".format(SYSIMG_PATH))
 
-    initrd, kernel_version= systeminfo.getKernelVersion(vars,log)
+    initrd, kernel_version = systeminfo.getKernelVersion(vars,log)
     try:
-        utils.removefile( "%s/boot/%s" % (SYSIMG_PATH, initrd) )
+        utils.removefile("{}/boot/{}".format(SYSIMG_PATH, initrd))
     except:
-        print "%s/boot/%s is already removed" % (SYSIMG_PATH, initrd)
+        print("{}/boot/{} is already removed".format(SYSIMG_PATH, initrd))
 
     # hack for CentOS 5.3
-    bypassRaidIfNeeded(SYSIMG_PATH , log )
+    bypassRaidIfNeeded(SYSIMG_PATH , log)
     # specify ext3 for fedora14 and above as their default fs is ext4
-    utils.sysexec_chroot( SYSIMG_PATH, "mkinitrd -v --with=ext3 --allow-missing /boot/initrd-%s.img %s" % \
-               (kernel_version, kernel_version), log )
+    utils.sysexec_chroot(SYSIMG_PATH,
+                         "mkinitrd -v --with=ext3 --allow-missing /boot/initrd-{}.img {}"
+                         .format(kernel_version, kernel_version), log)
 
-    utils.sysexec_noerr("umount %s/sys" % SYSIMG_PATH , log )
-    utils.sysexec_noerr("umount %s/dev" % SYSIMG_PATH , log)
+    utils.sysexec_noerr("umount {}/sys".format(SYSIMG_PATH), log)
+    utils.sysexec_noerr("umount {}/dev".format(SYSIMG_PATH), log)
 
index aadef79..57e12d5 100644 (file)
@@ -21,11 +21,11 @@ import UpdateRunLevelWithPLC
 
 
 # two possible names of the configuration files
-NEW_CONF_FILE_NAME= "plnode.txt"
-OLD_CONF_FILE_NAME= "planet.cnf"
+NEW_CONF_FILE_NAME = "plnode.txt"
+OLD_CONF_FILE_NAME = "planet.cnf"
 
 
-def Run( vars, log ):   
+def Run(vars, log):   
     """
     read the machines node configuration file, which contains
     the node key and the node_id for this machine.
@@ -77,263 +77,268 @@ def Run( vars, log ):
     configuration file.
     """
 
-    log.write( "\n\nStep: Reading node configuration file.\n" )
+    log.write("\n\nStep: Reading node configuration file.\n")
 
 
     # make sure we have the variables we need
 
-    INTERFACE_SETTINGS= {}
-    INTERFACE_SETTINGS['method']= "dhcp"
-    INTERFACE_SETTINGS['ip']= ""
-    INTERFACE_SETTINGS['mac']= ""
-    INTERFACE_SETTINGS['gateway']= ""
-    INTERFACE_SETTINGS['network']= ""
-    INTERFACE_SETTINGS['broadcast']= ""
-    INTERFACE_SETTINGS['netmask']= ""
-    INTERFACE_SETTINGS['dns1']= ""
-    INTERFACE_SETTINGS['dns2']= ""
-    INTERFACE_SETTINGS['hostname']= "localhost"
-    INTERFACE_SETTINGS['domainname']= "localdomain"
-    vars['INTERFACE_SETTINGS']= INTERFACE_SETTINGS
+    INTERFACE_SETTINGS = {}
+    INTERFACE_SETTINGS['method'] = "dhcp"
+    INTERFACE_SETTINGS['ip'] = ""
+    INTERFACE_SETTINGS['mac'] = ""
+    INTERFACE_SETTINGS['gateway'] = ""
+    INTERFACE_SETTINGS['network'] = ""
+    INTERFACE_SETTINGS['broadcast'] = ""
+    INTERFACE_SETTINGS['netmask'] = ""
+    INTERFACE_SETTINGS['dns1'] = ""
+    INTERFACE_SETTINGS['dns2'] = ""
+    INTERFACE_SETTINGS['hostname'] = "localhost"
+    INTERFACE_SETTINGS['domainname'] = "localdomain"
+    vars['INTERFACE_SETTINGS'] = INTERFACE_SETTINGS
 
-    vars['NODE_ID']= 0
-    vars['NODE_KEY']= ""
+    vars['NODE_ID'] = 0
+    vars['NODE_KEY'] = ""
 
-    vars['WAS_NODE_ID_IN_CONF']= 0
-    vars['WAS_NODE_KEY_IN_CONF']= 0
+    vars['WAS_NODE_ID_IN_CONF'] = 0
+    vars['WAS_NODE_KEY_IN_CONF'] = 0
 
-    vars['DISCONNECTED_OPERATION']= ''
+    vars['DISCONNECTED_OPERATION'] = ''
 
     # for any devices that need to be mounted to get the configuration
     # file, mount them here.
-    mount_point= "/tmp/conffilemount"
-    utils.makedirs( mount_point )
+    mount_point = "/tmp/conffilemount"
+    utils.makedirs(mount_point)
 
-    old_conf_file_contents= None
-    conf_file_contents= None
+    old_conf_file_contents = None
+    conf_file_contents = None
     
     
     # 1. check the regular floppy device
-    log.write( "Checking standard floppy disk for plnode.txt file.\n" )
+    log.write("Checking standard floppy disk for plnode.txt file.\n")
 
-    log.write( "Mounting /dev/fd0 on %s\n" % mount_point )
-    utils.sysexec_noerr( "mount -o ro -t ext2,msdos /dev/fd0 %s " \
-                         % mount_point, log )
+    log.write("Mounting /dev/fd0 on {}\n".format(mount_point))
+    utils.sysexec_noerr("mount -o ro -t ext2,msdos /dev/fd0 {} "
+                        .format(mount_point), log)
 
-    conf_file_path= "%s/%s" % (mount_point,NEW_CONF_FILE_NAME)
+    conf_file_path = "{}/{}".format(mount_point, NEW_CONF_FILE_NAME)
     
-#    log.write( "Checking for existence of %s\n" % conf_file_path )
-    if os.access( conf_file_path, os.R_OK ):
+#    log.write("Checking for existence of {}\n".format(conf_file_path))
+    if os.access(conf_file_path, os.R_OK):
         try:
-            conf_file= file(conf_file_path,"r")
-            conf_file_contents= conf_file.read()
+            conf_file = file(conf_file_path,"r")
+            conf_file_contents = conf_file.read()
             conf_file.close()
-            log.write( "Read in contents of file %s\n" % conf_file_path )
-        except IOError, e:
-            log.write( "Unable to read file %s\n" % conf_file_path )
+            log.write("Read in contents of file {}\n".format(conf_file_path))
+        except IOError as e:
+            log.write("Unable to read file {}\n".format(conf_file_path))
             pass
 
-        utils.sysexec_noerr( "umount %s" % mount_point, log )
-        if __parse_configuration_file( vars, log, conf_file_contents):
-            log.write("ReadNodeConfiguration: [1] using %s from floppy /dev/fd0\n"%NEW_CONF_FILE_NAME)
+        utils.sysexec_noerr("umount {}".format(mount_point), log)
+        if __parse_configuration_file(vars, log, conf_file_contents):
+            log.write("ReadNodeConfiguration: [1] using {} from floppy /dev/fd0\n"
+                      .format(NEW_CONF_FILE_NAME))
             return 1
         else:
-            raise BootManagerException( "Found configuration file plnode.txt " \
-                                        "on floppy, but was unable to parse it." )
+            raise BootManagerException("Found configuration file plnode.txt "
+                                        "on floppy, but was unable to parse it.")
 
 
     # try the old file name, same device. its actually number 3 on the search
     # order, but do it now to save mounting/unmounting the disk twice.
     # try to parse it later...
-    conf_file_path= "%s/%s" % (mount_point,OLD_CONF_FILE_NAME)
+    conf_file_path = "{}/{}".format(mount_point, OLD_CONF_FILE_NAME)
 
 # this message really does not convey any useful information
-#    log.write( "Checking for existence of %s (used later)\n" % conf_file_path )
-    if os.access( conf_file_path, os.R_OK ):
+#    log.write("Checking for existence of %s (used later)\n" % conf_file_path)
+    if os.access(conf_file_path, os.R_OK):
         try:
-            old_conf_file= file(conf_file_path,"r")
-            old_conf_file_contents= old_conf_file.read()
+            old_conf_file = file(conf_file_path, "r")
+            old_conf_file_contents = old_conf_file.read()
             old_conf_file.close()
-            log.write( "Read in contents of file %s\n" % conf_file_path )
-        except IOError, e:
-            log.write( "Unable to read file %s\n" % conf_file_path )
+            log.write("Read in contents of file {}\n".format(conf_file_path))
+        except IOError as e:
+            log.write("Unable to read file {}\n".format(conf_file_path))
             pass
         
-    utils.sysexec_noerr( "umount %s" % mount_point, log )
+    utils.sysexec_noerr("umount {}".format(mount_point), log)
 
     # 2. check flash devices on 3.0 based cds
-    log.write( "Checking flash devices for plnode.txt file.\n" )
+    log.write("Checking flash devices for plnode.txt file.\n")
 
     # this is done the same way the 3.0 cds do it, by attempting
     # to mount and sd*1 devices that are removable
-    devices= os.listdir("/sys/block/")
+    devices = os.listdir("/sys/block/")
 
     for device in devices:
         if device[:2] != "sd":
-            log.write( "Skipping non-scsi device %s\n" % device )
+            log.write("Skipping non-scsi device {}\n".format(device))
             continue
 
         # test removable
-        removable_file_path= "/sys/block/%s/removable" % device
+        removable_file_path = "/sys/block/{}/removable".format(device)
         try:
-            removable= int(file(removable_file_path,"r").read().strip())
-        except ValueError, e:
+            removable = int(file(removable_file_path,"r").read().strip())
+        except ValueError as e:
             continue
-        except IOError, e:
+        except IOError as e:
             continue
 
         if not removable:
-            log.write( "Skipping non-removable device %s\n" % device )
+            log.write("Skipping non-removable device {}\n".format(device))
             continue
 
-        log.write( "Checking removable device %s\n" % device )
+        log.write("Checking removable device {}\n".format(device))
 
-        partitions= file("/proc/partitions", "r")
+        partitions = file("/proc/partitions", "r")
         for line in partitions:
-            found_file= 0
-            parsed_file= 0
+            found_file = 0
+            parsed_file = 0
             
-            if not re.search("%s[0-9]*$" % device, line):
+            if not re.search("{}[0-9]*$".format(device), line):
                 continue
 
             try:
                 # major minor  #blocks  name
-                parts= string.split(line)
+                parts = string.split(line)
 
                 # ok, try to mount it and see if we have a conf file.
-                full_device= "/dev/%s" % parts[3]
-            except IndexError, e:
-                log.write( "Incorrect /proc/partitions line:\n%s\n" % line )
+                full_device = "/dev/{}".format(parts[3])
+            except IndexError as e:
+                log.write("Incorrect /proc/partitions line:\n{}\n".format(line))
                 continue
 
-            log.write( "Mounting %s on %s\n" % (full_device,mount_point) )
+            log.write("Mounting {} on {}\n".format(full_device, mount_point))
             try:
-                utils.sysexec( "mount -o ro -t ext2,msdos %s %s" \
-                               % (full_device,mount_point), log )
-            except BootManagerException, e:
-                log.write( "Unable to mount, trying next partition\n" )
+                utils.sysexec("mount -o ro -t ext2,msdos {} {}"
+                              .format(full_device, mount_point), log)
+            except BootManagerException as e:
+                log.write("Unable to mount, trying next partition\n")
                 continue
 
-            conf_file_path= "%s/%s" % (mount_point,NEW_CONF_FILE_NAME)
+            conf_file_path = "{}/{}".format(mount_point, NEW_CONF_FILE_NAME)
 
-            log.write( "Checking for existence of %s\n" % conf_file_path )
-            if os.access( conf_file_path, os.R_OK ):
+            log.write("Checking for existence of {}\n".format(conf_file_path))
+            if os.access(conf_file_path, os.R_OK):
                 try:
-                    conf_file= file(conf_file_path,"r")
-                    conf_file_contents= conf_file.read()
+                    conf_file = file(conf_file_path,"r")
+                    conf_file_contents = conf_file.read()
                     conf_file.close()
-                    found_file= 1
-                    log.write( "Read in contents of file %s\n" % \
-                               conf_file_path )
+                    found_file = 1
+                    log.write("Read in contents of file {}\n"
+                              .format(conf_file_path))
 
-                    if __parse_configuration_file( vars, log, conf_file_contents):
-                        parsed_file= 1
-                except IOError, e:
-                    log.write( "Unable to read file %s\n" % conf_file_path )
+                    if __parse_configuration_file(vars, log, conf_file_contents):
+                        parsed_file = 1
+                except IOError as e:
+                    log.write("Unable to read file {}\n".format(conf_file_path))
 
-            utils.sysexec_noerr( "umount %s" % mount_point, log )
+            utils.sysexec_noerr("umount {}".format(mount_point), log)
             if found_file:
                 if parsed_file:
-                    log.write("ReadNodeConfiguration: [2] using %s from partition %s\n"%\
-                                  (NEW_CONF_FILE_NAME,full_device))
+                    log.write("ReadNodeConfiguration: [2] using {} from partition {}\n"
+                              .format(NEW_CONF_FILE_NAME, full_device))
                     return 1
                 else:
-                    raise BootManagerException( \
-                        "Found configuration file on %s, but was unable to parse it."%full_device)
+                    raise BootManagerException("Found configuration file on {}, "
+                                               "but was unable to parse it.".format(full_device))
 
 
             
     # 3. check standard floppy disk for old file name planet.cnf
-    log.write( "Checking standard floppy disk for planet.cnf file (for legacy nodes).\n" )
+    log.write("Checking standard floppy disk for planet.cnf file (for legacy nodes).\n")
 
     if old_conf_file_contents:
-        if __parse_configuration_file( vars, log, old_conf_file_contents):
-            log.write("ReadNodeConfiguration: [3] using %s from floppy /dev/fd0\n"%OLD_CONF_FILE_NAME)
+        if __parse_configuration_file(vars, log, old_conf_file_contents):
+            log.write("ReadNodeConfiguration: [3] using {} from floppy /dev/fd0\n"
+                      .format(OLD_CONF_FILE_NAME))
             return 1
         else:
-            raise BootManagerException( "Found configuration file planet.cnf " \
-                                        "on floppy, but was unable to parse it." )
+            raise BootManagerException("Found configuration file planet.cnf "
+                                        "on floppy, but was unable to parse it.")
 
 
     # 4. check for plnode.txt in / (ramdisk)
-    log.write( "Checking / (ramdisk) for plnode.txt file.\n" )
+    log.write("Checking / (ramdisk) for plnode.txt file.\n")
     
-    conf_file_path= "/%s" % NEW_CONF_FILE_NAME
+    conf_file_path = "/{}".format(NEW_CONF_FILE_NAME)
 
-    log.write( "Checking for existence of %s\n" % conf_file_path )
+    log.write("Checking for existence of {}\n".format(conf_file_path))
     if os.access(conf_file_path,os.R_OK):
         try:
-            conf_file= file(conf_file_path,"r")
-            conf_file_contents= conf_file.read()
+            conf_file = file(conf_file_path,"r")
+            conf_file_contents = conf_file.read()
             conf_file.close()
-            log.write( "Read in contents of file %s\n" % conf_file_path )
-        except IOError, e:
-            log.write( "Unable to read file %s\n" % conf_file_path )
+            log.write("Read in contents of file {}\n".format(conf_file_path))
+        except IOError as e:
+            log.write("Unable to read file {}\n".format(conf_file_path))
             pass
     
-        if __parse_configuration_file( vars, log, conf_file_contents):            
-            log.write("ReadNodeConfiguration: [4] using %s from ramdisk\n"%NEW_CONF_FILE_NAME)
+        if __parse_configuration_file(vars, log, conf_file_contents):            
+            log.write("ReadNodeConfiguration: [4] using {} from ramdisk\n"
+                      .format(NEW_CONF_FILE_NAME))
             return 1
         else:
-            raise BootManagerException( "Found configuration file plnode.txt " \
+            raise BootManagerException("Found configuration file plnode.txt "
                                         "in /, but was unable to parse it.")
 
     
     # 5. check for plnode.txt in /usr/boot (mounted already)
-    log.write( "Checking /usr/boot (cd) for plnode.txt file.\n" )
+    log.write("Checking /usr/boot (cd) for plnode.txt file.\n")
     
-    conf_file_path= "/usr/boot/%s" % NEW_CONF_FILE_NAME
+    conf_file_path = "/usr/boot/{}".format(NEW_CONF_FILE_NAME)
 
-    log.write( "Checking for existence of %s\n" % conf_file_path )
+    log.write("Checking for existence of {}\n".format(conf_file_path))
     if os.access(conf_file_path,os.R_OK):
         try:
-            conf_file= file(conf_file_path,"r")
-            conf_file_contents= conf_file.read()
+            conf_file = file(conf_file_path,"r")
+            conf_file_contents = conf_file.read()
             conf_file.close()
-            log.write( "Read in contents of file %s\n" % conf_file_path )
-        except IOError, e:
-            log.write( "Unable to read file %s\n" % conf_file_path )
+            log.write("Read in contents of file {}\n".format(conf_file_path))
+        except IOError as e:
+            log.write("Unable to read file {}\n".format(conf_file_path))
             pass
     
-        if __parse_configuration_file( vars, log, conf_file_contents):            
-            log.write("ReadNodeConfiguration: [5] using %s from CD in /usr/boot\n"%NEW_CONF_FILE_NAME)
+        if __parse_configuration_file(vars, log, conf_file_contents):            
+            log.write("ReadNodeConfiguration: [5] using {} from CD in /usr/boot\n"
+                      .format(NEW_CONF_FILE_NAME))
             return 1
         else:
-            raise BootManagerException( "Found configuration file plnode.txt " \
+            raise BootManagerException("Found configuration file plnode.txt "
                                         "in /usr/boot, but was unable to parse it.")
 
 
 
     # 6. check for plnode.txt in /usr (mounted already)
-    log.write( "Checking /usr (cd) for plnode.txt file.\n" )
+    log.write("Checking /usr (cd) for plnode.txt file.\n")
     
-    conf_file_path= "/usr/%s" % NEW_CONF_FILE_NAME
+    conf_file_path = "/usr/{}".format(NEW_CONF_FILE_NAME)
 
-    log.write( "Checking for existence of %s\n" % conf_file_path )
+    log.write("Checking for existence of {}\n".format(conf_file_path))
     if os.access(conf_file_path,os.R_OK):
         try:
-            conf_file= file(conf_file_path,"r")
-            conf_file_contents= conf_file.read()
+            conf_file = file(conf_file_path,"r")
+            conf_file_contents = conf_file.read()
             conf_file.close()
-            log.write( "Read in contents of file %s\n" % conf_file_path )
-        except IOError, e:
-            log.write( "Unable to read file %s\n" % conf_file_path )
+            log.write("Read in contents of file {}\n".format(conf_file_path))
+        except IOError as e:
+            log.write("Unable to read file {}\n".format(conf_file_path))
             pass    
     
-        if __parse_configuration_file( vars, log, conf_file_contents):            
-            log.write("ReadNodeConfiguration: [6] using %s from /usr\n"%NEW_CONF_FILE_NAME)
+        if __parse_configuration_file(vars, log, conf_file_contents):            
+            log.write("ReadNodeConfiguration: [6] using {} from /usr\n"
+                      .format(NEW_CONF_FILE_NAME))
             return 1
         else:
-            raise BootManagerException( "Found configuration file plnode.txt " \
+            raise BootManagerException("Found configuration file plnode.txt "
                                         "in /usr, but was unable to parse it.")
 
 
-    raise BootManagerException, "Unable to find and read a node configuration file."
+    raise BootManagerException("Unable to find and read a node configuration file.")
     
 
 
 
-def __parse_configuration_file( vars, log, file_contents ):
+def __parse_configuration_file(vars, log, file_contents):
     """
     parse a configuration file, set keys in var INTERFACE_SETTINGS
     in vars (see comment for function ReadNodeConfiguration). this
@@ -341,14 +346,14 @@ def __parse_configuration_file( vars, log, file_contents ):
     of the configuration file is completed.
     """
 
-    INTERFACE_SETTINGS= vars["INTERFACE_SETTINGS"]
+    INTERFACE_SETTINGS = vars["INTERFACE_SETTINGS"]
     
     if file_contents is None:
-        log.write( "__parse_configuration_file called with no file contents\n" )
+        log.write("__parse_configuration_file called with no file contents\n")
         return 0
     
     try:
-        line_num= 0
+        line_num = 0
         for line in file_contents.split("\n"):
 
             line_num = line_num + 1
@@ -358,183 +363,183 @@ def __parse_configuration_file( vars, log, file_contents ):
                 continue
 
             # file is setup as name="value" pairs
-            parts= string.split(line, "=", 1)
+            parts = string.split(line, "=", 1)
 
-            name= string.strip(parts[0])
-            value= string.strip(parts[1])
+            name = string.strip(parts[0])
+            value = string.strip(parts[1])
 
             # make sure value starts and ends with
             # single or double quotes
-            quotes= value[0] + value[len(value)-1]
+            quotes = value[0] + value[len(value)-1]
             if quotes != "''" and quotes != '""':
-                log.write( "Invalid line %d in configuration file:\n" % line_num )
-                log.write( line + "\n" )
+                log.write("Invalid line {} in configuration file:\n".format(line_num))
+                log.write(line + "\n")
                 return 0
 
             # get rid of the quotes around the value
-            value= string.strip(value[1:len(value)-1])
+            value = string.strip(value[1:len(value)-1])
 
             if name == "NODE_ID":
                 try:
-                    vars['NODE_ID']= int(value)
-                    vars['WAS_NODE_ID_IN_CONF']= 1
-                except ValueError, e:
-                    log.write( "Non-numeric node_id in configuration file.\n" )
+                    vars['NODE_ID'] = int(value)
+                    vars['WAS_NODE_ID_IN_CONF'] = 1
+                except ValueError as e:
+                    log.write("Non-numeric node_id in configuration file.\n")
                     return 0
 
             if name == "NODE_KEY":
-                vars['NODE_KEY']= value
-                vars['WAS_NODE_KEY_IN_CONF']= 1
+                vars['NODE_KEY'] = value
+                vars['WAS_NODE_KEY_IN_CONF'] = 1
 
             if name == "IP_METHOD":
-                value= string.lower(value)
+                value = string.lower(value)
                 if value != "static" and value != "dhcp":
-                    log.write( "Invalid IP_METHOD in configuration file:\n" )
-                    log.write( line + "\n" )
+                    log.write("Invalid IP_METHOD in configuration file:\n")
+                    log.write(line + "\n")
                     return 0
-                INTERFACE_SETTINGS['method']= value.strip()
+                INTERFACE_SETTINGS['method'] = value.strip()
 
             if name == "IP_ADDRESS":
-                INTERFACE_SETTINGS['ip']= value.strip()
+                INTERFACE_SETTINGS['ip'] = value.strip()
 
             if name == "IP_GATEWAY":
-                INTERFACE_SETTINGS['gateway']= value.strip()
+                INTERFACE_SETTINGS['gateway'] = value.strip()
 
             if name == "IP_NETMASK":
-                INTERFACE_SETTINGS['netmask']= value.strip()
+                INTERFACE_SETTINGS['netmask'] = value.strip()
 
             if name == "IP_NETADDR":
-                INTERFACE_SETTINGS['network']= value.strip()
+                INTERFACE_SETTINGS['network'] = value.strip()
 
             if name == "IP_BROADCASTADDR":
-                INTERFACE_SETTINGS['broadcast']= value.strip()
+                INTERFACE_SETTINGS['broadcast'] = value.strip()
 
             if name == "IP_DNS1":
-                INTERFACE_SETTINGS['dns1']= value.strip()
+                INTERFACE_SETTINGS['dns1'] = value.strip()
 
             if name == "IP_DNS2":
-                INTERFACE_SETTINGS['dns2']= value.strip()
+                INTERFACE_SETTINGS['dns2'] = value.strip()
 
             if name == "HOST_NAME":
-                INTERFACE_SETTINGS['hostname']= string.lower(value)
+                INTERFACE_SETTINGS['hostname'] = string.lower(value)
 
             if name == "DOMAIN_NAME":
-                INTERFACE_SETTINGS['domainname']= string.lower(value)
+                INTERFACE_SETTINGS['domainname'] = string.lower(value)
 
             if name == "NET_DEVICE":
-                INTERFACE_SETTINGS['mac']= string.upper(value)
+                INTERFACE_SETTINGS['mac'] = string.upper(value)
 
             if name == "DISCONNECTED_OPERATION":
-                vars['DISCONNECTED_OPERATION']= value.strip()
+                vars['DISCONNECTED_OPERATION'] = value.strip()
 
-    except IndexError, e:
-        log.write( "Unable to parse configuration file\n" )
+    except IndexError as e:
+        log.write("Unable to parse configuration file\n")
         return 0
 
     # now if we are set to dhcp, clear out any fields
     # that don't make sense
     if INTERFACE_SETTINGS["method"] == "dhcp":
-        INTERFACE_SETTINGS["ip"]= ""
-        INTERFACE_SETTINGS["gateway"]= ""     
-        INTERFACE_SETTINGS["netmask"]= ""
-        INTERFACE_SETTINGS["network"]= ""
-        INTERFACE_SETTINGS["broadcast"]= ""
-        INTERFACE_SETTINGS["dns1"]= ""
-        INTERFACE_SETTINGS["dns2"]= ""
+        INTERFACE_SETTINGS["ip"] = ""
+        INTERFACE_SETTINGS["gateway"] = ""     
+        INTERFACE_SETTINGS["netmask"] = ""
+        INTERFACE_SETTINGS["network"] = ""
+        INTERFACE_SETTINGS["broadcast"] = ""
+        INTERFACE_SETTINGS["dns1"] = ""
+        INTERFACE_SETTINGS["dns2"] = ""
 
-    log.write("Successfully read and parsed node configuration file.\n" )
+    log.write("Successfully read and parsed node configuration file.\n")
 
     # if the mac wasn't specified, read it in from the system.
     if INTERFACE_SETTINGS["mac"] == "":
-        device= "eth0"
-        mac_addr= utils.get_mac_from_interface(device)
+        device = "eth0"
+        mac_addr = utils.get_mac_from_interface(device)
 
         if mac_addr is None:
-            log.write( "Could not get mac address for device eth0.\n" )
+            log.write("Could not get mac address for device eth0.\n")
             return 0
 
-        INTERFACE_SETTINGS["mac"]= string.upper(mac_addr)
+        INTERFACE_SETTINGS["mac"] = string.upper(mac_addr)
 
-        log.write( "Got mac address %s for device %s\n" %
-                   (INTERFACE_SETTINGS["mac"],device) )
+        log.write("Got mac address {} for device {}\n"
+                  .format(INTERFACE_SETTINGS["mac"], device))
         
 
     # now, if the conf file didn't contain a node id, post the mac address
     # to plc to get the node_id value
     if vars['NODE_ID'] is None or vars['NODE_ID'] == 0:
-        log.write( "Configuration file does not contain the node_id value.\n" )
-        log.write( "Querying PLC for node_id.\n" )
+        log.write("Configuration file does not contain the node_id value.\n")
+        log.write("Querying PLC for node_id.\n")
 
-        bs_request= BootServerRequest.BootServerRequest(vars)
+        bs_request = BootServerRequest.BootServerRequest(vars)
         
-        postVars= {"mac_addr" : INTERFACE_SETTINGS["mac"]}
-        result= bs_request.DownloadFile( "/boot/getnodeid.php",
+        postVars = {"mac_addr" : INTERFACE_SETTINGS["mac"]}
+        result = bs_request.DownloadFile("/boot/getnodeid.php",
                                          None, postVars, 1, 1,
                                          "/tmp/node_id")
         if result == 0:
-            log.write( "Unable to make request to get node_id.\n" )
+            log.write("Unable to make request to get node_id.\n")
             return 0
 
         try:
-            node_id_file= file("/tmp/node_id","r")
-            node_id= string.strip(node_id_file.read())
+            node_id_file = file("/tmp/node_id","r")
+            node_id = string.strip(node_id_file.read())
             node_id_file.close()
         except IOError:
-            log.write( "Unable to read node_id from /tmp/node_id\n" )
+            log.write("Unable to read node_id from /tmp/node_id\n")
             return 0
 
         try:
-            node_id= int(string.strip(node_id))
+            node_id = int(string.strip(node_id))
         except ValueError:
-            log.write( "Got node_id from PLC, but not numeric: %s" % str(node_id) )
+            log.write("Got node_id from PLC, but not numeric: {}".format(node_id))
             return 0
 
         if node_id == -1:
-            log.write( "Got node_id, but it returned -1\n\n" )
-
-            log.write( "------------------------------------------------------\n" )
-            log.write( "This indicates that this node could not be identified\n" )
-            log.write( "by PLC. You will need to add the node to your site,\n" )
-            log.write( "and regenerate the network configuration file.\n" )
-            log.write( "See the Technical Contact guide for node setup\n" )
-            log.write( "procedures.\n\n" )
-            log.write( "Boot process canceled until this is completed.\n" )
-            log.write( "------------------------------------------------------\n" )
+            log.write("Got node_id, but it returned -1\n\n")
+
+            log.write("------------------------------------------------------\n")
+            log.write("This indicates that this node could not be identified\n")
+            log.write("by PLC. You will need to add the node to your site,\n")
+            log.write("and regenerate the network configuration file.\n")
+            log.write("See the Technical Contact guide for node setup\n")
+            log.write("procedures.\n\n")
+            log.write("Boot process canceled until this is completed.\n")
+            log.write("------------------------------------------------------\n")
             
-            cancel_boot_flag= "/tmp/CANCEL_BOOT"
+            cancel_boot_flag = "/tmp/CANCEL_BOOT"
             # this will make the initial script stop requesting scripts from PLC
-            utils.sysexec( "touch %s" % cancel_boot_flag, log )
+            utils.sysexec("touch {}".format(cancel_boot_flag), log)
 
             return 0
 
-        log.write( "Got node_id from PLC: %s\n" % str(node_id) )
-        vars['NODE_ID']= node_id
+        log.write("Got node_id from PLC: {}\n".format(node_id))
+        vars['NODE_ID'] = node_id
 
 
 
     if vars['NODE_KEY'] is None or vars['NODE_KEY'] == "":
-        log.write( "Configuration file does not contain a node_key value.\n" )
-        log.write( "Using boot nonce instead.\n" )
+        log.write("Configuration file does not contain a node_key value.\n")
+        log.write("Using boot nonce instead.\n")
 
         # 3.x cds stored the file in /tmp/nonce in ascii form, so they
         # can be read and used directly. 2.x cds stored in the same place
         # but in binary form, so we need to convert it to ascii the same
         # way the old boot scripts did so it matches whats in the db
         # (php uses bin2hex, 
-        read_mode= "r"
+        read_mode = "r"
             
         try:
-            nonce_file= file("/tmp/nonce",read_mode)
-            nonce= nonce_file.read()
+            nonce_file = file("/tmp/nonce",read_mode)
+            nonce = nonce_file.read()
             nonce_file.close()
         except IOError:
-            log.write( "Unable to read nonce from /tmp/nonce\n" )
+            log.write("Unable to read nonce from /tmp/nonce\n")
             return 0
 
-        nonce= string.strip(nonce)
+        nonce = string.strip(nonce)
 
-        log.write( "Read nonce, using as key.\n" )
-        vars['NODE_KEY']= nonce
+        log.write("Read nonce, using as key.\n")
+        vars['NODE_KEY'] = nonce
         
         
     # at this point, we've read the network configuration file.
@@ -546,78 +551,77 @@ def __parse_configuration_file( vars, log, file_contents ):
     # in the configuration file matches the ip address. if it fails
     # notify the owners
 
-    hostname= INTERFACE_SETTINGS['hostname'] + "." + \
+    hostname = INTERFACE_SETTINGS['hostname'] + "." + \
               INTERFACE_SETTINGS['domainname']
 
     # set to 0 if any part of the hostname resolution check fails
-    hostname_resolve_ok= 1
+    hostname_resolve_ok = 1
 
     # set to 0 if the above fails, and, we are using dhcp in which
     # case we don't know the ip of this machine (without having to
     # parse ifconfig or something). In that case, we won't be able
     # to make api calls, so printing a message to the screen will
     # have to suffice.
-    can_make_api_call= 1
+    can_make_api_call = 1
 
-    log.write( "Checking that hostname %s resolves\n" % hostname )
+    log.write("Checking that hostname {} resolves\n".format(hostname))
 
     # try a regular dns lookup first
     try:
-        resolved_node_ip= socket.gethostbyname(hostname)
-    except socket.gaierror, e:
-        hostname_resolve_ok= 0
+        resolved_node_ip = socket.gethostbyname(hostname)
+    except socket.gaierror as e:
+        hostname_resolve_ok = 0
         
 
     if INTERFACE_SETTINGS['method'] == "dhcp":
         if hostname_resolve_ok:
-            INTERFACE_SETTINGS['ip']= resolved_node_ip
-            node_ip= resolved_node_ip
+            INTERFACE_SETTINGS['ip'] = resolved_node_ip
+            node_ip = resolved_node_ip
         else:
-            can_make_api_call= 0
+            can_make_api_call = 0
     else:
-        node_ip= INTERFACE_SETTINGS['ip']
+        node_ip = INTERFACE_SETTINGS['ip']
 
     # make sure the dns lookup matches what the configuration file says
     if hostname_resolve_ok:
         if node_ip != resolved_node_ip:
-            log.write( "Hostname %s does not resolve to %s, but %s:\n" % \
-                       (hostname,node_ip,resolved_node_ip) )
-            hostname_resolve_ok= 0
+            log.write("Hostname {} does not resolve to {}, but {}:\n"
+                      .format(hostname, node_ip, resolved_node_ip))
+            hostname_resolve_ok = 0
         else:
-            log.write( "Hostname %s correctly resolves to %s:\n" %
-                       (hostname,node_ip) )
+            log.write("Hostname {} correctly resolves to {}:\n"
+                      .format(hostname, node_ip))
 
         
-    vars["INTERFACE_SETTINGS"]= INTERFACE_SETTINGS
+    vars["INTERFACE_SETTINGS"] = INTERFACE_SETTINGS
 
     if (not hostname_resolve_ok and not vars['DISCONNECTED_OPERATION'] and
         'NAT_MODE' not in vars):
-        log.write( "Hostname does not resolve correctly, will not continue.\n" )
+        log.write("Hostname does not resolve correctly, will not continue.\n")
 
         if can_make_api_call:
-            log.write( "Notifying contacts of problem.\n" )
+            log.write("Notifying contacts of problem.\n")
 
-            vars['RUN_LEVEL']= 'failboot'
-            vars['STATE_CHANGE_NOTIFY']= 1
-            vars['STATE_CHANGE_NOTIFY_MESSAGE']= \
+            vars['RUN_LEVEL'] = 'failboot'
+            vars['STATE_CHANGE_NOTIFY'] = 1
+            vars['STATE_CHANGE_NOTIFY_MESSAGE'] = \
                                      notify_messages.MSG_HOSTNAME_NOT_RESOLVE
             
-            UpdateRunLevelWithPLC.Run( vars, log )
+            UpdateRunLevelWithPLC.Run(vars, log)
                     
-        log.write( "\n\n" )
-        log.write( "The hostname and/or ip in the network configuration\n" )
-        log.write( "file do not resolve and match.\n" )
-        log.write( "Please make sure the hostname set in the network\n" )
-        log.write( "configuration file resolves to the ip also specified\n" )
-        log.write( "there.\n\n" )
-        log.write( "Debug mode is being started on this cd. When the above\n" )
-        log.write( "is corrected, reboot the machine to try again.\n" )
+        log.write("\n\n")
+        log.write("The hostname and/or ip in the network configuration\n")
+        log.write("file do not resolve and match.\n")
+        log.write("Please make sure the hostname set in the network\n")
+        log.write("configuration file resolves to the ip also specified\n")
+        log.write("there.\n\n")
+        log.write("Debug mode is being started on this cd. When the above\n")
+        log.write("is corrected, reboot the machine to try again.\n")
         
-        raise BootManagerException, \
-              "Configured node hostname does not resolve."
+        raise BootManagerException("Configured node hostname does not resolve.")
     
     try:
-        log.write("Using NODE_ID %d\n"%vars['NODE_ID'])
+        log.write("Using NODE_ID {}\n".format(vars['NODE_ID']))
     except:
         log.write("Unknown NODE_ID")
 
index 1f5dd4b..52ad003 100644 (file)
@@ -6,14 +6,12 @@
 # Copyright (c) 2004-2006 The Trustees of Princeton University
 # All rights reserved.
 
-
 from Exceptions import *
 
+def Run(vars, log):
 
-def Run( vars, log ):
-
-    log.write( "\n\nStep: Sending hardware configuration to PLC.\n" )
+    log.write("\n\nStep: Sending hardware configuration to PLC.\n")
 
-    log.write( "Not implemented, continuing.\n" )
+    log.write("step SendHardwareConfigToPLC Not implemented, continuing.\n")
     
     return
index 6a9e130..65af3f1 100644 (file)
@@ -6,13 +6,15 @@
 # Copyright (c) 2004-2006 The Trustees of Princeton University
 # All rights reserved.
 
+from __future__ import print_function
+
 import os
 
 from Exceptions import *
 import utils
 
 
-warning_message= \
+warning_message = \
 """
 ---------------------------------------------------------
 This machine has entered a temporary debug state, so
@@ -31,7 +33,7 @@ Thank you.
 # and/or it can be invoked as a fallback very early in the bootmanager logic,
 # so we can reach the node regardless of what happens (e.g. bm sometimes hangs)
 
-def Run( vars, log, last_resort = True):
+def Run(vars, log, last_resort = True):
 
     """
     Bring up sshd inside the boot cd environment for debug purposes.
@@ -45,16 +47,16 @@ def Run( vars, log, last_resort = True):
     """
 
     if last_resort:
-        message="Starting debug mode"
+        message = "Starting debug mode"
     else:
-        message="Starting fallback sshd"
+        message = "Starting fallback sshd"
 
 
-    log.write( "\n\nStep: %s.\n"%message )
+    log.write("\n\nStep: %s.\n"%message)
     
     # make sure we have the variables we need
     try:
-        BM_SOURCE_DIR= vars["BM_SOURCE_DIR"]
+        BM_SOURCE_DIR = vars["BM_SOURCE_DIR"]
         if BM_SOURCE_DIR == "":
             raise ValueError, "BM_SOURCE_DIR"
 
@@ -64,16 +66,16 @@ def Run( vars, log, last_resort = True):
         raise BootManagerException, "Variable in vars, shouldn't be: %s\n" % var
 
     # constants
-    ssh_source_files= "%s/debug_files/" % BM_SOURCE_DIR    
-    ssh_dir= "/etc/ssh/"
-    ssh_home= "/root/.ssh"
-    cancel_boot_flag= "/tmp/CANCEL_BOOT"
-    sshd_started_flag= "/tmp/SSHD_RUNNING"
+    ssh_source_files = "%s/debug_files/" % BM_SOURCE_DIR    
+    ssh_dir = "/etc/ssh/"
+    ssh_home = "/root/.ssh"
+    cancel_boot_flag = "/tmp/CANCEL_BOOT"
+    sshd_started_flag = "/tmp/SSHD_RUNNING"
 
     # pre-sshd
-    pre_sshd_script= os.path.join(ssh_source_files, "pre-sshd")
+    pre_sshd_script = os.path.join(ssh_source_files, "pre-sshd")
     if os.path.exists(pre_sshd_script):
-        utils.sysexec_noerr( pre_sshd_script, log )
+        utils.sysexec_noerr(pre_sshd_script, log)
     
     # create host keys if needed
     if not os.path.isdir (ssh_dir):
@@ -98,29 +100,29 @@ def Run( vars, log, last_resort = True):
     ### xxx ### xxx ### xxx ### xxx ### xxx 
 
     # always update the key, may have changed in this instance of the bootmanager
-    log.write( "Installing debug ssh key for root user\n" )
-    if not os.path.isdir ( ssh_home):
-        utils.makedirs( ssh_home )
-    utils.sysexec( "cp -f %s/debug_root_ssh_key %s/authorized_keys" % (ssh_source_files,ssh_home), log )
-    utils.sysexec( "chmod 700 %s" % ssh_home, log )
-    utils.sysexec( "chmod 600 %s/authorized_keys" % ssh_home, log )
+    log.write("Installing debug ssh key for root user\n")
+    if not os.path.isdir (ssh_home):
+        utils.makedirs(ssh_home)
+    utils.sysexec("cp -f {}/debug_root_ssh_key {}/authorized_keys".format(ssh_source_files, ssh_home), log)
+    utils.sysexec("chmod 700 {}".format(ssh_home), log)
+    utils.sysexec("chmod 600 {}/authorized_keys".format(ssh_home), log)
 
     # start sshd
     if not os.path.isfile(sshd_started_flag):
-        log.write( "Starting sshd\n" )
-        utils.sysexec( "service sshd start", log )
+        log.write("Starting sshd\n")
+        utils.sysexec("service sshd start", log)
         # flag that ssh is running
-        utils.sysexec( "touch %s" % sshd_started_flag, log )
+        utils.sysexec("touch {}".format(sshd_started_flag), log)
     else:
         # it is expected that sshd is already running when last_resort==True
         if not last_resort:
-            log.write( "sshd is already running\n" )
+            log.write("sshd is already running\n")
 
     if last_resort:
         # this will make the initial script stop requesting scripts from PLC
-        utils.sysexec( "touch %s" % cancel_boot_flag, log )
+        utils.sysexec("touch {}".format(cancel_boot_flag), log)
 
     if last_resort:
-        print warning_message
+        print(warning_message)
     
     return