don't unnecessarily shutdown/startup lvm between successful install and
[bootmanager.git] / source / steps / ValidateNodeInstall.py
1 import os
2
3 from Exceptions import *
4 import utils
5 from systeminfo import systeminfo
6 import compatibility
7
8
9 def Run( vars, log ):
10     """
11     See if a node installation is valid. More checks should certainly be
12     done in the future, but for now, make sure that the sym links kernel-boot
13     and initrd-boot exist in /boot
14     
15     Expect the following variables to be set:
16     SYSIMG_PATH              the path where the system image will be mounted
17                              (always starts with TEMP_PATH)
18     BOOT_CD_VERSION          A tuple of the current bootcd version
19     ROOT_MOUNTED             the node root file system is mounted
20     
21     Set the following variables upon successfully running:
22     ROOT_MOUNTED             the node root file system is mounted
23     """
24
25     log.write( "\n\nStep: Validating node installation.\n" )
26
27     # make sure we have the variables we need
28     try:
29         BOOT_CD_VERSION= vars["BOOT_CD_VERSION"]
30         if BOOT_CD_VERSION == "":
31             raise ValueError, "BOOT_CD_VERSION"
32
33         SYSIMG_PATH= vars["SYSIMG_PATH"]
34         if SYSIMG_PATH == "":
35             raise ValueError, "SYSIMG_PATH"
36
37     except KeyError, var:
38         raise BootManagerException, "Missing variable in vars: %s\n" % var
39     except ValueError, var:
40         raise BootManagerException, "Variable in vars, shouldn't be: %s\n" % var
41
42
43     ROOT_MOUNTED= 0
44     if 'ROOT_MOUNTED' in vars.keys():
45         ROOT_MOUNTED= vars['ROOT_MOUNTED']
46
47     # mount the root system image if we haven't already.
48     # capture BootManagerExceptions during the vgscan/change and mount
49     # calls, so we can return 0 instead
50     if ROOT_MOUNTED == 0:
51         # old cds need extra utilities to run lvm
52         if BOOT_CD_VERSION[0] == 2:
53             compatibility.setup_lvm_2x_cd( vars, log )
54             
55         # simply creating an instance of this class and listing the system
56         # block devices will make them show up so vgscan can find the planetlab
57         # volume group
58         systeminfo().get_block_device_list()
59
60         try:
61             utils.sysexec( "vgscan", log )
62             utils.sysexec( "vgchange -ay planetlab", log )
63         except BootManagerException, e:
64             log.write( "BootManagerException during vgscan/vgchange: %s\n" %
65                        str(e) )
66             return 0
67             
68         utils.makedirs( SYSIMG_PATH )
69
70         try:
71             utils.sysexec( "mount /dev/planetlab/root %s" % SYSIMG_PATH, log )
72             utils.sysexec( "mount /dev/planetlab/vservers %s/vservers" %
73                            SYSIMG_PATH, log )
74         except BootManagerException, e:
75             log.write( "BootManagerException during vgscan/vgchange: %s\n" %
76                        str(e) )
77             return 0
78
79         ROOT_MOUNTED= 1
80         vars['ROOT_MOUNTED']= 1
81         
82     valid= 0
83     
84     if os.access("%s/boot/kernel-boot" % SYSIMG_PATH, os.F_OK | os.R_OK) and \
85            os.access("%s/boot/initrd-boot" % SYSIMG_PATH, os.F_OK | os.R_OK):
86         valid= 1
87
88     if not valid:
89         log.write( "Node does not appear to be installed correctly:\n" )
90         log.write( "missing file /boot/ initrd-boot or kernel-boot\n" )
91         return 0
92
93     log.write( "Everything appears to be ok\n" )
94     
95     return 1