diff options
-rw-r--r-- | lib/chef/knife/bootstrap/train_connector.rb | 5 | ||||
-rw-r--r-- | spec/unit/knife/bootstrap/train_connector_spec.rb | 9 |
2 files changed, 13 insertions, 1 deletions
diff --git a/lib/chef/knife/bootstrap/train_connector.rb b/lib/chef/knife/bootstrap/train_connector.rb index 59de880cbd..da5db65de0 100644 --- a/lib/chef/knife/bootstrap/train_connector.rb +++ b/lib/chef/knife/bootstrap/train_connector.rb @@ -117,7 +117,10 @@ class Chef cmd = windows? ? MKTEMP_WIN_COMMAND : MKTEMP_NIX_COMMAND @tmpdir ||= begin res = run_command!(cmd) - dir = res.stdout.chomp.strip + # Since pty is enabled in the connection, stderr to be merged into stdout. + # So, there are cases where unnecessary multi-line output + # is included before the result of mktemp. + dir = res.stdout.split.last unless windows? # Ensure that dir has the correct owner. We are possibly # running with sudo right now - so this directory would be owned by root. diff --git a/spec/unit/knife/bootstrap/train_connector_spec.rb b/spec/unit/knife/bootstrap/train_connector_spec.rb index c3c559c65b..52345f3cde 100644 --- a/spec/unit/knife/bootstrap/train_connector_spec.rb +++ b/spec/unit/knife/bootstrap/train_connector_spec.rb @@ -163,6 +163,15 @@ describe Chef::Knife::Bootstrap::TrainConnector do expect(subject.temp_dir).to eq "/a/path" end + context "with noise in stderr" do + it "uses the *nix command to create the temp dir and sets ownership to logged-in user" do + expected_command = Chef::Knife::Bootstrap::TrainConnector::MKTEMP_NIX_COMMAND + expect(subject).to receive(:run_command!).with(expected_command) + .and_return double("result", stdout: "sudo: unable to resolve host hostname.localhost\r\n" + "/a/path\r\n") + expect(subject).to receive(:run_command!).with("chown user1 '/a/path'") + expect(subject.temp_dir).to eq "/a/path" + end + end end end context "#upload_file_content!" do |