diff options
author | Marc A. Paradise <marc.paradise@gmail.com> | 2019-05-01 11:06:28 -0400 |
---|---|---|
committer | Marc A. Paradise <marc.paradise@gmail.com> | 2019-05-03 17:30:08 -0400 |
commit | f2d590eecc90da7a78593b61437dbac27a480322 (patch) | |
tree | 8f5e6dc0d0b1342b87381c6d26fedec05d60f0b0 | |
parent | faeddcb492020f3ead4aa433e93a9903d16ab652 (diff) | |
download | chef-f2d590eecc90da7a78593b61437dbac27a480322.tar.gz |
`prerelease` -> `channel` in bootstrap contexts
Updates BootstrapContext and WindowsBootstrapContext to
expect a 'channel' config value instead of a 'prelease' value.
This removes the old behavior of inferring pre-release (current) from
the presence of a fourth version number in the version string (eg
1.2.3.pre) - that was specific to gem installs, and gem installs are not
used in bootstrap.
Signed-off-by: Marc A. Paradise <marc.paradise@gmail.com>
-rw-r--r-- | lib/chef/knife/core/bootstrap_context.rb | 41 | ||||
-rw-r--r-- | lib/chef/knife/core/windows_bootstrap_context.rb | 35 | ||||
-rw-r--r-- | spec/unit/knife/bootstrap_spec.rb | 10 | ||||
-rw-r--r-- | spec/unit/knife/core/bootstrap_context_spec.rb | 25 | ||||
-rw-r--r-- | spec/unit/knife/core/windows_bootstrap_context_spec.rb | 19 |
5 files changed, 67 insertions, 63 deletions
diff --git a/lib/chef/knife/core/bootstrap_context.rb b/lib/chef/knife/core/bootstrap_context.rb index c46a6bc079..5889a77f25 100644 --- a/lib/chef/knife/core/bootstrap_context.rb +++ b/lib/chef/knife/core/bootstrap_context.rb @@ -187,26 +187,31 @@ class Chef 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 + # 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. + # + # @return [String] CLI arguments to pass into the chef download helper script def latest_current_chef_version_string - installer_version_string = nil - if @config[:prerelease] - installer_version_string = ["-p"] - else - 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] + # 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 - # 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.concat(["-v", version]) unless version.nil? installer_version_string.join(" ") end diff --git a/lib/chef/knife/core/windows_bootstrap_context.rb b/lib/chef/knife/core/windows_bootstrap_context.rb index c6b8bc4d2b..42d46aa67a 100644 --- a/lib/chef/knife/core/windows_bootstrap_context.rb +++ b/lib/chef/knife/core/windows_bootstrap_context.rb @@ -158,24 +158,33 @@ 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 - installer_version_string = nil - if @config[:prerelease] - installer_version_string = "&prerelease=true" - else - chef_version_string = if knife_config[:bootstrap_version] - knife_config[:bootstrap_version] + # 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 bootstrapping a pre-release version add the prerelease query string - if chef_version_string.split(".").length > 3 - installer_version_string << "&prerelease=true" - end - end + installer_version_string << "&v=#{chef_version_string}" if chef_version_string installer_version_string end diff --git a/spec/unit/knife/bootstrap_spec.rb b/spec/unit/knife/bootstrap_spec.rb index d82dc7614e..4261a3a166 100644 --- a/spec/unit/knife/bootstrap_spec.rb +++ b/spec/unit/knife/bootstrap_spec.rb @@ -1603,10 +1603,7 @@ describe Chef::Knife::Bootstrap do end context "when a deprecated CLI flag is given on the CLI" do - before do - knife.config[:ssh_user] = "sshuser" - knife.merge_configs - end + let(:bootstrap_cli_options) { %w{--ssh-user sshuser} } it "maps the key value to the new key and points the human to the new flag" do expect(knife.ui).to receive(:warn).with(/You provided --ssh-user. This flag is deprecated. Please use '--connection-user USERNAME' instead./) knife.verify_deprecated_flags! @@ -1616,11 +1613,6 @@ describe Chef::Knife::Bootstrap do context "when a deprecated CLI flag is given on the CLI, along with its replacement" do let(:bootstrap_cli_options) { %w{--connection-user a --ssh-user b} } - before do - knife.config[:ssh_user] = "sshuser" - knife.config[:connection_user] = "real-user" - knife.merge_configs - end it "informs the human that both are provided and exits" do expect(knife.ui).to receive(:error).with(/You provided both --connection-user and --ssh-user.*Please use.*/m) diff --git a/spec/unit/knife/core/bootstrap_context_spec.rb b/spec/unit/knife/core/bootstrap_context_spec.rb index e72acf9b7a..d3db342257 100644 --- a/spec/unit/knife/core/bootstrap_context_spec.rb +++ b/spec/unit/knife/core/bootstrap_context_spec.rb @@ -163,32 +163,31 @@ describe Chef::Knife::Core::BootstrapContext do } end - it "should send the full version to the installer" do + 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" } } - describe "and it is a prerelease version" do + 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: "11.12.4.xyz" }, + knife: { bootstrap_version: "16.2.2" }, } end - it "should set the version and set -p" do - expect(bootstrap_context.latest_current_chef_version_string).to eq("-v 11.12.4.xyz -p") + 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 prerelease is specified" do - let(:config) { { prerelease: true } } - - it "should send -p to the installer" do - expect(bootstrap_context.latest_current_chef_version_string).to eq("-p") - 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. diff --git a/spec/unit/knife/core/windows_bootstrap_context_spec.rb b/spec/unit/knife/core/windows_bootstrap_context_spec.rb index a39a3a9242..ea6609a0bf 100644 --- a/spec/unit/knife/core/windows_bootstrap_context_spec.rb +++ b/spec/unit/knife/core/windows_bootstrap_context_spec.rb @@ -191,19 +191,18 @@ describe Chef::Knife::Core::WindowsBootstrapContext do end end - context "when prerelease is true" do - let(:config) { { prerelease: true } } + 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 - end - - context "when a prerelease bootstrap_version is specified" do - before do - Chef::Config[:knife][:bootstrap_version] = "15.1.2.xyz" - end - it "includes prerelease indicator and the given version" do - expect(bootstrap_context.latest_current_windows_chef_version_query).to eq("&v=15.1.2.xyz&prerelease=true") + 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 |