Skip to content

Commit

Permalink
Merge pull request #528 from chef/tm/8.3.0
Browse files Browse the repository at this point in the history
8.3.0
  • Loading branch information
thommay committed Apr 27, 2015
2 parents 6ff7c8f + 9788661 commit 74426e7
Show file tree
Hide file tree
Showing 11 changed files with 93 additions and 27 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
# Ohai Changelog

## Unreleased:
## Release 8.3.0

* [**Jeremy Mauro**](https://github.com/jmauro):
Removing trailing space and '\r' for windows #474
* [**Tim Smith**](https://github.com/tas50):
Ensure Gentoo based Linuxen get IP information

* Work correctly when IPv6 is disabled on Linux
* Move Windows drivers out of kernel plugin

## Release 8.2.0

Expand Down
3 changes: 2 additions & 1 deletion lib/ohai/common/dmi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ def convenience_keys(dmi)
next if field.to_s == 'size'
next if field.to_s == 'record_id'
translated = field.downcase.gsub(/[^a-z0-9]/, '_')
value = value.strip
if in_common.has_key?(translated)
in_common[translated] = nil unless in_common[translated] == value
else
Expand All @@ -115,7 +116,7 @@ def convenience_keys(dmi)
}
in_common.each{ |field, value|
next if value == nil
dmi[type][field] = value
dmi[type][field] = value.strip
}
}
end
Expand Down
1 change: 1 addition & 0 deletions lib/ohai/plugins/dmi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
# ... similar lines trimmed
so.stdout.lines do |line|
next if blank_line.match(line)
line = line.encode(line.encoding, :universal_newline => true)

if dmidecode_version = dmidecode_version_line.match(line)
dmi[:dmidecode_version] = dmidecode_version[1]
Expand Down
18 changes: 0 additions & 18 deletions lib/ohai/plugins/kernel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -183,23 +183,5 @@ def os_lookup(sys_type)

kernel[:machine] = machine_lookup("#{kernel[:cs_info][:system_type]}")

kext = Mash.new
pnp_drivers = Mash.new

drivers = wmi.instances_of('Win32_PnPSignedDriver')
drivers.each do |driver|
pnp_drivers[driver['deviceid']] = Mash.new
driver.wmi_ole_object.properties_.each do |p|
pnp_drivers[driver['deviceid']][p.name.wmi_underscore.to_sym] = driver[p.name.downcase]
end
if driver['devicename']
kext[driver['devicename']] = pnp_drivers[driver['deviceid']]
kext[driver['devicename']][:version] = pnp_drivers[driver['deviceid']][:driver_version]
kext[driver['devicename']][:date] = pnp_drivers[driver['deviceid']][:driver_date] ? pnp_drivers[driver['deviceid']][:driver_date].to_s[0..7] : nil
end
end

kernel[:pnp_drivers] = pnp_drivers
kernel[:modules] = kext
end
end
12 changes: 9 additions & 3 deletions lib/ohai/plugins/linux/network.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,12 @@ def linux_encaps_lookup(encap)
encap
end

def ipv6_enabled?
File.exist? "/proc/net/if_inet6"
end

def iproute2_binary_available?
["/sbin/ip", "/usr/bin/ip"].any? { |path| File.exist?(path) }
["/sbin/ip", "/usr/bin/ip", "/bin/ip"].any? { |path| File.exist?(path) }
end

collect_data(:linux) do
Expand All @@ -60,12 +64,14 @@ def iproute2_binary_available?
:default_route => "0.0.0.0/0",
:default_prefix => :default,
:neighbour_attribute => :arp
},{
}]

families << {
:name => "inet6",
:default_route => "::/0",
:default_prefix => :default_inet6,
:neighbour_attribute => :neighbour_inet6
}]
} if ipv6_enabled?

so = shell_out("ip addr")
cint = nil
Expand Down
47 changes: 47 additions & 0 deletions lib/ohai/plugins/windows/drivers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#
# Copyright:: Copyright (c) 2015 Chef Software
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

Ohai.plugin(:Drivers) do
provides "kernel/pnp_drivers", "kernel/modules"
depends "kernel"

collect_data(:windows) do
require 'wmi-lite/wmi'

wmi = WmiLite::Wmi.new

kext = Mash.new
pnp_drivers = Mash.new

drivers = wmi.instances_of('Win32_PnPSignedDriver')
drivers.each do |driver|
pnp_drivers[driver['deviceid']] = Mash.new
driver.wmi_ole_object.properties_.each do |p|
pnp_drivers[driver['deviceid']][p.name.wmi_underscore.to_sym] = driver[p.name.downcase]
end
if driver['devicename']
kext[driver['devicename']] = pnp_drivers[driver['deviceid']]
kext[driver['devicename']][:version] = pnp_drivers[driver['deviceid']][:driver_version]
kext[driver['devicename']][:date] = pnp_drivers[driver['deviceid']][:driver_date] ? pnp_drivers[driver['deviceid']][:driver_date].to_s[0..7] : nil
end
end

kernel[:pnp_drivers] = pnp_drivers
kernel[:modules] = kext

end
end
2 changes: 1 addition & 1 deletion lib/ohai/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@

module Ohai
OHAI_ROOT = File.expand_path(File.dirname(__FILE__))
VERSION = '8.2.0'
VERSION = '8.3.0'
end
4 changes: 4 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ def get_plugin(plugin, ohai = Ohai::System.new, path = PLUGIN_PATH)
loader.load_plugin(File.join(path, "#{plugin}.rb"))
end

def convert_windows_output(stdout)
stdout.gsub("\n", "\r\n")
end

def it_should_check_from(plugin, attribute, from, value)
it "should set the #{attribute} to the value from '#{from}'" do
@plugin.run
Expand Down
6 changes: 6 additions & 0 deletions spec/unit/plugins/dmi_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@
@plugin.run
expect(@plugin[:dmi][id][attribute]).to eql(value)
end
it "should have [:dmi][:#{id}][:#{attribute}] set for windows output" do
@stdout = convert_windows_output(DMI_OUT)
expect(@plugin).to receive(:shell_out).with("dmidecode").and_return(mock_shell_out(0, @stdout, ""))
@plugin.run
expect(@plugin[:dmi][id][attribute]).to eql(value)
end
end
end
end
3 changes: 1 addition & 2 deletions spec/unit/plugins/kernel_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,10 @@
cs_wmi = WmiLite::Wmi::Instance.new(cs)

expect_any_instance_of(WmiLite::Wmi).to receive(:first_of).with('Win32_ComputerSystem').and_return(cs_wmi)
expect_any_instance_of(WmiLite::Wmi).to receive(:instances_of).with('Win32_PnPSignedDriver').and_return([])

@plugin.run
end
it "should set the corrent system information" do
it "should set the correct system information" do
expect(@ohai_system.data[:kernel][:name]).to eq("Microsoft Windows 7 Ultimate")
expect(@ohai_system.data[:kernel][:release]).to eq("6.1.7601")
expect(@ohai_system.data[:kernel][:version]).to eq("6.1.7601 Service Pack 1 Build 7601")
Expand Down
14 changes: 13 additions & 1 deletion spec/unit/plugins/linux/network_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@
end

describe "#iproute2_binary_available?" do
["/sbin/ip", "/usr/bin/ip"].each do |path|
["/sbin/ip", "/usr/bin/ip", "/bin/ip"].each do |path|
it "accepts #{path}" do
allow(File).to receive(:exist?).and_return(false)
allow(File).to receive(:exist?).with(path).and_return(true)
Expand Down Expand Up @@ -546,6 +546,7 @@
describe "for newer network features using iproute2 only" do
before(:each) do
allow(File).to receive(:exist?).with("/sbin/ip").and_return(true) # iproute2 only
allow(File).to receive(:exist?).with("/proc/net/if_inet6").and_return(true) # ipv6 is enabled
plugin.run
end

Expand Down Expand Up @@ -591,6 +592,17 @@
expect(plugin['network']['interfaces']['eth3']['state']).to eq('up')
end

describe "when IPv6 is disabled" do
before :each do
allow(File).to receive(:exist?).with("/proc/net/if_inet6").and_return(false)
plugin.run
end

it "doesn't set ip6address" do
expect(plugin['ip6address']).to be_nil
end
end

describe "when dealing with routes" do
it "adds routes" do
plugin.run
Expand Down

0 comments on commit 74426e7

Please sign in to comment.