summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSerdar Sutay <serdar@opscode.com>2014-01-17 09:54:11 -0800
committerSerdar Sutay <serdar@opscode.com>2014-01-17 09:54:11 -0800
commit2e20e3b1dce05ed3489488bed1e55a49406600c6 (patch)
tree6ee2afe1bc5c79fb611c5d07bd0cee80709cce0a
parent17369e52c7e510d62a20c9dd5e144e5dd86c988a (diff)
parent68739a56a558dd8d38c8152ca260440f301d91a7 (diff)
downloadohai-2e20e3b1dce05ed3489488bed1e55a49406600c6.tar.gz
Merge pull request #281 from opscode/windows-ohai-verifier
Fixes from running ohai-verifier on windows.
-rw-r--r--Gemfile9
-rw-r--r--lib/ohai/plugins/kernel.rb6
-rw-r--r--ohai.gemspec2
-rw-r--r--spec/unit/plugins/kernel_spec.rb45
4 files changed, 50 insertions, 12 deletions
diff --git a/Gemfile b/Gemfile
index 2b17af9c..08b98ec2 100644
--- a/Gemfile
+++ b/Gemfile
@@ -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'
diff --git a/lib/ohai/plugins/kernel.rb b/lib/ohai/plugins/kernel.rb
index ee734379..a4edb884 100644
--- a/lib/ohai/plugins/kernel.rb
+++ b/lib/ohai/plugins/kernel.rb
@@ -158,7 +158,7 @@ Ohai.plugin(:Kernel) do
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
@@ -168,9 +168,7 @@ Ohai.plugin(:Kernel) do
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)
diff --git a/ohai.gemspec b/ohai.gemspec
index e9620314..cac54f0f 100644
--- a/ohai.gemspec
+++ b/ohai.gemspec
@@ -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"
diff --git a/spec/unit/plugins/kernel_spec.rb b/spec/unit/plugins/kernel_spec.rb
index 737573c6..3ba9bea3 100644
--- a/spec/unit/plugins/kernel_spec.rb
+++ b/spec/unit/plugins/kernel_spec.rb
@@ -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.
@@ -35,4 +35,45 @@ describe Ohai::System, "plugin kernel" do
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