a2f60866be57ffbf65dd9fd405af4238dff0c378
[bootmanager.git] / source / steps / InstallUninitHardware.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
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 as var:
53         raise BootManagerException("Missing variable in vars: {}\n".format(var))
54     except ValueError as var:
55         raise BootManagerException("Variable in vars, shouldn't be: {}\n".format(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 as part:
64         raise BootManagerException("Missing partition in PARTITIONS: {}\n".format(part))
65
66     try:
67         # backwards compat, though, we should never hit this case post PL 3.2
68         os.stat("{}/rcfs/taskclass".format(SYSIMG_PATH))
69         utils.sysexec_chroot_noerr(SYSIMG_PATH, "umount /rcfs", log)
70     except OSError as e:
71         pass
72             
73     log.write("Shutting down swap\n")
74     utils.sysexec("swapoff {}".format(PARTITIONS["swap"]), log)
75
76     return 1