mirror of
https://github.com/inspec/inspec
synced 2024-12-02 17:40:00 +00:00
f6c7bffe78
* Add mode method to test the value of Bonding Mode Signed-off-by: Eammon Hanlon <eammon.hanlon@microsoft.com> * Add test for bonding mode in bond unit test Signed-off-by: Eammon Hanlon <eammon.hanlon@microsoft.com> * Add documentation on mode matcher for bond resource Signed-off-by: Eammon Hanlon <eammon.hanlon@microsoft.com> * Update example for 'Test parameters for bond0' Signed-off-by: Eammon Hanlon <eammon.hanlon@microsoft.com>
69 lines
1.5 KiB
Ruby
69 lines
1.5 KiB
Ruby
# encoding: utf-8
|
|
# author: Christoph Hartmann
|
|
# author: Dominik Richter
|
|
|
|
require 'resources/file'
|
|
|
|
module Inspec::Resources
|
|
class Bond < FileResource
|
|
name 'bond'
|
|
desc 'Use the bond InSpec audit resource to test a logical, bonded network interface (i.e. "two or more network interfaces aggregated into a single, logical network interface"). On Linux platforms, any value in the /proc/net/bonding directory may be tested.'
|
|
example "
|
|
describe bond('bond0') do
|
|
it { should exist }
|
|
end
|
|
"
|
|
|
|
def initialize(bond)
|
|
@bond = bond
|
|
@path = "/proc/net/bonding/#{bond}"
|
|
@file = inspec.file(@path)
|
|
@content = nil
|
|
@params = {}
|
|
@loaded = false
|
|
end
|
|
|
|
def read_content
|
|
# parse the file
|
|
@content = @file.content
|
|
@params = SimpleConfig.new(
|
|
@file.content,
|
|
assignment_regex: /^\s*([^:]*?)\s*:\s*(.*?)\s*$/,
|
|
multiple_values: true,
|
|
).params if @file.exist?
|
|
@loaded = true
|
|
@content
|
|
end
|
|
|
|
# ensures the content is loaded before we return the params
|
|
def params
|
|
read_content if @loaded == false
|
|
@params
|
|
end
|
|
|
|
def content
|
|
read_content if @loaded == false
|
|
@content
|
|
end
|
|
|
|
def exist?
|
|
@file.exist?
|
|
end
|
|
|
|
def has_interface?(interface)
|
|
params['Slave Interface'].include?(interface)
|
|
end
|
|
|
|
def interfaces
|
|
params['Slave Interface']
|
|
end
|
|
|
|
def mode
|
|
params['Bonding Mode'].first
|
|
end
|
|
|
|
def to_s
|
|
"Bond #{@bond}"
|
|
end
|
|
end
|
|
end
|