diff options
author | Bryan McLellan <btm@loftninjas.org> | 2014-03-24 15:28:01 -0400 |
---|---|---|
committer | Bryan McLellan <btm@loftninjas.org> | 2014-03-24 15:28:01 -0400 |
commit | b0571f339717f065ecdcc3a72ddf24356a74d550 (patch) | |
tree | 7e707066760fd797d2801b402b1a9f4e7486056f | |
parent | 27cb087c51eb40e3a75d5dad04ba661a00aae7e1 (diff) | |
parent | d198bef09ba2ff8f2e1029558705c8c03a390898 (diff) | |
download | chef-b0571f339717f065ecdcc3a72ddf24356a74d550.tar.gz |
Merge pull request #1334 from opscode/btm/CHEF-4888
CHEF-4888: Call WIN32OLE.ole_initialize in sub-threads
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | lib/chef/platform/query_helpers.rb | 8 | ||||
-rw-r--r-- | lib/chef/win32/version.rb | 8 | ||||
-rw-r--r-- | spec/unit/platform/query_helpers_spec.rb | 32 |
4 files changed, 48 insertions, 1 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index f05cf40299..e634d371f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -53,6 +53,7 @@ * Add knife 'ssl check' and 'ssl fetch' commands for debugging SSL errors (CHEF-4711) * Cron resource accepts a weekday attribute as a symbol. (CHEF-4848) * Cron resource accepts special strings, e.g. @reboot (CHEF-2816) +* Call WIN32OLE.ole_initialize before using WMI (CHEF-4888) ## Last Release: 11.10.0 (02/06/2014) diff --git a/lib/chef/platform/query_helpers.rb b/lib/chef/platform/query_helpers.rb index 028a220a5d..52d6649890 100644 --- a/lib/chef/platform/query_helpers.rb +++ b/lib/chef/platform/query_helpers.rb @@ -30,11 +30,17 @@ class Chef def windows_server_2003? return false unless windows? - 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 + # https://github.com/ruby/ruby/commit/27ed294c7134c0de582007af3c915a635a6506cd + WIN32OLE.ole_initialize + host = WMI::Win32_OperatingSystem.find(:first) (host.version && host.version.start_with?("5.2")) + + WIN32OLE.ole_uninitialize end end diff --git a/lib/chef/win32/version.rb b/lib/chef/win32/version.rb index e008ff15e8..7f5fcceead 100644 --- a/lib/chef/win32/version.rb +++ b/lib/chef/win32/version.rb @@ -116,9 +116,17 @@ class Chef # 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 + # https://github.com/ruby/ruby/commit/27ed294c7134c0de582007af3c915a635a6506cd + + WIN32OLE.ole_initialize + os_info = WMI::Win32_OperatingSystem.find(:first) os_version = os_info.send('Version') + WIN32OLE.ole_uninitialize + # The operating system version is a string in the following form # that can be split into components based on the '.' delimiter: # MajorVersionNumber.MinorVersionNumber.BuildNumber diff --git a/spec/unit/platform/query_helpers_spec.rb b/spec/unit/platform/query_helpers_spec.rb new file mode 100644 index 0000000000..2414bdf552 --- /dev/null +++ b/spec/unit/platform/query_helpers_spec.rb @@ -0,0 +1,32 @@ +# +# Author:: Bryan McLellan <btm@loftninjas.org> +# Copyright:: Copyright (c) 2014 Chef Software, Inc. +# 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. +# + +require 'spec_helper' + +describe "Chef::Platform#windows_server_2003?" do + it "returns false early when not on windows" do + Chef::Platform.stub(:windows?).and_return(false) + expect(Chef::Platform).not_to receive(:require) + expect(Chef::Platform.windows_server_2003?).to be_false + end + + # CHEF-4888: Need to call WIN32OLE.ole_initialize in new threads + it "does not raise an exception" do + expect { Thread.fork { Chef::Platform.windows_server_2003? }.join }.not_to raise_error + end +end |