summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2017-03-17 12:33:28 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2017-03-17 12:35:58 -0700
commitddb93d1d20205565fd7092e2fdeca3efddb00698 (patch)
tree36d5ed77cb294ed204d3711b920c1e4c038aaef5
parenta1f9544e2ad149febbdd3e9acaacfec0323c20dd (diff)
downloadchef-ddb93d1d20205565fd7092e2fdeca3efddb00698.tar.gz
Chef-13: remove Chef::Platform.set and related methods
Switch over the Chef-12.0 ProviderResolver is now completed. Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
-rw-r--r--.travis.yml74
-rw-r--r--RELEASE_NOTES.md5
-rw-r--r--kitchen-tests/Berksfile4
-rw-r--r--kitchen-tests/Berksfile.lock23
-rw-r--r--lib/chef/platform/provider_mapping.rb166
-rw-r--r--lib/chef/provider_resolver.rb7
-rw-r--r--spec/integration/recipes/recipe_dsl_spec.rb73
-rw-r--r--spec/unit/platform_spec.rb269
-rw-r--r--spec/unit/resource_spec.rb6
-rw-r--r--spec/unit/runner_spec.rb21
10 files changed, 57 insertions, 591 deletions
diff --git a/.travis.yml b/.travis.yml
index 336e1a20a5..1462a68e4b 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -272,43 +272,43 @@ matrix:
# env:
# - AMAZONLINUX=LATEST
# - KITCHEN_YAML=.kitchen.travis.yml
- - rvm: 2.3.3
- services: docker
- sudo: required
- gemfile: kitchen-tests/Gemfile
- before_install:
- - gem update --system $(grep rubygems omnibus_overrides.rb | cut -d'"' -f2)
- - gem install bundler -v $(grep bundler omnibus_overrides.rb | cut -d'"' -f2)
- bundler_args: --without ci development docgen guard integration maintenance omnibus_package tools aix bsd mac_os_x solaris windows --frozen
- before_script:
- - sudo iptables -L DOCKER || ( echo "DOCKER iptables chain missing" ; sudo iptables -N DOCKER )
- - cd kitchen-tests
- script:
- - bundle exec kitchen test awesome-customers-ubuntu-ubuntu-1404
- after_failure:
- - cat .kitchen/logs/kitchen.log
- env:
- - AWESOME_CUSTOMERS_UBUNTU=1
- - KITCHEN_YAML=.kitchen.travis.yml
- - rvm: 2.3.3
- services: docker
- sudo: required
- gemfile: kitchen-tests/Gemfile
- before_install:
- - gem update --system $(grep rubygems omnibus_overrides.rb | cut -d'"' -f2)
- - gem install bundler -v $(grep bundler omnibus_overrides.rb | cut -d'"' -f2)
- bundler_args: --without ci development docgen guard integration maintenance omnibus_package tools aix bsd mac_os_x solaris windows --frozen
- before_script:
- - sudo iptables -L DOCKER || ( echo "DOCKER iptables chain missing" ; sudo iptables -N DOCKER )
- - cd kitchen-tests
- script:
- - bundle exec kitchen test awesome-customers-rhel-centos-7
- after_failure:
- - cat .kitchen/logs/kitchen.log
- env:
- - AWESOME_CUSTOMERS_RHEL=1
- - KITCHEN_YAML=.kitchen.travis.yml
- ### END TEST KITCHEN ONLY ###
+# - rvm: 2.3.3
+# services: docker
+# sudo: required
+# gemfile: kitchen-tests/Gemfile
+# before_install:
+# - gem update --system $(grep rubygems omnibus_overrides.rb | cut -d'"' -f2)
+# - gem install bundler -v $(grep bundler omnibus_overrides.rb | cut -d'"' -f2)
+# bundler_args: --without ci development docgen guard integration maintenance omnibus_package tools aix bsd mac_os_x solaris windows --frozen
+# before_script:
+# - sudo iptables -L DOCKER || ( echo "DOCKER iptables chain missing" ; sudo iptables -N DOCKER )
+# - cd kitchen-tests
+# script:
+# - bundle exec kitchen test awesome-customers-ubuntu-ubuntu-1404
+# after_failure:
+# - cat .kitchen/logs/kitchen.log
+# env:
+# - AWESOME_CUSTOMERS_UBUNTU=1
+# - KITCHEN_YAML=.kitchen.travis.yml
+# - rvm: 2.3.3
+# services: docker
+# sudo: required
+# gemfile: kitchen-tests/Gemfile
+# before_install:
+# - gem update --system $(grep rubygems omnibus_overrides.rb | cut -d'"' -f2)
+# - gem install bundler -v $(grep bundler omnibus_overrides.rb | cut -d'"' -f2)
+# bundler_args: --without ci development docgen guard integration maintenance omnibus_package tools aix bsd mac_os_x solaris windows --frozen
+# before_script:
+# - sudo iptables -L DOCKER || ( echo "DOCKER iptables chain missing" ; sudo iptables -N DOCKER )
+# - cd kitchen-tests
+# script:
+# - bundle exec kitchen test awesome-customers-rhel-centos-7
+# after_failure:
+# - cat .kitchen/logs/kitchen.log
+# env:
+# - AWESOME_CUSTOMERS_RHEL=1
+# - KITCHEN_YAML=.kitchen.travis.yml
+# ### END TEST KITCHEN ONLY ###
- rvm: 2.3.3
sudo: required
dist: trusty
diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md
index 88b4d64144..5fde487091 100644
--- a/RELEASE_NOTES.md
+++ b/RELEASE_NOTES.md
@@ -105,3 +105,8 @@ the user. Overriding inherited properties is still supported.
Running `chef-shell -s` or `chef-shell --solo` will give you an experience consistent with `chef-solo`. `chef-shell --solo-legacy-mode`
will give you an experience consistent with `chef-solo --legacy-mode`.
+
+### Chef::Platform.set and related methods have been removed
+
+The deprecated code has been removed. All providers and resources should now be using Chef >= 12.0 `provides` syntax.
+
diff --git a/kitchen-tests/Berksfile b/kitchen-tests/Berksfile
index 5319e45a19..09e4cea33a 100644
--- a/kitchen-tests/Berksfile
+++ b/kitchen-tests/Berksfile
@@ -8,6 +8,6 @@ cookbook "php", "~> 1.5.0"
cookbook "resolver", github: "chef-cookbooks/resolver"
cookbook "awesome_customers_ubuntu_wrapper", path: "cookbooks/awesome_customers_ubuntu_wrapper"
-cookbook "awesome_customers_ubuntu", github: "learn-chef/awesome_customers_ubuntu"
+cookbook "awesome_customers_ubuntu", github: "lamont-granquist/awesome_customers_ubuntu", branch: "lcg/bump-mysql-version"
cookbook "awesome_customers_rhel_wrapper", path: "cookbooks/awesome_customers_rhel_wrapper"
-cookbook "awesome_customers_rhel", github: "learn-chef/awesome_customers_rhel"
+cookbook "awesome_customers_rhel", github: "lamont-granquist/awesome_customers_rhel", branch: "lcg/bump-mysql-version"
diff --git a/kitchen-tests/Berksfile.lock b/kitchen-tests/Berksfile.lock
index ee11d811c0..51217e0602 100644
--- a/kitchen-tests/Berksfile.lock
+++ b/kitchen-tests/Berksfile.lock
@@ -1,12 +1,14 @@
DEPENDENCIES
awesome_customers_rhel
- git: https://github.com/learn-chef/awesome_customers_rhel.git
- revision: b576fcf2988e2cdf156e7ba6ff59a94d556e16f1
+ git: https://github.com/lamont-granquist/awesome_customers_rhel.git
+ revision: ed730957b1b75c8701c708e2deb0740ca8325322
+ branch: lcg/bump-mysql-version
awesome_customers_rhel_wrapper
path: cookbooks/awesome_customers_rhel_wrapper
awesome_customers_ubuntu
- git: https://github.com/learn-chef/awesome_customers_ubuntu.git
- revision: fea174c5855266f28218f76f00f6eff69e850244
+ git: https://github.com/lamont-granquist/awesome_customers_ubuntu.git
+ revision: 9d40958413d0ed1ef1e68c74d41895158c724964
+ branch: lcg/bump-mysql-version
awesome_customers_ubuntu_wrapper
path: cookbooks/awesome_customers_ubuntu_wrapper
base
@@ -23,7 +25,7 @@ GRAPH
database (~> 6.0)
firewall (~> 2.5)
httpd (~> 0.4)
- mysql (~> 7.0)
+ mysql (~> 8.0)
mysql2_chef_gem (~> 1.1)
selinux (~> 0.9)
awesome_customers_rhel_wrapper (0.1.0)
@@ -33,7 +35,7 @@ GRAPH
database (~> 6.0)
firewall (~> 2.5)
httpd (~> 0.4)
- mysql (~> 7.0)
+ mysql (~> 8.0)
mysql2_chef_gem (~> 1.1)
awesome_customers_ubuntu_wrapper (0.1.0)
awesome_customers_ubuntu (>= 0.0.0)
@@ -86,9 +88,7 @@ GRAPH
seven_zip (>= 0.0.0)
multipackage (4.0.0)
compat_resource (>= 0.0.0)
- mysql (7.2.0)
- smf (>= 0.0.0)
- yum-mysql-community (>= 0.0.0)
+ mysql (8.2.0)
mysql2_chef_gem (1.1.0)
build-essential (>= 0.0.0)
mariadb (>= 0.0.0)
@@ -110,13 +110,10 @@ GRAPH
build-essential (>= 2.0.0)
compat_resource (>= 12.16.3)
openssl (>= 4.0)
- rbac (1.0.3)
resolver (2.0.1)
selinux (0.9.0)
seven_zip (2.0.2)
windows (>= 1.2.2)
- smf (2.2.8)
- rbac (>= 1.0.1)
sudo (3.3.1)
ubuntu (2.0.1)
apt (>= 0.0.0)
@@ -128,8 +125,6 @@ GRAPH
yum (5.0.0)
yum-epel (2.1.1)
compat_resource (>= 12.16.3)
- yum-mysql-community (2.0.3)
- compat_resource (>= 12.16.3)
yum-scl (0.2.0)
inifile_chef_gem (>= 0.0.0)
yum (>= 0.0.0)
diff --git a/lib/chef/platform/provider_mapping.rb b/lib/chef/platform/provider_mapping.rb
index 55e831c343..ed65a8a715 100644
--- a/lib/chef/platform/provider_mapping.rb
+++ b/lib/chef/platform/provider_mapping.rb
@@ -1,6 +1,6 @@
#
# Author:: Adam Jacob (<adam@chef.io>)
-# Copyright:: Copyright 2008-2016, Chef Software Inc.
+# Copyright:: Copyright 2008-2017, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -26,45 +26,8 @@ class Chef
class Platform
class << self
- attr_writer :platforms
-
- def platforms
- @platforms ||= { default: {} }
- end
-
include Chef::Mixin::ParamsValidate
- def find(name, version)
- Chef.deprecated(:chef_platform_methods, "#{self.name}.find is deprecated")
- provider_map = platforms[:default].clone
-
- name_sym = name
- if name.kind_of?(String)
- name = name.downcase
- name.gsub!(/\s/, "_")
- name_sym = name.to_sym
- end
-
- if platforms.has_key?(name_sym)
- platform_versions = platforms[name_sym].select { |k, v| k != :default }
- if platforms[name_sym].has_key?(:default)
- provider_map.merge!(platforms[name_sym][:default])
- end
- platform_versions.each do |platform_version, provider|
- begin
- version_constraint = Chef::VersionConstraint::Platform.new(platform_version)
- if version_constraint.include?(version)
- Chef::Log.debug("Platform #{name} version #{version} found")
- provider_map.merge!(provider)
- end
- rescue Chef::Exceptions::InvalidPlatformVersion
- Chef::Log.debug("Chef::Version::Comparable does not know how to parse the platform version: #{version}")
- end
- end
- end
- provider_map
- end
-
def find_platform_and_version(node)
platform = nil
version = nil
@@ -90,133 +53,6 @@ class Chef
[platform, version]
end
- def provider_for_resource(resource, action = :nothing)
- Chef.deprecated(:chef_platform_methods, "#{name}.provider_for_resource is deprecated")
- node = resource.run_context && resource.run_context.node
- raise ArgumentError, "Cannot find the provider for a resource with no run context set" unless node
- provider = find_provider_for_node(node, resource).new(resource, resource.run_context)
- provider.action = action
- provider
- end
-
- def provider_for_node(node, resource_type)
- raise NotImplementedError, "#{name} no longer supports #provider_for_node"
- end
-
- def find_provider_for_node(node, resource_type)
- Chef.deprecated(:chef_platform_methods, "#{name}.find_provider_for_node is deprecated")
- platform, version = find_platform_and_version(node)
- find_provider(platform, version, resource_type)
- end
-
- def set(args)
- Chef.deprecated(:chef_platform_methods, "#{name}.set is deprecated")
- validate(
- args,
- {
- :platform => {
- :kind_of => Symbol,
- :required => false,
- },
- :version => {
- :kind_of => String,
- :required => false,
- },
- :resource => {
- :kind_of => Symbol,
- },
- :provider => {
- :kind_of => [ String, Symbol, Class ],
- },
- }
- )
- if args.has_key?(:platform)
- if args.has_key?(:version)
- if platforms.has_key?(args[:platform])
- if platforms[args[:platform]].has_key?(args[:version])
- platforms[args[:platform]][args[:version]][args[:resource].to_sym] = args[:provider]
- else
- platforms[args[:platform]][args[:version]] = {
- args[:resource].to_sym => args[:provider],
- }
- end
- else
- platforms[args[:platform]] = {
- args[:version] => {
- args[:resource].to_sym => args[:provider],
- },
- }
- end
- else
- if platforms.has_key?(args[:platform])
- if platforms[args[:platform]].has_key?(:default)
- platforms[args[:platform]][:default][args[:resource].to_sym] = args[:provider]
- elsif args[:platform] == :default
- platforms[:default][args[:resource].to_sym] = args[:provider]
- else
- platforms[args[:platform]] = { :default => { args[:resource].to_sym => args[:provider] } }
- end
- else
- platforms[args[:platform]] = {
- :default => {
- args[:resource].to_sym => args[:provider],
- },
- }
- end
- end
- else
- if platforms.has_key?(:default)
- platforms[:default][args[:resource].to_sym] = args[:provider]
- else
- platforms[:default] = {
- args[:resource].to_sym => args[:provider],
- }
- end
- end
- end
-
- def find_provider(platform, version, resource_type)
- Chef.deprecated(:chef_platform_methods, "#{name}.find_provider is deprecated")
- provider_klass = explicit_provider(platform, version, resource_type) ||
- platform_provider(platform, version, resource_type) ||
- resource_matching_provider(platform, version, resource_type)
-
- raise Chef::Exceptions::ProviderNotFound, "Cannot find a provider for #{resource_type} on #{platform} version #{version}" if provider_klass.nil?
-
- provider_klass
- end
-
- private
-
- def explicit_provider(platform, version, resource_type)
- resource_type.kind_of?(Chef::Resource) ? resource_type.provider : nil
- end
-
- def platform_provider(platform, version, resource_type)
- pmap = Chef::Platform.find(platform, version)
- rtkey = resource_type.kind_of?(Chef::Resource) ? resource_type.resource_name.to_sym : resource_type
- pmap.has_key?(rtkey) ? pmap[rtkey] : nil
- end
-
- include Chef::Mixin::ConvertToClassName
-
- def resource_matching_provider(platform, version, resource_type)
- if resource_type.kind_of?(Chef::Resource)
- class_name = if resource_type.class.name
- resource_type.class.name.split("::").last
- else
- convert_to_class_name(resource_type.resource_name.to_s)
- end
-
- if Chef::Provider.const_defined?(class_name, false)
- Chef::Log.warn("Class Chef::Provider::#{class_name} does not declare 'provides #{convert_to_snake_case(class_name).to_sym.inspect}'.")
- Chef::Log.warn("This will no longer work in Chef 13: you must use 'provides' to use the resource's DSL.")
- return Chef::Provider.const_get(class_name, false)
- end
- end
- nil
- end
-
end
end
end
diff --git a/lib/chef/provider_resolver.rb b/lib/chef/provider_resolver.rb
index 2eb4d72ba5..439a7e9f5f 100644
--- a/lib/chef/provider_resolver.rb
+++ b/lib/chef/provider_resolver.rb
@@ -59,7 +59,7 @@ class Chef
def resolve
maybe_explicit_provider(resource) ||
maybe_dynamic_provider_resolution(resource, action) ||
- maybe_chef_platform_lookup(resource)
+ raise(Chef::Exceptions::ProviderNotFound, "Cannot find a provider for #{resource} on #{node["platform"]} version #{node["platform_version"]}")
end
# Does NOT call provides? on the resource (it is assumed this is being
@@ -126,11 +126,6 @@ class Chef
handler
end
- # try the old static lookup of providers by platform
- def maybe_chef_platform_lookup(resource)
- Chef::Platform.find_provider_for_node(node, resource)
- end
-
def priority_map
Chef.provider_priority_map
end
diff --git a/spec/integration/recipes/recipe_dsl_spec.rb b/spec/integration/recipes/recipe_dsl_spec.rb
index e2fa7df1fc..27176f65d8 100644
--- a/spec/integration/recipes/recipe_dsl_spec.rb
+++ b/spec/integration/recipes/recipe_dsl_spec.rb
@@ -81,52 +81,6 @@ describe "Recipe DSL methods" do
Chef::Config[:treat_deprecation_warnings_as_errors] = false
end
- context "with a resource 'backcompat_thingy' declared in Chef::Resource and Chef::Provider" do
- before(:context) do
-
- class Chef::Resource::BackcompatThingy < Chef::Resource
- default_action :create
- end
- class Chef::Provider::BackcompatThingy < Chef::Provider
- def load_current_resource
- end
-
- def action_create
- BaseThingy.created_resource = new_resource.class
- BaseThingy.created_provider = self.class
- end
- end
-
- end
-
- it "backcompat_thingy creates a Chef::Resource::BackcompatThingy" do
- recipe = converge do
- backcompat_thingy("blah") {}
- end
- expect(BaseThingy.created_resource).to eq Chef::Resource::BackcompatThingy
- expect(BaseThingy.created_provider).to eq Chef::Provider::BackcompatThingy
- end
-
- context "and another resource 'backcompat_thingy' in BackcompatThingy with 'provides'" do
- before(:context) do
-
- class RecipeDSLSpecNamespace::BackcompatThingy < BaseThingy
- provides :backcompat_thingy
- resource_name :backcompat_thingy
- end
-
- end
-
- it "backcompat_thingy creates a BackcompatThingy" do
- recipe = converge do
- backcompat_thingy("blah") {}
- end
- expect(recipe.logged_warnings).to match(/Class Chef::Provider::BackcompatThingy does not declare 'provides :backcompat_thingy'./)
- expect(BaseThingy.created_resource).not_to be_nil
- end
- end
- end
-
context "with a resource named RecipeDSLSpecNamespace::Bar::BarThingy" do
before(:context) do
@@ -1493,31 +1447,4 @@ describe "Recipe DSL methods" do
end
end
end
-
- context "with a dynamically defined resource and regular provider" do
- before(:context) do
- Class.new(Chef::Resource) do
- resource_name :lw_resource_with_hw_provider_test_case
- default_action :create
- attr_accessor :created_provider
- end
- class Chef::Provider::LwResourceWithHwProviderTestCase < Chef::Provider
- def load_current_resource
- end
-
- def action_create
- new_resource.created_provider = self.class
- end
- end
- end
-
- it "looks up the provider in Chef::Provider converting the resource name from snake case to camel case" do
- Chef::Config[:treat_deprecation_warnings_as_errors] = false
- resource = nil
- recipe = converge do
- resource = lw_resource_with_hw_provider_test_case("blah") {}
- end
- expect(resource.created_provider).to eq(Chef::Provider::LwResourceWithHwProviderTestCase)
- end
- end
end
diff --git a/spec/unit/platform_spec.rb b/spec/unit/platform_spec.rb
deleted file mode 100644
index 3a562d3ce6..0000000000
--- a/spec/unit/platform_spec.rb
+++ /dev/null
@@ -1,269 +0,0 @@
-#
-# Author:: Adam Jacob (<adam@chef.io>)
-# Copyright:: Copyright 2008-2016, Chef Software Inc.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-require "spec_helper"
-
-describe Chef::Platform do
-
- context "while testing with fake data" do
- def expect_platform_warning(method_name, times: 1, recurse: true)
- expect(Chef).to receive(:deprecated).with(:chef_platform_methods, "Chef::Platform.#{method_name} is deprecated").exactly(times).times
- return unless recurse
-
- expect_platform_warning(:find_provider_for_node, times: times) if method_name == :provider_for_resource
- expect_platform_warning(:find_provider, times: times) if method_name == :find_provider_for_node
- expect_platform_warning(:find, times: times) if method_name == :find_provider
- end
-
- before :all do
- @original_platform_map = Chef::Platform.platforms
- end
-
- after :all do ||
- Chef::Platform.platforms = @original_platform_map
- end
-
- before(:each) do
- Chef::Platform.platforms = {
- :darwin => {
- ">= 10.11" => {
- :file => "new_darwinian",
- },
- "9.2.2" => {
- :file => "darwinian",
- :else => "thing",
- },
- :default => {
- :file => "old school",
- :snicker => "snack",
- },
- },
- :mars_volta => {
- },
- :default => {
- :file => Chef::Provider::File,
- :pax => "brittania",
- :cat => "nice",
- },
- }
- @events = Chef::EventDispatch::Dispatcher.new
- end
-
- it "should allow you to look up a platform by name and version, returning the provider map for it" do
- expect_platform_warning(:find)
- pmap = Chef::Platform.find("Darwin", "9.2.2")
- expect(pmap).to be_a_kind_of(Hash)
- expect(pmap[:file]).to eql("darwinian")
- end
-
- it "should allow you to look up a platform by name and version using \"greater than\" style operators" do
- expect_platform_warning(:find)
- pmap = Chef::Platform.find("Darwin", "11.1.0")
- expect(pmap).to be_a_kind_of(Hash)
- expect(pmap[:file]).to eql("new_darwinian")
- end
-
- it "should use the default providers for an os if the specific version does not exist" do
- expect_platform_warning(:find)
- pmap = Chef::Platform.find("Darwin", "1")
- expect(pmap).to be_a_kind_of(Hash)
- expect(pmap[:file]).to eql("old school")
- end
-
- it "should use the default providers if the os doesn't give me a default, but does exist" do
- expect_platform_warning(:find)
- pmap = Chef::Platform.find("mars_volta", "1")
- expect(pmap).to be_a_kind_of(Hash)
- expect(pmap[:file]).to eql(Chef::Provider::File)
- end
-
- it "should use the default provider if the os does not exist" do
- expect_platform_warning(:find)
- pmap = Chef::Platform.find("AIX", "1")
- expect(pmap).to be_a_kind_of(Hash)
- expect(pmap[:file]).to eql(Chef::Provider::File)
- end
-
- it "should merge the defaults for an os with the specific version" do
- expect_platform_warning(:find)
- pmap = Chef::Platform.find("Darwin", "9.2.2")
- expect(pmap[:file]).to eql("darwinian")
- expect(pmap[:snicker]).to eql("snack")
- end
-
- it "should merge the defaults for an os with the universal defaults" do
- expect_platform_warning(:find)
- pmap = Chef::Platform.find("Darwin", "9.2.2")
- expect(pmap[:file]).to eql("darwinian")
- expect(pmap[:pax]).to eql("brittania")
- end
-
- it "should allow you to look up a provider for a platform directly by symbol" do
- expect_platform_warning(:find_provider)
- expect(Chef::Platform.find_provider("Darwin", "9.2.2", :file)).to eql("darwinian")
- end
-
- it "should raise an exception if a provider cannot be found for a resource type" do
- expect_platform_warning(:find_provider)
- expect { Chef::Platform.find_provider("Darwin", "9.2.2", :coffee) }.to raise_error(Chef::Exceptions::ProviderNotFound)
- end
-
- it "should look up a provider for a resource with a Chef::Resource object" do
- kitty = Chef::Resource::Cat.new("loulou")
- expect_platform_warning(:find_provider)
- expect(Chef::Platform.find_provider("Darwin", "9.2.2", kitty)).to eql("nice")
- end
-
- it "should look up a provider with a node and a Chef::Resource object" do
- kitty = Chef::Resource::Cat.new("loulou")
- node = Chef::Node.new
- node.name("Intel")
- node.automatic_attrs[:platform] = "mac_os_x"
- node.automatic_attrs[:platform_version] = "9.2.2"
- expect_platform_warning(:find_provider_for_node)
- expect(Chef::Platform.find_provider_for_node(node, kitty)).to eql("nice")
- end
-
- it "should not throw an exception when the platform version has an unknown format" do
- expect_platform_warning(:find_provider)
- expect(Chef::Platform.find_provider(:darwin, "bad-version", :file)).to eql("old school")
- end
-
- it "should prefer an explicit provider" do
- kitty = Chef::Resource::Cat.new("loulou")
- allow(kitty).to receive(:provider).and_return(Chef::Provider::File)
- node = Chef::Node.new
- node.name("Intel")
- node.automatic_attrs[:platform] = "mac_os_x"
- node.automatic_attrs[:platform_version] = "9.2.2"
- expect_platform_warning(:find_provider_for_node, recurse: false)
- expect_platform_warning(:find_provider, recurse: false)
- expect(Chef::Platform.find_provider_for_node(node, kitty)).to eql(Chef::Provider::File)
- end
-
- it "should look up a provider based on the resource name if nothing else matches" do
- kitty = Chef::Resource::Cat.new("loulou")
- class Chef::Provider::Cat < Chef::Provider; end
- Chef::Platform.platforms[:default].delete(:cat)
- node = Chef::Node.new
- node.name("Intel")
- node.automatic_attrs[:platform] = "mac_os_x"
- node.automatic_attrs[:platform_version] = "8.5"
- expect_platform_warning(:find_provider_for_node)
- expect(Chef::Platform.find_provider_for_node(node, kitty)).to eql(Chef::Provider::Cat)
- end
-
- def setup_file_resource
- node = Chef::Node.new
- node.automatic_attrs[:platform] = "mac_os_x"
- node.automatic_attrs[:platform_version] = "9.2.2"
- run_context = Chef::RunContext.new(node, {}, @events)
- [ Chef::Resource::File.new("whateva", run_context), run_context ]
- end
-
- it "returns a provider object given a Chef::Resource object which has a valid run context and an action" do
- file, run_context = setup_file_resource
- expect_platform_warning(:provider_for_resource)
- provider = Chef::Platform.provider_for_resource(file, :foo)
- expect(provider).to be_an_instance_of(Chef::Provider::File)
- expect(provider.new_resource).to equal(file)
- expect(provider.run_context).to equal(run_context)
- end
-
- it "returns a provider object given a Chef::Resource object which has a valid run context without an action" do
- file, run_context = setup_file_resource
- expect_platform_warning(:provider_for_resource)
- provider = Chef::Platform.provider_for_resource(file)
- expect(provider).to be_an_instance_of(Chef::Provider::File)
- expect(provider.new_resource).to equal(file)
- expect(provider.run_context).to equal(run_context)
- end
-
- it "raises an error when trying to find the provider for a resource with no run context" do
- file = Chef::Resource::File.new("whateva")
- expect_platform_warning(:provider_for_resource, recurse: false)
- expect { Chef::Platform.provider_for_resource(file) }.to raise_error(ArgumentError)
- end
-
- it "does not support finding a provider by resource and node -- a run context is required" do
- expect { Chef::Platform.provider_for_node("node", "resource") }.to raise_error(NotImplementedError)
- end
-
- it "should update the provider map with map" do
- expect_platform_warning(:set, times: 7)
- Chef::Platform.set(
- :platform => :darwin,
- :version => "9.2.2",
- :resource => :file,
- :provider => "masterful"
- )
- expect(Chef::Platform.platforms[:darwin]["9.2.2"][:file]).to eql("masterful")
- Chef::Platform.set(
- :platform => :darwin,
- :resource => :file,
- :provider => "masterful"
- )
- expect(Chef::Platform.platforms[:darwin][:default][:file]).to eql("masterful")
- Chef::Platform.set(
- :resource => :file,
- :provider => "masterful"
- )
- expect(Chef::Platform.platforms[:default][:file]).to eql("masterful")
-
- Chef::Platform.set(
- :platform => :hero,
- :version => "9.2.2",
- :resource => :file,
- :provider => "masterful"
- )
- expect(Chef::Platform.platforms[:hero]["9.2.2"][:file]).to eql("masterful")
-
- Chef::Platform.set(
- :resource => :file,
- :provider => "masterful"
- )
- expect(Chef::Platform.platforms[:default][:file]).to eql("masterful")
-
- Chef::Platform.platforms = {}
-
- Chef::Platform.set(
- :resource => :file,
- :provider => "masterful"
- )
- expect(Chef::Platform.platforms[:default][:file]).to eql("masterful")
-
- Chef::Platform.platforms = { :neurosis => {} }
- Chef::Platform.set(:platform => :neurosis, :resource => :package, :provider => "masterful")
- expect(Chef::Platform.platforms[:neurosis][:default][:package]).to eql("masterful")
-
- end
-
- it "does not overwrite the platform map when using :default platform" do
- expect_platform_warning(:set)
- Chef::Platform.set(
- :resource => :file,
- :platform => :default,
- :provider => "new school"
- )
- expect(Chef::Platform.platforms[:default][:file]).to eql("new school")
- expect(Chef::Platform.platforms[:default][:cat]).to eql("nice")
- end
-
- end
-
-end
diff --git a/spec/unit/resource_spec.rb b/spec/unit/resource_spec.rb
index 11289a41c6..a83b22ea0f 100644
--- a/spec/unit/resource_spec.rb
+++ b/spec/unit/resource_spec.rb
@@ -798,11 +798,7 @@ describe Chef::Resource do
snitch_var1 = snitch_var2 = 0
runner = Chef::Runner.new(run_context)
- Chef::Config[:treat_deprecation_warnings_as_errors] = false
- Chef::Platform.set(
- :resource => :cat,
- :provider => Chef::Provider::SnakeOil
- )
+ Chef::Provider::SnakeOil.provides :cat
resource1.only_if { snitch_var1 = 1 }
resource1.not_if { snitch_var2 = 2 }
diff --git a/spec/unit/runner_spec.rb b/spec/unit/runner_spec.rb
index 4e7f4d6671..ea721965c7 100644
--- a/spec/unit/runner_spec.rb
+++ b/spec/unit/runner_spec.rb
@@ -1,6 +1,6 @@
# Author:: Adam Jacob (<adam@chef.io>)
-# Copyright:: Copyright 2008-2016, Chef Software Inc.
+# Copyright:: Copyright 2008-2017, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -98,25 +98,6 @@ describe Chef::Runner do
run_context.resource_collection << first_resource
end
- context "when we fall through to old Chef::Platform resolution" do
- let(:provider_resolver) { Chef::ProviderResolver.new(node, first_resource, nil) }
- before do
- Chef::Config[:treat_deprecation_warnings_as_errors] = false
- # set up old Chef::Platform resolution instead of provider_resolver
- Chef::Platform.set(
- :resource => :cat,
- :provider => Chef::Provider::SnakeOil
- )
- allow(Chef::ProviderResolver).to receive(:new).and_return(provider_resolver)
- allow(provider_resolver).to receive(:maybe_dynamic_provider_resolution).with(first_resource, anything()).and_return(nil)
- end
-
- it "should use the platform provider if it has one" do
- expect(Chef::Platform).to receive(:find_provider_for_node).with(node, first_resource).and_call_original
- runner.converge
- end
- end
-
context "when we are doing dynamic provider resolution" do
it "should pass each resource in the collection to a provider" do