merge to HEAD as of 2006-08-21
[bootmanager.git] / source / steps / ValidateNodeInstall.py
index db4680c..30cb0af 100644 (file)
@@ -1,9 +1,18 @@
+#!/usr/bin/python2 -u
+
+# Copyright (c) 2003 Intel Corporation
+# All rights reserved.
+#
+# Copyright (c) 2004-2006 The Trustees of Princeton University
+# All rights reserved.
+
 import os
 
 from Exceptions import *
 import utils
-from systeminfo import systeminfo
+import systeminfo
 import compatibility
+import ModelOptions
 
 
 def Run( vars, log ):
@@ -17,6 +26,8 @@ def Run( vars, log ):
                              (always starts with TEMP_PATH)
     BOOT_CD_VERSION          A tuple of the current bootcd version
     ROOT_MOUNTED             the node root file system is mounted
+    NODE_ID                  The db node_id for this machine
+    PLCONF_DIR               The directory to store the configuration file in
     
     Set the following variables upon successfully running:
     ROOT_MOUNTED             the node root file system is mounted
@@ -34,6 +45,20 @@ def Run( vars, log ):
         if SYSIMG_PATH == "":
             raise ValueError, "SYSIMG_PATH"
 
+        NODE_ID= vars["NODE_ID"]
+        if NODE_ID == "":
+            raise ValueError, "NODE_ID"
+
+        PLCONF_DIR= vars["PLCONF_DIR"]
+        if PLCONF_DIR == "":
+            raise ValueError, "PLCONF_DIR"
+        
+        NODE_MODEL_OPTIONS= vars["NODE_MODEL_OPTIONS"]
+
+        PARTITIONS= vars["PARTITIONS"]
+        if PARTITIONS == None:
+            raise ValueError, "PARTITIONS"
+
     except KeyError, var:
         raise BootManagerException, "Missing variable in vars: %s\n" % var
     except ValueError, var:
@@ -44,19 +69,19 @@ def Run( vars, log ):
     if 'ROOT_MOUNTED' in vars.keys():
         ROOT_MOUNTED= vars['ROOT_MOUNTED']
 
-    # old cds need extra utilities to run lvm
-    if BOOT_CD_VERSION[0] == 2:
-        compatibility.setup_lvm_2x_cd( vars, log )
-        
-    # simply creating an instance of this class and listing the system
-    # block devices will make them show up so vgscan can find the planetlab
-    # volume group
-    systeminfo().get_block_device_list()
-
     # mount the root system image if we haven't already.
     # capture BootManagerExceptions during the vgscan/change and mount
     # calls, so we can return 0 instead
     if ROOT_MOUNTED == 0:
+        # old cds need extra utilities to run lvm
+        if BOOT_CD_VERSION[0] == 2:
+            compatibility.setup_lvm_2x_cd( vars, log )
+            
+        # simply creating an instance of this class and listing the system
+        # block devices will make them show up so vgscan can find the planetlab
+        # volume group
+        systeminfo.get_block_device_list(vars, log)
+
         try:
             utils.sysexec( "vgscan", log )
             utils.sysexec( "vgchange -ay planetlab", log )
@@ -68,9 +93,10 @@ def Run( vars, log ):
         utils.makedirs( SYSIMG_PATH )
 
         try:
-            utils.sysexec( "mount /dev/planetlab/root %s" % SYSIMG_PATH, log )
-            utils.sysexec( "mount /dev/planetlab/vservers %s/vservers" %
-                           SYSIMG_PATH, log )
+            utils.sysexec("mount %s %s" % (PARTITIONS["root"],SYSIMG_PATH),log)
+            utils.sysexec("mount %s %s/vservers" % \
+                          (PARTITIONS["vservers"], SYSIMG_PATH), log)
+            utils.sysexec( "mount -t proc none %s/proc" % SYSIMG_PATH, log )
         except BootManagerException, e:
             log.write( "BootManagerException during vgscan/vgchange: %s\n" %
                        str(e) )
@@ -79,15 +105,43 @@ def Run( vars, log ):
         ROOT_MOUNTED= 1
         vars['ROOT_MOUNTED']= 1
         
-    valid= 0
     
-    if os.access("%s/boot/kernel-boot" % SYSIMG_PATH, os.F_OK | os.R_OK) and \
-           os.access("%s/boot/initrd-boot" % SYSIMG_PATH, os.F_OK | os.R_OK):
-        valid= 1
+    # check if the base kernel is installed
+    try:
+        os.stat("%s/boot/kernel-boot" % SYSIMG_PATH)
+        os.stat("%s/boot/initrd-boot" % SYSIMG_PATH)
+    except OSError, e:            
+        log.write( "FATAL: Couldn't locate base kernel.\n")                
+        return 0
 
-    if not valid:
-        log.write( "Node does not appear to be installed correctly:\n" )
-        log.write( "missing file /boot/ initrd-boot or kernel-boot\n" )
+    # check if the model specified kernel is installed
+    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")
+            
+    # write out the node id to /etc/planetlab/node_id. if this fails, return
+    # 0, indicating the node isn't a valid install.
+    try:
+        node_id_file_path= "%s/%s/node_id" % (SYSIMG_PATH,PLCONF_DIR)
+        node_id_file= file( node_id_file_path, "w" )
+        node_id_file.write( str(NODE_ID) )
+        node_id_file.close()
+        node_id_file= None
+        log.write( "Updated /etc/planetlab/node_id\n" )
+    except IOError, e:
+        log.write( "Unable to write out /etc/planetlab/node_id\n" )
         return 0
+
+    log.write( "Everything appears to be ok\n" )
     
     return 1