From 2e9789882242f62d60dc687a68b31c4b2488def7 Mon Sep 17 00:00:00 2001 From: danielsdeleo Date: Thu, 5 Nov 2015 17:29:18 -0800 Subject: Handle nil run list option in knife bootstrap --- lib/chef/knife/bootstrap.rb | 10 +++++++++- spec/unit/knife/bootstrap_spec.rb | 15 +++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/chef/knife/bootstrap.rb b/lib/chef/knife/bootstrap.rb index 8502ccb8eb..6830342b89 100644 --- a/lib/chef/knife/bootstrap.rb +++ b/lib/chef/knife/bootstrap.rb @@ -455,7 +455,15 @@ class Chef # True if policy_name and run_list are both given def policyfile_and_run_list_given? - !config[:run_list].empty? && !!config[:policy_name] + run_list_given? && policyfile_options_given? + end + + def run_list_given? + !config[:run_list].nil? && !config[:run_list].empty? + end + + def policyfile_options_given? + !!config[:policy_name] end # True if one of policy_name or policy_group was given, but not both diff --git a/spec/unit/knife/bootstrap_spec.rb b/spec/unit/knife/bootstrap_spec.rb index 342c1878f1..8c5a62e6f0 100644 --- a/spec/unit/knife/bootstrap_spec.rb +++ b/spec/unit/knife/bootstrap_spec.rb @@ -472,6 +472,21 @@ describe Chef::Knife::Bootstrap do end + # https://github.com/chef/chef/issues/4131 + # Arguably a bug in the plugin: it shouldn't be setting this to nil, but it + # worked before, so make it work now. + context "when a plugin sets the run list option to nil" do + + before do + knife.config[:run_list] = nil + end + + it "passes options validation" do + expect { knife.validate_options! }.to_not raise_error + end + + end + end describe "when configuring the underlying knife ssh command" do -- cgit v1.2.1