~ivoks/charms/trusty/neutron-contrail/contrail-nova-driver

« back to all changes in this revision

Viewing changes to hooks/neutron_contrail_utils.py

  • Committer: Robert Ayres
  • Date: 2015-11-06 17:51:17 UTC
  • Revision ID: robert.ayres@canonical.com-20151106175117-e27kmm9ibgn5bgph
DKMS autoinstall vrouter module in cases where juju has upgraded the kernel of the machine, fixes lp #1513618

Show diffs side-by-side

added added

removed removed

Lines of Context:
156
156
    log("Bringing up {}".format(interfaces if interfaces else "interfaces"))
157
157
    check_call(["ifup"] + interfaces if interfaces else ["-a"])
158
158
 
159
 
def modprobe(module, auto_load=False):
160
 
    """Load a kernel module"""
 
159
def modprobe(module, auto_load=False, dkms_autoinstall=False):
 
160
    """Load a kernel module.
 
161
 
 
162
    Allows loading of a kernel module.
 
163
 
 
164
    'dkms_autoinstall' is useful for DKMS kernel modules. Juju often upgrades
 
165
    units to newer kernels before charm install, which won't be used until the
 
166
    machine is rebooted. In these cases, some modules may not be compiled for
 
167
    the newer kernel. Setting this argument to True will ensure these modules
 
168
    are compiled for newer kernels.
 
169
 
 
170
    :param module: module to load
 
171
    :param auto_load: load module on boot (default False)
 
172
    :param dkms_autoinstall: invoke DKMS autoinstall for other kernels
 
173
                             (default False)
 
174
    """
161
175
    log("Loading kernel module {}".format(module))
162
176
    check_call(["modprobe", module])
163
177
    if auto_load:
164
178
        with open("/etc/modules", "a") as modules:
165
179
            modules.write(module)
166
180
            modules.write("\n")
 
181
    if dkms_autoinstall:
 
182
        current = check_output(["uname", "-r"]).rstrip()
 
183
        for kernel in os.listdir("/lib/modules"):
 
184
            if kernel == current:
 
185
                continue
 
186
            log("DKMS auto installing for kernel {}".format(kernel))
 
187
            check_call(["dkms", "autoinstall", "-k", kernel])
167
188
 
168
189
def network_ctx():
169
190
    return { "control_network_ip": netifaces.ifaddresses("vhost0")[netifaces.AF_INET][0]["addr"] }