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-07 13:06:55 -0700
commit5612e54e0367193a71925a0b11bf3379969e523f (patch)
tree14236d60224dd3913a7ab2a6f282513037dcb26a
parentcb4383bb80656be29db6194308d6a913894ad218 (diff)
downloadchef-5612e54e0367193a71925a0b11bf3379969e523f.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 e44d4d6937..fb5dd98b07 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" }