db214641f764d968048f7bdbb0588f53333922e4
[bootmanager.git] / source / steps / InstallInit.py
1 #!/usr/bin/python
2 #
3 # Copyright (c) 2003 Intel Corporation
4 # All rights reserved.
5 #
6 # Copyright (c) 2004-2006 The Trustees of Princeton University
7 # All rights reserved.
8 # expected /proc/partitions format
9
10 import os, sys, string
11
12 import utils
13 from Exceptions import *
14
15 def Run( vars, log ):
16     """
17     Setup the install environment:
18     - unmount anything in the temp/sysimg path (possible from previous
19       aborted installs)
20     - create temp directories
21     
22     Expect the following variables from the store:
23     TEMP_PATH         the path to download and store temp files to
24     SYSIMG_DIR        the directory name of the system image
25                       contained in TEMP_PATH
26     PLCONF_DIR        The directory to store the configuration file in
27     
28     Sets the following variables:
29     SYSIMG_PATH       the directory where the system image will be mounted,
30                       (= TEMP_PATH/SYSIMG_DIR)
31     """
32
33     log.write( "\n\nStep: Install: Initializing.\n" )
34     
35     # make sure we have the variables we need
36     try:
37         TEMP_PATH= vars["TEMP_PATH"]
38         if TEMP_PATH == "":
39             raise ValueError("TEMP_PATH")
40
41         SYSIMG_PATH= vars["SYSIMG_PATH"]
42         if SYSIMG_PATH == "":
43             raise ValueError("SYSIMG_PATH")
44
45         PLCONF_DIR= vars["PLCONF_DIR"]
46         if PLCONF_DIR == "":
47             raise ValueError, "PLCONF_DIR"
48
49     except KeyError, var:
50         raise BootManagerException, "Missing variable in vars: %s\n" % var
51     except ValueError, var:
52         raise BootManagerException, "Variable in vars, shouldn't be: %s\n" % var
53
54     # if this is a fresh install, then nothing should be
55     # here, but we support restarted installs without rebooting
56     # so who knows what the current state is
57
58     log.write( "Unmounting any previous mounts\n" )
59
60     try:
61         # backwards compat, though, we should never hit this case post PL 3.2
62         os.stat("%s/rcfs/taskclass"%SYSIMG_PATH)
63         utils.sysexec_chroot_noerr( SYSIMG_PATH, "umount /rcfs", log )
64     except OSError, e:
65         pass
66
67     # NOTE: added /sys and /dev b/c some nodes fail due to this when disk is
68     # nearly full.
69     utils.sysexec_noerr( "umount %s/proc" % SYSIMG_PATH , log )
70     utils.sysexec_noerr( "umount %s/mnt/cdrom" % SYSIMG_PATH , log )
71     utils.sysexec_noerr( "umount %s/vservers" % SYSIMG_PATH , log )
72     utils.sysexec_noerr( "umount %s/sys" % SYSIMG_PATH , log )
73     utils.sysexec_noerr( "umount %s/dev" % SYSIMG_PATH , log )
74     utils.sysexec_noerr( "umount %s" % SYSIMG_PATH , log )
75     vars['ROOT_MOUNTED']= 0
76
77 #    log.write( "Removing any old files, directories\n" )
78 #    utils.removedir( TEMP_PATH )
79     
80     log.write( "Cleaning up any existing PlanetLab config files\n" )
81     try:
82         flist = os.listdir( PLCONF_DIR)
83         for file in flist:
84             utils.removedir( file )
85     except OSError:
86         pass
87     
88     # create the temp path and sysimg path. since sysimg
89     # path is in temp path, both are created here
90     log.write( "Creating system image path\n" )
91     utils.makedirs( SYSIMG_PATH )
92
93     return 1