- fix to support /smp model option for rins
[bootmanager.git] / source / steps / InstallWriteConfig.py
index f7e164f..a0dfac5 100644 (file)
@@ -46,7 +46,7 @@ from Exceptions import *
 import utils
 from systeminfo import systeminfo
 import BootAPI
-
+import ModelOptions
 
 def Run( vars, log ):
 
@@ -175,7 +175,8 @@ def Run( vars, log ):
     fstab.write( "none         /proc       proc      defaults  0 0\n" )
     fstab.write( "none         /dev/shm    tmpfs     defaults  0 0\n" )
     fstab.write( "none         /dev/pts    devpts    defaults  0 0\n" )
-    fstab.write( "none         /rcfs       rcfs      defaults  0 0\n" )
+    # no longer needed
+    # fstab.write( "none         /rcfs       rcfs      defaults  0 0\n" )
     fstab.close()
 
 
@@ -219,20 +220,19 @@ def Run( vars, log ):
     log.write( "Making initrd\n" )
 
     # trick mkinitrd in case the current environment does not have device mapper
-    fake_root_lvm= 0
+    fake_root_lvm= False
     if not os.path.exists( "%s/%s" % (SYSIMG_PATH,PARTITIONS["mapper-root"]) ):
-        fake_root_lvm= 1
+        fake_root_lvm= True
         utils.makedirs( "%s/dev/mapper" % SYSIMG_PATH )
         rootdev= file( "%s/%s" % (SYSIMG_PATH,PARTITIONS["mapper-root"]), "w" )
         rootdev.close()
 
-    initrd= os.readlink( "%s/boot/initrd-boot" % SYSIMG_PATH )
-    kernel_version= initrd.replace("initrd-", "").replace(".img", "")
+    initrd, kernel_version= getKernelVersion(vars,log)
     utils.removefile( "%s/boot/%s" % (SYSIMG_PATH, initrd) )
     utils.sysexec( "chroot %s mkinitrd /boot/initrd-%s.img %s" % \
                    (SYSIMG_PATH, kernel_version, kernel_version), log )
 
-    if fake_root_lvm == 1:
+    if fake_root_lvm == True:
         utils.removefile( "%s/%s" % (SYSIMG_PATH,PARTITIONS["mapper-root"]) )
 
     log.write( "Writing node install version\n" )
@@ -387,7 +387,7 @@ def write_network_configuration( vars, log ):
 
 
 
-def write_modprobeconf_file( vars, log ):
+def write_modprobeconf_file( vars, log, filename = "/etc/modprobe.conf"):
     """
     write out the system file /etc/modprobe.conf with the current
     set of modules.
@@ -409,11 +409,7 @@ def write_modprobeconf_file( vars, log ):
     except ValueError, var:
         raise BootManagerException, "Variable in vars, shouldn't be: %s\n" % var
 
-    
-    # get the kernel version
-    initrd= os.readlink( "%s/boot/initrd-boot" % SYSIMG_PATH )
-    kernel_version= initrd.replace("initrd-", "").replace(".img", "")
-
+    initrd, kernel_version= getKernelVersion(vars,log)
     sysinfo= systeminfo()
     sysmods= sysinfo.get_system_modules(SYSIMG_PATH, kernel_version)
     if sysmods is None:
@@ -422,7 +418,7 @@ def write_modprobeconf_file( vars, log ):
     eth_count= 0
     scsi_count= 0
 
-    modulesconf_file= file("%s/etc/modprobe.conf" % SYSIMG_PATH, "w" )
+    modulesconf_file= file("%s/%s" % (SYSIMG_PATH,filename), "w" )
 
     for type in sysmods:
         if type == sysinfo.MODULE_CLASS_SCSI:
@@ -446,3 +442,33 @@ def write_modprobeconf_file( vars, log ):
 
     return (eth_count,scsi_count)
 
+def getKernelVersion( vars, log):
+    # make sure we have the variables we need
+    try:
+        SYSIMG_PATH= vars["SYSIMG_PATH"]
+        if SYSIMG_PATH == "":
+            raise ValueError, "SYSIMG_PATH"
+
+        NODE_MODEL_OPTIONS=vars["NODE_MODEL_OPTIONS"]
+    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
+
+    option = ''
+    if NODE_MODEL_OPTIONS & ModelOptions.SMP:
+        option = 'smp'
+        try:
+            os.stat("%s/boot/kernel-boot%s" % (SYSIMG_PATH,option))
+            os.stat("%s/boot/initrd-boot%s" % (SYSIMG_PATH,option))
+        except OSError, e:
+            # smp kernel is not there; remove option from modeloptions
+            # such that the rest of the code base thinks we are just
+            # using the base kernel.
+            NODE_MODEL_OPTIONS = NODE_MODEL_OPTIONS & ~ModelOptions.SMP
+            vars["NODE_MODEL_OPTIONS"] = NODE_MODEL_OPTIONS
+            log.write( "WARNING: Couldn't locate smp kernel.\n")
+            option = ''
+    initrd= os.readlink( "%s/boot/initrd-boot%s" % (SYSIMG_PATH,option) )
+    kernel_version= initrd.replace("initrd-", "").replace(".img", "")    
+    return (initrd, kernel_version)