summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames FitzGibbon <james.i.fitzgibbon@nordstrom.com>2015-03-04 15:47:25 -0800
committerJames FitzGibbon <james.i.fitzgibbon@nordstrom.com>2015-03-04 15:47:25 -0800
commitf246fe546c965720eadadc01c7318569d2795aba (patch)
tree8415b292818bfa090fd454420fba410efc2adbe6
parent0bb2861228fd33fd6a4ef296a1dd223abb6dec9f (diff)
downloadchef-f246fe546c965720eadadc01c7318569d2795aba.tar.gz
Add warnings to 'knife node run list remove ...' when the item to be removed doesn't exist
-rw-r--r--lib/chef/knife/node_run_list_remove.rb13
-rw-r--r--spec/unit/knife/node_run_list_remove_spec.rb17
2 files changed, 29 insertions, 1 deletions
diff --git a/lib/chef/knife/node_run_list_remove.rb b/lib/chef/knife/node_run_list_remove.rb
index 4b8953a264..ef03c176b8 100644
--- a/lib/chef/knife/node_run_list_remove.rb
+++ b/lib/chef/knife/node_run_list_remove.rb
@@ -42,7 +42,18 @@ class Chef
entries = @name_args[1].split(',').map { |e| e.strip }
end
- entries.each { |e| node.run_list.remove(e) }
+ # iterate over the list of things to remove,
+ # warning if one of them was not found
+ entries.each do |e|
+ if node.run_list.find { |rli| e == rli.to_s }
+ node.run_list.remove(e)
+ else
+ ui.warn "#{e} is not in the run list"
+ unless e =~ /^(recipe|role)\[/
+ ui.warn '(did you forget recipe[] or role[] around it?)'
+ end
+ end
+ end
node.save
diff --git a/spec/unit/knife/node_run_list_remove_spec.rb b/spec/unit/knife/node_run_list_remove_spec.rb
index ceceef7178..a279a59635 100644
--- a/spec/unit/knife/node_run_list_remove_spec.rb
+++ b/spec/unit/knife/node_run_list_remove_spec.rb
@@ -84,6 +84,23 @@ describe Chef::Knife::NodeRunListRemove do
expect(@node.run_list).not_to include('role[monkey]')
expect(@node.run_list).not_to include('recipe[duck::type]')
end
+
+ it "should warn when the thing to remove is not in the runlist" do
+ @node.run_list << 'role[blah]'
+ @node.run_list << 'recipe[duck::type]'
+ @knife.name_args = [ 'adam', 'role[blork]' ]
+ expect(@knife.ui).to receive(:warn).with("role[blork] is not in the run list")
+ @knife.run
+ end
+
+ it "should warn even more when the thing to remove is not in the runlist and unqualified" do
+ @node.run_list << 'role[blah]'
+ @node.run_list << 'recipe[duck::type]'
+ @knife.name_args = [ 'adam', 'blork' ]
+ expect(@knife.ui).to receive(:warn).with("blork is not in the run list")
+ expect(@knife.ui).to receive(:warn).with(/did you forget recipe\[\] or role\[\]/)
+ @knife.run
+ end
end
end
end