diff options
author | Marc A. Paradise <marc.paradise@gmail.com> | 2019-05-03 17:28:02 -0400 |
---|---|---|
committer | Marc A. Paradise <marc.paradise@gmail.com> | 2019-05-03 18:05:49 -0400 |
commit | a1c438aa2b15b310ecccd062ae714026f39d3f12 (patch) | |
tree | 8c1e21b43837d3f5dc3bfbdacc66f3caea177180 | |
parent | 4dde88da4d24148987ca80b3dd7a5f802516f68d (diff) | |
download | chef-a1c438aa2b15b310ecccd062ae714026f39d3f12.tar.gz |
Pass channel directly into the script/url to determine Chef Infra downloadmp/bootstrap/restore-prerelease
Signed-off-by: Marc A. Paradise <marc.paradise@gmail.com>
-rw-r--r-- | RELEASE_NOTES.md | 2 | ||||
-rw-r--r-- | lib/chef/knife/bootstrap.rb | 4 | ||||
-rw-r--r-- | lib/chef/knife/bootstrap/templates/chef-full.erb | 4 | ||||
-rw-r--r-- | lib/chef/knife/core/bootstrap_context.rb | 33 | ||||
-rw-r--r-- | lib/chef/knife/core/windows_bootstrap_context.rb | 39 | ||||
-rw-r--r-- | spec/unit/knife/core/bootstrap_context_spec.rb | 63 | ||||
-rw-r--r-- | spec/unit/knife/core/windows_bootstrap_context_spec.rb | 49 |
7 files changed, 55 insertions, 139 deletions
diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 14e52d68f7..ea1871d677 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -114,7 +114,7 @@ Using removed options will cause the command to fail. | --ssh-port | --connection-port | `knife[:ssh_port]` config setting remains available. | --ssh-user | --connection-user | `knife[:ssh_user]` config setting remains available. | --ssl-peer-fingerprint | --winrm-ssl-peer-fingerprint | | -| --prerelease |--channel CHANNEL | This now allows you to specify the channel that Chef Infra Client gets installed from. Valid values: _stable_, current. 'current' has the same effect as using the old --prerelease. | +| --prerelease |--channel CHANNEL | This now allows you to specify the channel that Chef Infra Client gets installed from. Valid values are _stable_, current, and unstable. 'current' has the same effect as using the old --prerelease. | | --winrm-authentication-protocol=PROTO | --winrm-auth-method=AUTH-METHOD | Valid values: plaintext, kerberos, ssl, _negotiate_| | --winrm-password| --connection-password | | | --winrm-port| --connection-port | `knife[:winrm_port]` config setting remains available.| diff --git a/lib/chef/knife/bootstrap.rb b/lib/chef/knife/bootstrap.rb index 92f6fbcec3..5d76736e06 100644 --- a/lib/chef/knife/bootstrap.rb +++ b/lib/chef/knife/bootstrap.rb @@ -159,9 +159,9 @@ class Chef option :channel, long: "--channel CHANNEL", - description: "Install from the given channel. Valid values are 'current' and 'stable'. Default is 'stable'", + description: "Install from the given channel. Valid values are 'stable, 'current', and 'unstable'. Default is 'stable'", default: "stable", - in: %w{stable current} + in: %w{stable current unstable} # client.rb content via chef-full/bootstrap_context option :bootstrap_proxy, diff --git a/lib/chef/knife/bootstrap/templates/chef-full.erb b/lib/chef/knife/bootstrap/templates/chef-full.erb index 58a64a23b8..54fa3a61d1 100644 --- a/lib/chef/knife/bootstrap/templates/chef-full.erb +++ b/lib/chef/knife/bootstrap/templates/chef-full.erb @@ -175,9 +175,9 @@ do_download() { if test -f /usr/bin/<%= Chef::Dist::CLIENT %>}; then echo "-----> Existing <%= Chef::Dist::PRODUCT %> installation detected" else - echo "-----> Installing Chef Omnibus (<%= latest_current_chef_version_string %>)" + echo "-----> Installing Chef Omnibus (<%= @config[:channel] %>/<%= version_to_install %>)" do_download ${install_sh} $tmp_dir/install.sh - sh $tmp_dir/install.sh -P chef <%= latest_current_chef_version_string %> + sh $tmp_dir/install.sh -P chef -c <%= @config[:channel] %> -v <%= version_to_install %> fi <% end %> diff --git a/lib/chef/knife/core/bootstrap_context.rb b/lib/chef/knife/core/bootstrap_context.rb index 5889a77f25..5a27836da8 100644 --- a/lib/chef/knife/core/bootstrap_context.rb +++ b/lib/chef/knife/core/bootstrap_context.rb @@ -187,32 +187,17 @@ class Chef end # - # Determine that CLI arguments to retrieve the correct version of Chef Infra Client from omnitruck - # By default, bootstrap will look for the latest version of the currently-running major release of on stable. + # Returns the version of Chef to install (as recognized by the Omnitruck API) # - # @return [String] CLI arguments to pass into the chef download helper script - def latest_current_chef_version_string - # NOTE: Changes here should also be reflected in Knife::Core::BootstrapContext#latest_current_chef_version_string - installer_version_string = [] - use_current_channel = (@config[:channel] == "current") - installer_version_string << "-p" if use_current_channel - version = if knife_config[:bootstrap_version] - knife_config[:bootstrap_version] - else - # We will take the latest current by default, - # if no specific version is given. - if use_current_channel - # Take the latest stable version from the current major release. - # Note that if the current major release is not yet in stable, - # you must also specify channel "current". - nil - else - Chef::VERSION.split(".").first - end - end + # @return [String] download version string + def version_to_install + return knife_config[:bootstrap_version] if knife_config[:bootstrap_version] - installer_version_string.concat(["-v", version]) unless version.nil? - installer_version_string.join(" ") + if @config[:channel] == "stable" + Chef::VERSION.split(".").first + else + "latest" + end end def first_boot diff --git a/lib/chef/knife/core/windows_bootstrap_context.rb b/lib/chef/knife/core/windows_bootstrap_context.rb index 42d46aa67a..109f8e6f37 100644 --- a/lib/chef/knife/core/windows_bootstrap_context.rb +++ b/lib/chef/knife/core/windows_bootstrap_context.rb @@ -158,37 +158,6 @@ class Chef start_chef << "chef-client -c c:/chef/client.rb -j c:/chef/first-boot.json#{bootstrap_environment_option}\n" end - # - # Provide the query arguments to a URL that will be appeded to the URL in #msi_url(). This is used - # to get the latest version of Chef Infra Client via omnitruck - # By default, bootstrap will look for the latest version of the currently-running major release of on stable. - # - # @return [String] query arguments to append to the download request. - def latest_current_windows_chef_version_query - # NOTE: Changes here should also be reflected in Knife::Core::BootstrapContext#latest_current_chef_version_string - use_current_channel = (@config[:channel] == "current") - installer_version_string = use_current_channel ? "&prerelease=true" : "" - - chef_version_string = if knife_config[:bootstrap_version] - knife_config[:bootstrap_version] - else - if use_current_channel - # We will take the latest current by default, - # if no specific version is given. - nil - else - # Take the latest stable version from the current major release. - # Note that if the current major release is not yet in stable, - # you must also specify channel "current". - Chef::VERSION.split(".").first - end - end - - installer_version_string << "&v=#{chef_version_string}" if chef_version_string - - installer_version_string - end - def win_wget # I tried my best to figure out how to properly url decode and switch / to \ # but this is VBScript - so I don't really care that badly. @@ -294,16 +263,16 @@ class Chef "%TEMP%\\#{Chef::Dist::CLIENT}-latest.msi" end + # Build a URL to query www.chef.io that will redirect to the correct + # Chef Infra msi download. def msi_url(machine_os = nil, machine_arch = nil, download_context = nil) - # The default msi path has a number of url query parameters - we attempt to substitute - # such parameters in as long as they are provided by the template. - if @config[:msi_url].nil? || @config[:msi_url].empty? url = "https://www.chef.io/chef/download?p=windows" url += "&pv=#{machine_os}" unless machine_os.nil? url += "&m=#{machine_arch}" unless machine_arch.nil? url += "&DownloadContext=#{download_context}" unless download_context.nil? - url += latest_current_windows_chef_version_query + url += "&channel=#{@config[:channel]}" + url += "&v=#{version_to_install}" else @config[:msi_url] end diff --git a/spec/unit/knife/core/bootstrap_context_spec.rb b/spec/unit/knife/core/bootstrap_context_spec.rb index d3db342257..d57e254793 100644 --- a/spec/unit/knife/core/bootstrap_context_spec.rb +++ b/spec/unit/knife/core/bootstrap_context_spec.rb @@ -156,45 +156,6 @@ describe Chef::Knife::Core::BootstrapContext do end end - describe "when a bootstrap_version is specified" do - let(:chef_config) do - { - knife: { bootstrap_version: "11.12.4" }, - } - end - - it "should return full version installer specified with -v" do - expect(bootstrap_context.latest_current_chef_version_string).to eq("-v 11.12.4") - end - end - - describe "when current channel is specified" do - let(:config) { { channel: "current" } } - - it "should return only the -p flag" do - expect(bootstrap_context.latest_current_chef_version_string).to eq("-p") - end - context "and a bootstrap version is specified" do - let(:chef_config) do - { - knife: { bootstrap_version: "16.2.2" }, - } - end - - it "should return both full version and prerelease flags" do - expect(bootstrap_context.latest_current_chef_version_string).to eq("-p -v 16.2.2") - end - end - - end - - describe "when a bootstrap_version is not specified" do - it "should send the latest current to the installer" do - # Intentionally hard coded in order not to replicate the logic. - expect(bootstrap_context.latest_current_chef_version_string).to eq("-v #{Chef::VERSION.to_i}") - end - end - describe "ssl_verify_mode" do it "isn't set in the config_content by default" do expect(bootstrap_context.config_content).not_to include("ssl_verify_mode") @@ -312,4 +273,28 @@ describe Chef::Knife::Core::BootstrapContext do end end + + describe "#version_to_install" do + context "when bootstrap_version is provided" do + let(:chef_config) { { knife: { bootstrap_version: "awesome" } } } + + it "returns bootstrap_version" do + expect(bootstrap_context.version_to_install).to eq "awesome" + end + end + + context "when bootstrap_version is not provided" do + let(:config) { { channel: "stable" } } + it "returns the currently running major version out of Chef::VERSION" do + expect(bootstrap_context.version_to_install).to eq Chef::VERSION.split(".").first + end + end + + context "and channel is other than stable" do + let(:config) { { channel: "unstable" } } + it "returns the version string 'latest'" do + expect(bootstrap_context.version_to_install).to eq "latest" + end + end + end end diff --git a/spec/unit/knife/core/windows_bootstrap_context_spec.rb b/spec/unit/knife/core/windows_bootstrap_context_spec.rb index ea6609a0bf..7bc73c113a 100644 --- a/spec/unit/knife/core/windows_bootstrap_context_spec.rb +++ b/spec/unit/knife/core/windows_bootstrap_context_spec.rb @@ -176,53 +176,30 @@ describe Chef::Knife::Core::WindowsBootstrapContext do end end - describe "latest_current_windows_chef_version_query" do - it "includes the major version of the current version of Chef" do - stub_const("Chef::VERSION", "15.1.2") - expect(bootstrap_context.latest_current_windows_chef_version_query).to eq("&v=15") - end - - context "when bootstrap_version is given" do - before do - Chef::Config[:knife][:bootstrap_version] = "15.1.2" - end - it "includes the requested version" do - expect(bootstrap_context.latest_current_windows_chef_version_query).to eq("&v=15.1.2") - end - end - - context "when channel is current" do - let(:config) { { channel: "current" } } - it "includes prerelease indicator " do - expect(bootstrap_context.latest_current_windows_chef_version_query).to eq("&prerelease=true") - end - context "and bootstrap_version is given" do - before do - Chef::Config[:knife][:bootstrap_version] = "16.2.2" - end - it "includes the requested version" do - expect(bootstrap_context.latest_current_windows_chef_version_query).to eq("&prerelease=true&v=16.2.2") - end - end - end - - end - describe "msi_url" do - context "when config option is not set" do + context "when msi_url config option is not set" do + let(:config) { { channel: "stable" } } before do - expect(bootstrap_context).to receive(:latest_current_windows_chef_version_query).and_return("&v=something") + expect(bootstrap_context).to receive(:version_to_install).and_return("something") end it "returns a chef.io msi url with minimal url parameters" do - reference_url = "https://www.chef.io/chef/download?p=windows&v=something" + reference_url = "https://www.chef.io/chef/download?p=windows&channel=stable&v=something" expect(bootstrap_context.msi_url).to eq(reference_url) end it "returns a chef.io msi url with provided url parameters substituted" do - reference_url = "https://www.chef.io/chef/download?p=windows&pv=machine&m=arch&DownloadContext=ctx&v=something" + reference_url = "https://www.chef.io/chef/download?p=windows&pv=machine&m=arch&DownloadContext=ctx&channel=stable&v=something" expect(bootstrap_context.msi_url("machine", "arch", "ctx")).to eq(reference_url) end + + context "when a channel is provided in config" do + let(:config) { { channel: "current" } } + it "returns a chef.io msi url with the requested channel" do + reference_url = "https://www.chef.io/chef/download?p=windows&channel=current&v=something" + expect(bootstrap_context.msi_url).to eq(reference_url) + end + end end context "when msi_url config option is set" do |