summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc A. Paradise <marc.paradise@gmail.com>2019-04-30 17:44:48 -0400
committerMarc A. Paradise <marc.paradise@gmail.com>2019-05-03 17:30:07 -0400
commitba50ae6d20ef86ab39b9fa2eee982f929cd70c7e (patch)
tree56f5d03eef665e65fa6611ee236cc52bb59a9c97
parent58db2c3f47e86d539d21f9365adb135726719e38 (diff)
downloadchef-ba50ae6d20ef86ab39b9fa2eee982f929cd70c7e.tar.gz
Restore bootstrap pre-release support
It was originally removed after discussion in community slack, but it turns out to have a little more utility than we thought. When enabled, it will cause the package to be downloaded from the `current` channel. Option description has been updated from 'install prerelease gem' to 'install from current channel'. This commit otherwise restores the original behavior and adds some tests. Signed-off-by: Marc A. Paradise <marc.paradise@gmail.com>
-rw-r--r--RELEASE_NOTES.md1
-rw-r--r--lib/chef/knife/bootstrap.rb4
-rw-r--r--lib/chef/knife/core/bootstrap_context.rb23
-rw-r--r--lib/chef/knife/core/windows_bootstrap_context.rb24
-rw-r--r--spec/unit/knife/core/bootstrap_context_spec.rb21
-rw-r--r--spec/unit/knife/core/windows_bootstrap_context_spec.rb27
6 files changed, 86 insertions, 14 deletions
diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md
index b0913a2a2f..ff598126af 100644
--- a/RELEASE_NOTES.md
+++ b/RELEASE_NOTES.md
@@ -131,7 +131,6 @@ Using removed options will cause the command to fail.
|--kerberos-keytab-file| This option existed but was not implemented.|
|--winrm-codepage| This was used under knife-windows because bootstrapping was performed over a `cmd` shell. It is now invoked from `powershell`, so this option is no longer used.|
|--winrm-shell|This option was ignored for bootstrap.|
-|--prerelease|Chef now releases all development builds to our current channel and does not perform pre-release gem releases.|
|--install-as-service|Installing Chef client as a service is not supported|
#### Usage Changes
diff --git a/lib/chef/knife/bootstrap.rb b/lib/chef/knife/bootstrap.rb
index 69d9ffb8c0..701c207503 100644
--- a/lib/chef/knife/bootstrap.rb
+++ b/lib/chef/knife/bootstrap.rb
@@ -156,6 +156,10 @@ class Chef
description: "The version of #{Chef::Dist::PRODUCT} to install.",
proc: lambda { |v| Chef::Config[:knife][:bootstrap_version] = v }
+ option :prerelease,
+ long: "--prerelease",
+ description: "Install from 'current' channel"
+
# client.rb content via chef-full/bootstrap_context
option :bootstrap_proxy,
long: "--bootstrap-proxy PROXY_URL",
diff --git a/lib/chef/knife/core/bootstrap_context.rb b/lib/chef/knife/core/bootstrap_context.rb
index dcca7b8a69..c46a6bc079 100644
--- a/lib/chef/knife/core/bootstrap_context.rb
+++ b/lib/chef/knife/core/bootstrap_context.rb
@@ -190,13 +190,24 @@ class Chef
# 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
def latest_current_chef_version_string
- chef_version_string = if knife_config[:bootstrap_version]
- knife_config[:bootstrap_version]
- else
- Chef::VERSION.split(".").first
- end
+ 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]
- "-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"
+ end
+ end
+ installer_version_string.join(" ")
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 6054743106..c6b8bc4d2b 100644
--- a/lib/chef/knife/core/windows_bootstrap_context.rb
+++ b/lib/chef/knife/core/windows_bootstrap_context.rb
@@ -159,13 +159,25 @@ class Chef
end
def latest_current_windows_chef_version_query
- chef_version_string = if knife_config[:bootstrap_version]
- knife_config[:bootstrap_version]
- else
- Chef::VERSION.split(".").first
- end
+ 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]
+ else
+ Chef::VERSION.split(".").first
+ 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
- "&v=#{chef_version_string}"
+ installer_version_string
end
def win_wget
diff --git a/spec/unit/knife/core/bootstrap_context_spec.rb b/spec/unit/knife/core/bootstrap_context_spec.rb
index 2ed8b6bc51..e72acf9b7a 100644
--- a/spec/unit/knife/core/bootstrap_context_spec.rb
+++ b/spec/unit/knife/core/bootstrap_context_spec.rb
@@ -166,6 +166,27 @@ describe Chef::Knife::Core::BootstrapContext do
it "should send the full version to the installer" do
expect(bootstrap_context.latest_current_chef_version_string).to eq("-v 11.12.4")
end
+
+ describe "and it is a prerelease version" do
+ let(:chef_config) do
+ {
+ knife: { bootstrap_version: "11.12.4.xyz" },
+ }
+ 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")
+ 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
diff --git a/spec/unit/knife/core/windows_bootstrap_context_spec.rb b/spec/unit/knife/core/windows_bootstrap_context_spec.rb
index a19ad11247..a39a3a9242 100644
--- a/spec/unit/knife/core/windows_bootstrap_context_spec.rb
+++ b/spec/unit/knife/core/windows_bootstrap_context_spec.rb
@@ -177,11 +177,36 @@ describe Chef::Knife::Core::WindowsBootstrapContext do
end
describe "latest_current_windows_chef_version_query" do
- it "returns the major version of the current version of Chef" 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 prerelease is true" do
+ let(:config) { { prerelease: true } }
+ 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")
+ end
+ end
+
end
describe "msi_url" do