summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2022-03-29 18:12:31 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2022-03-29 18:26:26 -0700
commit7907accc8e930ac84625970226d86f2414e444d8 (patch)
treec391a3084c31102f6e83189ce161e2066ee3fecc
parent37f3241392ecebd6be7aeffc3e0d8152b9c22e5e (diff)
downloadchef-7907accc8e930ac84625970226d86f2414e444d8.tar.gz
Fix chef15 perf regression in docker? helperlcg/chef15-perf-regression3
Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
-rw-r--r--chef-utils/lib/chef-utils/dsl/introspection.rb4
-rw-r--r--chef-utils/spec/unit/dsl/introspection_spec.rb16
-rw-r--r--spec/support/shared/unit/provider/file.rb3
-rw-r--r--spec/unit/provider/apt_update_spec.rb2
-rw-r--r--spec/unit/provider/template_spec.rb3
5 files changed, 17 insertions, 11 deletions
diff --git a/chef-utils/lib/chef-utils/dsl/introspection.rb b/chef-utils/lib/chef-utils/dsl/introspection.rb
index 4edfb8d139..e398bf045d 100644
--- a/chef-utils/lib/chef-utils/dsl/introspection.rb
+++ b/chef-utils/lib/chef-utils/dsl/introspection.rb
@@ -37,9 +37,7 @@ module ChefUtils
# @return [Boolean]
#
def docker?(node = __getnode)
- # Using "File.exist?('/.dockerinit') || File.exist?('/.dockerenv')" makes Travis sad,
- # and that makes us sad too.
- !!(node && node.read("virtualization", "systems", "docker") == "guest")
+ File.exist?("/.dockerinit") || File.exist?("/.dockerenv")
end
# Determine if the node uses the systemd init system.
diff --git a/chef-utils/spec/unit/dsl/introspection_spec.rb b/chef-utils/spec/unit/dsl/introspection_spec.rb
index 2a841dee68..7609edf63a 100644
--- a/chef-utils/spec/unit/dsl/introspection_spec.rb
+++ b/chef-utils/spec/unit/dsl/introspection_spec.rb
@@ -33,18 +33,20 @@ RSpec.describe ChefUtils::DSL::Introspection do
let(:test_instance) { IntrospectionTestClass.new(node) }
context "#docker?" do
- # FIXME: use a real VividMash for these tests instead of stubbing
it "is false by default" do
- expect(node).to receive(:read).with("virtualization", "systems", "docker").and_return(nil)
+ allow(File).to receive(:exist?).with("/.dockerinit").and_return(false)
+ allow(File).to receive(:exist?).with("/.dockerenv").and_return(false)
expect(ChefUtils.docker?(node)).to be false
end
- it "is true when ohai reports a docker guest" do
- expect(node).to receive(:read).with("virtualization", "systems", "docker").and_return("guest")
+ it "is true when /.dockerinit exists" do
+ allow(File).to receive(:exist?).with("/.dockerinit").and_return(true)
+ allow(File).to receive(:exist?).with("/.dockerenv").and_return(false)
expect(ChefUtils.docker?(node)).to be true
end
- it "is false for any other value other than guest" do
- expect(node).to receive(:read).with("virtualization", "systems", "docker").and_return("some nonsense")
- expect(ChefUtils.docker?(node)).to be false
+ it "is true when /.dockerenv exists" do
+ allow(File).to receive(:exist?).with("/.dockerinit").and_return(false)
+ allow(File).to receive(:exist?).with("/.dockerenv").and_return(true)
+ expect(ChefUtils.docker?(node)).to be true
end
end
diff --git a/spec/support/shared/unit/provider/file.rb b/spec/support/shared/unit/provider/file.rb
index 654765e82d..af4f165a98 100644
--- a/spec/support/shared/unit/provider/file.rb
+++ b/spec/support/shared/unit/provider/file.rb
@@ -36,7 +36,7 @@ end
# forwards-vs-reverse slashes on windows sucks
def windows_path
- windows? ? normalized_path.tr('\\', "/") : normalized_path
+ windows? ? normalized_path.tr("\\", "/") : normalized_path
end
# this is all getting a bit stupid, CHEF-4802 cut to remove all this
@@ -139,6 +139,7 @@ shared_examples_for Chef::Provider::File do
allow(content).to receive(:tempfile).and_return(tempfile)
allow(File).to receive(:exist?).with(tempfile.path).and_call_original
allow(File).to receive(:exists?).with(tempfile.path).and_call_original
+ allow(resource).to receive(:docker?).and_return(false)
end
after do
diff --git a/spec/unit/provider/apt_update_spec.rb b/spec/unit/provider/apt_update_spec.rb
index 6e11235e30..bb8db7930f 100644
--- a/spec/unit/provider/apt_update_spec.rb
+++ b/spec/unit/provider/apt_update_spec.rb
@@ -82,6 +82,7 @@ describe "Chef::Provider::AptUpdate" do
it "should run if the time stamp is old" do
expect(File).to receive(:mtime).with("#{stamp_dir}/update-success-stamp").and_return(Time.now - 86_500)
+ allow_any_instance_of(Chef::Resource::File).to receive(:docker?).and_return(false)
expect_any_instance_of(Chef::Provider::Execute).to receive(:shell_out_compacted!).with(*apt_update_cmd, anything)
provider.run_action(:periodic)
expect(new_resource).to be_updated_by_last_action
@@ -101,6 +102,7 @@ describe "Chef::Provider::AptUpdate" do
it "should run if the time stamp is old" do
expect(File).to receive(:mtime).with("#{stamp_dir}/update-success-stamp").and_return(Time.now - 500)
+ allow_any_instance_of(Chef::Resource::File).to receive(:docker?).and_return(false)
expect_any_instance_of(Chef::Provider::Execute).to receive(:shell_out_compacted!).with(*apt_update_cmd, anything)
provider.run_action(:periodic)
expect(new_resource).to be_updated_by_last_action
diff --git a/spec/unit/provider/template_spec.rb b/spec/unit/provider/template_spec.rb
index 84cbfc5d08..63f366479a 100644
--- a/spec/unit/provider/template_spec.rb
+++ b/spec/unit/provider/template_spec.rb
@@ -57,6 +57,9 @@ describe Chef::Provider::Template do
it_behaves_like Chef::Provider::File
context "when creating the template" do
+ before(:each) do
+ allow(resource).to receive(:docker?).and_return(false)
+ end
let(:enclosing_directory) do
canonicalize_path(File.expand_path(File.join(CHEF_SPEC_DATA, "templates")))