summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith84@gmail.com>2020-04-07 13:06:55 -0700
committerTim Smith <tsmith84@gmail.com>2020-04-10 15:47:57 -0700
commit4257dc12aba45c2b4e23fe383300a1bfdd350a16 (patch)
treef07a776da0026fde3f9f93d6ded24c35098ba621
parente9edd60143ecebd592450eec4a22a1d7909cd8fc (diff)
downloadchef-4257dc12aba45c2b4e23fe383300a1bfdd350a16.tar.gz
Add arm? helper to chef-utils
It's tagged as first shipping in chef 15.10 since I plan to backport this and that'll make sense in the docs. Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r--chef-utils/README.md14
-rw-r--r--chef-utils/lib/chef-utils/dsl/architecture.rb11
-rw-r--r--chef-utils/spec/unit/dsl/architecture_spec.rb8
3 files changed, 24 insertions, 9 deletions
diff --git a/chef-utils/README.md b/chef-utils/README.md
index 36ca1810d4..40e5583d34 100644
--- a/chef-utils/README.md
+++ b/chef-utils/README.md
@@ -108,17 +108,21 @@ The OS helpers provide an alternative to comparing data from `node['os']`.
Architecture Helpers allow you to determine the processor architecture of your node.
-* `_64_bit?`
* `_32_bit?`
+* `_64_bit?`
+* `aarch64?`
+* `arch64?`
+* `arm64?`
+* `arm?`
+* `armhf?`
* `i386?`
* `intel?`
-* `sparc?`
+* `powerpc?`
* `ppc64?`
* `ppc64le?`
-* `powerpc?`
-* `armhf?`
-* `s390x?`
* `s390?`
+* `s390x?`
+* `sparc?`
### Cloud Helpers
diff --git a/chef-utils/lib/chef-utils/dsl/architecture.rb b/chef-utils/lib/chef-utils/dsl/architecture.rb
index d20c6c5a76..30e908d694 100644
--- a/chef-utils/lib/chef-utils/dsl/architecture.rb
+++ b/chef-utils/lib/chef-utils/dsl/architecture.rb
@@ -103,6 +103,17 @@ module ChefUtils
%w{powerpc}.include?(node["kernel"]["machine"])
end
+ # Determine if the current architecture is arm
+ #
+ # @since 15.10
+ #
+ # @return [Boolean]
+ #
+ def arm?(node = __getnode)
+ %w{armhf aarch64 arm64 arch64}
+ .include?(node["kernel"]["machine"])
+ end
+
# Determine if the current architecture is 32-bit ARM.
#
# @since 15.5
diff --git a/chef-utils/spec/unit/dsl/architecture_spec.rb b/chef-utils/spec/unit/dsl/architecture_spec.rb
index a2ce300fe0..c43b2d0733 100644
--- a/chef-utils/spec/unit/dsl/architecture_spec.rb
+++ b/chef-utils/spec/unit/dsl/architecture_spec.rb
@@ -84,17 +84,17 @@ RSpec.describe ChefUtils::DSL::Architecture do
context "on aarch64" do
let(:arch) { "aarch64" }
- arch_reports_true_for(:_64_bit?)
+ arch_reports_true_for(:_64_bit?, :arm?)
end
context "on arch64" do
let(:arch) { "arch64" }
- arch_reports_true_for(:_64_bit?)
+ arch_reports_true_for(:_64_bit?, :arm?)
end
context "on arm64" do
let(:arch) { "arm64" }
- arch_reports_true_for(:_64_bit?)
+ arch_reports_true_for(:_64_bit?, :arm?)
end
context "on sun4v" do
let(:arch) { "sun4v" }
@@ -129,7 +129,7 @@ RSpec.describe ChefUtils::DSL::Architecture do
context "on armhf" do
let(:arch) { "armhf" }
- arch_reports_true_for(:armhf?, :_32_bit?)
+ arch_reports_true_for(:armhf?, :_32_bit?, :arm?)
end
context "on s390" do
let(:arch) { "s390" }