run parted with the --script option to prevent from hanging
[bootmanager.git] / source / steps / CheckForNewDisks.py
index 0c121c3..09a001d 100644 (file)
@@ -1,5 +1,5 @@
-#!/usr/bin/python2
-
+#!/usr/bin/python
+#
 # Copyright (c) 2003 Intel Corporation
 # All rights reserved.
 #
@@ -11,10 +11,11 @@ import string
 import InstallPartitionDisks
 from Exceptions import *
 import systeminfo
-import compatibility
 import utils
 import os
 
+import ModelOptions
+
 
 def Run( vars, log ):
     """
@@ -22,8 +23,8 @@ def Run( vars, log ):
     
     Expect the following variables to be set:
     SYSIMG_PATH          the path where the system image will be mounted
-    BOOT_CD_VERSION          A tuple of the current bootcd version
     MINIMUM_DISK_SIZE       any disks smaller than this size, in GB, are not used
+    NODE_MODEL_OPTIONS   the node's model options
     
     Set the following variables upon successfully running:
     ROOT_MOUNTED             the node root file system is mounted
@@ -33,10 +34,6 @@ def Run( vars, log ):
 
     # make sure we have the variables we need
     try:
-        BOOT_CD_VERSION= vars["BOOT_CD_VERSION"]
-        if BOOT_CD_VERSION == "":
-            raise ValueError, "BOOT_CD_VERSION"
-
         SYSIMG_PATH= vars["SYSIMG_PATH"]
         if SYSIMG_PATH == "":
             raise ValueError, "SYSIMG_PATH"
@@ -47,6 +44,7 @@ def Run( vars, log ):
         if PARTITIONS == None:
             raise ValueError, "PARTITIONS"
         
+        NODE_MODEL_OPTIONS= vars["NODE_MODEL_OPTIONS"]
     except KeyError, var:
         raise BootManagerException, "Missing variable in vars: %s\n" % var
     except ValueError, var:
@@ -54,11 +52,6 @@ def Run( vars, log ):
 
     all_devices= systeminfo.get_block_device_list(vars, log)
     
-    # find out if there are unused disks in all_devices that are greater
-    # than old cds need extra utilities to run lvm
-    if BOOT_CD_VERSION[0] == 2:
-        compatibility.setup_lvm_2x_cd( vars, log )
-        
     # will contain the new devices to add to the volume group
     new_devices= []
 
@@ -86,14 +79,11 @@ def Run( vars, log ):
                    "of the volume group.\n" % device )
 
         # this is the lvm partition, if it exists on that device
-        lvm_partition= "%s1" % device
-        cciss_lvm_partition= "%sp1" % device
-        cmd = "pvdisplay %s | grep -q 'planetlab'"
-
-        already_added= utils.sysexec_noerr(cmd % lvm_partition, log)
-        cciss_already_added= utils.sysexec_noerr(cmd % cciss_lvm_partition, log)
+        lvm_partition= InstallPartitionDisks.get_partition_path_from_device( device, vars, log )
+        cmd = "pvdisplay %s | grep -q 'planetlab'" % lvm_partition
+        already_added = utils.sysexec_noerr(cmd, log, shell=True)
 
-        if already_added or cciss_already_added:
+        if already_added:
             log.write( "It appears %s is part of the volume group, continuing.\n" %
                        device )
             continue
@@ -101,7 +91,7 @@ def Run( vars, log ):
         # just to be extra paranoid, ignore the device if it already has
         # an lvm partition on it (new disks won't have this, and that is
         # what this code is for, so it should be ok).
-        cmd = "sfdisk -l %s | grep -q 'Linux LVM'" % device 
+        cmd = "parted --script --list %s | grep -q lvm$" % device
         has_lvm= utils.sysexec_noerr(cmd, log)
         if has_lvm:
             log.write( "It appears %s has lvm already setup on it.\n" % device)
@@ -110,16 +100,21 @@ def Run( vars, log ):
                 log.write("To paranoid to add %s to vservers lvm.\n" % device)
                 continue
         
-        log.write( "Attempting to add %s to the volume group\n" % device )
-
         if not InstallPartitionDisks.single_partition_device( device, vars, log ):
             log.write( "Unable to partition %s, not using it.\n" % device )
             continue
 
-        log.write( "Successfully initialized %s\n" % device )
+        log.write( "Successfully partitioned %s\n" % device )
+
+        if NODE_MODEL_OPTIONS & ModelOptions.RAWDISK:
+            log.write( "Running on a raw disk node, not using it.\n" )
+            continue
 
         part_path= InstallPartitionDisks.get_partition_path_from_device( device,
                                                                          vars, log )
+
+        log.write( "Attempting to add %s to the volume group\n" % device )
+
         if not InstallPartitionDisks.create_lvm_physical_volume( part_path,
                                                                  vars, log ):
             log.write( "Unable to create lvm physical volume %s, not using it.\n" %
@@ -141,7 +136,7 @@ def Run( vars, log ):
         try:
             # backwards compat, though, we should never hit this case post PL 3.2
             os.stat("%s/rcfs/taskclass"%SYSIMG_PATH)
-            utils.sysexec_noerr( "chroot %s umount /rcfs" % SYSIMG_PATH, log )
+            utils.sysexec_chroot_noerr( SYSIMG_PATH, "umount /rcfs", log )
         except OSError, e:
             pass
 
@@ -174,22 +169,19 @@ def Run( vars, log ):
                 res = 1
                 break
 
-            log.write( "making the ext3 filesystem match new logical volume size.\n" )
-            if BOOT_CD_VERSION[0] == 2:
-                cmd = "resize2fs %s" % PARTITIONS["vservers"]
-                resize = utils.sysexec_noerr(cmd,log)
-            elif BOOT_CD_VERSION[0] == 3:
-                vars['ROOT_MOUNTED']= 1
-                cmd = "mount %s %s" % (PARTITIONS["root"],SYSIMG_PATH)
-                utils.sysexec_noerr( cmd, log )
-                cmd = "mount %s %s/vservers" % \
-                      (PARTITIONS["vservers"],SYSIMG_PATH)
-                utils.sysexec_noerr( cmd, log )
-                cmd = "ext2online %s/vservers" % SYSIMG_PATH
-                resize = utils.sysexec_noerr(cmd,log)
-                utils.sysexec_noerr( "umount %s/vservers" % SYSIMG_PATH, log )
-                utils.sysexec_noerr( "umount %s" % SYSIMG_PATH, log )
-                vars['ROOT_MOUNTED']= 0
+            log.write( "making the ext filesystem match new logical volume size.\n" )
+
+            vars['ROOT_MOUNTED']= 1
+            cmd = "mount %s %s" % (PARTITIONS["root"],SYSIMG_PATH)
+            utils.sysexec_noerr( cmd, log )
+            cmd = "mount %s %s/vservers" % \
+                (PARTITIONS["vservers"],SYSIMG_PATH)
+            utils.sysexec_noerr( cmd, log )
+            cmd = "resize2fs %s" % PARTITIONS["vservers"]
+            resize = utils.sysexec_noerr(cmd,log)
+            utils.sysexec_noerr( "umount %s/vservers" % SYSIMG_PATH, log )
+            utils.sysexec_noerr( "umount %s" % SYSIMG_PATH, log )
+            vars['ROOT_MOUNTED']= 0
 
             utils.sysexec( "vgchange -an", log )