diff options
author | Bryan McLellan <btm@loftninjas.org> | 2019-05-20 16:03:40 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-20 16:03:40 -0400 |
commit | 99cf0ead6e260e471294fd17ea1e17bdf49df3b7 (patch) | |
tree | b073fe511477f9603c002b1a12855ebab9d8f837 | |
parent | cfbb01cb5648297835941679bc9638d3a823ad5e (diff) | |
parent | f5f0f730969255851bd7e9f57a421e791b8bd034 (diff) | |
download | chef-99cf0ead6e260e471294fd17ea1e17bdf49df3b7.tar.gz |
Merge pull request #8567 from chef/btm/client_key_validator_fix
Only set client_pem in bootstrap_context when validatorless
-rw-r--r-- | lib/chef/knife/bootstrap.rb | 5 | ||||
-rw-r--r-- | spec/unit/knife/bootstrap_spec.rb | 13 |
2 files changed, 10 insertions, 8 deletions
diff --git a/lib/chef/knife/bootstrap.rb b/lib/chef/knife/bootstrap.rb index 66d73a3372..2a9eab6f8e 100644 --- a/lib/chef/knife/bootstrap.rb +++ b/lib/chef/knife/bootstrap.rb @@ -546,9 +546,6 @@ class Chef register_client connect! - unless client_builder.client_path.nil? - bootstrap_context.client_pem = client_builder.client_path - end content = render_template bootstrap_path = upload_bootstrap(content) perform_bootstrap(bootstrap_path) @@ -569,6 +566,8 @@ class Chef end client_builder.run chef_vault_handler.run(client_builder.client) + + bootstrap_context.client_pem = client_builder.client_path else ui.info <<~EOM Performing legacy client registration with the validation key at #{Chef::Config[:validation_key]}... diff --git a/spec/unit/knife/bootstrap_spec.rb b/spec/unit/knife/bootstrap_spec.rb index 8467b6dc70..4a7286bd6f 100644 --- a/spec/unit/knife/bootstrap_spec.rb +++ b/spec/unit/knife/bootstrap_spec.rb @@ -1654,10 +1654,6 @@ describe Chef::Knife::Bootstrap do end end describe "#run" do - before do - allow(knife.client_builder).to receive(:client_path).and_return("/key.pem") - end - it "performs the steps we expect to run a bootstrap" do expect(knife).to receive(:check_license) expect(knife).to receive(:verify_deprecated_flags!).ordered @@ -1678,7 +1674,6 @@ describe Chef::Knife::Bootstrap do knife.run # Post-run verify expected state changes (not many directly in #run) - expect(knife.bootstrap_context.client_pem).to eq "/key.pem" expect($stdout.sync).to eq true end end @@ -1731,6 +1726,7 @@ describe Chef::Knife::Bootstrap do let(:node_name) { "test" } before do allow(client_builder_mock).to receive(:client).and_return "client" + allow(client_builder_mock).to receive(:client_path).and_return "/key.pem" end it "runs client_builder and vault_handler" do @@ -1738,6 +1734,13 @@ describe Chef::Knife::Bootstrap do expect(vault_handler_mock).to receive(:run).with("client") knife.register_client end + + it "sets the path to the client key in the bootstrap context" do + allow(client_builder_mock).to receive(:run) + allow(vault_handler_mock).to receive(:run).with("client") + knife.register_client + expect(knife.bootstrap_context.client_pem).to eq "/key.pem" + end end context "when no valid node name is present" do |