Merge pull request #4230 from yeoldegrove/sys_info

add resource sys_info.manufacturer and sys_info.model
This commit is contained in:
Ryan Davis 2019-07-22 14:39:28 -07:00 committed by GitHub
commit 7a1e1bb775
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 70 additions and 4 deletions

View file

@ -50,3 +50,15 @@ For a full list of available matchers, please visit our [matchers page](https://
The `hostname` matcher tests the host for which standard output is returned:
its('hostname') { should eq 'value' }
### manufacturer
The `manufacturer` matcher tests the host for which standard output is returned:
its('manufacturer') { should eq 'ACME Corp.' }
### model
The `model` matcher tests the host for which standard output is returned:
its('model') { should eq 'Flux Capacitor' }

View file

@ -26,5 +26,33 @@ module Inspec::Resources
skip_resource "The `sys_info.hostname` resource is not supported on your OS yet."
end
end
# returns the Manufacturer of the local system
def manufacturer
os = inspec.os
if os.darwin?
"Apple Inc."
elsif os.linux?
inspec.command("cat /sys/class/dmi/id/sys_vendor").stdout.chomp
elsif os.windows?
inspec.powershell("Get-CimInstance -ClassName Win32_ComputerSystem | Select Manufacturer -ExpandProperty Manufacturer").stdout.chomp
else
skip_resource "The `sys_info.manufacturer` resource is not supported on your OS yet."
end
end
# returns the ServerModel of the local system
def model
os = inspec.os
if os.darwin?
inspec.command("sysctl -n hw.model").stdout.chomp
elsif os.linux?
inspec.command("cat /sys/class/dmi/id/product_name").stdout.chomp
elsif os.windows?
inspec.powershell("Get-CimInstance -ClassName Win32_ComputerSystem | Select Model -ExpandProperty Model").stdout.chomp
else
skip_resource "The `sys_info.model` resource is not supported on your OS yet."
end
end
end
end

View file

@ -365,10 +365,20 @@ class MockLoader
"netstat -an -f inet" => cmd.call("hpux-netstat-inet"),
# ipv6 ports on hpux
"netstat -an -f inet6" => cmd.call("hpux-netstat-inet6"),
# hostname linux
# hostname linux and darwin
"hostname" => cmd.call("hostname"),
# hostname windows
"$env:computername" => cmd.call("$env-computername"),
# Manufacturer linux
"cat /sys/class/dmi/id/sys_vendor" => cmd.call("manufacturer"),
# Manufacturer windows
"Get-CimInstance -ClassName Win32_ComputerSystem | Select Manufacturer -ExpandProperty Manufacturer" => cmd.call("manufacturer"),
# Model linux
"cat /sys/class/dmi/id/product_name" => cmd.call("model"),
# Model darwin
"sysctl -n hw.model" => cmd.call("model_darwin"),
# Model windows
"Get-CimInstance -ClassName Win32_ComputerSystem | Select Model -ExpandProperty Model" => cmd.call("model"),
# windows_hotfix windows
"get-hotfix -id KB4019215" => cmd.call("kb4019215"),
# windows_hotfix windows doesn't exist

View file

@ -0,0 +1 @@
ACME Corp.

1
test/unit/mock/cmd/model Normal file
View file

@ -0,0 +1 @@
Flux Capacitor

View file

@ -0,0 +1 @@
MacBookPro13,3

View file

@ -4,19 +4,32 @@ require "inspec/resources/sys_info"
describe "Inspec::Resources::SysInfo" do
describe "sys_info" do
it "check ssh config parsing for Ubuntu" do
it "check sys_info on Ubuntu" do
resource = MockLoader.new(:ubuntu1504).load_resource("sys_info")
_(resource.hostname).must_equal "example.com"
_(resource.manufacturer).must_equal "ACME Corp."
_(resource.model).must_equal "Flux Capacitor"
end
it "check ssh config parsing for Ubuntu" do
it "check sys_info on OSX" do
resource = MockLoader.new(:osx104).load_resource("sys_info")
_(resource.hostname).must_equal "example.com"
_(resource.manufacturer).must_equal "Apple Inc."
_(resource.model).must_equal "MacBookPro13,3"
end
it "check sys_info on Windows" do
resource = MockLoader.new(:windows).load_resource("sys_info")
_(resource.hostname).must_equal "WIN-CIV7VMLVHLD"
_(resource.manufacturer).must_equal "ACME Corp."
_(resource.model).must_equal "Flux Capacitor"
end
it "check ssh config parsing for freebsd" do
it "check sysinfo on freebsd" do
resource = MockLoader.new(:freebsd10).load_resource("sys_info")
_(resource.hostname).must_equal "The `sys_info.hostname` resource is not supported on your OS yet."
_(resource.manufacturer).must_equal "The `sys_info.manufacturer` resource is not supported on your OS yet."
_(resource.model).must_equal "The `sys_info.model` resource is not supported on your OS yet."
end
end
end