summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSerdar Sutay <serdar@opscode.com>2014-08-26 15:48:31 -0700
committerSerdar Sutay <serdar@opscode.com>2014-08-26 15:48:31 -0700
commitde8e2612785c1f9f4bdd05787dcc47d55ef348c6 (patch)
treeeddbd0f470d4146db358b90699c68d5f4b14bf90
parentf5ff27125f1da00fede09ff66b298f583cce5257 (diff)
parent0a9096649287245d12b06ad58168ab4630733a64 (diff)
downloadchef-de8e2612785c1f9f4bdd05787dcc47d55ef348c6.tar.gz
Merge pull request #1885 from opscode/sersut/bootstrap-12
Chef 12 bootstrap cleanup
-rw-r--r--CHANGELOG.md3
-rw-r--r--RELEASE_NOTES.md8
-rw-r--r--lib/chef/config.rb7
-rw-r--r--lib/chef/knife/bootstrap.rb106
-rw-r--r--lib/chef/knife/bootstrap/archlinux-gems.erb2
-rw-r--r--lib/chef/knife/bootstrap/centos5-gems.erb62
-rw-r--r--lib/chef/knife/bootstrap/chef-full.erb1
-rw-r--r--lib/chef/knife/bootstrap/fedora13-gems.erb44
-rw-r--r--lib/chef/knife/bootstrap/ubuntu10.04-apt.erb53
-rw-r--r--lib/chef/knife/bootstrap/ubuntu10.04-gems.erb48
-rw-r--r--lib/chef/knife/bootstrap/ubuntu12.04-gems.erb46
-rw-r--r--lib/chef/knife/core/bootstrap_context.rb43
-rw-r--r--spec/unit/knife/bootstrap_spec.rb457
-rw-r--r--spec/unit/knife/core/bootstrap_context_spec.rb29
14 files changed, 357 insertions, 552 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index eabdfbdff4..ca8cff3958 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -106,6 +106,9 @@
* ChefSpec can find freebsd_package resource correctly when a package resource is declared on Freebsd.
* Autodetect/decrypt encrypted data bag items with data_bag_item dsl method. (Issue 1837, Issue 1849)
* windows_user: look up username instead of resource name (Issue #1705)
+* Remove the unused bootstrap templates that install chef from rubygems
+* Remove the Chef 10 functionality from bootstrap.
+* Deprecate --distro / --template_file options in favor of --boostrap-template
## Last Release: 11.14.2
diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md
index 0e207f315b..d67a1b9a04 100644
--- a/RELEASE_NOTES.md
+++ b/RELEASE_NOTES.md
@@ -1,5 +1,13 @@
# Chef Client Release Notes 12.0.0:
+## Boostrap Changes
+
+Chef Client 12 introduces a set of changes to `knife bootstrap`. Here is the list of changes:
+
+* Unused / untested bootstrap templates that install Chef Client from rubygems are removed. The recommended installation path for Chef Client is to use the omnibus packages. `chef-full` template (which is the default) installs Chef Client using omnibus packages on all the supported platforms.
+* `--distro` & `--template-file` options are deprecated in Chef 12 in favor of `--boostrap-template` option. This option can take a boostrap template name (e.g. 'chef-full') or the full path to a bootstrap template.
+
+
## Solaris Mount Provider
The Solaris provider now supports specifying the fsck_device attribute (which defaults to '-' for backwards compat).
diff --git a/lib/chef/config.rb b/lib/chef/config.rb
index c1de4546ac..08a377ca12 100644
--- a/lib/chef/config.rb
+++ b/lib/chef/config.rb
@@ -417,10 +417,6 @@ class Chef
# This secret is used to decrypt encrypted data bag items.
default(:encrypted_data_bag_secret) do
- # We have to check for the existence of the default file before setting it
- # since +Chef::Config[:encrypted_data_bag_secret]+ is read by older
- # bootstrap templates to determine if the local secret should be uploaded to
- # node being bootstrapped. This should be removed in Chef 12.
if File.exist?(platform_specific_path("/etc/chef/encrypted_data_bag_secret"))
platform_specific_path("/etc/chef/encrypted_data_bag_secret")
else
@@ -505,6 +501,9 @@ class Chef
default :ssh_gateway, nil
default :bootstrap_version, nil
default :bootstrap_proxy, nil
+ default :bootstrap_template, "chef-full"
+ default :secret, nil
+ default :secret_file, nil
default :identity_file, nil
default :host_key_verify, nil
default :forward_agent, nil
diff --git a/lib/chef/knife/bootstrap.rb b/lib/chef/knife/bootstrap.rb
index d3d45bad4b..cf4f3c7a0c 100644
--- a/lib/chef/knife/bootstrap.rb
+++ b/lib/chef/knife/bootstrap.rb
@@ -94,11 +94,20 @@ class Chef
:description => "Do not proxy locations for the node being bootstrapped; this option is used internally by Opscode",
:proc => Proc.new { |np| Chef::Config[:knife][:bootstrap_no_proxy] = np }
+ # DEPR: Remove this option in Chef 13
option :distro,
:short => "-d DISTRO",
:long => "--distro DISTRO",
- :description => "Bootstrap a distro using a template",
- :default => "chef-full"
+ :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 :bootstrap_template,
+ :short => "-t TEMPLATE",
+ :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",
@@ -110,10 +119,14 @@ class Chef
:description => "Execute the bootstrap via sudo with password",
:boolean => false
+ # DEPR: Remove this option in Chef 13
option :template_file,
:long => "--template-file TEMPLATE",
- :description => "Full path to location of template to use",
- :default => false
+ :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,
:short => "-r RUN_LIST",
@@ -141,7 +154,8 @@ class Chef
:proc => Proc.new { |h|
Chef::Config[:knife][:hints] ||= Hash.new
name, path = h.split("=")
- Chef::Config[:knife][:hints][name] = path ? Chef::JSONCompat.parse(::File.read(path)) : Hash.new }
+ Chef::Config[:knife][:hints][name] = path ? Chef::JSONCompat.parse(::File.read(path)) : Hash.new
+ }
option :secret,
:short => "-s SECRET",
@@ -174,53 +188,59 @@ class Chef
:description => "Add options to curl when install chef-client",
:proc => Proc.new { |co| Chef::Config[:knife][:bootstrap_curl_options] = co }
- def find_template(template=nil)
- # Are we bootstrapping using an already shipped template?
- if config[:template_file]
- bootstrap_files = config[:template_file]
- else
- bootstrap_files = []
- bootstrap_files << File.join(File.dirname(__FILE__), 'bootstrap', "#{config[:distro]}.erb")
- bootstrap_files << File.join(Knife.chef_config_dir, "bootstrap", "#{config[:distro]}.erb") if Knife.chef_config_dir
- bootstrap_files << File.join(ENV['HOME'], '.chef', 'bootstrap', "#{config[:distro]}.erb") if ENV['HOME']
- bootstrap_files << Gem.find_files(File.join("chef","knife","bootstrap","#{config[:distro]}.erb"))
- bootstrap_files.flatten!
+ 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 = bootstrap_template
+
+ # Use the template directly if it's a path to an actual file
+ if File.exists?(template)
+ Chef::Log.debug("Using the specified bootstrap template: #{File.dirname(template)}")
+ return template
end
- template = Array(bootstrap_files).find do |bootstrap_template|
+ # Otherwise search the template directories until we find the right one
+ bootstrap_files = []
+ bootstrap_files << File.join(File.dirname(__FILE__), 'bootstrap', "#{template}.erb")
+ bootstrap_files << File.join(Knife.chef_config_dir, "bootstrap", "#{template}.erb") if Chef::Knife.chef_config_dir
+ bootstrap_files << File.join(ENV['HOME'], '.chef', 'bootstrap', "#{template}.erb") if ENV['HOME']
+ bootstrap_files << Gem.find_files(File.join("chef","knife","bootstrap","#{template}.erb"))
+ bootstrap_files.flatten!
+
+ template_file = Array(bootstrap_files).find do |bootstrap_template|
Chef::Log.debug("Looking for bootstrap template in #{File.dirname(bootstrap_template)}")
File.exists?(bootstrap_template)
end
- unless template
- ui.info("Can not find bootstrap definition for #{config[:distro]}")
+ unless template_file
+ ui.info("Can not find bootstrap definition for #{template}")
raise Errno::ENOENT
end
- Chef::Log.debug("Found bootstrap template in #{File.dirname(template)}")
+ Chef::Log.debug("Found bootstrap template in #{File.dirname(template_file)}")
- template
+ template_file
end
- def render_template(template=nil)
+ def render_template
+ template_file = find_template
+ template = IO.read(template_file).chomp
context = Knife::Core::BootstrapContext.new(config, config[:run_list], Chef::Config)
Erubis::Eruby.new(template).evaluate(context)
end
- def read_template
- IO.read(@template_file).chomp
- end
-
def run
validate_name_args!
- warn_chef_config_secret_key
- @template_file = find_template(config[:bootstrap_template])
@node_name = Array(@name_args).first
- # back compat--templates may use this setting:
- config[:server_name] = @node_name
$stdout.sync = true
-
ui.info("Connecting to #{ui.color(@node_name, :bold)}")
begin
@@ -272,7 +292,7 @@ class Chef
end
def ssh_command
- command = render_template(read_template)
+ command = render_template
if config[:use_sudo]
command = config[:use_sudo_password] ? "echo '#{config[:ssh_password]}' | sudo -S #{command}" : "sudo #{command}"
@@ -281,28 +301,6 @@ class Chef
command
end
- def warn_chef_config_secret_key
- unless Chef::Config[:encrypted_data_bag_secret].nil?
- ui.warn "* " * 40
- ui.warn(<<-WARNING)
-Specifying the encrypted data bag secret key using an 'encrypted_data_bag_secret'
-entry in 'knife.rb' is deprecated. Please see CHEF-4011 for more details. You
-can supress this warning and still distribute the secret key to all bootstrapped
-machines by adding the following to your 'knife.rb' file:
-
- knife[:secret_file] = "/path/to/your/secret"
-
-If you would like to selectively distribute a secret key during bootstrap
-please use the '--secret' or '--secret-file' options of this command instead.
-
-#{ui.color('IMPORTANT:', :red, :bold)} In a future version of Chef, this
-behavior will be removed and any 'encrypted_data_bag_secret' entries in
-'knife.rb' will be ignored completely.
-WARNING
- ui.warn "* " * 40
- end
- end
-
end
end
end
diff --git a/lib/chef/knife/bootstrap/archlinux-gems.erb b/lib/chef/knife/bootstrap/archlinux-gems.erb
index ab2aa7a7f1..bb84340c05 100644
--- a/lib/chef/knife/bootstrap/archlinux-gems.erb
+++ b/lib/chef/knife/bootstrap/archlinux-gems.erb
@@ -6,7 +6,7 @@ if [ ! -f /usr/bin/chef-client ]; then
pacman -S --noconfirm ruby ntp base-devel
ntpdate -u pool.ntp.org
gem install ohai --no-user-install --no-document --verbose
- gem install chef --no-user-install --no-document --verbose <%= bootstrap_version_string %>
+ gem install chef --no-user-install --no-document --verbose <%= Chef::VERSION %>
fi
mkdir -p /etc/chef
diff --git a/lib/chef/knife/bootstrap/centos5-gems.erb b/lib/chef/knife/bootstrap/centos5-gems.erb
deleted file mode 100644
index 6aacc47179..0000000000
--- a/lib/chef/knife/bootstrap/centos5-gems.erb
+++ /dev/null
@@ -1,62 +0,0 @@
-bash -c '
-<%= "export http_proxy=\"#{knife_config[:bootstrap_proxy]}\"" if knife_config[:bootstrap_proxy] -%>
-
-if [ ! -f /usr/bin/chef-client ]; then
- tmp_dir=$(mktemp -d) || exit 1
- pushd "$tmp_dir"
-
- yum install -y wget
-
- wget <%= "--proxy=on " if knife_config[:bootstrap_proxy] %>http://dl.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm
- rpm -Uvh epel-release-5-4.noarch.rpm
- wget <%= "--proxy=on " if knife_config[:bootstrap_proxy] %>http://rpm.aegisco.com/aegisco/rhel/aegisco-rhel.rpm
- rpm -Uvh aegisco-rhel.rpm
-
- yum install -y ruby ruby-devel gcc gcc-c++ automake autoconf make
-
- wget <%= "--proxy=on " if knife_config[:bootstrap_proxy] %>http://production.cf.rubygems.org/rubygems/rubygems-1.6.2.tgz -O - | tar zxf -
- (cd rubygems-1.6.2 && ruby setup.rb --no-format-executable)
-
- popd
- rm -r "$tmp_dir"
-fi
-
-gem update --system
-gem update
-gem install ohai --no-rdoc --no-ri --verbose
-gem install chef --no-rdoc --no-ri --verbose <%= bootstrap_version_string %>
-
-mkdir -p /etc/chef
-
-cat > /etc/chef/validation.pem <<'EOP'
-<%= validation_key %>
-EOP
-chmod 0600 /etc/chef/validation.pem
-
-<% if encrypted_data_bag_secret -%>
-cat > /etc/chef/encrypted_data_bag_secret <<'EOP'
-<%= encrypted_data_bag_secret %>
-EOP
-chmod 0600 /etc/chef/encrypted_data_bag_secret
-<% end -%>
-
-<%# Generate Ohai Hints -%>
-<% unless @chef_config[:knife][:hints].nil? || @chef_config[:knife][:hints].empty? -%>
-mkdir -p /etc/chef/ohai/hints
-
-<% @chef_config[:knife][:hints].each do |name, hash| -%>
-cat > /etc/chef/ohai/hints/<%= name %>.json <<'EOP'
-<%= hash.to_json %>
-EOP
-<% end -%>
-<% end -%>
-
-cat > /etc/chef/client.rb <<'EOP'
-<%= config_content %>
-EOP
-
-cat > /etc/chef/first-boot.json <<'EOP'
-<%= first_boot.to_json %>
-EOP
-
-<%= start_chef %>'
diff --git a/lib/chef/knife/bootstrap/chef-full.erb b/lib/chef/knife/bootstrap/chef-full.erb
index c953a7e433..a4e85b9d67 100644
--- a/lib/chef/knife/bootstrap/chef-full.erb
+++ b/lib/chef/knife/bootstrap/chef-full.erb
@@ -23,7 +23,6 @@ exists() {
<%= knife_config[:bootstrap_install_command] %>
<% else %>
install_sh="<%= knife_config[:bootstrap_url] ? knife_config[:bootstrap_url] : "https://www.opscode.com/chef/install.sh" %>"
- version_string="-v <%= chef_version %>"
if ! exists /usr/bin/chef-client; then
echo "Installing Chef Client..."
if exists wget; then
diff --git a/lib/chef/knife/bootstrap/fedora13-gems.erb b/lib/chef/knife/bootstrap/fedora13-gems.erb
deleted file mode 100644
index 0aabc31085..0000000000
--- a/lib/chef/knife/bootstrap/fedora13-gems.erb
+++ /dev/null
@@ -1,44 +0,0 @@
-bash -c '
-<%= "export http_proxy=\"#{knife_config[:bootstrap_proxy]}\"" if knife_config[:bootstrap_proxy] -%>
-
-yum install -y ruby ruby-devel gcc gcc-c++ automake autoconf rubygems make
-
-gem update --system
-gem update
-gem install ohai --no-rdoc --no-ri --verbose
-gem install chef --no-rdoc --no-ri --verbose <%= bootstrap_version_string %>
-
-mkdir -p /etc/chef
-
-cat > /etc/chef/validation.pem <<'EOP'
-<%= validation_key %>
-EOP
-chmod 0600 /etc/chef/validation.pem
-
-<% if encrypted_data_bag_secret -%>
-cat > /etc/chef/encrypted_data_bag_secret <<'EOP'
-<%= encrypted_data_bag_secret %>
-EOP
-chmod 0600 /etc/chef/encrypted_data_bag_secret
-<% end -%>
-
-<%# Generate Ohai Hints -%>
-<% unless @chef_config[:knife][:hints].nil? || @chef_config[:knife][:hints].empty? -%>
-mkdir -p /etc/chef/ohai/hints
-
-<% @chef_config[:knife][:hints].each do |name, hash| -%>
-cat > /etc/chef/ohai/hints/<%= name %>.json <<'EOP'
-<%= hash.to_json %>
-EOP
-<% end -%>
-<% end -%>
-
-cat > /etc/chef/client.rb <<'EOP'
-<%= config_content %>
-EOP
-
-cat > /etc/chef/first-boot.json <<'EOP'
-<%= first_boot.to_json %>
-EOP
-
-<%= start_chef %>'
diff --git a/lib/chef/knife/bootstrap/ubuntu10.04-apt.erb b/lib/chef/knife/bootstrap/ubuntu10.04-apt.erb
deleted file mode 100644
index 4549b94d2b..0000000000
--- a/lib/chef/knife/bootstrap/ubuntu10.04-apt.erb
+++ /dev/null
@@ -1,53 +0,0 @@
-bash -c '
-<%= "export http_proxy=\"#{knife_config[:bootstrap_proxy]}\"" if knife_config[:bootstrap_proxy] -%>
-
-if [ ! -f /usr/bin/chef-client ]; then
- apt-get install -y wget
- echo "chef chef/chef_server_url string <%= @chef_config[:chef_server_url] %>" | debconf-set-selections
- [ -f /etc/apt/sources.list.d/opscode.list ] || echo "deb http://apt.opscode.com <%= chef_version.to_f == 0.10 ? "lucid-0.10" : "lucid" %> main" > /etc/apt/sources.list.d/opscode.list
- wget <%= "--proxy=on " if knife_config[:bootstrap_proxy] %>-O- http://apt.opscode.com/packages@opscode.com.gpg.key | apt-key add -
-fi
-apt-get update
-apt-get install -y chef
-
-cat > /etc/chef/validation.pem <<'EOP'
-<%= validation_key %>
-EOP
-chmod 0600 /etc/chef/validation.pem
-
-<% if encrypted_data_bag_secret -%>
-cat > /etc/chef/encrypted_data_bag_secret <<'EOP'
-<%= encrypted_data_bag_secret %>
-EOP
-chmod 0600 /etc/chef/encrypted_data_bag_secret
-<% end -%>
-
-<%# Generate Ohai Hints -%>
-<% unless @chef_config[:knife][:hints].nil? || @chef_config[:knife][:hints].empty? -%>
-mkdir -p /etc/chef/ohai/hints
-
-<% @chef_config[:knife][:hints].each do |name, hash| -%>
-cat > /etc/chef/ohai/hints/<%= name %>.json <<'EOP'
-<%= hash.to_json %>
-EOP
-<% end -%>
-<% end -%>
-
-<% unless @chef_config[:validation_client_name] == "chef-validator" -%>
-[ `grep -qx "validation_client_name \"<%= @chef_config[:validation_client_name] %>\"" /etc/chef/client.rb` ] || echo "validation_client_name \"<%= @chef_config[:validation_client_name] %>\"" >> /etc/chef/client.rb
-<% end -%>
-
-<% if @config[:chef_node_name] %>
-[ `grep -qx "node_name \"<%= @config[:chef_node_name] %>\"" /etc/chef/client.rb` ] || echo "node_name \"<%= @config[:chef_node_name] %>\"" >> /etc/chef/client.rb
-<% end -%>
-
-<% if knife_config[:bootstrap_proxy] %>
-echo 'http_proxy "knife_config[:bootstrap_proxy]"' >> /etc/chef/client.rb
-echo 'https_proxy "knife_config[:bootstrap_proxy]"' >> /etc/chef/client.rb
-<% end -%>
-
-cat > /etc/chef/first-boot.json <<'EOP'
-<%= first_boot.to_json %>
-EOP
-
-<%= start_chef %>'
diff --git a/lib/chef/knife/bootstrap/ubuntu10.04-gems.erb b/lib/chef/knife/bootstrap/ubuntu10.04-gems.erb
deleted file mode 100644
index 62ff7c857e..0000000000
--- a/lib/chef/knife/bootstrap/ubuntu10.04-gems.erb
+++ /dev/null
@@ -1,48 +0,0 @@
-bash -c '
-<%= "export http_proxy=\"#{knife_config[:bootstrap_proxy]}\"" if knife_config[:bootstrap_proxy] -%>
-
-if [ ! -f /usr/bin/chef-client ]; then
- apt-get update
- apt-get install -y ruby ruby1.8-dev build-essential wget libruby-extras libruby1.8-extras
- wget <%= "--proxy=on " if knife_config[:bootstrap_proxy] %>http://production.cf.rubygems.org/rubygems/rubygems-1.6.2.tgz -O - | tar zxf -
- (cd rubygems-1.6.2 && ruby setup.rb --no-format-executable)
-fi
-
-gem update --no-rdoc --no-ri
-gem install ohai --no-rdoc --no-ri --verbose
-gem install chef --no-rdoc --no-ri --verbose <%= bootstrap_version_string %>
-
-mkdir -p /etc/chef
-
-cat > /etc/chef/validation.pem <<'EOP'
-<%= validation_key %>
-EOP
-chmod 0600 /etc/chef/validation.pem
-
-<% if encrypted_data_bag_secret -%>
-cat > /etc/chef/encrypted_data_bag_secret <<'EOP'
-<%= encrypted_data_bag_secret %>
-EOP
-chmod 0600 /etc/chef/encrypted_data_bag_secret
-<% end -%>
-
-<%# Generate Ohai Hints -%>
-<% unless @chef_config[:knife][:hints].nil? || @chef_config[:knife][:hints].empty? -%>
-mkdir -p /etc/chef/ohai/hints
-
-<% @chef_config[:knife][:hints].each do |name, hash| -%>
-cat > /etc/chef/ohai/hints/<%= name %>.json <<'EOP'
-<%= hash.to_json %>
-EOP
-<% end -%>
-<% end -%>
-
-cat > /etc/chef/client.rb <<'EOP'
-<%= config_content %>
-EOP
-
-cat > /etc/chef/first-boot.json <<'EOP'
-<%= first_boot.to_json %>
-EOP
-
-<%= start_chef %>'
diff --git a/lib/chef/knife/bootstrap/ubuntu12.04-gems.erb b/lib/chef/knife/bootstrap/ubuntu12.04-gems.erb
deleted file mode 100644
index 8e9c6583d0..0000000000
--- a/lib/chef/knife/bootstrap/ubuntu12.04-gems.erb
+++ /dev/null
@@ -1,46 +0,0 @@
-bash -c '
-<%= "export http_proxy=\"#{knife_config[:bootstrap_proxy]}\"" if knife_config[:bootstrap_proxy] -%>
-
-if [ ! -f /usr/bin/chef-client ]; then
- aptitude update
- aptitude install -y ruby ruby1.8-dev build-essential wget libruby1.8 rubygems
-fi
-
-gem update --no-rdoc --no-ri
-gem install ohai --no-rdoc --no-ri --verbose
-gem install chef --no-rdoc --no-ri --verbose <%= bootstrap_version_string %>
-
-mkdir -p /etc/chef
-
-cat > /etc/chef/validation.pem <<'EOP'
-<%= validation_key %>
-EOP
-chmod 0600 /etc/chef/validation.pem
-
-<% if encrypted_data_bag_secret -%>
-cat > /etc/chef/encrypted_data_bag_secret <<'EOP'
-<%= encrypted_data_bag_secret %>
-EOP
-chmod 0600 /etc/chef/encrypted_data_bag_secret
-<% end -%>
-
-<%# Generate Ohai Hints -%>
-<% unless @chef_config[:knife][:hints].nil? || @chef_config[:knife][:hints].empty? -%>
-mkdir -p /etc/chef/ohai/hints
-
-<% @chef_config[:knife][:hints].each do |name, hash| -%>
-cat > /etc/chef/ohai/hints/<%= name %>.json <<'EOP'
-<%= hash.to_json %>
-EOP
-<% end -%>
-<% end -%>
-
-cat > /etc/chef/client.rb <<'EOP'
-<%= config_content %>
-EOP
-
-cat > /etc/chef/first-boot.json <<'EOP'
-<%= first_boot.to_json %>
-EOP
-
-<%= start_chef %>'
diff --git a/lib/chef/knife/core/bootstrap_context.rb b/lib/chef/knife/core/bootstrap_context.rb
index 742ef226a3..0fdd77594a 100644
--- a/lib/chef/knife/core/bootstrap_context.rb
+++ b/lib/chef/knife/core/bootstrap_context.rb
@@ -34,14 +34,6 @@ class Chef
@chef_config = chef_config
end
- def bootstrap_version_string
- if @config[:prerelease]
- "--prerelease"
- else
- "--version #{chef_version}"
- end
- end
-
def bootstrap_environment
@chef_config[:environment] || '_default'
end
@@ -54,8 +46,8 @@ class Chef
knife_config[:secret] || begin
if knife_config[:secret_file] && File.exist?(knife_config[:secret_file])
IO.read(File.expand_path(knife_config[:secret_file]))
- elsif @chef_config[:encrypted_data_bag_secret] && File.exist?(@chef_config[:encrypted_data_bag_secret])
- IO.read(File.expand_path(@chef_config[:encrypted_data_bag_secret]))
+ else
+ nil
end
end
end
@@ -93,7 +85,7 @@ CONFIG
client_path = @chef_config[:chef_client_path] || 'chef-client'
s = "#{client_path} -j /etc/chef/first-boot.json"
s << ' -l debug' if @config[:verbosity] and @config[:verbosity] >= 2
- s << " -E #{bootstrap_environment}" if chef_version.to_f != 0.9 # only use the -E option on Chef 0.10+
+ s << " -E #{bootstrap_environment}"
s
end
@@ -102,29 +94,26 @@ CONFIG
end
#
- # This function is used by older bootstrap templates other than chef-full
- # and potentially by custom templates as well hence it's logic needs to be
- # preserved for backwards compatibility reasons until we hit Chef 12.
- def chef_version
- knife_config[:bootstrap_version] || Chef::VERSION
- end
-
- #
# chef version string to fetch the latest current version from omnitruck
# If user is on X.Y.Z bootstrap will use the latest X release
# X here can be 10 or 11
def latest_current_chef_version_string
- chef_version_string = if knife_config[:bootstrap_version]
- knife_config[:bootstrap_version]
+ installer_version_string = nil
+ if @config[:prerelease]
+ installer_version_string = "-p"
else
- Chef::VERSION.split(".").first
- end
+ chef_version_string = if knife_config[:bootstrap_version]
+ knife_config[:bootstrap_version]
+ else
+ Chef::VERSION.split(".").first
+ end
- installer_version_string = ["-v", chef_version_string]
+ installer_version_string = ["-v", chef_version_string]
- # If bootstrapping a pre-release version add -p to the installer string
- if chef_version_string.split(".").length > 3
- installer_version_string << "-p"
+ # If bootstrapping a pre-release version add -p to the installer string
+ if chef_version_string.split(".").length > 3
+ installer_version_string << "-p"
+ end
end
installer_version_string.join(" ")
diff --git a/spec/unit/knife/bootstrap_spec.rb b/spec/unit/knife/bootstrap_spec.rb
index 999a845c83..f28879fb4e 100644
--- a/spec/unit/knife/bootstrap_spec.rb
+++ b/spec/unit/knife/bootstrap_spec.rb
@@ -22,111 +22,200 @@ Chef::Knife::Bootstrap.load_deps
require 'net/ssh'
describe Chef::Knife::Bootstrap do
- before(:each) do
+ let(:knife) do
Chef::Log.logger = Logger.new(StringIO.new)
- @knife = Chef::Knife::Bootstrap.new
- # Merge default settings in.
- @knife.merge_configs
- @knife.config[:template_file] = File.expand_path(File.join(CHEF_SPEC_DATA, "bootstrap", "test.erb"))
- @stdout = StringIO.new
- @knife.ui.stub(:stdout).and_return(@stdout)
- @stderr = StringIO.new
- @knife.ui.stub(:stderr).and_return(@stderr)
- end
+ Chef::Config[:knife][:bootstrap_template] = bootstrap_template unless bootstrap_template.nil?
- it "should return a name of default bootstrap template" do
- @knife.find_template.should be_a_kind_of(String)
- end
+ k = Chef::Knife::Bootstrap.new
+ k.merge_configs
- it "should error if template can not be found" do
- @knife.config[:template_file] = false
- @knife.config[:distro] = 'penultimate'
- lambda { @knife.find_template }.should raise_error
+ k.ui.stub(:stderr).and_return(stderr)
+ k
end
- it "should look for templates early in the run" do
- File.stub(:exists?).and_return(true)
- @knife.name_args = ['shatner']
- @knife.stub(:read_template).and_return("")
- @knife.stub(:knife_ssh).and_return(true)
- @knife_ssh = @knife.knife_ssh
- @knife.should_receive(:find_template).ordered
- @knife.should_receive(:knife_ssh).ordered
- @knife_ssh.should_receive(:run) # rspec appears to keep order per object
- @knife.run
- end
+ let(:stderr) { StringIO.new }
- it "should load the specified template" do
- @knife.config[:distro] = 'fedora13-gems'
- lambda { @knife.find_template }.should_not raise_error
- end
+ let(:bootstrap_template) { nil }
- it "should load the specified template from a Ruby gem" do
- @knife.config[:template_file] = false
- Gem.stub(:find_files).and_return(["/Users/schisamo/.rvm/gems/ruby-1.9.2-p180@chef-0.10/gems/knife-windows-0.5.4/lib/chef/knife/bootstrap/fake-bootstrap-template.erb"])
- File.stub(:exists?).and_return(true)
- IO.stub(:read).and_return('random content')
- @knife.config[:distro] = 'fake-bootstrap-template'
- lambda { @knife.find_template }.should_not raise_error
+ it "should use chef-full as default template" do
+ knife.bootstrap_template.should be_a_kind_of(String)
+ File.basename(knife.bootstrap_template).should eq("chef-full")
end
- it "should return an empty run_list" do
- @knife.instance_variable_set("@template_file", @knife.config[:template_file])
- template_string = @knife.read_template
- @knife.render_template(template_string).should == '{"run_list":[]}'
- end
+ context "when finding templates" do
+ context "when :bootstrap_template config is set to a file" do
+ context "that doesn't exist" do
+ let(:bootstrap_template) { "/opt/blah/not/exists/template.erb" }
- it "should have role[base] in the run_list" do
- @knife.instance_variable_set("@template_file", @knife.config[:template_file])
- template_string = @knife.read_template
- @knife.parse_options(["-r","role[base]"])
- @knife.render_template(template_string).should == '{"run_list":["role[base]"]}'
- end
+ it "raises an error" do
+ lambda { knife.find_template }.should raise_error
+ end
+ end
- it "should have role[base] and recipe[cupcakes] in the run_list" do
- @knife.instance_variable_set("@template_file", @knife.config[:template_file])
- template_string = @knife.read_template
- @knife.parse_options(["-r", "role[base],recipe[cupcakes]"])
- @knife.render_template(template_string).should == '{"run_list":["role[base]","recipe[cupcakes]"]}'
- end
+ context "that exists" do
+ let(:bootstrap_template) { File.expand_path(File.join(CHEF_SPEC_DATA, "bootstrap", "test.erb")) }
+
+ it "loads the given file as the template" do
+ Chef::Log.should_receive(:debug)
+ knife.find_template.should eq(File.expand_path(File.join(CHEF_SPEC_DATA, "bootstrap", "test.erb")))
+ end
+ end
+ end
+
+ context "when :bootstrap_template config is set to a template name" do
+ let(:bootstrap_template) { "example" }
+
+ let(:builtin_template_path) { File.expand_path(File.join(File.dirname(__FILE__), '../../../lib/chef/knife/bootstrap', "example.erb"))}
+
+ let(:chef_config_dir_template_path) { "/knife/chef/config/bootstrap/example.erb" }
+
+ let(:env_home_template_path) { "/env/home/.chef/bootstrap/example.erb" }
+
+ let(:gem_files_template_path) { "/Users/schisamo/.rvm/gems/ruby-1.9.2-p180@chef-0.10/gems/knife-windows-0.5.4/lib/chef/knife/bootstrap/fake-bootstrap-template.erb" }
+
+ def configure_chef_config_dir
+ Chef::Knife.stub(:chef_config_dir).and_return("/knife/chef/config")
+ end
+
+ def configure_env_home
+ ENV['HOME'] = "/env/home"
+ end
+
+ def configure_gem_files
+ Gem.stub(:find_files).and_return([ gem_files_template_path ])
+ end
+
+ before(:each) do
+ @original_home = ENV['HOME']
+ ENV['HOME'] = nil
+ File.should_receive(:exists?).with(bootstrap_template).and_return(false)
+ end
+
+ after(:each) do
+ ENV['HOME'] = @original_home
+ end
+
+ context "when file is available everywhere" do
+ before do
+ configure_chef_config_dir
+ configure_env_home
+ configure_gem_files
+
+ File.should_receive(:exists?).with(builtin_template_path).and_return(true)
+ end
+
+ it "should load the template from built-in templates" do
+ knife.find_template.should eq(builtin_template_path)
+ end
+ end
+
+ context "when file is available in chef_config_dir" do
+ before do
+ configure_chef_config_dir
+ configure_env_home
+ configure_gem_files
+
+ File.should_receive(:exists?).with(builtin_template_path).and_return(false)
+ File.should_receive(:exists?).with(chef_config_dir_template_path).and_return(true)
- it "should have foo => {bar => baz} in the first_boot" do
- @knife.instance_variable_set("@template_file", @knife.config[:template_file])
- template_string = @knife.read_template
- @knife.parse_options(["-j", '{"foo":{"bar":"baz"}}'])
- expected_hash = FFI_Yajl::Parser.new.parse('{"foo":{"bar":"baz"},"run_list":[]}')
- actual_hash = FFI_Yajl::Parser.new.parse(@knife.render_template(template_string))
- actual_hash.should == expected_hash
+ it "should load the template from chef_config_dir" do
+ knife.find_template.should eq(chef_config_dir_template_path)
+ end
+ end
+ end
+
+ context "when file is available in ENV['HOME']" do
+ before do
+ configure_chef_config_dir
+ configure_env_home
+ configure_gem_files
+
+ File.should_receive(:exists?).with(builtin_template_path).and_return(false)
+ File.should_receive(:exists?).with(chef_config_dir_template_path).and_return(false)
+ File.should_receive(:exists?).with(env_home_template_path).and_return(true)
+ end
+
+ it "should load the template from chef_config_dir" do
+ knife.find_template.should eq(env_home_template_path)
+ end
+ end
+
+ context "when file is available in Gem files" do
+ before do
+ configure_chef_config_dir
+ configure_gem_files
+
+ File.should_receive(:exists?).with(builtin_template_path).and_return(false)
+ File.should_receive(:exists?).with(chef_config_dir_template_path).and_return(false)
+ File.should_receive(:exists?).with(gem_files_template_path).and_return(true)
+ end
+
+ it "should load the template from Gem files" do
+ knife.find_template.should eq(gem_files_template_path)
+ end
+ end
+ end
end
- it "should create a hint file when told to" do
- @knife.config[:template_file] = File.expand_path(File.join(CHEF_SPEC_DATA, "bootstrap", "test-hints.erb"))
- @knife.instance_variable_set("@template_file", @knife.config[:template_file])
- template_string = @knife.read_template
- @knife.parse_options(["--hint", "openstack"])
- @knife.render_template(template_string).should match /\/etc\/chef\/ohai\/hints\/openstack.json/
+ ["-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"])
+ knife.merge_configs
+ knife.bootstrap_template.should eq("blahblah")
+ end
+ end
end
- it "should populate a hint file with JSON when given a file to read" do
- @knife.stub(:find_template).and_return(true)
- @knife.config[:template_file] = File.expand_path(File.join(CHEF_SPEC_DATA, "bootstrap", "test-hints.erb"))
- ::File.stub(:read).and_return('{ "foo" : "bar" }')
- @knife.instance_variable_set("@template_file", @knife.config[:template_file])
- template_string = @knife.read_template
- @knife.stub(:read_template).and_return('{ "foo" : "bar" }')
- @knife.parse_options(["--hint", "openstack=hints/openstack.json"])
- @knife.render_template(template_string).should match /\{\"foo\":\"bar\"\}/
+ context "with run_list template" do
+ let(:bootstrap_template) { File.expand_path(File.join(CHEF_SPEC_DATA, "bootstrap", "test.erb")) }
+
+ it "should return an empty run_list" do
+ knife.render_template.should == '{"run_list":[]}'
+ end
+
+ 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
+ end
end
- it "should take the node name from ARGV" do
- @knife.name_args = ['barf']
- @knife.name_args.first.should == "barf"
+ context "with hints template" do
+ let(:bootstrap_template) { File.expand_path(File.join(CHEF_SPEC_DATA, "bootstrap", "test-hints.erb")) }
+
+ 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
describe "specifying no_proxy with various entries" do
subject(:knife) do
k = described_class.new
- k.instance_variable_set("@template_file", template_file)
+ Chef::Config[:knife][:bootstrap_template] = template_file
k.parse_options(options)
k.merge_configs
k
@@ -139,8 +228,7 @@ describe Chef::Knife::Bootstrap do
let(:options){ ["--bootstrap-no-proxy", setting, "-s", "foo"] }
let(:template_file) { File.expand_path(File.join(CHEF_SPEC_DATA, "bootstrap", "no_proxy.erb")) }
let(:rendered_template) do
- template_string = knife.read_template
- knife.render_template(template_string)
+ knife.render_template
end
context "via --bootstrap-no-proxy" do
@@ -161,16 +249,14 @@ describe Chef::Knife::Bootstrap do
end
describe "specifying the encrypted data bag secret key" do
- subject(:knife) { described_class.new }
let(:secret) { "supersekret" }
let(:secret_file) { File.join(CHEF_SPEC_DATA, 'bootstrap', 'encrypted_data_bag_secret') }
let(:options) { [] }
- let(:template_file) { File.expand_path(File.join(CHEF_SPEC_DATA, "bootstrap", "secret.erb")) }
+ let(:bootstrap_template) { File.expand_path(File.join(CHEF_SPEC_DATA, "bootstrap", "secret.erb")) }
let(:rendered_template) do
- knife.instance_variable_set("@template_file", template_file)
knife.parse_options(options)
- template_string = knife.read_template
- knife.render_template(template_string)
+ knife.merge_configs
+ knife.render_template
end
context "via --secret" do
@@ -198,10 +284,27 @@ describe Chef::Knife::Bootstrap do
end
end
- context "via Chef::Config[:encrypted_data_bag_secret]" do
- before(:each) { Chef::Config[:encrypted_data_bag_secret] = secret_file }
+ context "secret via config" do
+ before do
+ Chef::Config[:knife][:secret] = secret
+ end
+
+ it "creates a secret file" do
+ rendered_template.should match(%r{#{secret}})
+ end
+
+ it "renders the client.rb with an encrypted_data_bag_secret entry" do
+ rendered_template.should match(%r{encrypted_data_bag_secret\s*"/etc/chef/encrypted_data_bag_secret"})
+ end
+ end
+
+ context "secret-file via config" do
let(:secret) { IO.read(secret_file) }
+ before do
+ Chef::Config[:knife][:secret_file] = secret_file
+ end
+
it "creates a secret file" do
rendered_template.should match(%r{#{secret}})
end
@@ -214,183 +317,171 @@ describe Chef::Knife::Bootstrap do
describe "when configuring the underlying knife ssh command" do
context "from the command line" do
- before do
- @knife.name_args = ["foo.example.com"]
- @knife.config[:ssh_user] = "rooty"
- @knife.config[:ssh_port] = "4001"
- @knife.config[:ssh_password] = "open_sesame"
+ let(:knife_ssh) do
+ knife.name_args = ["foo.example.com"]
+ knife.config[:ssh_user] = "rooty"
+ knife.config[:ssh_port] = "4001"
+ knife.config[:ssh_password] = "open_sesame"
Chef::Config[:knife][:ssh_user] = nil
Chef::Config[:knife][:ssh_port] = nil
- @knife.config[:forward_agent] = true
- @knife.config[:identity_file] = "~/.ssh/me.rsa"
- @knife.stub(:read_template).and_return("")
- @knife_ssh = @knife.knife_ssh
+ knife.config[:forward_agent] = true
+ knife.config[:identity_file] = "~/.ssh/me.rsa"
+ knife.stub(:render_template).and_return("")
+ knife.knife_ssh
end
it "configures the hostname" do
- @knife_ssh.name_args.first.should == "foo.example.com"
+ knife_ssh.name_args.first.should == "foo.example.com"
end
it "configures the ssh user" do
- @knife_ssh.config[:ssh_user].should == 'rooty'
+ knife_ssh.config[:ssh_user].should == 'rooty'
end
it "configures the ssh password" do
- @knife_ssh.config[:ssh_password].should == 'open_sesame'
+ knife_ssh.config[:ssh_password].should == 'open_sesame'
end
it "configures the ssh port" do
- @knife_ssh.config[:ssh_port].should == '4001'
+ knife_ssh.config[:ssh_port].should == '4001'
end
it "configures the ssh agent forwarding" do
- @knife_ssh.config[:forward_agent].should == true
+ knife_ssh.config[:forward_agent].should == true
end
it "configures the ssh identity file" do
- @knife_ssh.config[:identity_file].should == '~/.ssh/me.rsa'
+ knife_ssh.config[:identity_file].should == '~/.ssh/me.rsa'
end
end
+
context "validating use_sudo_password" do
before do
- @knife.config[:distro] = "ubuntu"
- @knife.config[:ssh_password] = "password"
- @knife.stub(:read_template).and_return(IO.read(@knife.find_template).chomp)
+ knife.config[:ssh_password] = "password"
+ knife.stub(:render_template).and_return("")
end
it "use_sudo_password contains description and long params for help" do
- @knife.options.should have_key(:use_sudo_password) \
- and @knife.options[:use_sudo_password][:description].to_s.should_not == ''\
- and @knife.options[:use_sudo_password][:long].to_s.should_not == ''
+ knife.options.should have_key(:use_sudo_password) \
+ and knife.options[:use_sudo_password][:description].to_s.should_not == ''\
+ and knife.options[:use_sudo_password][:long].to_s.should_not == ''
end
it "uses the password from --ssh-password for sudo when --use-sudo-password is set" do
- @knife.config[:use_sudo] = true
- @knife.config[:use_sudo_password] = true
- @knife.ssh_command.should include("echo \'#{@knife.config[:ssh_password]}\' | sudo -S")
+ knife.config[:use_sudo] = true
+ knife.config[:use_sudo_password] = true
+ knife.ssh_command.should include("echo \'#{knife.config[:ssh_password]}\' | sudo -S")
end
it "should not honor --use-sudo-password when --use-sudo is not set" do
- @knife.config[:use_sudo] = false
- @knife.config[:use_sudo_password] = true
- @knife.ssh_command.should_not include("echo #{@knife.config[:ssh_password]} | sudo -S")
+ knife.config[:use_sudo] = false
+ knife.config[:use_sudo_password] = true
+ knife.ssh_command.should_not include("echo #{knife.config[:ssh_password]} | sudo -S")
end
end
+
context "from the knife config file" do
- before do
- @knife.name_args = ["config.example.com"]
- @knife.config[:ssh_user] = nil
- @knife.config[:ssh_port] = nil
- @knife.config[:ssh_gateway] = nil
- @knife.config[:forward_agent] = nil
- @knife.config[:identity_file] = nil
- @knife.config[:host_key_verify] = nil
+ let(:knife_ssh) do
+ knife.name_args = ["config.example.com"]
+ knife.config[:ssh_user] = nil
+ knife.config[:ssh_port] = nil
+ knife.config[:ssh_gateway] = nil
+ knife.config[:forward_agent] = nil
+ knife.config[:identity_file] = nil
+ knife.config[:host_key_verify] = nil
Chef::Config[:knife][:ssh_user] = "curiosity"
Chef::Config[:knife][:ssh_port] = "2430"
Chef::Config[:knife][:forward_agent] = true
Chef::Config[:knife][:identity_file] = "~/.ssh/you.rsa"
Chef::Config[:knife][:ssh_gateway] = "towel.blinkenlights.nl"
Chef::Config[:knife][:host_key_verify] = true
- @knife.stub(:read_template).and_return("")
- @knife_ssh = @knife.knife_ssh
+ knife.stub(:render_template).and_return("")
+ knife.knife_ssh
end
it "configures the ssh user" do
- @knife_ssh.config[:ssh_user].should == 'curiosity'
+ knife_ssh.config[:ssh_user].should == 'curiosity'
end
it "configures the ssh port" do
- @knife_ssh.config[:ssh_port].should == '2430'
+ knife_ssh.config[:ssh_port].should == '2430'
end
it "configures the ssh agent forwarding" do
- @knife_ssh.config[:forward_agent].should == true
+ knife_ssh.config[:forward_agent].should == true
end
it "configures the ssh identity file" do
- @knife_ssh.config[:identity_file].should == '~/.ssh/you.rsa'
+ knife_ssh.config[:identity_file].should == '~/.ssh/you.rsa'
end
it "configures the ssh gateway" do
- @knife_ssh.config[:ssh_gateway].should == 'towel.blinkenlights.nl'
+ knife_ssh.config[:ssh_gateway].should == 'towel.blinkenlights.nl'
end
it "configures the host key verify mode" do
- @knife_ssh.config[:host_key_verify].should == true
+ knife_ssh.config[:host_key_verify].should == true
end
end
describe "when falling back to password auth when host key auth fails" do
- before do
- @knife.name_args = ["foo.example.com"]
- @knife.config[:ssh_user] = "rooty"
- @knife.config[:identity_file] = "~/.ssh/me.rsa"
- @knife.stub(:read_template).and_return("")
- @knife_ssh = @knife.knife_ssh
+ let(:knife_ssh_with_password_auth) do
+ knife.name_args = ["foo.example.com"]
+ knife.config[:ssh_user] = "rooty"
+ knife.config[:identity_file] = "~/.ssh/me.rsa"
+ knife.stub(:render_template).and_return("")
+ k = knife.knife_ssh
+ k.stub(:get_password).and_return('typed_in_password')
+ knife.stub(:knife_ssh).and_return(k)
+ knife.knife_ssh_with_password_auth
end
it "prompts the user for a password " do
- @knife.stub(:knife_ssh).and_return(@knife_ssh)
- @knife_ssh.stub(:get_password).and_return('typed_in_password')
- alternate_knife_ssh = @knife.knife_ssh_with_password_auth
- alternate_knife_ssh.config[:ssh_password].should == 'typed_in_password'
+ knife_ssh_with_password_auth.config[:ssh_password].should == 'typed_in_password'
end
it "configures knife not to use the identity file that didn't work previously" do
- @knife.stub(:knife_ssh).and_return(@knife_ssh)
- @knife_ssh.stub(:get_password).and_return('typed_in_password')
- alternate_knife_ssh = @knife.knife_ssh_with_password_auth
- alternate_knife_ssh.config[:identity_file].should be_nil
+ knife_ssh_with_password_auth.config[:identity_file].should be_nil
end
end
end
- describe "when running the bootstrap" do
- before do
- @knife.name_args = ["foo.example.com"]
- @knife.config[:ssh_user] = "rooty"
- @knife.config[:identity_file] = "~/.ssh/me.rsa"
- @knife.stub(:read_template).and_return("")
- @knife_ssh = @knife.knife_ssh
- @knife.stub(:knife_ssh).and_return(@knife_ssh)
- end
+ it "verifies that a server to bootstrap was given as a command line arg" do
+ knife.name_args = nil
+ lambda { knife.run }.should raise_error(SystemExit)
+ stderr.string.should match /ERROR:.+FQDN or ip/
+ end
- it "verifies that a server to bootstrap was given as a command line arg" do
- @knife.name_args = nil
- lambda { @knife.run }.should raise_error(SystemExit)
- @stderr.string.should match /ERROR:.+FQDN or ip/
+ describe "when running the bootstrap" do
+ let(:knife_ssh) do
+ knife.name_args = ["foo.example.com"]
+ knife.config[:ssh_user] = "rooty"
+ knife.config[:identity_file] = "~/.ssh/me.rsa"
+ knife.stub(:render_template).and_return("")
+ knife_ssh = knife.knife_ssh
+ knife.stub(:knife_ssh).and_return(knife_ssh)
+ knife_ssh
end
it "configures the underlying ssh command and then runs it" do
- @knife_ssh.should_receive(:run)
- @knife.run
+ knife_ssh.should_receive(:run)
+ knife.run
end
it "falls back to password based auth when auth fails the first time" do
- @knife.stub(:puts)
+ knife.stub(:puts)
- @fallback_knife_ssh = @knife_ssh.dup
- @knife_ssh.should_receive(:run).and_raise(Net::SSH::AuthenticationFailed.new("no ssh for you"))
- @knife.stub(:knife_ssh_with_password_auth).and_return(@fallback_knife_ssh)
- @fallback_knife_ssh.should_receive(:run)
- @knife.run
+ fallback_knife_ssh = knife_ssh.dup
+ knife_ssh.should_receive(:run).and_raise(Net::SSH::AuthenticationFailed.new("no ssh for you"))
+ knife.stub(:knife_ssh_with_password_auth).and_return(fallback_knife_ssh)
+ fallback_knife_ssh.should_receive(:run)
+ knife.run
end
it "raises the exception if config[:ssh_password] is set and an authentication exception is raised" do
- @knife.config[:ssh_password] = "password"
- @knife_ssh.should_receive(:run).and_raise(Net::SSH::AuthenticationFailed)
- lambda { @knife.run }.should raise_error(Net::SSH::AuthenticationFailed)
- end
-
- context "Chef::Config[:encrypted_data_bag_secret] is set" do
- let(:secret_file) { File.join(CHEF_SPEC_DATA, 'bootstrap', 'encrypted_data_bag_secret') }
- before { Chef::Config[:encrypted_data_bag_secret] = secret_file }
-
- it "warns the configuration option is deprecated" do
- @knife_ssh.should_receive(:run)
- @knife.ui.should_receive(:warn).at_least(3).times
- @knife.run
- end
+ knife.config[:ssh_password] = "password"
+ knife_ssh.should_receive(:run).and_raise(Net::SSH::AuthenticationFailed)
+ lambda { knife.run }.should raise_error(Net::SSH::AuthenticationFailed)
end
end
diff --git a/spec/unit/knife/core/bootstrap_context_spec.rb b/spec/unit/knife/core/bootstrap_context_spec.rb
index d78b48cad3..c5ad531a27 100644
--- a/spec/unit/knife/core/bootstrap_context_spec.rb
+++ b/spec/unit/knife/core/bootstrap_context_spec.rb
@@ -33,10 +33,6 @@ describe Chef::Knife::Core::BootstrapContext do
subject(:bootstrap_context) { described_class.new(config, run_list, chef_config) }
- it "installs the same version of chef on the remote host" do
- bootstrap_context.bootstrap_version_string.should eq "--version #{Chef::VERSION}"
- end
-
it "runs chef with the first-boot.json in the _default environment" do
bootstrap_context.start_chef.should eq "chef-client -j /etc/chef/first-boot.json -E _default"
end
@@ -95,24 +91,6 @@ EXPECTED
end
end
- describe "when installing a prerelease version of chef" do
- let(:config){ {:prerelease => true }}
- it "supplies --prerelease as the version string" do
- bootstrap_context.bootstrap_version_string.should eq '--prerelease'
- end
- end
-
- describe "when installing an explicit version of chef" do
- let(:chef_config) do
- {
- :knife => { :bootstrap_version => '123.45.678' }
- }
- end
- it "gives --version $VERSION as the version string" do
- bootstrap_context.bootstrap_version_string.should eq '--version 123.45.678'
- end
- end
-
describe "when JSON attributes are given" do
let(:config) { {:first_boot_attributes => {:baz => :quux}} }
it "adds the attributes to first_boot" do
@@ -158,13 +136,6 @@ EXPECTED
it "sets the @run_list instance variable" do
bootstrap_context.instance_variable_get(:@run_list).should eq run_list
end
-
- describe "accepts encrypted_data_bag_secret via Chef::Config" do
- let(:chef_config) { {:encrypted_data_bag_secret => secret_file }}
- it "reads the encrypted_data_bag_secret" do
- bootstrap_context.encrypted_data_bag_secret.should eq IO.read(secret_file)
- end
- end
end
describe "when a bootstrap_version is specified" do