diff options
author | Tim Smith <tsmith@chef.io> | 2021-04-07 20:01:40 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-07 20:01:40 -0700 |
commit | 4e9f9a5c72d89716d741bb2094be607481ca4ea7 (patch) | |
tree | fbaab0a50acc9ddae553849d1c9f4f66d1ce35dc | |
parent | aa33ea719c0e8c99008504fe19fc89981aff8427 (diff) | |
parent | 5dec823581b689cc3fd85ef3943b469293bc487d (diff) | |
download | chef-4e9f9a5c72d89716d741bb2094be607481ca4ea7.tar.gz |
Merge pull request #11331 from ramereth/chef-16-centos-stream-helper
Chef 16: Add centos_stream_platform? helper
-rw-r--r-- | chef-utils/lib/chef-utils/dsl/platform.rb | 15 | ||||
-rw-r--r-- | chef-utils/spec/unit/dsl/platform_spec.rb | 14 |
2 files changed, 29 insertions, 0 deletions
diff --git a/chef-utils/lib/chef-utils/dsl/platform.rb b/chef-utils/lib/chef-utils/dsl/platform.rb index f44cb811bb..047c742dc8 100644 --- a/chef-utils/lib/chef-utils/dsl/platform.rb +++ b/chef-utils/lib/chef-utils/dsl/platform.rb @@ -123,6 +123,21 @@ module ChefUtils # chef-sugar backcompat method alias_method :centos?, :centos_platform? + # Determine if the current node is CentOS Stream. + # + # @param [Chef::Node] node the node to check + # @since 16.13 + # + # @return [Boolean] + # + def centos_stream_platform?(node = __getnode) + if node["os_release"] + node.dig("os_release", "name") == "CentOS Stream" + else + node.dig("lsb", "id") == "CentOSStream" + end + end + # Determine if the current node is Oracle Linux. # # @param [Chef::Node] node the node to check diff --git a/chef-utils/spec/unit/dsl/platform_spec.rb b/chef-utils/spec/unit/dsl/platform_spec.rb index 216e15f112..8ebdcbae8f 100644 --- a/chef-utils/spec/unit/dsl/platform_spec.rb +++ b/chef-utils/spec/unit/dsl/platform_spec.rb @@ -145,6 +145,20 @@ RSpec.describe ChefUtils::DSL::Platform do platform_reports_true_for(:centos?, :centos_platform?) end + context "on centos stream w/o os_release" do + let(:options) { { platform: "centos" } } + let(:node) { { "platform" => "centos", "platform_version" => "8", "platform_family" => "rhel", "os" => "linux", "lsb" => { "id" => "CentOSStream" }, "os_release" => nil } } + + platform_reports_true_for(:centos?, :centos_platform?, :centos_stream_platform?) + end + + context "on centos stream w/ os_release" do + let(:options) { { platform: "centos" } } + let(:node) { { "platform" => "centos", "platform_version" => "8", "platform_family" => "rhel", "os" => "linux", "os_release" => { "name" => "CentOS Stream" } } } + + platform_reports_true_for(:centos?, :centos_platform?, :centos_stream_platform?) + end + context "on clearos" do let(:options) { { platform: "clearos" } } |