summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2021-06-10 20:31:10 -0700
committerGitHub <noreply@github.com>2021-06-10 20:31:10 -0700
commite664552c118ca7ceada3bf4e0b13cd1482dcf4e1 (patch)
treefc5728bb728a45989a3579e701038a35a2bd36e1
parent0bc0a13cbc5775a34fbc2984f3abf5d13897f60d (diff)
parent42d25566129770a9bf08dce496b18c8d9625ec77 (diff)
downloadchef-e664552c118ca7ceada3bf4e0b13cd1482dcf4e1.tar.gz
Merge pull request #11693 from chef/lcg/add-macos-ruby-helper
Add macos_ruby? helper and wire to the macos? helper
-rw-r--r--chef-utils/README.md1
-rw-r--r--chef-utils/lib/chef-utils/dsl/platform_family.rb13
-rw-r--r--chef-utils/lib/chef-utils/parallel_map.rb2
-rw-r--r--chef-utils/spec/unit/dsl/platform_family_spec.rb16
-rw-r--r--chef-utils/spec/unit/parallel_map_spec.rb4
5 files changed, 30 insertions, 6 deletions
diff --git a/chef-utils/README.md b/chef-utils/README.md
index 6b0052e073..9dcbd9b9ea 100644
--- a/chef-utils/README.md
+++ b/chef-utils/README.md
@@ -27,6 +27,7 @@ The Platform Family helpers provide an alternative to comparing values from `nod
* `freebsd?`
* `gentoo?`
* `macos?`
+* `macos_ruby?` - this is always true if the ruby VM is running on a mac host and is not stubbed by ChefSpec
* `netbsd?`
* `openbsd?`
* `rhel?` - includes redhat, centos, scientific, oracle, and clearos platforms
diff --git a/chef-utils/lib/chef-utils/dsl/platform_family.rb b/chef-utils/lib/chef-utils/dsl/platform_family.rb
index 10d7b35901..dd3c589e77 100644
--- a/chef-utils/lib/chef-utils/dsl/platform_family.rb
+++ b/chef-utils/lib/chef-utils/dsl/platform_family.rb
@@ -77,7 +77,7 @@ module ChefUtils
# @return [Boolean]
#
def macos?(node = __getnode)
- node["platform_family"] == "mac_os_x"
+ node ? node["platform_family"] == "mac_os_x" : macos_ruby?
end
# chef-sugar backcompat method
alias_method :osx?, :macos?
@@ -86,6 +86,17 @@ module ChefUtils
# chef-sugar backcompat method
alias_method :mac_os_x?, :macos?
+ # Determine if the Ruby VM is currently running on a Mac node (This is useful primarily for internal use
+ # by Chef Infra Client before the node object exists).
+ #
+ # @since 17.3
+ #
+ # @return [Boolean]
+ #
+ def macos_ruby?
+ !!(RUBY_PLATFORM =~ /darwin/)
+ end
+
# Determine if the current node is a member of the 'rhel' platform family (Red Hat, CentOS, Oracle or Scientific Linux, but NOT Amazon Linux or Fedora).
#
# @param [Chef::Node] node the node to check
diff --git a/chef-utils/lib/chef-utils/parallel_map.rb b/chef-utils/lib/chef-utils/parallel_map.rb
index abc8279cc5..3c1be22006 100644
--- a/chef-utils/lib/chef-utils/parallel_map.rb
+++ b/chef-utils/lib/chef-utils/parallel_map.rb
@@ -45,7 +45,7 @@ module ChefUtils
pool ||= ChefUtils::DefaultThreadPool.instance.pool
futures = map do |item|
- future = Concurrent::Future.execute(executor: pool) do
+ Concurrent::Future.execute(executor: pool) do
yield item
end
end
diff --git a/chef-utils/spec/unit/dsl/platform_family_spec.rb b/chef-utils/spec/unit/dsl/platform_family_spec.rb
index 714a9f0a45..c4363c8e8d 100644
--- a/chef-utils/spec/unit/dsl/platform_family_spec.rb
+++ b/chef-utils/spec/unit/dsl/platform_family_spec.rb
@@ -25,7 +25,7 @@ def pf_reports_true_for(*args)
expect(described_class.send(method, node)).to be true
end
end
- (PLATFORM_FAMILY_HELPERS - [ :windows_ruby? ] - args).each do |method|
+ (PLATFORM_FAMILY_HELPERS - %i{windows_ruby? macos_ruby?} - args).each do |method|
it "reports false for #{method}" do
expect(described_class.send(method, node)).to be false
end
@@ -41,7 +41,7 @@ RSpec.describe ChefUtils::DSL::PlatformFamily do
end
end
- ( PLATFORM_FAMILY_HELPERS - [ :windows_ruby? ]).each do |helper|
+ ( PLATFORM_FAMILY_HELPERS - %i{windows_ruby? macos_ruby?}).each do |helper|
it "has the #{helper} in the ChefUtils module" do
expect(ChefUtils).to respond_to(helper)
end
@@ -220,4 +220,16 @@ RSpec.describe ChefUtils::DSL::PlatformFamily do
end
end
end
+
+ context "node-independent mac APIs" do
+ if RUBY_PLATFORM.match?(/darwin/)
+ it "reports true for :macos_ruby?" do
+ expect(described_class.macos_ruby?).to be true
+ end
+ else
+ it "reports false for :macos_ruby?" do
+ expect(described_class.macos_ruby?).to be false
+ end
+ end
+ end
end
diff --git a/chef-utils/spec/unit/parallel_map_spec.rb b/chef-utils/spec/unit/parallel_map_spec.rb
index 94a1b5342c..1346a9171e 100644
--- a/chef-utils/spec/unit/parallel_map_spec.rb
+++ b/chef-utils/spec/unit/parallel_map_spec.rb
@@ -112,7 +112,7 @@ RSpec.describe ChefUtils::ParallelMap do
end
it "recursive parallel_each will not deadlock" do
- ans = Timeout.timeout(30) do
+ Timeout.timeout(30) do
(1..2).parallel_each { |i| (1..2).parallel_each { |i| i } }
end
end
@@ -125,7 +125,7 @@ RSpec.describe ChefUtils::ParallelMap do
end
it "parallel_each is lazy" do
- ans = Timeout.timeout(30) do
+ Timeout.timeout(30) do
(1..).lazy.parallel_each { |i| i }.first(5)
end
end