summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSerdar Sutay <serdar@opscode.com>2014-05-30 14:27:46 -0700
committerSerdar Sutay <serdar@opscode.com>2014-05-30 14:27:46 -0700
commit315f8b819f783e19deab86766d919dca8bf749e3 (patch)
treed4722eff939883abda9e59de197eb0a8f6f54247
parenta6b19c08da6365e883d38d0ed202068df16301ab (diff)
parentf1d0e7254be1c7029d95cc1fb2f33174c8f13cb5 (diff)
downloadchef-315f8b819f783e19deab86766d919dca8bf749e3.tar.gz
Merge pull request #1435 from opscode/adamed/wmi-lite
Replace ruby-wmi dependency with wmi-lite to address Ruby 2.0 faults
-rw-r--r--CHANGELOG.md1
-rw-r--r--chef-x86-mingw32.gemspec2
-rw-r--r--chef.gemspec2
-rw-r--r--lib/chef/platform/query_helpers.rb7
-rw-r--r--lib/chef/provider/env/windows.rb13
-rw-r--r--lib/chef/win32/registry.rb1
-rw-r--r--lib/chef/win32/version.rb7
-rw-r--r--spec/functional/win32/versions_spec.rb8
-rw-r--r--spec/support/platform_helpers.rb12
9 files changed, 32 insertions, 21 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c4edd543ed..4b25a72b10 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -43,6 +43,7 @@
* knife now bootstraps node with the latest current version of chef-client. (CHEF-4911)
* Add config options for attribute whitelisting in node.save. (CHEF-3811)
* Use user's .chef as a fallback cache path if /var/chef is not accessible. (CHEF-5259)
+* Fixed Ruby 2.0 Windows compatibility issues around ruby-wmi gem by replacing it with wmi-lite gem.
## Release: 11.12.4 (04/30/2014)
http://www.getchef.com/blog/2014/04/30/release-chef-client-11-12-4-ohai-7-0-4/
diff --git a/chef-x86-mingw32.gemspec b/chef-x86-mingw32.gemspec
index 49a15bcf00..e34724ae51 100644
--- a/chef-x86-mingw32.gemspec
+++ b/chef-x86-mingw32.gemspec
@@ -4,7 +4,6 @@ gemspec = eval(IO.read(File.expand_path("../chef.gemspec", __FILE__)))
gemspec.platform = "x86-mingw32"
gemspec.add_dependency "ffi", "1.5.0"
-gemspec.add_dependency "rdp-ruby-wmi", "0.3.1"
gemspec.add_dependency "windows-api", "0.4.2"
gemspec.add_dependency "windows-pr", "1.2.2"
gemspec.add_dependency "win32-api", "1.5.1"
@@ -14,5 +13,6 @@ gemspec.add_dependency "win32-mutex", "0.4.1"
gemspec.add_dependency "win32-process", "0.7.3"
gemspec.add_dependency "win32-service", "0.8.2"
gemspec.add_dependency "win32-mmap", "0.4.0"
+gemspec.add_dependency "wmi-lite", "~> 1.0"
gemspec
diff --git a/chef.gemspec b/chef.gemspec
index c5508dd854..f4bfae1b94 100644
--- a/chef.gemspec
+++ b/chef.gemspec
@@ -17,7 +17,7 @@ Gem::Specification.new do |s|
s.add_dependency "mixlib-log", "~> 1.3"
s.add_dependency "mixlib-authentication", "~> 1.3"
s.add_dependency "mixlib-shellout", "~> 1.4"
- s.add_dependency "ohai", "~> 7.0"
+ s.add_dependency "ohai", "= 7.2.0.alpha.0"
s.add_dependency "rest-client", ">= 1.0.4", "< 1.7.0"
# rest-client has an unbounded dependency on mime-types.
diff --git a/lib/chef/platform/query_helpers.rb b/lib/chef/platform/query_helpers.rb
index f9f7af0343..f6f5309de5 100644
--- a/lib/chef/platform/query_helpers.rb
+++ b/lib/chef/platform/query_helpers.rb
@@ -30,15 +30,16 @@ class Chef
def windows_server_2003?
return false unless windows?
- require 'ruby-wmi'
+ require 'wmi-lite/wmi'
# CHEF-4888: Work around ruby #2618, expected to be fixed in Ruby 2.1.0
# https://github.com/ruby/ruby/commit/588504b20f5cc880ad51827b93e571e32446e5db
# https://github.com/ruby/ruby/commit/27ed294c7134c0de582007af3c915a635a6506cd
WIN32OLE.ole_initialize
- host = WMI::Win32_OperatingSystem.find(:first)
- is_server_2003 = (host.version && host.version.start_with?("5.2"))
+ wmi = WmiLite::Wmi.new
+ host = wmi.first_of('Win32_OperatingSystem')
+ is_server_2003 = (host['version'] && host['version'].start_with?("5.2"))
WIN32OLE.ole_uninitialize
diff --git a/lib/chef/provider/env/windows.rb b/lib/chef/provider/env/windows.rb
index bf728b1fae..297de94083 100644
--- a/lib/chef/provider/env/windows.rb
+++ b/lib/chef/provider/env/windows.rb
@@ -17,7 +17,6 @@
#
if RUBY_PLATFORM =~ /mswin|mingw32|windows/
- require 'ruby-wmi'
require 'Win32API'
end
@@ -51,9 +50,17 @@ class Chef
return obj ? obj.variablevalue : nil
end
+ def find_env(environment_variables, key_name)
+ environment_variables.find do | environment_variable |
+ environment_variable['name'].downcase == key_name
+ end
+ end
+
def env_obj(key_name)
- WMI::Win32_Environment.find(:first,
- :conditions => { :name => key_name })
+ wmi = WmiLite::Wmi.new
+ environment_variables = wmi.instances_of('Win32_Environment')
+ existing_variable = find_env(environment_variables, key_name)
+ existing_variable.nil? ? nil : existing_variable.wmi_ole_object
end
#see: http://msdn.microsoft.com/en-us/library/ms682653%28VS.85%29.aspx
diff --git a/lib/chef/win32/registry.rb b/lib/chef/win32/registry.rb
index 1e8f53b464..18f12d26b8 100644
--- a/lib/chef/win32/registry.rb
+++ b/lib/chef/win32/registry.rb
@@ -20,7 +20,6 @@ require 'chef/reserved_names'
if RUBY_PLATFORM =~ /mswin|mingw32|windows/
require 'win32/registry'
- require 'ruby-wmi'
require 'win32/api'
end
diff --git a/lib/chef/win32/version.rb b/lib/chef/win32/version.rb
index 7f5fcceead..233e31fe76 100644
--- a/lib/chef/win32/version.rb
+++ b/lib/chef/win32/version.rb
@@ -18,6 +18,7 @@
require 'chef/win32/api'
require 'chef/win32/api/system'
+require 'wmi-lite/wmi'
class Chef
module ReservedNames::Win32
@@ -114,7 +115,6 @@ class Chef
# version numbers on Windows Server 2012 R2 and Windows 8.1 --
# WMI always returns the truth. See article at
# http://msdn.microsoft.com/en-us/library/windows/desktop/ms724439(v=vs.85).aspx
- require 'ruby-wmi'
# CHEF-4888: Work around ruby #2618, expected to be fixed in Ruby 2.1.0
# https://github.com/ruby/ruby/commit/588504b20f5cc880ad51827b93e571e32446e5db
@@ -122,8 +122,9 @@ class Chef
WIN32OLE.ole_initialize
- os_info = WMI::Win32_OperatingSystem.find(:first)
- os_version = os_info.send('Version')
+ wmi = WmiLite::Wmi.new
+ os_info = wmi.first_of('Win32_OperatingSystem')
+ os_version = os_info['version']
WIN32OLE.ole_uninitialize
diff --git a/spec/functional/win32/versions_spec.rb b/spec/functional/win32/versions_spec.rb
index b983b711da..6c8f6b2aaa 100644
--- a/spec/functional/win32/versions_spec.rb
+++ b/spec/functional/win32/versions_spec.rb
@@ -19,13 +19,13 @@
require 'spec_helper'
if Chef::Platform.windows?
require 'chef/win32/version'
- require 'ruby-wmi'
end
describe "Chef::ReservedNames::Win32::Version", :windows_only, :not_supported_on_win2k3 do
before do
- host = WMI::Win32_OperatingSystem.find(:first)
+ wmi = WmiLite::Wmi.new
+ host = wmi.first_of('Win32_OperatingSystem')
# Use WMI to determine current OS version.
# On Win2k8R2 and later, we can dynamically obtain marketing
@@ -44,7 +44,7 @@ describe "Chef::ReservedNames::Win32::Version", :windows_only, :not_supported_on
# The name from WMI is actually what we want in Win2k8R2+.
# So this expectation sould continue to hold without modification
# as new versions of Windows are released.
- @current_os_version = host.caption
+ @current_os_version = host['caption']
end
@version = Chef::ReservedNames::Win32::Version.new
@@ -98,7 +98,7 @@ describe "Chef::ReservedNames::Win32::Version", :windows_only, :not_supported_on
def is_windows_server_2008?(wmi_host)
is_win2k8 = false
- os_version = wmi_host.send('Version')
+ os_version = wmi_host['version']
# The operating system version is a string in the following form
# that can be split into components based on the '.' delimiter:
diff --git a/spec/support/platform_helpers.rb b/spec/support/platform_helpers.rb
index 884893865f..75ab0c9cde 100644
--- a/spec/support/platform_helpers.rb
+++ b/spec/support/platform_helpers.rb
@@ -27,18 +27,20 @@ def windows?
!!(RUBY_PLATFORM =~ /mswin|mingw|windows/)
end
-require 'ruby-wmi' if windows?
+require 'wmi-lite/wmi' if windows?
def windows_domain_joined?
return false unless windows?
- WMI::Win32_ComputerSystem.find(:first).PartOfDomain
+ wmi = WmiLite::Wmi.new
+ computer_system = wmi.first_of('Win32_ComputerSystem')
+ computer_system['partofdomain']
end
def windows_win2k3?
return false unless windows?
-
- host = WMI::Win32_OperatingSystem.find(:first)
- (host.version && host.version.start_with?("5.2"))
+ wmi = WmiLite::Wmi.new
+ host = wmi.first_of('Win32_OperatingSystem')
+ (host['version'] && host['version'].start_with?("5.2"))
end
def mac_osx_106?