mirror of
https://github.com/inspec/inspec
synced 2024-11-24 05:33:17 +00:00
577688a3a0
Many of the resources are named as a top-level class with a fairly generic class name, such as "OS". This causes an issue specifically with kitchen-google which depends on a gem which depends on the "os" gem which itself defines an OS class with a different superclass. This prevents users from using TK, Google Compute, and Inspec without this fix. Some mocked commands had their digest changed as well due to the new indentation, specifically in the User and RegistryKey classes. I strongly recommend viewing this diff with `git diff --ignore-space-change` to see the *real* changes. :)
43 lines
1.2 KiB
Ruby
43 lines
1.2 KiB
Ruby
# encoding: utf-8
|
|
# author: Christoph Hartmann
|
|
# author: Dominik Richter
|
|
# license: All rights reserved
|
|
|
|
module Inspec::Resources
|
|
class KernelModule < Inspec.resource(1)
|
|
name 'kernel_module'
|
|
desc 'Use the kernel_module InSpec audit resource to test kernel modules on Linux platforms. These parameters are located under /lib/modules. Any submodule may be tested using this resource.'
|
|
example "
|
|
describe kernel_module('bridge') do
|
|
it { should be_loaded }
|
|
end
|
|
"
|
|
|
|
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
|
|
|
|
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
|
|
|
|
def to_s
|
|
"Kernel Module #{@module}"
|
|
end
|
|
end
|
|
end
|