Class: KernelModule

Inherits:
Object
  • Object
show all
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

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

Returns:

  • (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_sObject



37
38
39
# File 'lib/resources/kernel_module.rb', line 37

def to_s
  "Kernel Module #{@module}"
end