diff options
author | Lance Albertson <lance@osuosl.org> | 2021-04-06 13:00:32 -0700 |
---|---|---|
committer | Lance Albertson <lance@osuosl.org> | 2021-04-07 17:28:18 -0700 |
commit | 64d9b27945f3fd4986ac7d670b1436a052d42827 (patch) | |
tree | d007ccae0c1e5358bb06b60244f5fb6b9863b5bd /chef-utils | |
parent | c881e323e867727b759d0fde947c4ff8f511c0a2 (diff) | |
download | chef-64d9b27945f3fd4986ac7d670b1436a052d42827.tar.gz |
Switch to using lsb/id node data for centos_stream_platform? helper
This simplifies the previous commit to just rely on ohai node data coming from
the lsb plugin instead of doing the work ohai is already doing. This of course
assumes that lsb_release exists on the system for it to work.
Signed-off-by: Lance Albertson <lance@osuosl.org>
Diffstat (limited to 'chef-utils')
-rw-r--r-- | chef-utils/lib/chef-utils/dsl/platform.rb | 7 | ||||
-rw-r--r-- | chef-utils/spec/unit/dsl/platform_spec.rb | 140 |
2 files changed, 37 insertions, 110 deletions
diff --git a/chef-utils/lib/chef-utils/dsl/platform.rb b/chef-utils/lib/chef-utils/dsl/platform.rb index c90117cb33..8dd852af3e 100644 --- a/chef-utils/lib/chef-utils/dsl/platform.rb +++ b/chef-utils/lib/chef-utils/dsl/platform.rb @@ -17,13 +17,11 @@ # require_relative "../internal" -require_relative "train_helpers" module ChefUtils module DSL module Platform include Internal - include TrainHelpers # NOTE: if you are adding new platform helpers they should all have the `_platform?` suffix. # DO NOT add new short aliases without the suffix (they will be deprecated in the future) @@ -127,12 +125,13 @@ module ChefUtils # Determine if the current node is CentOS Stream. # + # @param [Chef::Node] node the node to check # @since 17.0 # # @return [Boolean] # - def centos_stream_platform? - file_exist?("/etc/os-release") && file_read("/etc/os-release").match?("CentOS Stream") + def centos_stream_platform?(node = __getnode) + node.dig("lsb", "id") == "CentOSStream" end # Determine if the current node is Oracle Linux. diff --git a/chef-utils/spec/unit/dsl/platform_spec.rb b/chef-utils/spec/unit/dsl/platform_spec.rb index 7d2b353b38..997d1d5f43 100644 --- a/chef-utils/spec/unit/dsl/platform_spec.rb +++ b/chef-utils/spec/unit/dsl/platform_spec.rb @@ -21,67 +21,34 @@ require "fauxhai" def platform_reports_true_for(*args) args.each do |method| - if method.match?("centos_stream_platform") - it "reports true for #{method} on the module given a node" do - expect(described_class.send(method)).to be true - end - it "reports true for #{method} when mixed into a class with a node" do - expect(thing_with_a_node.send(method)).to be true - end - it "reports true for #{method} when mixed into a class with a run_context" do - expect(thing_with_a_run_context.send(method)).to be true - end - it "reports true for #{method} when mixed into a class with the dsl" do - expect(thing_with_the_dsl.send(method)).to be true - end - it "reports true for #{method} on the main class give a node" do - expect(ChefUtils.send(method)).to be true - end - else - it "reports true for #{method} on the module given a node" do - expect(described_class.send(method, node)).to be true - end - it "reports true for #{method} when mixed into a class with a node" do - expect(thing_with_a_node.send(method, node)).to be true - end - it "reports true for #{method} when mixed into a class with a run_context" do - expect(thing_with_a_run_context.send(method, node)).to be true - end - it "reports true for #{method} when mixed into a class with the dsl" do - expect(thing_with_the_dsl.send(method, node)).to be true - end - it "reports true for #{method} on the main class give a node" do - expect(ChefUtils.send(method, node)).to be true - end + it "reports true for #{method} on the module given a node" do + expect(described_class.send(method, node)).to be true + end + it "reports true for #{method} when mixed into a class with a node" do + expect(thing_with_a_node.send(method, node)).to be true + end + it "reports true for #{method} when mixed into a class with a run_context" do + expect(thing_with_a_run_context.send(method, node)).to be true + end + it "reports true for #{method} when mixed into a class with the dsl" do + expect(thing_with_the_dsl.send(method, node)).to be true + end + it "reports true for #{method} on the main class give a node" do + expect(ChefUtils.send(method, node)).to be true end end - (PLATFORM_HELPERS - ChefUtils::DSL::TrainHelpers.methods - args).each do |method| - if method.match?("centos_stream_platform") - it "reports false for #{method} on the module given a node" do - expect(described_class.send(method)).to be false - end - it "reports false for #{method} when mixed into a class with a node" do - expect(thing_with_a_node.send(method)).to be false - end - it "reports false for #{method} when mixed into a class with the dsl" do - expect(thing_with_the_dsl.send(method)).to be false - end - it "reports false for #{method} on the main class give a node" do - expect(ChefUtils.send(method)).to be false - end - else - it "reports false for #{method} on the module given a node" do - expect(described_class.send(method, node)).to be false - end - it "reports false for #{method} when mixed into a class with a node" do - expect(thing_with_a_node.send(method, node)).to be false - end - it "reports false for #{method} when mixed into a class with the dsl" do - expect(thing_with_the_dsl.send(method, node)).to be false - end - it "reports false for #{method} on the main class give a node" do - expect(ChefUtils.send(method, node)).to be false - end + (PLATFORM_HELPERS - args).each do |method| + it "reports false for #{method} on the module given a node" do + expect(described_class.send(method, node)).to be false + end + it "reports false for #{method} when mixed into a class with a node" do + expect(thing_with_a_node.send(method, node)).to be false + end + it "reports false for #{method} when mixed into a class with the dsl" do + expect(thing_with_the_dsl.send(method, node)).to be false + end + it "reports false for #{method} on the main class give a node" do + expect(ChefUtils.send(method, node)).to be false end end end @@ -126,7 +93,7 @@ RSpec.describe ChefUtils::DSL::Platform do ( HELPER_MODULES - [ described_class ] ).each do |klass| it "does not have methods that collide with #{klass}" do - expect((klass.methods - Module.methods - ChefUtils::DSL::TrainHelpers.methods ) & PLATFORM_HELPERS).to be_empty + expect((klass.methods - Module.methods) & PLATFORM_HELPERS).to be_empty end end @@ -178,6 +145,13 @@ RSpec.describe ChefUtils::DSL::Platform do platform_reports_true_for(:centos?, :centos_platform?) end + context "on centos stream" do + let(:options) { { platform: "centos" } } + let(:node) { { "platform" => "centos", "platform_version" => "8", "platform_family" => "rhel", "os" => "linux", "lsb" => { "id" => "CentOSStream" } } } + + platform_reports_true_for(:centos?, :centos_platform?, :centos_stream_platform?) + end + context "on clearos" do let(:options) { { platform: "clearos" } } @@ -269,49 +243,3 @@ RSpec.describe ChefUtils::DSL::Platform do end end - -RSpec.describe ChefUtils::DSL::Platform do - class PlatformTestClass - include ChefUtils::DSL::Platform - end - - let(:test_instance) { PlatformTestClass.new } - - let(:os_release_stream) do - <<~OS_RELEASE - NAME="CentOS Stream" - VERSION="8" - ID="centos" - ID_LIKE="rhel fedora" - VERSION_ID="8" - PRETTY_NAME="CentOS Stream 8" - OS_RELEASE - end - - let(:os_release_centos) do - <<~OS_RELEASE - NAME="CentOS Linux" - VERSION="8" - ID="centos" - ID_LIKE="rhel fedora" - VERSION_ID="8" - PRETTY_NAME="CentOS Linux 8" - OS_RELEASE - end - - context "on centos stream" do - it "returns true if on centos_stream_platform?" do - expect(File).to receive(:exist?).with("/etc/os-release").and_return(true) - expect(File).to receive(:open).with("/etc/os-release").and_return(StringIO.new(os_release_stream)) - expect(test_instance.centos_stream_platform?).to be true - end - end - - context "on centos linux" do - it "returns false if on centos_stream_platform?" do - expect(File).to receive(:exist?).with("/etc/os-release").and_return(true) - expect(File).to receive(:open).with("/etc/os-release").and_return(StringIO.new(os_release_centos)) - expect(test_instance.centos_stream_platform?).to be false - end - end -end |