Skip to content

Commit

Permalink
Merge ff46887 into e9f3e2f
Browse files Browse the repository at this point in the history
  • Loading branch information
Vasundhara Jagdale committed Jun 7, 2019
2 parents e9f3e2f + ff46887 commit ee45b52
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/train/extras/command_wrapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,13 @@ class CommandWrapper
include_options WindowsCommand

def self.load(transport, options)
if transport.os.unix?
if transport.class != Train::Transports::Local::Connection && !transport.connected?
# Need to call run_command here to get the message and show it to user while raising exception
msg = transport.run_command("whoami").stdout
# this will throw the error as
# Train::UserError: Ssh failed: Please login as the user "username" rather than the user "root".
raise Train::UserError.new("Ssh failed: #{msg}")
elsif transport.os.unix?
return nil unless LinuxCommand.active?(options)
res = LinuxCommand.new(transport, options)
verification_res = res.verify
Expand Down
5 changes: 5 additions & 0 deletions lib/train/transports/ssh_connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ def login_command
LoginCommand.new("ssh", args)
end

def connected?
return false if session.nil?
session.exec!("whoami").match?(/Please login as the user/) ? false : true
end

# (see Base::Connection#upload)
def upload(locals, remote)
waits = []
Expand Down

0 comments on commit ee45b52

Please sign in to comment.