diff options
23 files changed, 274 insertions, 109 deletions
diff --git a/.travis.yml b/.travis.yml index 80695c09e3..2969849875 100644 --- a/.travis.yml +++ b/.travis.yml @@ -334,6 +334,7 @@ matrix: sudo: required before_install: - gem update --system $(grep rubygems omnibus_overrides.rb | cut -d'"' -f2) + - rvm @global do gem uninstall bundler -a -x - gem install bundler -v $(grep bundler omnibus_overrides.rb | cut -d'"' -f2) - sudo apt-get update - sudo apt-get -y install squid3 git curl diff --git a/CHANGELOG.md b/CHANGELOG.md index 5f8d57affb..5871d707fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,15 +1,19 @@ <!-- usage documentation: http://expeditor-docs.es.chef.io/configuration/changelog/ --> -<!-- latest_release 14.0.13 --> -## [v14.0.13](https://github.com/chef/chef/tree/v14.0.13) (2018-01-22) +<!-- latest_release 14.0.17 --> +## [v14.0.17](https://github.com/chef/chef/tree/v14.0.17) (2018-01-23) #### Merged Pull Requests -- Revert "add create and delete actions for windows_service" [#6763](https://github.com/chef/chef/pull/6763) ([lamont-granquist](https://github.com/lamont-granquist)) +- [MSYS-727] Added support for setting node policy name and group from knife [#6656](https://github.com/chef/chef/pull/6656) ([piyushawasthi](https://github.com/piyushawasthi)) <!-- latest_release --> <!-- release_rollup since=13.6.4 --> ### Changes since 13.6.4 release #### Merged Pull Requests +- [MSYS-727] Added support for setting node policy name and group from knife [#6656](https://github.com/chef/chef/pull/6656) ([piyushawasthi](https://github.com/piyushawasthi)) <!-- 14.0.17 --> +- Convert node map to last-writer-wins for ties [#6765](https://github.com/chef/chef/pull/6765) ([lamont-granquist](https://github.com/lamont-granquist)) <!-- 14.0.16 --> +- Remove node.set and node.set_unless attribute levels [#6762](https://github.com/chef/chef/pull/6762) ([lamont-granquist](https://github.com/lamont-granquist)) <!-- 14.0.15 --> +- Rename the OpenSSL mixin to avoid name conflicts [#6764](https://github.com/chef/chef/pull/6764) ([tas50](https://github.com/tas50)) <!-- 14.0.14 --> - Revert "add create and delete actions for windows_service" [#6763](https://github.com/chef/chef/pull/6763) ([lamont-granquist](https://github.com/lamont-granquist)) <!-- 14.0.13 --> - Convert actions in Chef::Resource::Notification to symbols to prevent double notification [#6515](https://github.com/chef/chef/pull/6515) ([dimsh99](https://github.com/dimsh99)) <!-- 14.0.12 --> - add create and delete actions for windows_service [#6595](https://github.com/chef/chef/pull/6595) ([jasonwbarnett](https://github.com/jasonwbarnett)) <!-- 14.0.11 --> diff --git a/Gemfile.lock b/Gemfile.lock index af84189bfb..e11118e435 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -35,10 +35,10 @@ GIT PATH remote: . specs: - chef (14.0.13) + chef (14.0.17) addressable bundler (>= 1.10) - chef-config (= 14.0.13) + chef-config (= 14.0.17) chef-zero (>= 13.0) diff-lcs (~> 1.2, >= 1.2.4) erubis (~> 2.7) @@ -65,10 +65,10 @@ PATH specinfra (~> 2.10) syslog-logger (~> 1.6) uuidtools (~> 2.1.5) - chef (14.0.13-universal-mingw32) + chef (14.0.17-universal-mingw32) addressable bundler (>= 1.10) - chef-config (= 14.0.13) + chef-config (= 14.0.17) chef-zero (>= 13.0) diff-lcs (~> 1.2, >= 1.2.4) erubis (~> 2.7) @@ -110,7 +110,7 @@ PATH PATH remote: chef-config specs: - chef-config (14.0.13) + chef-config (14.0.17) addressable fuzzyurl mixlib-config (~> 2.0) @@ -1 +1 @@ -14.0.13
\ No newline at end of file +14.0.17
\ No newline at end of file diff --git a/chef-config/lib/chef-config/version.rb b/chef-config/lib/chef-config/version.rb index 3905432695..0f3129f0fe 100644 --- a/chef-config/lib/chef-config/version.rb +++ b/chef-config/lib/chef-config/version.rb @@ -21,7 +21,7 @@ module ChefConfig CHEFCONFIG_ROOT = File.expand_path("../..", __FILE__) - VERSION = "14.0.13" + VERSION = "14.0.17" end # diff --git a/lib/chef/knife/node_policy_set.rb b/lib/chef/knife/node_policy_set.rb new file mode 100644 index 0000000000..404446fe0e --- /dev/null +++ b/lib/chef/knife/node_policy_set.rb @@ -0,0 +1,79 @@ +# +# Author:: Piyush Awasthi (<piyush.awasthi@chef.io>) +# Copyright:: Copyright 2017-2018, 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 "chef/knife" + +class Chef + class Knife + class NodePolicySet < Knife + + deps do + require "chef/node" + require "chef/json_compat" + end + + banner "knife node policy set NODE POLICY_GROUP POLICY_NAME (options)" + + def run + validate_node! + validate_options! + node = Chef::Node.load(@name_args[0]) + set_policy(node) + if node.save + ui.info "Successfully set the policy on node #{node.name}" + else + ui.info "Error in updating node #{node.name}" + end + end + + private + + # Set policy name and group to node + def set_policy(node) + policy_group, policy_name = @name_args[1..-1] + node.policy_name = policy_name + node.policy_group = policy_group + end + + # Validate policy name and policy group + def validate_options! + if incomplete_policyfile_options? + ui.error("Policy group and name must be specified together") + exit 1 + end + true + end + + # Validate node pass in CLI + def validate_node! + if @name_args[0].nil? + ui.error("You must specify a node name") + show_usage + exit 1 + end + end + + # True if one of policy_name or policy_group was given, but not both + def incomplete_policyfile_options? + policy_group, policy_name = @name_args[1..-1] + (policy_group.nil? || policy_name.nil? || @name_args[1..-1].size > 2) + end + + end + end +end diff --git a/lib/chef/mixin/openssl.rb b/lib/chef/mixin/openssl_helper.rb index e868da9ac4..fb2638f0e9 100644 --- a/lib/chef/mixin/openssl.rb +++ b/lib/chef/mixin/openssl_helper.rb @@ -17,7 +17,7 @@ class Chef module Mixin - module OpenSSL + module OpenSSLHelper def self.included(_base) require "openssl" unless defined?(::OpenSSL) end diff --git a/lib/chef/node.rb b/lib/chef/node.rb index 20134ca11b..7b530e1132 100644 --- a/lib/chef/node.rb +++ b/lib/chef/node.rb @@ -199,11 +199,6 @@ class Chef attributes.normal end - def set - Chef.deprecated(:attributes, "node.set is deprecated and will be removed in Chef 14, please use node.default/node.override (or node.normal only if you really need persistence)") - normal - end - # Set a default of this node, but auto-vivify any Mashes that might # be missing def default diff --git a/lib/chef/node/attribute.rb b/lib/chef/node/attribute.rb index 389968f543..142150aeef 100644 --- a/lib/chef/node/attribute.rb +++ b/lib/chef/node/attribute.rb @@ -1,7 +1,7 @@ #-- # Author:: Adam Jacob (<adam@chef.io>) # Author:: AJ Christensen (<aj@chef.io>) -# Copyright:: Copyright 2008-2017, Chef Software Inc. +# Copyright:: Copyright 2008-2018, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -446,11 +446,6 @@ class Chef write(:override, *args) if override.read(*args[0...-1]).nil? end - def set_unless(*args) - Chef.deprecated(:attributes, "node.set_unless is deprecated and will be removed in Chef 14, please use node.default_unless/node.override_unless (or node.normal_unless if you really need persistence)") - normal_unless(*args) - end - def has_key?(key) COMPONENTS.any? do |component_ivar| instance_variable_get(component_ivar).has_key?(key) diff --git a/lib/chef/node_map.rb b/lib/chef/node_map.rb index dde93a437d..ecd5c9df8f 100644 --- a/lib/chef/node_map.rb +++ b/lib/chef/node_map.rb @@ -1,6 +1,6 @@ # # Author:: Lamont Granquist (<lamont@chef.io>) -# Copyright:: Copyright 2014-2017, Chef Software Inc. +# Copyright:: Copyright 2014-2018, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -192,8 +192,10 @@ class Chef !!canonical == !!matcher[:canonical] end - # @api private - def dispatch_compare_matchers(key, new_matcher, matcher) + # + # "provides" lines with identical filters sort by class name (ascending). + # + def compare_matchers(key, new_matcher, matcher) cmp = compare_matcher_properties(new_matcher[:block], matcher[:block]) return cmp if cmp != 0 cmp = compare_matcher_properties(new_matcher[:platform_version], matcher[:platform_version]) @@ -210,26 +212,6 @@ class Chef 0 end - # - # "provides" lines with identical filters sort by class name (ascending). - # - def compare_matchers(key, new_matcher, matcher) - cmp = dispatch_compare_matchers(key, new_matcher, matcher) - if cmp == 0 - # Sort by class name (ascending) as well, if all other properties - # are exactly equal - # XXX: remove this in Chef-14 and use last-writer-wins (prepend if they match) - if !new_matcher[:override] - # we only sort classes, which only sorts the handler array, this magically does not sort - # the priority array via the invisible else here. - if new_matcher[:klass].is_a?(Class) - cmp = compare_matcher_properties(new_matcher[:klass].name, matcher[:klass].name) - end - end - end - cmp - end - def compare_matcher_properties(a, b) # falsity comparisons here handle both "nil" and "false" return 1 if !a && b diff --git a/lib/chef/resource/file.rb b/lib/chef/resource/file.rb index 43d9c57150..787992fc24 100644 --- a/lib/chef/resource/file.rb +++ b/lib/chef/resource/file.rb @@ -1,7 +1,7 @@ # # Author:: Adam Jacob (<adam@chef.io>) # Author:: Seth Chisamore (<schisamo@chef.io>) -# Copyright:: Copyright 2008-2016 Chef Software, Inc. +# Copyright:: Copyright 2008-2018, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/chef/resource/link.rb b/lib/chef/resource/link.rb index 7a106b1703..d51d42b506 100644 --- a/lib/chef/resource/link.rb +++ b/lib/chef/resource/link.rb @@ -1,7 +1,7 @@ # # Author:: Adam Jacob (<adam@chef.io>) # Author:: Tyler Cloke (<tyler@chef.io>) -# Copyright:: Copyright 2008-2016, Chef Software Inc. +# Copyright:: Copyright 2008-2018, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -34,6 +34,7 @@ class Chef # original file. class Link < Chef::Resource include Chef::Mixin::Securable + resource_name :link identity_attr :target_file diff --git a/lib/chef/resource/openssl_dhparam.rb b/lib/chef/resource/openssl_dhparam.rb index cec27d21bd..693061f535 100644 --- a/lib/chef/resource/openssl_dhparam.rb +++ b/lib/chef/resource/openssl_dhparam.rb @@ -26,8 +26,8 @@ class Chef # # @since 14.0 class OpensslDhparam < Chef::Resource - require "chef/mixin/openssl" - include Chef::Mixin::OpenSSL + require "chef/mixin/openssl_helper" + include Chef::Mixin::OpenSSLHelper resource_name :openssl_dhparam diff --git a/lib/chef/resource/openssl_rsa_private_key.rb b/lib/chef/resource/openssl_rsa_private_key.rb index 32c394846b..4b0bae2fd0 100644 --- a/lib/chef/resource/openssl_rsa_private_key.rb +++ b/lib/chef/resource/openssl_rsa_private_key.rb @@ -27,8 +27,8 @@ class Chef # # @since 14.0 class OpensslRsaPrivateKey < Chef::Resource - require "chef/mixin/openssl" - include Chef::Mixin::OpenSSL + require "chef/mixin/openssl_helper" + include Chef::Mixin::OpenSSLHelper resource_name :openssl_rsa_private_key provides :openssl_rsa_private_key diff --git a/lib/chef/resource/openssl_rsa_public_key.rb b/lib/chef/resource/openssl_rsa_public_key.rb index 602b48065e..5ab7206938 100644 --- a/lib/chef/resource/openssl_rsa_public_key.rb +++ b/lib/chef/resource/openssl_rsa_public_key.rb @@ -23,8 +23,8 @@ class Chef # # @since 14.0 class OpensslRsaPublicKey < Chef::Resource - require "chef/mixin/openssl" - include Chef::Mixin::OpenSSL + require "chef/mixin/openssl_helper" + include Chef::Mixin::OpenSSLHelper resource_name :openssl_rsa_public_key diff --git a/lib/chef/version.rb b/lib/chef/version.rb index f2d98c0ec6..fbe17efc4f 100644 --- a/lib/chef/version.rb +++ b/lib/chef/version.rb @@ -23,7 +23,7 @@ require "chef/version_string" class Chef CHEF_ROOT = File.expand_path("../..", __FILE__) - VERSION = Chef::VersionString.new("14.0.13") + VERSION = Chef::VersionString.new("14.0.17") end # diff --git a/spec/integration/recipes/recipe_dsl_spec.rb b/spec/integration/recipes/recipe_dsl_spec.rb index f9970afc92..0250786f0e 100644 --- a/spec/integration/recipes/recipe_dsl_spec.rb +++ b/spec/integration/recipes/recipe_dsl_spec.rb @@ -446,11 +446,11 @@ describe "Recipe DSL methods" do end - it "thingy3 works in a recipe and yields Thingy3 (the alphabetical one)" do + it "thingy3 works in a recipe and yields Thingy4 (the last one)" do recipe = converge do thingy3("blah") {} end - expect(BaseThingy.created_resource).to eq RecipeDSLSpecNamespace::Thingy3 + expect(BaseThingy.created_resource).to eq RecipeDSLSpecNamespace::Thingy4 end it "thingy4 does not work in a recipe" do @@ -460,7 +460,7 @@ describe "Recipe DSL methods" do end it "resource_matching_short_name returns Thingy4" do - expect(Chef::Resource.resource_matching_short_name(:thingy3)).to eq RecipeDSLSpecNamespace::Thingy3 + expect(Chef::Resource.resource_matching_short_name(:thingy3)).to eq RecipeDSLSpecNamespace::Thingy4 end end end @@ -501,14 +501,14 @@ describe "Recipe DSL methods" do expect(BaseThingy.created_resource).to eq RecipeDSLSpecNamespace::Thingy6 end - it "thingy5 works in a recipe and yields Foo::Thingy5 (the alphabetical one)" do + it "thingy5 works in a recipe and yields Foo::Thingy6 (the last one)" do recipe = converge do thingy5("blah") {} end - expect(BaseThingy.created_resource).to eq RecipeDSLSpecNamespace::Thingy5 + expect(BaseThingy.created_resource).to eq RecipeDSLSpecNamespace::Thingy6 end - it "resource_matching_short_name returns Thingy5" do + it "resource_matching_short_name returns Thingy6" do expect(Chef::Resource.resource_matching_short_name(:thingy5)).to eq RecipeDSLSpecNamespace::Thingy5 end @@ -540,11 +540,11 @@ describe "Recipe DSL methods" do end - it "thingy5_2 works in a recipe and yields the RecipeDSLSpaceNamespace one (the alphabetical one)" do + it "thingy5_2 works in a recipe and yields the ZRecipeDSLSpaceNamespace one (the last one)" do recipe = converge do thingy5_2("blah") {} end - expect(BaseThingy.created_resource).to eq RecipeDSLSpecNamespace::Thingy5 + expect(BaseThingy.created_resource).to eq ZRecipeDSLSpecNamespace::Thingy5 end end @@ -593,11 +593,11 @@ describe "Recipe DSL methods" do end - it "thingy3 works in a recipe and yields Thingy3 (the alphabetical one)" do + it "thingy3 works in a recipe and yields Thingy4 (the last one)" do recipe = converge do thingy3("blah") {} end - expect(BaseThingy.created_resource).to eq RecipeDSLSpecNamespace::Thingy3 + expect(BaseThingy.created_resource).to eq RecipeDSLSpecNamespace::Thingy4 end it "thingy4 does not work in a recipe" do @@ -607,7 +607,7 @@ describe "Recipe DSL methods" do end it "resource_matching_short_name returns Thingy4" do - expect(Chef::Resource.resource_matching_short_name(:thingy3)).to eq RecipeDSLSpecNamespace::Thingy3 + expect(Chef::Resource.resource_matching_short_name(:thingy3)).to eq RecipeDSLSpecNamespace::Thingy4 end end @@ -620,11 +620,11 @@ describe "Recipe DSL methods" do end - it "thingy3 works in a recipe and yields Thingy3 (the alphabetical one)" do + it "thingy3 works in a recipe and yields Thingy4 (the last one)" do recipe = converge do thingy3("blah") {} end - expect(BaseThingy.created_resource).to eq RecipeDSLSpecNamespace::Thingy3 + expect(BaseThingy.created_resource).to eq RecipeDSLSpecNamespace::Thingy4 end it "thingy4 does not work in a recipe" do @@ -634,7 +634,7 @@ describe "Recipe DSL methods" do end it "resource_matching_short_name returns Thingy4" do - expect(Chef::Resource.resource_matching_short_name(:thingy3)).to eq RecipeDSLSpecNamespace::Thingy3 + expect(Chef::Resource.resource_matching_short_name(:thingy3)).to eq RecipeDSLSpecNamespace::Thingy4 end end end @@ -667,11 +667,11 @@ describe "Recipe DSL methods" do expect(BaseThingy.created_resource).to eq RecipeDSLSpecNamespace::Thingy7 end - it "thingy8 works in a recipe and yields Thingy7 (alphabetical)" do + it "thingy8 works in a recipe and yields Thingy7 (last)" do recipe = converge do thingy8("blah") {} end - expect(BaseThingy.created_resource).to eq RecipeDSLSpecNamespace::Thingy7 + expect(BaseThingy.created_resource).to eq RecipeDSLSpecNamespace::Thingy8 end it "resource_matching_short_name returns Thingy8" do @@ -853,17 +853,17 @@ describe "Recipe DSL methods" do end before { resource_class_z } # pull on it so it gets defined before the recipe runs - it "two_classes_one_dsl resolves to B (alphabetically earliest)" do + it "two_classes_one_dsl resolves to Z (last)" do temp_two_classes_one_dsl = two_classes_one_dsl recipe = converge do instance_eval("#{temp_two_classes_one_dsl} 'blah'") end expect(recipe.logged_warnings).to eq "" - expect(BaseThingy.created_resource).to eq resource_class + expect(BaseThingy.created_resource).to eq resource_class_z end - it "resource_matching_short_name returns B" do - expect(Chef::Resource.resource_matching_short_name(two_classes_one_dsl)).to eq resource_class + it "resource_matching_short_name returns Z" do + expect(Chef::Resource.resource_matching_short_name(two_classes_one_dsl)).to eq resource_class_z end context "and a priority array [ Z, B ]" do @@ -880,8 +880,8 @@ describe "Recipe DSL methods" do expect(BaseThingy.created_resource).to eq resource_class_z end - it "resource_matching_short_name returns B" do - expect(Chef::Resource.resource_matching_short_name(two_classes_one_dsl)).to eq resource_class + it "resource_matching_short_name returns Z" do + expect(Chef::Resource.resource_matching_short_name(two_classes_one_dsl)).to eq resource_class_z end context "when Z provides(:two_classes_one_dsl) { false }" do @@ -919,8 +919,8 @@ describe "Recipe DSL methods" do expect(BaseThingy.created_resource).to eq resource_class_z end - it "resource_matching_short_name returns B" do - expect(Chef::Resource.resource_matching_short_name(two_classes_one_dsl)).to eq resource_class + it "resource_matching_short_name returns Z" do + expect(Chef::Resource.resource_matching_short_name(two_classes_one_dsl)).to eq resource_class_z end context "when Z provides(:two_classes_one_dsl) { false }" do @@ -1047,13 +1047,13 @@ describe "Recipe DSL methods" do context "which provides :two_classes_one_dsl" do before { provider_class_z.provides two_classes_one_dsl } - it "two_classes_one_dsl resolves to B (alphabetically earliest)" do + it "two_classes_one_dsl resolves to Z (last)" do temp_two_classes_one_dsl = two_classes_one_dsl recipe = converge do instance_eval("#{temp_two_classes_one_dsl} 'blah'") end expect(recipe.logged_warnings).to eq "" - expect(BaseThingy.created_provider).to eq provider_class + expect(BaseThingy.created_provider).to eq provider_class_z end context "with a priority array [ Z, B ]" do diff --git a/spec/unit/data_collector/resource_report_spec.rb b/spec/unit/data_collector/resource_report_spec.rb index b3523622c4..278e94b53b 100644 --- a/spec/unit/data_collector/resource_report_spec.rb +++ b/spec/unit/data_collector/resource_report_spec.rb @@ -1,7 +1,7 @@ # # Author:: Salim Afiune (<afiune@chef.io) # -# Copyright:: Copyright 2012-2017, Chef Software Inc. +# Copyright:: Copyright 2012-2018, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -110,7 +110,7 @@ describe Chef::DataCollector::ResourceReport do context "for a lazy_resource that got skipped" do let(:resource) do klass = Class.new(Chef::Resource) do - resource_name "link" + resource_name "butters" property :sword, String, name_property: true, identity: true end resource = klass.new("hyrule") @@ -129,7 +129,7 @@ describe Chef::DataCollector::ResourceReport do "name" => "hyrule", "result" => "create", "status" => "skipped", - "type" => :link, + "type" => :butters, } end let(:conditional) do diff --git a/spec/unit/knife/node_policy_set_spec.rb b/spec/unit/knife/node_policy_set_spec.rb new file mode 100644 index 0000000000..35306937d8 --- /dev/null +++ b/spec/unit/knife/node_policy_set_spec.rb @@ -0,0 +1,122 @@ +# +# Author:: Piyush Awasthi (<piyush.awasthi@chef.io>) +# Copyright:: Copyright 2017-2018, 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::Knife::NodePolicySet do + let(:node) do + node = Chef::Node.new() + node.name("adam") + node.run_list = ["role[base]"] + node + end + + let(:knife) do + Chef::Log.logger = Logger.new(StringIO.new) + Chef::Config[:knife][:bootstrap_template] = bootstrap_template unless bootstrap_template.nil? + knife_obj = Chef::Knife::NodePolicySet.new(bootstrap_cli_options) + knife_obj.merge_configs + allow(knife_obj.ui).to receive(:stderr).and_return(stderr) + allow(knife_obj).to receive(:encryption_secret_provided_ignore_encrypt_flag?).and_return(false) + knife_obj + end + + let(:stderr) { StringIO.new } + let(:bootstrap_template) { nil } + let(:bootstrap_cli_options) { [ ] } + + describe "#run" do + context "when node_name is not given" do + let(:bootstrap_cli_options) { %w{ } } + it "returns an error that you must specify a node name" do + expect { knife.send(:validate_node!) }.to raise_error(SystemExit) + expect(stderr.string).to include("ERROR: You must specify a node name") + end + end + + context "when node is given" do + let(:bootstrap_cli_options) { %w{ adam staging my-app } } + it "should load the node" do + expect(Chef::Node).to receive(:load).with(bootstrap_cli_options[0]).and_return(node) + allow(node).to receive(:save).and_return(true) + knife.run + end + end + + context "when node not saved" do + let(:bootstrap_cli_options) { %w{ adam staging my-app } } + it "returns an error node not updated successfully" do + allow(Chef::Node).to receive(:load).with(bootstrap_cli_options[0]).and_return(node) + allow(node).to receive(:save).and_return(false) + knife.run + expect(stderr.string.strip).to eq("Error in updating node #{node.name}") + end + end + + context "when the policy is set successfully on the node" do + let(:bootstrap_cli_options) { %w{ adam staging my-app } } + it "returns node updated successfully" do + allow(Chef::Node).to receive(:load).with(bootstrap_cli_options[0]).and_return(node) + allow(node).to receive(:save).and_return(true) + knife.run + expect(stderr.string.strip).to eq("Successfully set the policy on node #{node.name}") + end + end + end + + describe "handling policy options" do + context "when policy_group and policy_name is not given" do + let(:bootstrap_cli_options) { %w{ } } + it "returns an error stating that policy_name and policy_group must be given together" do + expect { knife.send(:validate_options!) }.to raise_error(SystemExit) + expect(stderr.string).to include("ERROR: Policy group and name must be specified together") + end + end + + context "when only policy_name is given" do + let(:bootstrap_cli_options) { %w{ adam staging } } + it "returns an error stating that policy_name and policy_group must be given together" do + expect { knife.send(:validate_options!) }.to raise_error(SystemExit) + expect(stderr.string).to include("ERROR: Policy group and name must be specified together") + end + end + + context "when only policy_group is given" do + let(:bootstrap_cli_options) { %w{ adam my-app } } + it "returns an error stating that policy_name and policy_group must be given together" do + expect { knife.send(:validate_options!) }.to raise_error(SystemExit) + expect(stderr.string).to include("ERROR: Policy group and name must be specified together") + end + end + + context "when policy_name and policy_group are given with no conflicting options" do + let(:bootstrap_cli_options) { %w{ adam staging my-app } } + it "passes options validation" do + expect { knife.send(:validate_options!) }.to_not raise_error + end + + it "returns value set in config" do + allow(Chef::Node).to receive(:load).with(bootstrap_cli_options[0]).and_return(node) + allow(node).to receive(:save).and_return(false) + knife.run + expect(node.policy_name).to eq("my-app") + expect(node.policy_group).to eq("staging") + end + end + end +end diff --git a/spec/unit/mixin/openssl_spec.rb b/spec/unit/mixin/openssl_helper_spec.rb index 8a0206116c..6873fd8cf2 100644 --- a/spec/unit/mixin/openssl_spec.rb +++ b/spec/unit/mixin/openssl_helper_spec.rb @@ -14,11 +14,11 @@ # limitations under the License. require "spec_helper" -require "chef/mixin/openssl" +require "chef/mixin/openssl_helper" -describe Chef::Mixin::OpenSSL do +describe Chef::Mixin::OpenSSLHelper do let(:instance) do - Class.new { include Chef::Mixin::OpenSSL }.new + Class.new { include Chef::Mixin::OpenSSLHelper }.new end describe ".included" do diff --git a/spec/unit/node_map_spec.rb b/spec/unit/node_map_spec.rb index 7fa115b532..67bb741ec5 100644 --- a/spec/unit/node_map_spec.rb +++ b/spec/unit/node_map_spec.rb @@ -1,6 +1,6 @@ # # Author:: Lamont Granquist (<lamont@chef.io>) -# Copyright:: Copyright 2014-2017, Chef Software Inc. +# Copyright:: Copyright 2014-2018, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -122,16 +122,16 @@ describe Chef::NodeMap do describe "ordering classes" do class Foo; end class Bar; end - it "orders them alphabetically when they're set in the reverse order" do + it "last writer wins when its reverse alphabetic order" do node_map.set(:thing, Foo) node_map.set(:thing, Bar) expect(node_map.get(node, :thing)).to eql(Bar) end - it "orders them alphabetically when they're set in alphabetic order" do + it "last writer wins when its alphabetic order" do node_map.set(:thing, Bar) node_map.set(:thing, Foo) - expect(node_map.get(node, :thing)).to eql(Bar) + expect(node_map.get(node, :thing)).to eql(Foo) end end diff --git a/spec/unit/node_spec.rb b/spec/unit/node_spec.rb index 7dc972b5a0..2019f1ac42 100644 --- a/spec/unit/node_spec.rb +++ b/spec/unit/node_spec.rb @@ -1,6 +1,6 @@ # # Author:: Adam Jacob (<adam@chef.io>) -# Copyright:: Copyright 2008-2017, Chef Software Inc. +# Copyright:: Copyright 2008-2018, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -303,20 +303,6 @@ describe Chef::Node do expect(node["tags"]).to eq(%w{one two three four}) end - it "set is a deprecated alias for normal" do - Chef::Config[:treat_deprecation_warnings_as_errors] = false - expect(Chef).to receive(:deprecated).with(:attributes, /set is deprecated/) - node.set[:snoopy][:is_a_puppy] = true - expect(node.normal[:snoopy][:is_a_puppy]).to eq(true) - end - - it "set_unless is a deprecated alias for normal_unless" do - Chef::Config[:treat_deprecation_warnings_as_errors] = false - expect(Chef).to receive(:deprecated).with(:attributes, /set_unless is deprecated/) - node.set_unless[:snoopy][:is_a_puppy] = false - expect(node.normal[:snoopy][:is_a_puppy]).to eq(false) - end - it "normal_unless sets a value even if default or override attrs are set" do node.default[:decontamination] = true node.override[:decontamination] = false diff --git a/spec/unit/recipe_spec.rb b/spec/unit/recipe_spec.rb index 7a538b721b..93d03756a7 100644 --- a/spec/unit/recipe_spec.rb +++ b/spec/unit/recipe_spec.rb @@ -3,7 +3,7 @@ # Author:: Christopher Walters (<cw@chef.io>) # Author:: Tim Hinderliter (<tim@chef.io>) # Author:: Seth Chisamore (<schisamo@chef.io>) -# Copyright:: Copyright 2008-2017, Chef Software Inc. +# Copyright:: Copyright 2008-2018, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -141,16 +141,16 @@ describe Chef::Recipe do Object.send(:remove_const, :TottenhamHotspur) end - it "selects the first one alphabetically" do + it "selects the last-writer wins" do Sounders.provides :football, platform: "nbc_sports" TottenhamHotspur.provides :football, platform: "nbc_sports" res1 = recipe.football "club world cup" expect(res1.name).to eql("club world cup") - expect(res1).to be_a_kind_of(Sounders) + expect(res1).to be_a_kind_of(TottenhamHotspur) end - it "selects the first one alphabetically even if the declaration order is reversed" do + it "selects the last-writer wins even if the declaration order is reversed" do TottenhamHotspur.provides :football2, platform: "nbc_sports" Sounders.provides :football2, platform: "nbc_sports" |