2015-09-20 16:32:50 +00:00
|
|
|
# encoding: utf-8
|
2015-10-06 16:55:44 +00:00
|
|
|
# author: Christoph Hartmann
|
|
|
|
# author: Dominik Richter
|
2015-09-20 16:32:50 +00:00
|
|
|
# license: All rights reserved
|
|
|
|
|
|
|
|
# Verifies if a kernel module is loaded
|
|
|
|
# Usage:
|
|
|
|
# describe kernel_module('bridge') do
|
|
|
|
# it { should be_loaded }
|
|
|
|
# end
|
|
|
|
class KernelModule < Vulcano.resource(1)
|
|
|
|
name 'kernel_module'
|
|
|
|
|
|
|
|
def initialize(modulename = nil)
|
|
|
|
@module = modulename
|
|
|
|
|
|
|
|
# this resource is only supported on Linux
|
2015-10-23 11:57:03 +00:00
|
|
|
return skip_resource 'The `kernel_parameter` resource is not supported on your OS.' if !vulcano.os.linux?
|
2015-09-20 16:32:50 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def loaded?
|
2015-10-23 11:57:37 +00:00
|
|
|
# default lsmod command
|
|
|
|
lsmod_cmd = 'lsmod'
|
|
|
|
# special care for CentOS 5 and sudo
|
|
|
|
lsmod_cmd = '/sbin/lsmod' if vulcano.os[:family] == 'centos' && vulcano.os[:release].to_i == 5
|
|
|
|
|
2015-09-20 16:32:50 +00:00
|
|
|
# get list of all modules
|
2015-10-23 11:57:37 +00:00
|
|
|
cmd = vulcano.command(lsmod_cmd)
|
2015-09-21 11:02:27 +00:00
|
|
|
return false if cmd.exit_status != 0
|
2015-09-20 16:32:50 +00:00
|
|
|
|
|
|
|
# check if module is loaded
|
2015-09-21 11:02:27 +00:00
|
|
|
re = Regexp.new('^'+Regexp.quote(@module)+'\s')
|
|
|
|
found = cmd.stdout.match(re)
|
|
|
|
!found.nil?
|
2015-09-20 16:32:50 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def to_s
|
|
|
|
"Kernel Module #{@module}"
|
|
|
|
end
|
|
|
|
end
|