diff options
author | tyler-ball <tball@chef.io> | 2019-04-22 15:41:03 -0600 |
---|---|---|
committer | Mark Anderson <mark@chef.io> | 2019-05-03 21:40:19 -0700 |
commit | c99eef4077655ce0a8db87d7c9ead1017ec7dad7 (patch) | |
tree | dceb9dd0fdae49adfe5571a4bbcc92e98400245a | |
parent | a8dcabbb4a527816d4d19784fe2011dad28c470b (diff) | |
download | chef-c99eef4077655ce0a8db87d7c9ead1017ec7dad7.tar.gz |
Adding license acceptance support to 'knife bootstrap'
Signed-off-by: tyler-ball <tball@chef.io>
-rw-r--r-- | RELEASE_NOTES.md | 4 | ||||
-rw-r--r-- | kitchen-tests/Berksfile | 1 | ||||
-rw-r--r-- | kitchen-tests/Gemfile | 4 | ||||
-rw-r--r-- | lib/chef/knife/bootstrap.rb | 3 | ||||
-rw-r--r-- | lib/chef/knife/core/bootstrap_context.rb | 1 | ||||
-rw-r--r-- | spec/unit/knife/bootstrap_spec.rb | 12 |
6 files changed, 14 insertions, 11 deletions
diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 17f59406a7..cd23e5923a 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -16,8 +16,8 @@ Chef Client requires a EULA to be accepted by users before it can run. Users can `CHEF_LICENSE=accept-no-persist chef-client` Finally, if users run `chef-client` without any of these options, they will receive an interactive prompt asking for -license acceptance. If the license is accepted, a marker file will be written to the filesystem (unless `no-persist` is -specified). Once this marker file is persisted, users no longer need to set any of these flags. +license acceptance. If the license is accepted, a marker file will be written to the filesystem (unless +`accept-no-persist` is specified). Once this marker file is persisted, users no longer need to set any of these flags. ### Allow Using --delete-entire-chef-repo in Chef Local Mode diff --git a/kitchen-tests/Berksfile b/kitchen-tests/Berksfile index df9f0427e6..d699452ebe 100644 --- a/kitchen-tests/Berksfile +++ b/kitchen-tests/Berksfile @@ -2,4 +2,3 @@ source "https://supermarket.chef.io" cookbook "end_to_end", path: "cookbooks/end_to_end" cookbook "rspec", path: "cookbooks/rspec" -cookbook "chef-client", git: "https://github.com/tyler-ball/chef-client.git", branch: "chef_license_accept" diff --git a/kitchen-tests/Gemfile b/kitchen-tests/Gemfile index a8d064fb80..a1a438d071 100644 --- a/kitchen-tests/Gemfile +++ b/kitchen-tests/Gemfile @@ -6,5 +6,5 @@ gem "ohai", git: "https://github.com/chef/ohai.git", branch: "master" # avoids f gem "berkshelf", git: "https://github.com/berkshelf/berkshelf.git", branch: "master" gem "kitchen-dokken", "~> 2.0" gem "kitchen-inspec", git: "https://github.com/chef/kitchen-inspec.git", branch: "master" -gem "inspec", git: "https://github.com/inspec/inspec.git", branch: "master" # this goes away when we ship inspec 4 -gem "test-kitchen", git: "https://github.com/test-kitchen/test-kitchen.git", branch: "chef_license_accept" +gem "inspec" +gem "test-kitchen", git: "https://github.com/test-kitchen/test-kitchen.git", branch: "master" diff --git a/lib/chef/knife/bootstrap.rb b/lib/chef/knife/bootstrap.rb index 8539ee7c17..a46dea0e0e 100644 --- a/lib/chef/knife/bootstrap.rb +++ b/lib/chef/knife/bootstrap.rb @@ -26,7 +26,7 @@ class Chef class Knife class Bootstrap < Knife include DataBagSecretOptions - # include LicenseAcceptance::CLIFlags::MixlibCLI + include LicenseAcceptance::CLIFlags::MixlibCLI SUPPORTED_CONNECTION_PROTOCOLS = %w{ssh winrm}.freeze WINRM_AUTH_PROTOCOL_LIST = %w{plaintext kerberos ssl negotiate}.freeze @@ -406,6 +406,7 @@ class Chef def initialize(argv = []) super + LicenseAcceptance::Acceptor.check_and_persist!("infra-client", Chef::VERSION.to_s, logger: Chef::Log, provided: Chef::Config[:chef_license]) @client_builder = Chef::Knife::Bootstrap::ClientBuilder.new( chef_config: Chef::Config, knife_config: config, diff --git a/lib/chef/knife/core/bootstrap_context.rb b/lib/chef/knife/core/bootstrap_context.rb index dcca7b8a69..2b14d1e5d2 100644 --- a/lib/chef/knife/core/bootstrap_context.rb +++ b/lib/chef/knife/core/bootstrap_context.rb @@ -171,6 +171,7 @@ class Chef def start_chef # If the user doesn't have a client path configure, let bash use the PATH for what it was designed for client_path = @chef_config[:chef_client_path] || "#{Chef::Dist::CLIENT}" + # We know we can hardcode CHEF_LICENSE because the user cannot get here without accepting the license locally s = "CHEF_LICENSE=accept #{client_path} -j /etc/chef/first-boot.json" if @config[:verbosity] && @config[:verbosity] >= 3 s << " -l trace" diff --git a/spec/unit/knife/bootstrap_spec.rb b/spec/unit/knife/bootstrap_spec.rb index da6bebfd1c..90b3efe8cc 100644 --- a/spec/unit/knife/bootstrap_spec.rb +++ b/spec/unit/knife/bootstrap_spec.rb @@ -40,6 +40,7 @@ describe Chef::Knife::Bootstrap do let(:knife) do Chef::Log.logger = Logger.new(StringIO.new) Chef::Config[:knife][:bootstrap_template] = bootstrap_template unless bootstrap_template.nil? + expect(LicenseAcceptance::Acceptor).to receive(:check_and_persist!) k = Chef::Knife::Bootstrap.new(bootstrap_cli_options) allow(k.ui).to receive(:stderr).and_return(stderr) @@ -49,6 +50,11 @@ describe Chef::Knife::Bootstrap do k end + it "fails when LicenseAcceptance fails" do + expect(LicenseAcceptance::Acceptor).to receive(:check_and_persist!).and_raise("foo") + expect { k = Chef::Knife::Bootstrap.new(bootstrap_cli_options) }.to raise_error("foo") + end + context "#bootstrap_template" do it "should default to chef-full" do expect(knife.bootstrap_template).to be_a_kind_of(String) @@ -293,7 +299,6 @@ describe Chef::Knife::Bootstrap do end it "raises a Chef::Exceptions::BootstrapCommandInputError with the proper error message" do - # expect(LicenseAcceptance::Acceptor).to receive(:check_and_persist!) knife.parse_options(["-j", '{"foo":{"bar":"baz"}}']) knife.parse_options(["--json-attribute-file", jsonfile.path]) knife.merge_configs @@ -324,6 +329,7 @@ describe Chef::Knife::Bootstrap do describe "specifying no_proxy with various entries" do subject(:knife) do + expect(LicenseAcceptance::Acceptor).to receive(:check_and_persist!) k = described_class.new Chef::Config[:knife][:bootstrap_template] = template_file allow(k).to receive(:connection).and_return connection @@ -1794,16 +1800,12 @@ describe Chef::Knife::Bootstrap do end it "verifies that a server to bootstrap was given as a command line arg" do - # expect(LicenseAcceptance::Acceptor).to receive(:check_and_persist!) knife.name_args = nil expect { knife.run }.to raise_error(SystemExit) expect(stderr.string).to match(/ERROR:.+FQDN or ip/) end describe "#bootstrap_context" do - # before do - # expect(LicenseAcceptance::Acceptor).to receive(:check_and_persist!) - # end context "under Windows" do let(:windows_test) { true } it "creates a WindowsBootstrapContext" do |