summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSerdar Sutay <serdar@opscode.com>2014-08-26 12:45:06 -0700
committerSerdar Sutay <serdar@opscode.com>2014-08-26 15:42:27 -0700
commit9e9b5caf33179b7bb4060541064f2ff0ba98ca9f (patch)
treea4f7eee3edc2817290006e691618ee4ae38a8d10
parentc79ceca006bb18b59489ac077879710711bdfd99 (diff)
downloadchef-9e9b5caf33179b7bb4060541064f2ff0ba98ca9f.tar.gz
Fixes based on PR comments.
-rw-r--r--lib/chef/knife/bootstrap.rb34
-rw-r--r--spec/unit/knife/bootstrap_spec.rb15
2 files changed, 32 insertions, 17 deletions
diff --git a/lib/chef/knife/bootstrap.rb b/lib/chef/knife/bootstrap.rb
index 6d98a70b9b..cf4f3c7a0c 100644
--- a/lib/chef/knife/bootstrap.rb
+++ b/lib/chef/knife/bootstrap.rb
@@ -98,17 +98,16 @@ class Chef
option :distro,
:short => "-d DISTRO",
:long => "--distro DISTRO",
- :description => "Bootstrap a distro using a template. [DEPRECATED] Use -t / --template option instead.",
- :proc => Proc.new { |t|
- Chef::Log.warn("[DEPRECATED] -d / --distro option is deprecated. Use -t / --template option instead.")
- Chef::Config[:knife][:bootstrap_template] = t
+ :description => "Bootstrap a distro using a template. [DEPRECATED] Use -t / --bootstrap-template option instead.",
+ :proc => Proc.new { |v|
+ Chef::Log.warn("[DEPRECATED] -d / --distro option is deprecated. Use -t / --bootstrap-template option instead.")
+ v
}
- option :template,
+ option :bootstrap_template,
:short => "-t TEMPLATE",
- :long => "--template TEMPLATE",
- :description => "Bootstrap Chef using a built-in or custom template. Set to the full path of an erb template or use one of the built-in templates.",
- :proc => Proc.new { |t| Chef::Config[:knife][:bootstrap_template] = t }
+ :long => "--bootstrap-template TEMPLATE",
+ :description => "Bootstrap Chef using a built-in or custom template. Set to the full path of an erb template or use one of the built-in templates."
option :use_sudo,
:long => "--sudo",
@@ -123,10 +122,10 @@ class Chef
# DEPR: Remove this option in Chef 13
option :template_file,
:long => "--template-file TEMPLATE",
- :description => "Full path to location of template to use. [DEPRECATED] Use -t / --template option instead.",
- :proc => Proc.new { |t|
- Chef::Log.warn("[DEPRECATED] --template-file option is deprecated. Use -t / --template option instead.")
- Chef::Config[:knife][:bootstrap_template] = t
+ :description => "Full path to location of template to use. [DEPRECATED] Use -t / --bootstrap-template option instead.",
+ :proc => Proc.new { |v|
+ Chef::Log.warn("[DEPRECATED] --template-file option is deprecated. Use -t / --bootstrap-template option instead.")
+ v
}
option :run_list,
@@ -189,8 +188,17 @@ class Chef
:description => "Add options to curl when install chef-client",
:proc => Proc.new { |co| Chef::Config[:knife][:bootstrap_curl_options] = co }
+ def bootstrap_template
+ # For some reason knife.merge_configs doesn't pick up the default values from
+ # Chef::Config[:knife][:bootstrap_template] unless Chef::Config[:knife][:bootstrap_template]
+ # is forced to pick up the values before calling merge_configs.
+ # We therefore have Chef::Config[:knife][:bootstrap_template] to pick up the defaults
+ # if no option is specified.
+ config[:bootstrap_template] || config[:distro] || config[:template_file] || Chef::Config[:knife][:bootstrap_template]
+ end
+
def find_template
- template = Chef::Config[:knife][:bootstrap_template]
+ template = bootstrap_template
# Use the template directly if it's a path to an actual file
if File.exists?(template)
diff --git a/spec/unit/knife/bootstrap_spec.rb b/spec/unit/knife/bootstrap_spec.rb
index 5aae5bdddf..f28879fb4e 100644
--- a/spec/unit/knife/bootstrap_spec.rb
+++ b/spec/unit/knife/bootstrap_spec.rb
@@ -38,8 +38,8 @@ describe Chef::Knife::Bootstrap do
let(:bootstrap_template) { nil }
it "should use chef-full as default template" do
- knife.find_template.should be_a_kind_of(String)
- File.basename(knife.find_template).should eq("chef-full.erb")
+ knife.bootstrap_template.should be_a_kind_of(String)
+ File.basename(knife.bootstrap_template).should eq("chef-full")
end
context "when finding templates" do
@@ -157,11 +157,12 @@ describe Chef::Knife::Bootstrap do
end
end
- ["-d", "--distro", "-t", "--template", "--template-file"].each do |t|
+ ["-d", "--distro", "-t", "--bootstrap-template", "--template-file"].each do |t|
context "when #{t} option is given in the command line" do
it "sets the knife :bootstrap_template config" do
knife.parse_options([t,"blahblah"])
- Chef::Config[:knife][:bootstrap_template].should eq("blahblah")
+ knife.merge_configs
+ knife.bootstrap_template.should eq("blahblah")
end
end
end
@@ -175,16 +176,19 @@ describe Chef::Knife::Bootstrap do
it "should have role[base] in the run_list" do
knife.parse_options(["-r","role[base]"])
+ knife.merge_configs
knife.render_template.should == '{"run_list":["role[base]"]}'
end
it "should have role[base] and recipe[cupcakes] in the run_list" do
knife.parse_options(["-r", "role[base],recipe[cupcakes]"])
+ knife.merge_configs
knife.render_template.should == '{"run_list":["role[base]","recipe[cupcakes]"]}'
end
it "should have foo => {bar => baz} in the first_boot" do
knife.parse_options(["-j", '{"foo":{"bar":"baz"}}'])
+ knife.merge_configs
expected_hash = FFI_Yajl::Parser.new.parse('{"foo":{"bar":"baz"},"run_list":[]}')
actual_hash = FFI_Yajl::Parser.new.parse(knife.render_template)
actual_hash.should == expected_hash
@@ -196,12 +200,14 @@ describe Chef::Knife::Bootstrap do
it "should create a hint file when told to" do
knife.parse_options(["--hint", "openstack"])
+ knife.merge_configs
knife.render_template.should match /\/etc\/chef\/ohai\/hints\/openstack.json/
end
it "should populate a hint file with JSON when given a file to read" do
::File.stub(:read).and_return('{ "foo" : "bar" }')
knife.parse_options(["--hint", "openstack=hints/openstack.json"])
+ knife.merge_configs
knife.render_template.should match /\{\"foo\":\"bar\"\}/
end
end
@@ -249,6 +255,7 @@ describe Chef::Knife::Bootstrap do
let(:bootstrap_template) { File.expand_path(File.join(CHEF_SPEC_DATA, "bootstrap", "secret.erb")) }
let(:rendered_template) do
knife.parse_options(options)
+ knife.merge_configs
knife.render_template
end