3 # Copyright (c) 2003 Intel Corporation
6 # Copyright (c) 2004-2006 The Trustees of Princeton University
8 # expected /proc/partitions format
15 from Exceptions import *
17 import notify_messages
23 Make sure the hardware we are running on is sufficient for
24 the PlanetLab OS to be installed on. In the process, identify
25 the list of block devices that may be used for a node installation,
26 and identify the cdrom device that we booted off of.
28 Return 1 if requiremenst met, 0 if requirements not met. Raise
29 BootManagerException if any problems occur that prevent the requirements
32 Expect the following variables from the store:
34 MINIMUM_MEMORY minimum amount of memory in kb required
36 NODE_ID the node_id from the database for this node
37 MINIMUM_DISK_SIZE any disks smaller than this size, in GB, are not used
38 TOTAL_MINIMUM_DISK_SIZE total disk size in GB, if all usable disks
39 meet this number, there isn't enough disk space for
40 this node to be usable after install
41 SKIP_HARDWARE_REQUIREMENT_CHECK
42 If set, don't check if minimum requirements are met
43 BOOT_CD_VERSION A tuple of the current bootcd version
44 Sets the following variables:
45 INSTALL_BLOCK_DEVICES list of block devices to install onto
48 log.write( "\n\nStep: Checking if hardware requirements met.\n" )
51 MINIMUM_MEMORY= int(vars["MINIMUM_MEMORY"])
52 if MINIMUM_MEMORY == "":
53 raise ValueError, "MINIMUM_MEMORY"
55 NODE_ID= vars["NODE_ID"]
57 raise ValueError("NODE_ID")
59 MINIMUM_DISK_SIZE= int(vars["MINIMUM_DISK_SIZE"])
61 TOTAL_MINIMUM_DISK_SIZE= \
62 int(vars["TOTAL_MINIMUM_DISK_SIZE"])
64 SKIP_HARDWARE_REQUIREMENT_CHECK= \
65 int(vars["SKIP_HARDWARE_REQUIREMENT_CHECK"])
67 BOOT_CD_VERSION= vars["BOOT_CD_VERSION"]
68 if BOOT_CD_VERSION == "":
69 raise ValueError, "BOOT_CD_VERSION"
72 raise BootManagerException, \
73 "Missing variable in install store: %s" % var
74 except ValueError, var:
75 raise BootManagerException, \
76 "Variable in install store blank, shouldn't be: %s" % var
78 # lets see if we have enough memory to run
79 log.write( "Checking for available memory.\n" )
81 total_mem= systeminfo.get_total_phsyical_mem(vars, log)
83 raise BootManagerException, "Unable to read total physical memory"
85 if total_mem < MINIMUM_MEMORY:
86 if not SKIP_HARDWARE_REQUIREMENT_CHECK:
87 log.write( "Insufficient memory to run node: %s kb\n" % total_mem )
88 log.write( "Required memory: %s kb\n" % MINIMUM_MEMORY )
96 sent= BootAPI.call_api_function( vars, "BootNotifyOwners",
97 (notify_messages.MSG_INSUFFICIENT_MEMORY,
101 except BootManagerException, e:
102 log.write( "Call to BootNotifyOwners failed: %s.\n" % e )
105 log.write( "Unable to notify site contacts of problem.\n" )
107 log.write( "Notified contacts of problem.\n" )
111 log.write( "Memory requirements not met, but running anyway: %s kb\n"
114 log.write( "Looks like we have enough memory: %s kb\n" % total_mem )
118 # get a list of block devices to attempt to install on
119 # (may include cdrom devices)
120 install_devices= systeminfo.get_block_device_list(vars, log)
122 # save the list of block devices in the log
123 log.write( "Detected block devices:\n" )
124 log.write( repr(install_devices) + "\n" )
126 if not install_devices or len(install_devices) == 0:
127 log.write( "No block devices detected.\n" )
135 sent= BootAPI.call_api_function( vars, "BootNotifyOwners",
136 (notify_messages.MSG_INSUFFICIENT_DISK,
140 except BootManagerException, e:
141 log.write( "Call to BootNotifyOwners failed: %s.\n" % e )
144 log.write( "Unable to notify site contacts of problem.\n" )
148 # now, lets remove any block devices we know won't work (readonly,cdroms),
149 # or could be other writable removable disks (usb keychains, zip disks, etc)
150 # i'm not aware of anything that helps with the latter test, so,
151 # what we'll probably do is simply not use any block device below
152 # some size threshold (set in installstore)
154 # also, keep track of the total size for all devices that appear usable
157 for device in install_devices.keys():
159 (major,minor,blocks,gb_size,readonly)= install_devices[device]
161 # if the device string starts with
162 # planetlab or dm- (device mapper), ignore it (could be old lvm setup)
163 if device[:14] == "/dev/planetlab" or device[:8] == "/dev/dm-":
164 del install_devices[device]
167 if gb_size < MINIMUM_DISK_SIZE:
168 log.write( "Device is too small to use: %s \n(appears" \
169 " to be %4.2f GB)\n" % (device,gb_size) )
171 del install_devices[device]
177 log.write( "Device is readonly, not using: %s\n" % device )
179 del install_devices[device]
184 # add this sector count to the total count of usable
185 # sectors we've found.
186 total_size= total_size + gb_size
189 if len(install_devices) == 0:
190 log.write( "No suitable block devices found for install.\n" )
198 sent= BootAPI.call_api_function( vars, "BootNotifyOwners",
199 (notify_messages.MSG_INSUFFICIENT_DISK,
203 except BootManagerException, e:
204 log.write( "Call to BootNotifyOwners failed: %s.\n" % e )
207 log.write( "Unable to notify site contacts of problem.\n" )
212 # show the devices we found that are usable
213 log.write( "Usable block devices:\n" )
214 log.write( repr(install_devices.keys()) + "\n" )
216 # save the list of devices for the following steps
217 vars["INSTALL_BLOCK_DEVICES"]= install_devices.keys()
220 # ensure the total disk size is large enough. if
221 # not, we need to email the tech contacts the problem, and
222 # put the node into debug mode.
223 if total_size < TOTAL_MINIMUM_DISK_SIZE:
224 if not SKIP_HARDWARE_REQUIREMENT_CHECK:
225 log.write( "The total usable disk size of all disks is " \
226 "insufficient to be usable as a PlanetLab node.\n" )
233 sent= BootAPI.call_api_function( vars, "BootNotifyOwners",
234 (notify_messages.MSG_INSUFFICIENT_DISK,
238 except BootManagerException, e:
239 log.write( "Call to BootNotifyOwners failed: %s.\n" % e )
242 log.write( "Unable to notify site contacts of problem.\n" )
247 log.write( "The total usable disk size of all disks is " \
248 "insufficient, but running anyway.\n" )
250 log.write( "Total size for all usable block devices: %4.2f GB\n" % total_size )
252 # turn off UDMA for all block devices on 2.x cds (2.4 kernel)
253 if BOOT_CD_VERSION[0] == 2:
254 for device in install_devices:
255 log.write( "Disabling UDMA on %s\n" % device )
256 utils.sysexec_noerr( "/sbin/hdparm -d0 %s" % device, log )