diff options
-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 |