Detangled steps. No step makes calls into another step.
[bootmanager.git] / source / steps / WriteModprobeConfig.py
1 #!/usr/bin/python2 -u
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
9 import os, string
10
11 from Exceptions import *
12 import utils
13 import systeminfo
14 import BootAPI
15 import ModelOptions
16
17 def Run( vars, log, filename = "/etc/modprobe.conf"):
18     """
19     write out the system file /etc/modprobe.conf with the current
20     set of modules.
21
22     returns a tuple of the number of network driver lines and storage
23     driver lines written as (networkcount,storagecount)
24     """
25
26     # write out the modprobe.conf file for the system. make sure
27     # the order of the ethernet devices are listed in the same order
28     # as the boot cd loaded the modules. this is found in /tmp/loadedmodules
29     # ultimately, the order will only match the boot cd order if
30     # the kernel modules have the same name - which should be true for the later
31     # version boot cds because they use the same kernel version.
32     # older boot cds use a 2.4.19 kernel, and its possible some of the network
33     # module names have changed, in which case the system might not boot
34     # if the network modules are activated in a different order that the
35     # boot cd.
36
37     # make sure we have this class loaded
38     
39     try:
40         SYSIMG_PATH= vars["SYSIMG_PATH"]
41         if SYSIMG_PATH == "":
42             raise ValueError, "SYSIMG_PATH"
43
44     except KeyError, var:
45         raise BootManagerException, "Missing variable in vars: %s\n" % var
46     except ValueError, var:
47         raise BootManagerException, "Variable in vars, shouldn't be: %s\n" % var
48
49     sysmods= systeminfo.get_system_modules(vars, log)
50     if sysmods is None:
51         raise BootManagerException, "Unable to get list of system modules."
52         
53     eth_count= 0
54     scsi_count= 0
55
56     modulesconf_file= file("%s/%s" % (SYSIMG_PATH,filename), "w" )
57
58     for type in sysmods:
59         if type == systeminfo.MODULE_CLASS_SCSI:
60             for a_mod in sysmods[type]:
61                 if scsi_count == 0:
62                     modulesconf_file.write( "alias scsi_hostadapter %s\n" %
63                                             a_mod )
64                 else:
65                     modulesconf_file.write( "alias scsi_hostadapter%d %s\n" %
66                                             (scsi_count,a_mod) )
67                 scsi_count= scsi_count + 1
68
69         elif type == systeminfo.MODULE_CLASS_NETWORK:
70             for a_mod in sysmods[type]:
71                 modulesconf_file.write( "alias eth%d %s\n" %
72                                         (eth_count,a_mod) )
73                 eth_count= eth_count + 1
74
75     modulesconf_file.close()
76     modulesconf_file= None
77
78     # dump the modprobe.conf file to the log (not to screen)
79     log.write( "Contents of new modprobe.conf file:\n" )
80     modulesconf_file= file("%s/%s" % (SYSIMG_PATH,filename), "r" )
81     contents= modulesconf_file.read()
82     log.write( contents + "\n" )
83     modulesconf_file.close()
84     modulesconf_file= None
85     log.write( "End contents of new modprobe.conf file.\n" )
86
87     # before we do the real kexec, check to see if we had any
88     # network drivers written to modprobe.conf. if not, return -1,
89     # which will cause this node to be switched to a debug state.
90     if eth_count == 0:
91         log.write( "\nIt appears we don't have any network drivers. Aborting.\n" )
92         
93         vars['BOOT_STATE']= 'dbg'
94         vars['STATE_CHANGE_NOTIFY']= 1
95         vars['STATE_CHANGE_NOTIFY_MESSAGE']= \
96              notify_messages.MSG_NO_DETECTED_NETWORK
97         raise BootManagerException, \
98               notify_messages.MSG_NO_DETECTED_NETWORK
99
100