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")
56 except KeyError as var:
57 raise BootManagerException("Missing variable in vars: {}\n".format(var))
58 except ValueError as var:
59 raise BootManagerException("Variable in vars, shouldn't be: {}\n".format(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 as e:
80 log.write("BootManagerException during vgscan/vgchange: {}\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']
92 for filesystem in filesystems_tocheck:
94 # first run fsck to prevent fs corruption from hanging mount...
95 log.write("fsck {} file system\n".format(filesystem))
96 utils.sysexec("e2fsck -v -p {}".format(PARTITIONS[filesystem]), log, fsck=True)
97 except BootManagerException as e:
98 log.write("BootManagerException during fsck of {} ({}) filesystem : {}\n"\
99 .format(filesystem, PARTITIONS[filesystem], str(e)))
101 log.write("Trying to recover filesystem errors on {}\n".format(filesystem))
102 utils.sysexec("e2fsck -v -y {}".format(PARTITIONS[filesystem]), log, fsck=True)
103 except BootManagerException as e:
104 log.write("BootManagerException while trying to recover"
105 "filesystem errors on {} ({}) filesystem : {}\n"
106 .format(filesystem, PARTITIONS[filesystem], str(e)))
109 # disable time/count based filesystems checks
110 utils.sysexec_noerr("tune2fs -c -1 -i 0 {}".format(PARTITIONS[filesystem]), log)
113 # then attempt to mount them
114 log.write("mounting root file system\n")
115 utils.sysexec("mount -t ext3 {} {}".format(PARTITIONS["root"], SYSIMG_PATH),log)
116 except BootManagerException as e:
117 log.write("BootManagerException during mount of /root: {}\n".format(str(e)))
121 PROC_PATH = "{}/proc".format(SYSIMG_PATH)
122 utils.makedirs(PROC_PATH)
123 log.write("mounting /proc\n")
124 utils.sysexec("mount -t proc none {}".format(PROC_PATH), log)
125 except BootManagerException as e:
126 log.write("BootManagerException during mount of /proc: {}\n".format(str(e)))
130 one_partition = vars['ONE_PARTITION']=='1'
132 if (not one_partition):
134 VSERVERS_PATH = "{}/vservers".format(SYSIMG_PATH)
135 utils.makedirs(VSERVERS_PATH)
136 log.write("mounting vservers partition in root file system\n")
137 if vars['virt'] == 'vs':
138 utils.sysexec("mount -t ext3 {} {}".format(PARTITIONS["vservers"], VSERVERS_PATH), log)
140 utils.sysexec("mount -t btrfs {} {}".format(PARTITIONS["vservers"], VSERVERS_PATH), log)
141 except BootManagerException as e:
142 log.write("BootManagerException while mounting /vservers: {}\n".format(str(e)))
146 vars['ROOT_MOUNTED'] = 1
148 # check if the base kernel is installed
149 # these 2 links are created by our kernel's post-install scriplet
150 log.write("Checking for a custom kernel\n")
152 if vars['virt'] == 'vs':
153 os.stat("{}/boot/kernel-boot".format(SYSIMG_PATH))
156 kversion = os.popen("chroot {} rpm -qa kernel | tail -1 | cut -c 8-"\
157 .format(SYSIMG_PATH)).read().rstrip()
158 os.stat("{}/boot/vmlinuz-{}".format(SYSIMG_PATH, kversion))
159 major_version = int(kversion[0]) # Check if the string looks like a kernel version
161 kversion = os.popen("ls -lrt {}/lib/modules | tail -1 | awk '{print $9;}'"\
162 .format(SYSIMG_PATH)).read().rstrip()
164 log.write("Couldn't locate base kernel (you might be using the stock kernel).\n")
167 # check if the model specified kernel is installed
169 if NODE_MODEL_OPTIONS & ModelOptions.SMP:
172 os.stat("{}/boot/kernel-boot{}".format(SYSIMG_PATH, option))
174 # smp kernel is not there; remove option from modeloptions
175 # such that the rest of the code base thinks we are just
176 # using the base kernel.
177 NODE_MODEL_OPTIONS = NODE_MODEL_OPTIONS & ~ModelOptions.SMP
178 vars["NODE_MODEL_OPTIONS"] = NODE_MODEL_OPTIONS
179 log.write("WARNING: Couldn't locate smp kernel.\n")
181 # write out the node id to /etc/planetlab/node_id. if this fails, return
182 # 0, indicating the node isn't a valid install.
184 node_id_file_path = "{}/{}/node_id".format(SYSIMG_PATH, PLCONF_DIR)
185 node_id_file = file(node_id_file_path, "w")
186 node_id_file.write(str(NODE_ID))
189 log.write("Updated /etc/planetlab/node_id\n")
191 log.write("Unable to write out /etc/planetlab/node_id\n")
194 log.write("Node installation appears to be ok\n")