3 # Copyright (c) 2003 Intel Corporation
6 # Copyright (c) 2004-2006 The Trustees of Princeton University
11 from Exceptions import *
19 See if a node installation is valid. More checks should certainly be
20 done in the future, but for now, make sure that the sym links kernel-boot
23 Expect the following variables to be set:
24 SYSIMG_PATH the path where the system image will be mounted
25 (always starts with TEMP_PATH)
26 ROOT_MOUNTED the node root file system is mounted
27 NODE_ID The db node_id for this machine
28 PLCONF_DIR The directory to store the configuration file in
30 Set the following variables upon successfully running:
31 ROOT_MOUNTED the node root file system is mounted
34 log.write( "\n\nStep: Validating node installation.\n" )
36 # make sure we have the variables we need
38 SYSIMG_PATH= vars["SYSIMG_PATH"]
40 raise ValueError, "SYSIMG_PATH"
42 NODE_ID= vars["NODE_ID"]
44 raise ValueError, "NODE_ID"
46 PLCONF_DIR= vars["PLCONF_DIR"]
48 raise ValueError, "PLCONF_DIR"
50 NODE_MODEL_OPTIONS= vars["NODE_MODEL_OPTIONS"]
52 PARTITIONS= vars["PARTITIONS"]
53 if PARTITIONS == None:
54 raise ValueError, "PARTITIONS"
57 raise BootManagerException, "Missing variable in vars: %s\n" % var
58 except ValueError, var:
59 raise BootManagerException, "Variable in vars, shouldn't be: %s\n" % var
63 if vars.has_key('ROOT_MOUNTED'):
64 ROOT_MOUNTED= vars['ROOT_MOUNTED']
66 # mount the root system image if we haven't already.
67 # capture BootManagerExceptions during the vgscan/change and mount
68 # calls, so we can return 0 instead
71 # simply creating an instance of this class and listing the system
72 # block devices will make them show up so vgscan can find the planetlab
74 systeminfo.get_block_device_list(vars, log)
77 utils.sysexec( "vgscan", log )
78 utils.sysexec( "vgchange -ay planetlab", log )
79 except BootManagerException, e:
80 log.write( "BootManagerException during vgscan/vgchange: %s\n" %
84 utils.makedirs( SYSIMG_PATH )
86 # xxx - TODO - need to fsck the btrfs partition
87 if vars['virt'] == 'vs':
88 filesystems_tocheck = ['root', 'vservers']
90 filesystems_tocheck = ['root']
91 for filesystem in filesystems_tocheck:
93 # first run fsck to prevent fs corruption from hanging mount...
94 log.write( "fsck %s file system\n" % filesystem )
95 utils.sysexec("e2fsck -v -p %s" % (PARTITIONS[filesystem]), log, fsck=True)
96 except BootManagerException, e:
97 log.write( "BootManagerException during fsck of %s (%s) filesystem : %s\n" %
98 (filesystem, PARTITIONS[filesystem], str(e)) )
100 log.write( "Trying to recover filesystem errors on %s\n" % filesystem )
101 utils.sysexec("e2fsck -v -y %s" % (PARTITIONS[filesystem]),log, fsck=True)
102 except BootManagerException, e:
103 log.write( "BootManagerException during trying to recover filesystem errors on %s (%s) filesystem : %s\n" %
104 (filesystem, PARTITIONS[filesystem], str(e)) )
107 # disable time/count based filesystems checks
108 utils.sysexec_noerr( "tune2fs -c -1 -i 0 %s" % PARTITIONS[filesystem], log)
111 # then attempt to mount them
112 log.write( "mounting root file system\n" )
113 utils.sysexec("mount -t ext3 %s %s" % (PARTITIONS["root"],SYSIMG_PATH),log)
114 except BootManagerException, e:
115 log.write( "BootManagerException during mount of /root: %s\n" % str(e) )
119 PROC_PATH = "%s/proc" % SYSIMG_PATH
120 utils.makedirs(PROC_PATH)
121 log.write( "mounting /proc\n" )
122 utils.sysexec( "mount -t proc none %s" % PROC_PATH, log )
123 except BootManagerException, e:
124 log.write( "BootManagerException during mount of /proc: %s\n" % str(e) )
128 VSERVERS_PATH = "%s/vservers" % SYSIMG_PATH
129 utils.makedirs(VSERVERS_PATH)
130 log.write( "mounting vservers partition in root file system\n" )
131 if vars['virt']=='vs':
132 utils.sysexec("mount -t ext3 %s %s" % (PARTITIONS["vservers"], VSERVERS_PATH), log)
134 utils.sysexec("mount -t btrfs %s %s" % (PARTITIONS["vservers"], VSERVERS_PATH), log)
135 except BootManagerException, e:
136 log.write( "BootManagerException during mount of /vservers: %s\n" % str(e) )
140 vars['ROOT_MOUNTED']= 1
142 # check if the base kernel is installed
143 # these 2 links are created by our kernel's post-install scriplet
144 log.write("Checking for a custom kernel\n")
146 if vars['virt'] == 'vs':
147 os.stat("%s/boot/kernel-boot" % SYSIMG_PATH)
149 kversion = os.popen("chroot %s rpm -qa kernel | tail -1 | cut -c 8-" % SYSIMG_PATH).read().rstrip()
150 os.stat("%s/boot/vmlinuz-%s" % (SYSIMG_PATH,kversion))
152 log.write( "Couldn't locate base kernel (you might be using the stock kernel).\n")
155 # check if the model specified kernel is installed
157 if NODE_MODEL_OPTIONS & ModelOptions.SMP:
160 os.stat("%s/boot/kernel-boot%s" % (SYSIMG_PATH,option))
162 # smp kernel is not there; remove option from modeloptions
163 # such that the rest of the code base thinks we are just
164 # using the base kernel.
165 NODE_MODEL_OPTIONS = NODE_MODEL_OPTIONS & ~ModelOptions.SMP
166 vars["NODE_MODEL_OPTIONS"] = NODE_MODEL_OPTIONS
167 log.write( "WARNING: Couldn't locate smp kernel.\n")
169 # write out the node id to /etc/planetlab/node_id. if this fails, return
170 # 0, indicating the node isn't a valid install.
172 node_id_file_path= "%s/%s/node_id" % (SYSIMG_PATH,PLCONF_DIR)
173 node_id_file= file( node_id_file_path, "w" )
174 node_id_file.write( str(NODE_ID) )
177 log.write( "Updated /etc/planetlab/node_id\n" )
179 log.write( "Unable to write out /etc/planetlab/node_id\n" )
182 log.write( "Node installation appears to be ok\n" )