Class: KernelModule
- Inherits:
-
Object
- Object
- KernelModule
- Defined in:
- lib/resources/kernel_module.rb
Overview
Verifies if a kernel module is loaded Usage: describe kernel_module(‘bridge’) do
it { should be_loaded }
end
Instance Method Summary collapse
-
#initialize(modulename = nil) ⇒ KernelModule
constructor
A new instance of KernelModule.
- #loaded? ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(modulename = nil) ⇒ KernelModule
Returns a new instance of KernelModule.
14 15 16 17 18 19 |
# File 'lib/resources/kernel_module.rb', line 14 def initialize(modulename = nil) @module = modulename # this resource is only supported on Linux return skip_resource 'The `kernel_parameter` resource is not supported on your OS.' if !inspec.os.linux? end |
Instance Method Details
#loaded? ⇒ Boolean
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/resources/kernel_module.rb', line 21 def loaded? # default lsmod command lsmod_cmd = 'lsmod' # special care for CentOS 5 and sudo lsmod_cmd = '/sbin/lsmod' if inspec.os[:family] == 'centos' && inspec.os[:release].to_i == 5 # get list of all modules cmd = inspec.command(lsmod_cmd) return false if cmd.exit_status != 0 # check if module is loaded re = Regexp.new('^'+Regexp.quote(@module)+'\s') found = cmd.stdout.match(re) !found.nil? end |
#to_s ⇒ Object
37 38 39 |
# File 'lib/resources/kernel_module.rb', line 37 def to_s "Kernel Module #{@module}" end |