From f3df1226e3c5463d5f88600de2eaa164c9db9ef5 Mon Sep 17 00:00:00 2001 From: John McCrae Date: Mon, 4 Apr 2022 16:51:02 -0700 Subject: Updating For Ruby 3.1 Signed-off-by: John McCrae --- .github/CODEOWNERS | 2 +- .github/workflows/unit.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index ab984170..be56701b 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1,5 +1,5 @@ # Order is important. The last matching pattern has the most precedence. * @chef/chef-infra-reviewers @chef/chef-infra-approvers @chef/chef-infra-owners -.expeditor/ @chef/jex-team +.expeditor/ @chef/infra-packages *.md @chef/docs-team diff --git a/.github/workflows/unit.yml b/.github/workflows/unit.yml index 5d4b02eb..4d5b3007 100644 --- a/.github/workflows/unit.yml +++ b/.github/workflows/unit.yml @@ -15,7 +15,7 @@ jobs: fail-fast: false matrix: os: ['ubuntu-latest', 'macos-latest', 'windows-latest'] - ruby: ['2.7', '3.0'] + ruby: ['2.7', '3.0', '3.1'] name: Unit test on ${{ matrix.os }} with Ruby ${{ matrix.ruby }} runs-on: ${{ matrix.os }} steps: -- cgit v1.2.1 From 34e02d2527969f3d40cfe338f4c5dbf4fd9aa124 Mon Sep 17 00:00:00 2001 From: John McCrae Date: Wed, 6 Apr 2022 09:36:34 -0700 Subject: Updating For Ruby 3.1 Signed-off-by: John McCrae --- .github/workflows/unit.yml | 2 ++ Gemfile | 1 + lib/ohai/mixin/os.rb | 2 +- lib/ohai/plugins/azure.rb | 2 +- lib/ohai/plugins/ec2.rb | 2 +- lib/ohai/plugins/gce.rb | 2 +- lib/ohai/plugins/openstack.rb | 2 +- lib/ohai/plugins/rackspace.rb | 2 +- ohai.gemspec | 3 ++- spec/unit/mixin/shell_out_spec.rb | 9 +++++++-- spec/unit/plugins/azure_spec.rb | 1 + 11 files changed, 19 insertions(+), 9 deletions(-) diff --git a/.github/workflows/unit.yml b/.github/workflows/unit.yml index 4d5b3007..9bc13e99 100644 --- a/.github/workflows/unit.yml +++ b/.github/workflows/unit.yml @@ -18,6 +18,8 @@ jobs: ruby: ['2.7', '3.0', '3.1'] name: Unit test on ${{ matrix.os }} with Ruby ${{ matrix.ruby }} runs-on: ${{ matrix.os }} + env: + RUBYOPT: '--disable-error_highlight' steps: - uses: actions/checkout@v2 - uses: ruby/setup-ruby@v1 diff --git a/Gemfile b/Gemfile index 90e95e79..fb2e3a1c 100644 --- a/Gemfile +++ b/Gemfile @@ -6,6 +6,7 @@ gemspec # pull these gems from main of chef/chef so that we're testing against what we will release gem "chef-config", git: "https://github.com/chef/chef", branch: "main", glob: "chef-config/chef-config.gemspec" gem "chef-utils", git: "https://github.com/chef/chef", branch: "main", glob: "chef-utils/chef-utils.gemspec" +# gem "chef-utils", path: "C:\\foo\\chef\\chef-utils" # NOTE: do not submit PRs to add pry as a dep, add to your Gemfile.local group :development do diff --git a/lib/ohai/mixin/os.rb b/lib/ohai/mixin/os.rb index 44d3686f..a6bfdf46 100644 --- a/lib/ohai/mixin/os.rb +++ b/lib/ohai/mixin/os.rb @@ -110,7 +110,7 @@ module Ohai "dragonflybsd" when /solaris2/ "solaris2" - when /mswin|mingw32|windows/ + when /mswin|mingw|windows/ # After long discussion in IRC the "powers that be" have come to a consensus # that no Windows platform exists that was not based on the # Windows_NT kernel, so we herby decree that "windows" will refer to all diff --git a/lib/ohai/plugins/azure.rb b/lib/ohai/plugins/azure.rb index c21b8ac7..ef1d69f5 100644 --- a/lib/ohai/plugins/azure.rb +++ b/lib/ohai/plugins/azure.rb @@ -73,7 +73,7 @@ Ohai.plugin(:Azure) do end def tcp_ip_dhcp_domain - return unless RUBY_PLATFORM.match?(/mswin|mingw32|windows/) + return unless RUBY_PLATFORM.match?(/mswin|mingw|windows/) require "win32/registry" unless defined?(Win32::Registry) diff --git a/lib/ohai/plugins/ec2.rb b/lib/ohai/plugins/ec2.rb index 79c124fe..5799d838 100644 --- a/lib/ohai/plugins/ec2.rb +++ b/lib/ohai/plugins/ec2.rb @@ -81,7 +81,7 @@ Ohai.plugin(:EC2) do # linux hosts # @return [Boolean] do we have a Xen Identifying Number or not? def has_ec2_identifying_number? - if RUBY_PLATFORM.match?(/mswin|mingw32|windows/) + if RUBY_PLATFORM.match?(/mswin|mingw|windows/) require "wmi-lite/wmi" unless defined?(WmiLite::Wmi) wmi = WmiLite::Wmi.new if /^ec2/.match?(wmi.first_of("Win32_ComputerSystemProduct")["identifyingnumber"]) diff --git a/lib/ohai/plugins/gce.rb b/lib/ohai/plugins/gce.rb index 90d63e96..fdfce390 100644 --- a/lib/ohai/plugins/gce.rb +++ b/lib/ohai/plugins/gce.rb @@ -49,7 +49,7 @@ Ohai.plugin(:GCE) do # looks at the Manufacturer and Model WMI values to see if they starts with Google. # @return [Boolean] Are the manufacturer and model Google? def has_gce_system_info? - if RUBY_PLATFORM.match?(/mswin|mingw32|windows/) + if RUBY_PLATFORM.match?(/mswin|mingw|windows/) require "wmi-lite/wmi" unless defined?(WmiLite::Wmi) wmi = WmiLite::Wmi.new computer_system = wmi.first_of("Win32_ComputerSystem") diff --git a/lib/ohai/plugins/openstack.rb b/lib/ohai/plugins/openstack.rb index 1c1f7abc..b851ef02 100644 --- a/lib/ohai/plugins/openstack.rb +++ b/lib/ohai/plugins/openstack.rb @@ -49,7 +49,7 @@ Ohai.plugin(:Openstack) do # https://help.dreamhost.com/hc/en-us/articles/228377408-How-to-find-the-default-user-of-an-image def openstack_provider # dream host doesn't support windows so bail early if we're on windows - return "openstack" if RUBY_PLATFORM.match?(/mswin|mingw32|windows/) + return "openstack" if RUBY_PLATFORM.match?(/mswin|mingw|windows/) if Etc::Passwd.entries.map(&:name).include?("dhc-user") "dreamhost" diff --git a/lib/ohai/plugins/rackspace.rb b/lib/ohai/plugins/rackspace.rb index 469290b6..b7a1a795 100644 --- a/lib/ohai/plugins/rackspace.rb +++ b/lib/ohai/plugins/rackspace.rb @@ -48,7 +48,7 @@ Ohai.plugin(:Rackspace) do # true:: If the rackspace cloud can be identified # false:: Otherwise def has_rackspace_manufacturer? - return false unless RUBY_PLATFORM.match?(/mswin|mingw32|windows/) + return false unless RUBY_PLATFORM.match?(/mswin|mingw|windows/) require "wmi-lite/wmi" unless defined?(WmiLite::Wmi) wmi = WmiLite::Wmi.new diff --git a/ohai.gemspec b/ohai.gemspec index e7af4a7c..39a52d51 100644 --- a/ohai.gemspec +++ b/ohai.gemspec @@ -15,7 +15,8 @@ Gem::Specification.new do |s| s.required_ruby_version = ">= 2.7" s.add_dependency "chef-config", ">= 14.12", "< 19" - s.add_dependency "chef-utils", ">= 16.0", "< 19" + s.add_runtime_dependency "chef-utils" + # s.add_dependency "chef-utils", ">= 16.0", "< 19" s.add_dependency "ffi", "~> 1.9" s.add_dependency "ffi-yajl", "~> 2.2" s.add_dependency "ipaddress" diff --git a/spec/unit/mixin/shell_out_spec.rb b/spec/unit/mixin/shell_out_spec.rb index 7d08d9ff..0cf5baea 100644 --- a/spec/unit/mixin/shell_out_spec.rb +++ b/spec/unit/mixin/shell_out_spec.rb @@ -17,6 +17,7 @@ # require "spec_helper" +require "pry" describe Ohai::Mixin::ShellOut, "shell_out" do let(:cmd) { "sparkle-dream --version" } @@ -63,14 +64,14 @@ describe Ohai::Mixin::ShellOut, "shell_out" do let(:instance) { DummyPlugin.new } - before do + before(:each) do allow(instance).to receive(:logger).and_return(logger) allow(instance).to receive(:name).and_return(plugin_name) @original_env = ENV.to_hash ENV.clear end - after do + after(:each) do ENV.clear ENV.update(@original_env) end @@ -88,6 +89,10 @@ describe Ohai::Mixin::ShellOut, "shell_out" do describe "when the command does not exist" do it "logs the command and error message" do + require "pry" + Pry.config.input = STDIN + Pry.config.output = STDOUT + binding.pry expect(Mixlib::ShellOut).to receive(:new).with(cmd, options).and_return(shell_out) expect(shell_out).to receive(:run_command).and_raise(Errno::ENOENT, "sparkle-dream") expect(logger).to receive(:trace) diff --git a/spec/unit/plugins/azure_spec.rb b/spec/unit/plugins/azure_spec.rb index 4d875e80..0d9353d8 100644 --- a/spec/unit/plugins/azure_spec.rb +++ b/spec/unit/plugins/azure_spec.rb @@ -17,6 +17,7 @@ # require "spec_helper" +require "win32/registry" unless defined?(Win32::Registry) describe Ohai::System, "plugin azure" do let(:plugin) { get_plugin("azure") } -- cgit v1.2.1 From a9883654d5033f3d732d0d45c1a9ffda06488d30 Mon Sep 17 00:00:00 2001 From: John McCrae Date: Wed, 6 Apr 2022 11:15:37 -0700 Subject: Updating for Ruby 3.1 Signed-off-by: John McCrae --- spec/unit/mixin/shell_out_spec.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/spec/unit/mixin/shell_out_spec.rb b/spec/unit/mixin/shell_out_spec.rb index 0cf5baea..a754bdc1 100644 --- a/spec/unit/mixin/shell_out_spec.rb +++ b/spec/unit/mixin/shell_out_spec.rb @@ -89,10 +89,6 @@ describe Ohai::Mixin::ShellOut, "shell_out" do describe "when the command does not exist" do it "logs the command and error message" do - require "pry" - Pry.config.input = STDIN - Pry.config.output = STDOUT - binding.pry expect(Mixlib::ShellOut).to receive(:new).with(cmd, options).and_return(shell_out) expect(shell_out).to receive(:run_command).and_raise(Errno::ENOENT, "sparkle-dream") expect(logger).to receive(:trace) -- cgit v1.2.1 From ac1b3f111cf3da1d3a0f17a1e04185706f840e23 Mon Sep 17 00:00:00 2001 From: John McCrae Date: Wed, 6 Apr 2022 11:56:28 -0700 Subject: Updating for Ruby 3.1 Signed-off-by: John McCrae --- lib/ohai/plugins/azure.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/ohai/plugins/azure.rb b/lib/ohai/plugins/azure.rb index ef1d69f5..008a9a21 100644 --- a/lib/ohai/plugins/azure.rb +++ b/lib/ohai/plugins/azure.rb @@ -75,7 +75,9 @@ Ohai.plugin(:Azure) do def tcp_ip_dhcp_domain return unless RUBY_PLATFORM.match?(/mswin|mingw|windows/) - require "win32/registry" unless defined?(Win32::Registry) + if ChefUtils.windows? + require "win32/registry" unless defined?(Win32::Registry) + end begin key = Win32::Registry::HKEY_LOCAL_MACHINE.open("SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters") -- cgit v1.2.1 From 239de3b6a645b68e03b0d5cc4a5bbf9f589033f9 Mon Sep 17 00:00:00 2001 From: John McCrae Date: Wed, 6 Apr 2022 13:05:32 -0700 Subject: Updating for Ruby 3.1 Signed-off-by: John McCrae --- ohai.gemspec | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ohai.gemspec b/ohai.gemspec index 39a52d51..e7af4a7c 100644 --- a/ohai.gemspec +++ b/ohai.gemspec @@ -15,8 +15,7 @@ Gem::Specification.new do |s| s.required_ruby_version = ">= 2.7" s.add_dependency "chef-config", ">= 14.12", "< 19" - s.add_runtime_dependency "chef-utils" - # s.add_dependency "chef-utils", ">= 16.0", "< 19" + s.add_dependency "chef-utils", ">= 16.0", "< 19" s.add_dependency "ffi", "~> 1.9" s.add_dependency "ffi-yajl", "~> 2.2" s.add_dependency "ipaddress" -- cgit v1.2.1 From 8d495f6a851b4fa15aee0b5fc83163963b58d47e Mon Sep 17 00:00:00 2001 From: John McCrae Date: Wed, 6 Apr 2022 13:14:39 -0700 Subject: Updating for Ruby 3.1 Signed-off-by: John McCrae --- spec/unit/mixin/shell_out_spec.rb | 1 - spec/unit/plugins/azure_spec.rb | 6 +++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/spec/unit/mixin/shell_out_spec.rb b/spec/unit/mixin/shell_out_spec.rb index a754bdc1..d696546e 100644 --- a/spec/unit/mixin/shell_out_spec.rb +++ b/spec/unit/mixin/shell_out_spec.rb @@ -17,7 +17,6 @@ # require "spec_helper" -require "pry" describe Ohai::Mixin::ShellOut, "shell_out" do let(:cmd) { "sparkle-dream --version" } diff --git a/spec/unit/plugins/azure_spec.rb b/spec/unit/plugins/azure_spec.rb index 0d9353d8..f1950f46 100644 --- a/spec/unit/plugins/azure_spec.rb +++ b/spec/unit/plugins/azure_spec.rb @@ -17,7 +17,11 @@ # require "spec_helper" -require "win32/registry" unless defined?(Win32::Registry) +begin + require "win32/registry" unless defined?(Win32::Registry) +rescue LoadError => e + puts "Skipping missing rake dep: #{e}" +end describe Ohai::System, "plugin azure" do let(:plugin) { get_plugin("azure") } -- cgit v1.2.1 From bc545a24c0b76ba9281ec733cc42e8f440b01c0f Mon Sep 17 00:00:00 2001 From: John McCrae Date: Thu, 7 Apr 2022 15:39:10 -0700 Subject: Updating RUBY_PLATFORM on Windows for Ruby 3.1 Compatibility Signed-off-by: John McCrae --- Gemfile | 1 - 1 file changed, 1 deletion(-) diff --git a/Gemfile b/Gemfile index fb2e3a1c..90e95e79 100644 --- a/Gemfile +++ b/Gemfile @@ -6,7 +6,6 @@ gemspec # pull these gems from main of chef/chef so that we're testing against what we will release gem "chef-config", git: "https://github.com/chef/chef", branch: "main", glob: "chef-config/chef-config.gemspec" gem "chef-utils", git: "https://github.com/chef/chef", branch: "main", glob: "chef-utils/chef-utils.gemspec" -# gem "chef-utils", path: "C:\\foo\\chef\\chef-utils" # NOTE: do not submit PRs to add pry as a dep, add to your Gemfile.local group :development do -- cgit v1.2.1