Skip to content

Commit

Permalink
Merge pull request #281 from opscode/windows-ohai-verifier
Browse files Browse the repository at this point in the history
Fixes from running ohai-verifier on windows.
  • Loading branch information
Serdar Sutay committed Jan 17, 2014
2 parents 17369e5 + 68739a5 commit 2e20e3b
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 12 deletions.
9 changes: 4 additions & 5 deletions Gemfile
Expand Up @@ -2,12 +2,11 @@ source "https://rubygems.org"

gemspec

group :development do
platforms :mswin, :mingw do
gem "rdp-ruby-wmi", "0.3.1"
end

# Fixes https://tickets.opscode.com/browse/MIXLIB-17
# This line can be removed and replaced with a line in the gemspec that specifies
# that the mixlib::shellout version be > 1.2.0
gem "mixlib-shellout", :git => "https://github.com/opscode/mixlib-shellout.git"
group :development do

gem "sigar", :platform => "ruby"
gem 'plist'
Expand Down
6 changes: 2 additions & 4 deletions lib/ohai/plugins/kernel.rb
Expand Up @@ -158,7 +158,7 @@ def os_lookup(sys_type)
require 'ruby-wmi'
WIN32OLE.codepage = WIN32OLE::CP_UTF8

kernel = Mash.new
kernel Mash.new

host = WMI::Win32_OperatingSystem.find(:first)
kernel[:os_info] = Mash.new
Expand All @@ -168,9 +168,7 @@ def os_lookup(sys_type)

kernel[:name] = "#{kernel[:os_info][:caption]}"
kernel[:release] = "#{kernel[:os_info][:version]}"
kernel[:version] = "#{kernel[:os_info][:version]}
##{kernel[:os_info][:csd_version]} Build
###{kernel[:os_info][:build_number]}"
kernel[:version] = "#{kernel[:os_info][:version]} #{kernel[:os_info][:csd_version]} Build #{kernel[:os_info][:build_number]}"
kernel[:os] = os_lookup(kernel[:os_info][:os_type]) || languages[:ruby][:host_os]

host = WMI::Win32_ComputerSystem.find(:first)
Expand Down
2 changes: 1 addition & 1 deletion ohai.gemspec
Expand Up @@ -18,7 +18,7 @@ Gem::Specification.new do |s|
s.add_dependency "mixlib-cli"
s.add_dependency "mixlib-config", "~> 2.0"
s.add_dependency "mixlib-log"
s.add_dependency "mixlib-shellout"
s.add_dependency "mixlib-shellout", "~> 1.2"
s.add_dependency "ipaddress"
s.add_development_dependency "rake"
s.add_development_dependency "rspec-core"
Expand Down
45 changes: 43 additions & 2 deletions spec/unit/plugins/kernel_spec.rb
Expand Up @@ -6,9 +6,9 @@
# 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.
Expand All @@ -35,4 +35,45 @@
it_should_check_from_mash("kernel", "version", "uname -v", [0, "Darwin Kernel Version 9.5.0: Wed Sep 3 11:29:43 PDT 2008; root:xnu-1228.7.58~1\/RELEASE_I386\n", ""])
it_should_check_from_mash("kernel", "machine", "uname -m", [0, "i386\n", ""])

describe "when running on windows", :windows_only do
before do
require 'ruby-wmi'

@ohai_system = Ohai::System.new
@plugin = get_plugin("kernel", @ohai_system)

caption = double("WIN32OLE", :name => "caption")
version = double("WIN32OLE", :name => "version")
build_number = double("WIN32OLE", :name => "BuildNumber")
csd_version = double("WIN32OLE", :name => "CsdVersion")
os_type = double("WIN32OLE", :name => "OsType")
os_properties = [ caption, version, build_number, csd_version, os_type ]

os = double("WIN32OLE",
:properties_ => os_properties,
:caption => "Microsoft Windows 7 Ultimate",
:version => "6.1.7601",
:BuildNumber => "7601",
:CsdVersion => "Service Pack 1",
:OsType => 18)
WMI::Win32_OperatingSystem.should_receive(:find).with(:first).and_return(os)

cs = double("WIN32OLE",
:properties_ => [ double("WIN32OLE", :name => "SystemType") ],
:SystemType => "x64-based PC")
WMI::Win32_ComputerSystem.should_receive(:find).with(:first).and_return(cs)

WMI::Win32_PnPSignedDriver.should_receive(:find).with(:all).and_return([ ])

@plugin.run
end
it "should set the corrent system information" do
@ohai_system.data[:kernel][:name].should == "Microsoft Windows 7 Ultimate"
@ohai_system.data[:kernel][:release].should == "6.1.7601"
@ohai_system.data[:kernel][:version].should == "6.1.7601 Service Pack 1 Build 7601"
@ohai_system.data[:kernel][:os].should == "WINNT"
@ohai_system.data[:kernel][:machine].should == "x86_64"
end
end

end

0 comments on commit 2e20e3b

Please sign in to comment.