mirror of
https://github.com/inspec/inspec
synced 2024-12-25 04:23:15 +00:00
6be9c6822d
Signed-off-by: Dominik Richter <dominik.richter@gmail.com>
33 lines
823 B
Ruby
33 lines
823 B
Ruby
# encoding: utf-8
|
|
# 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
|
|
return skip_resource 'The `kernel_module` resource is not supported on your OS.' if !%w{ubuntu debian redhat fedora arch}.include? vulcano.os[:family]
|
|
end
|
|
|
|
def loaded?
|
|
# get list of all modules
|
|
cmd = vulcano.run_command('lsmod')
|
|
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
|
|
|
|
def to_s
|
|
"Kernel Module #{@module}"
|
|
end
|
|
end
|