Detangled steps. No step makes calls into another step.
[bootmanager.git] / source / steps / InstallUninitHardware.py
1 #!/usr/bin/python2
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
11
12 from Exceptions import *
13 import utils
14
15
16
17 def Run( vars, log ):
18     """
19     Unitializes hardware:
20     - unmount everything mounted during install, except the
21     /dev/planetlab/root and /dev/planetlab/vservers. This includes
22     calling swapoff for /dev/planetlab/swap.
23
24     Except the following variables from the store:
25     TEMP_PATH         the path to download and store temp files to
26     SYSIMG_PATH       the path where the system image will be mounted
27                       (always starts with TEMP_PATH)
28     PARTITIONS        dictionary of generic part. types (root/swap)
29                       and their associated devices.
30
31     Sets the following variables:
32     None
33     
34     """
35
36     log.write( "\n\nStep: Install: Shutting down installer.\n" )
37
38     # make sure we have the variables we need
39     try:
40         TEMP_PATH= vars["TEMP_PATH"]
41         if TEMP_PATH == "":
42             raise ValueError, "TEMP_PATH"
43
44         SYSIMG_PATH= vars["SYSIMG_PATH"]
45         if SYSIMG_PATH == "":
46             raise ValueError, "SYSIMG_PATH"
47
48         PARTITIONS= vars["PARTITIONS"]
49         if PARTITIONS == None:
50             raise ValueError, "PARTITIONS"
51
52     except KeyError, var:
53         raise BootManagerException, "Missing variable in vars: %s\n" % var
54     except ValueError, var:
55         raise BootManagerException, "Variable in vars, shouldn't be: %s\n" % var
56
57
58     try:
59         # make sure the required partitions exist
60         val= PARTITIONS["root"]
61         val= PARTITIONS["swap"]
62         val= PARTITIONS["vservers"]
63     except KeyError, part:
64         raise BootManagerException, "Missing partition in PARTITIONS: %s\n" % part
65
66     try:
67         # backwards compat, though, we should never hit this case post PL 3.2
68         os.stat("%s/rcfs/taskclass"%SYSIMG_PATH)
69         utils.sysexec_noerr( "chroot %s umount /rcfs" % SYSIMG_PATH, log )
70     except OSError, e:
71         pass
72             
73     log.write( "Unmounting proc.\n" )
74     utils.sysexec( "umount %s/proc" % SYSIMG_PATH, log )
75
76     log.write( "Shutting down swap\n" )
77     utils.sysexec( "swapoff %s" % PARTITIONS["swap"], log )
78
79     return 1