summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2017-09-14 18:08:23 -0700
committerTim Smith <tsmith@chef.io>2017-09-14 18:50:53 -0700
commit114c7786670c180c15cfc152432a7df1c0b1fc52 (patch)
treed7aab36d8c3cd081813c80dc4f476951d4692336
parentfe65320e7d009cd8822b9060ff910c57766693ec (diff)
downloadchef-114c7786670c180c15cfc152432a7df1c0b1fc52.tar.gz
Replace which apt-get check with simple debian check in apt resources
apt-get is a link to yast2 in suse so these resources fire there when someone wouldn't expect them to. Looking back we probably should have skipped the whole platform based no-op thing, but that ship sailed. This makes it behave the way a user would expect it to. What happens if you have apt compiled on your gentoo box? Well it's going to break. We'll just have to live with fixing it for 99.99% of users instead of the current 95%. Also: This is faster. Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r--lib/chef/provider/apt_preference.rb7
-rw-r--r--lib/chef/provider/apt_repository.rb6
-rw-r--r--lib/chef/provider/apt_update.rb8
-rw-r--r--lib/chef/resource/apt_preference.rb2
-rw-r--r--lib/chef/resource/apt_repository.rb4
-rw-r--r--lib/chef/resource/apt_update.rb2
-rw-r--r--spec/unit/provider/apt_repository_spec.rb2
-rw-r--r--spec/unit/resource/apt_preference_spec.rb18
-rw-r--r--spec/unit/resource/apt_repository_spec.rb24
-rw-r--r--spec/unit/resource/apt_update_spec.rb24
10 files changed, 54 insertions, 43 deletions
diff --git a/lib/chef/provider/apt_preference.rb b/lib/chef/provider/apt_preference.rb
index 55356dab94..5e19c33ce7 100644
--- a/lib/chef/provider/apt_preference.rb
+++ b/lib/chef/provider/apt_preference.rb
@@ -19,17 +19,12 @@
require "chef/provider"
require "chef/dsl/declare_resource"
require "chef/provider/noop"
-require "chef/mixin/which"
require "chef/log"
class Chef
class Provider
class AptPreference < Chef::Provider
- extend Chef::Mixin::Which
-
- provides :apt_preference do
- which("apt-get")
- end
+ provides :apt_preference, os: "linux", platform_family: [ "debian" ]
APT_PREFERENCE_DIR = "/etc/apt/preferences.d".freeze
diff --git a/lib/chef/provider/apt_repository.rb b/lib/chef/provider/apt_repository.rb
index d8995acd3d..6ef79a6902 100644
--- a/lib/chef/provider/apt_repository.rb
+++ b/lib/chef/provider/apt_repository.rb
@@ -19,7 +19,6 @@
require "chef/resource"
require "chef/dsl/declare_resource"
require "chef/mixin/shell_out"
-require "chef/mixin/which"
require "chef/http/simple"
require "chef/provider/noop"
@@ -27,11 +26,8 @@ class Chef
class Provider
class AptRepository < Chef::Provider
include Chef::Mixin::ShellOut
- extend Chef::Mixin::Which
- provides :apt_repository do
- which("apt-get")
- end
+ provides :apt_repository, os: "linux", platform_family: [ "debian" ]
LIST_APT_KEYS = "apt-key list".freeze
LIST_APT_KEY_FINGERPRINTS = "apt-key adv --list-public-keys --with-fingerprint --with-colons".freeze
diff --git a/lib/chef/provider/apt_update.rb b/lib/chef/provider/apt_update.rb
index 670f3ad7f6..b0a04a95e4 100644
--- a/lib/chef/provider/apt_update.rb
+++ b/lib/chef/provider/apt_update.rb
@@ -18,16 +18,12 @@
require "chef/provider"
require "chef/provider/noop"
-require "chef/mixin/which"
+require "chef/dsl/declare_resource"
class Chef
class Provider
class AptUpdate < Chef::Provider
- extend Chef::Mixin::Which
-
- provides :apt_update do
- which("apt-get")
- end
+ provides :apt_update, os: "linux", platform_family: [ "debian" ]
APT_CONF_DIR = "/etc/apt/apt.conf.d"
STAMP_DIR = "/var/lib/apt/periodic"
diff --git a/lib/chef/resource/apt_preference.rb b/lib/chef/resource/apt_preference.rb
index 603766d76b..b610f538a6 100644
--- a/lib/chef/resource/apt_preference.rb
+++ b/lib/chef/resource/apt_preference.rb
@@ -22,7 +22,7 @@ class Chef
class Resource
class AptPreference < Chef::Resource
resource_name :apt_preference
- provides :apt_preference
+ provides :apt_preference, os: "linux", platform_family: [ "debian" ]
property :package_name, String, name_property: true, regex: [/^([a-z]|[A-Z]|[0-9]|_|-|\.|\*|\+)+$/]
property :glob, String
diff --git a/lib/chef/resource/apt_repository.rb b/lib/chef/resource/apt_repository.rb
index 3a2d30be2c..0b2388d96b 100644
--- a/lib/chef/resource/apt_repository.rb
+++ b/lib/chef/resource/apt_repository.rb
@@ -1,6 +1,6 @@
#
# Author:: Thom May (<thom@chef.io>)
-# Copyright:: Copyright (c) 2016 Chef Software, Inc.
+# Copyright:: 2016-2017, Chef Software, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -22,7 +22,7 @@ class Chef
class Resource
class AptRepository < Chef::Resource
resource_name :apt_repository
- provides :apt_repository
+ provides :apt_repository, os: "linux", platform_family: [ "debian" ]
property :repo_name, String, name_property: true
property :uri, String
diff --git a/lib/chef/resource/apt_update.rb b/lib/chef/resource/apt_update.rb
index 67ca7fbfea..b985957529 100644
--- a/lib/chef/resource/apt_update.rb
+++ b/lib/chef/resource/apt_update.rb
@@ -22,7 +22,7 @@ class Chef
class Resource
class AptUpdate < Chef::Resource
resource_name :apt_update
- provides :apt_update
+ provides :apt_update, os: "linux", platform_family: [ "debian" ]
# allow bare apt_update with no name
property :name, String, default: ""
diff --git a/spec/unit/provider/apt_repository_spec.rb b/spec/unit/provider/apt_repository_spec.rb
index 6180582d69..cabf6551c9 100644
--- a/spec/unit/provider/apt_repository_spec.rb
+++ b/spec/unit/provider/apt_repository_spec.rb
@@ -1,6 +1,6 @@
#
# Author:: Thom May (<thom@chef.io>)
-# Copyright:: Copyright (c) 2016 Chef Software, Inc.
+# Copyright:: 2016-2017, Chef Software, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/spec/unit/resource/apt_preference_spec.rb b/spec/unit/resource/apt_preference_spec.rb
index 801434b4f3..66bb6e64bb 100644
--- a/spec/unit/resource/apt_preference_spec.rb
+++ b/spec/unit/resource/apt_preference_spec.rb
@@ -24,18 +24,26 @@ describe Chef::Resource::AptPreference do
let(:run_context) { Chef::RunContext.new(node, {}, events) }
let(:resource) { Chef::Resource::AptPreference.new("libmysqlclient16", run_context) }
- it "should create a new Chef::Resource::AptPreference" do
+ it "creates a new Chef::Resource::AptPreference" do
expect(resource).to be_a_kind_of(Chef::Resource)
expect(resource).to be_a_kind_of(Chef::Resource::AptPreference)
end
- it "should resolve to a Noop class when apt-get is not found" do
- expect(Chef::Provider::AptPreference).to receive(:which).with("apt-get").and_return(false)
+ it "resolves to a Noop class when on non-linux OS" do
+ node.automatic[:os] = "windows"
+ node.automatic[:platform_family] = "windows"
expect(resource.provider_for_action(:add)).to be_a(Chef::Provider::Noop)
end
- it "should resolve to a AptPreference class when apt-get is found" do
- expect(Chef::Provider::AptPreference).to receive(:which).with("apt-get").and_return(true)
+ it "resolves to a Noop class when on non-debian linux" do
+ node.automatic[:os] = "linux"
+ node.automatic[:platform_family] = "gentoo"
+ expect(resource.provider_for_action(:add)).to be_a(Chef::Provider::Noop)
+ end
+
+ it "resolves to a AptUpdate class when on a debian platform_family" do
+ node.automatic[:os] = "linux"
+ node.automatic[:platform_family] = "debian"
expect(resource.provider_for_action(:add)).to be_a(Chef::Provider::AptPreference)
end
end
diff --git a/spec/unit/resource/apt_repository_spec.rb b/spec/unit/resource/apt_repository_spec.rb
index 69cf94ae56..812fa0c843 100644
--- a/spec/unit/resource/apt_repository_spec.rb
+++ b/spec/unit/resource/apt_repository_spec.rb
@@ -1,6 +1,6 @@
#
# Author:: Thom May (<thom@chef.io>)
-# Copyright:: Copyright (c) 2016 Chef Software, Inc.
+# Copyright:: 2016-2017, Chef Software, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -24,27 +24,35 @@ describe Chef::Resource::AptRepository do
let(:run_context) { Chef::RunContext.new(node, {}, events) }
let(:resource) { Chef::Resource::AptRepository.new("multiverse", run_context) }
- it "should create a new Chef::Resource::AptRepository" do
+ it "creates a new Chef::Resource::AptRepository" do
expect(resource).to be_a_kind_of(Chef::Resource)
expect(resource).to be_a_kind_of(Chef::Resource::AptRepository)
end
- it "the default keyserver should be keyserver.ubuntu.com" do
+ it "uses keyserver.ubuntu.com as the keyserver" do
expect(resource.keyserver).to eql("keyserver.ubuntu.com")
end
- it "the default distribution should be nillable" do
+ it "default distribution is nillable" do
expect(resource.distribution(nil)).to eql(nil)
expect(resource.distribution).to eql(nil)
end
- it "should resolve to a Noop class when apt-get is not found" do
- expect(Chef::Provider::AptRepository).to receive(:which).with("apt-get").and_return(false)
+ it "resolves to a Noop class when on non-linux OS" do
+ node.automatic[:os] = "windows"
+ node.automatic[:platform_family] = "windows"
expect(resource.provider_for_action(:add)).to be_a(Chef::Provider::Noop)
end
- it "should resolve to a AptRepository class when apt-get is found" do
- expect(Chef::Provider::AptRepository).to receive(:which).with("apt-get").and_return(true)
+ it "resolves to a Noop class when on non-debian linux" do
+ node.automatic[:os] = "linux"
+ node.automatic[:platform_family] = "gentoo"
+ expect(resource.provider_for_action(:add)).to be_a(Chef::Provider::Noop)
+ end
+
+ it "resolves to a AptUpdate class when on a debian platform_family" do
+ node.automatic[:os] = "linux"
+ node.automatic[:platform_family] = "debian"
expect(resource.provider_for_action(:add)).to be_a(Chef::Provider::AptRepository)
end
end
diff --git a/spec/unit/resource/apt_update_spec.rb b/spec/unit/resource/apt_update_spec.rb
index dd72b18063..6b20092c56 100644
--- a/spec/unit/resource/apt_update_spec.rb
+++ b/spec/unit/resource/apt_update_spec.rb
@@ -1,6 +1,6 @@
#
# Author:: Thom May (<thom@chef.io>)
-# Copyright:: Copyright (c) 2016 Chef Software, Inc.
+# Copyright:: 2016-2017, Chef Software, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -24,27 +24,35 @@ describe Chef::Resource::AptUpdate do
let(:run_context) { Chef::RunContext.new(node, {}, events) }
let(:resource) { Chef::Resource::AptUpdate.new("update", run_context) }
- it "should create a new Chef::Resource::AptUpdate" do
+ it "creates a new Chef::Resource::AptUpdate" do
expect(resource).to be_a_kind_of(Chef::Resource)
expect(resource).to be_a_kind_of(Chef::Resource::AptUpdate)
end
- it "the default frequency should be 1 day" do
+ it "default frequency is set to be 1 day" do
expect(resource.frequency).to eql(86_400)
end
- it "the frequency should accept integers" do
+ it "frequency accepts integers" do
resource.frequency(400)
expect(resource.frequency).to eql(400)
end
- it "should resolve to a Noop class when apt-get is not found" do
- expect(Chef::Provider::AptUpdate).to receive(:which).with("apt-get").and_return(false)
+ it "resolves to a Noop class when on non-linux OS" do
+ node.automatic[:os] = "windows"
+ node.automatic[:platform_family] = "windows"
expect(resource.provider_for_action(:add)).to be_a(Chef::Provider::Noop)
end
- it "should resolve to a AptUpdate class when apt-get is found" do
- expect(Chef::Provider::AptUpdate).to receive(:which).with("apt-get").and_return(true)
+ it "resolves to a Noop class when on non-debian linux" do
+ node.automatic[:os] = "linux"
+ node.automatic[:platform_family] = "gentoo"
+ expect(resource.provider_for_action(:add)).to be_a(Chef::Provider::Noop)
+ end
+
+ it "resolves to a AptUpdate class when on a debian platform_family" do
+ node.automatic[:os] = "linux"
+ node.automatic[:platform_family] = "debian"
expect(resource.provider_for_action(:add)).to be_a(Chef::Provider::AptUpdate)
end
end