Permalink
Browse files

Merge pull request #75 from cloudbees/master

Reverting wait_for_ssh command
  • Loading branch information...
2 parents cf15db8 + 6d1e587 commit bf307f6df89a69f31f1811862800011978aab910 @rtyler committed Mar 30, 2013
Showing with 25 additions and 37 deletions.
  1. +2 −4 features/cli/scp.feature
  2. +1 −2 features/cli/ssh.feature
  3. +0 −1 features/step_definitions/cli_steps.rb
  4. +20 −6 lib/blimpy/box.rb
  5. +2 −24 lib/blimpy/cli.rb
View
@@ -13,8 +13,7 @@ Feature: SCP a file into a named VM
end
"""
And I have a file named "hello.txt"
- When I run `blimpy wait_for_ssh`
- And I run `blimpy scp Gherkins hello.txt`
+ When I run `blimpy scp Gherkins hello.txt`
Then the exit status should be 1
And the output should contain:
"""
@@ -35,6 +34,5 @@ Feature: SCP a file into a named VM
"""
And I have a file named "hello.txt"
And I run `blimpy start`
- When I run `blimpy wait_for_ssh`
- And I run `blimpy scp "Cucumber Host" hello.txt`
+ When I run `blimpy scp "Cucumber Host" hello.txt`
Then the exit status should be 0
View
@@ -12,8 +12,7 @@ Feature: SSH into a named VM
end
end
"""
- When I run `blimpy wait_for_ssh`
- And I run `blimpy ssh Gherkins`
+ When I run `blimpy ssh Gherkins`
Then the exit status should be 1
And the output should contain:
"""
@@ -34,7 +34,6 @@
When /^I ssh into the machine$/ do
step %{I run `blimpy start`}
- step %{I run `blimpy wait_for_ssh`}
step %{I run `blimpy ssh "Cucumber Host" -o StrictHostKeyChecking=no` interactively}
end
View
@@ -197,11 +197,15 @@ def run_command(*args)
end
end
+ def ssh_commands(*args)
+ ['ssh', '-o', 'PasswordAuthentication=no',
+ '-o', 'StrictHostKeyChecking=no',
+ '-p', (ssh_port||22).to_s,
+ '-l', username, dns, *args]
+ end
+
def ssh_into(*args)
- run_command('ssh', '-o', 'PasswordAuthentication=no',
- '-o', 'StrictHostKeyChecking=no',
- '-p', ssh_port||22.to_s,
- '-l', username, dns, *args)
+ run_command(*ssh_commands(*args))
end
def scp_file(filename, directory='', *args)
@@ -240,10 +244,20 @@ def wait_for_sshd
until @ssh_connected
# Run the `true` command and exit
@ssh_connected = ssh_into('-q', 'true')
- # if SSH is killed (such as Ctrl+C), abort right away
- raise Exception, "ssh was killed: #{$?.exitstatus}" if $?.exitstatus>128 && $?.exitstatus<200
+ # if SSH is killed, don't repeat
+ if $?.signaled?
+ if $?.termsig==2
+ # if Ctrl+C, report what we were doing
+ puts "Failed to connect. To try it yourself:\n#{ssh_commands('-v','true').join(' ')}"
+ end
+ raise Exception, "ssh was killed: #{$?}"
+ end
unless @ssh_connected
+ if !need_nl
+ p = ssh_port.nil? ? "" : ":#{ssh_port}"
+ print ">> Connecting #{username}@#{name}#{p}"
+ end
if (Time.now.to_i - start) < 60
print '.'
need_nl = true
View
@@ -143,31 +143,8 @@ def ssh(name=nil, *args)
end
end
- box.ssh_into *args
- end
-
- desc 'wait_for_ssh', 'Wait for SSHD to come online'
- def wait_for_ssh(name=nil, *args)
- unless name.nil?
- box = box_by_name(name)
- if box.nil?
- puts "Could not find a blimp named \"#{name}\""
- exit 1
- end
- else
- blimps = current_blimps
- unless blimps
- puts "No Blimps running!"
- exit 1
- end
-
- blimps.each do |blimp, data|
- next unless data[:name]
- box = box_by_name(data[:name])
- end
- end
-
box.wait_for_sshd
+ box.ssh_into *args
end
desc 'scp BLIMP_NAME FILE_NAME', 'Securely copy FILE_NAME into the blimp'
@@ -178,6 +155,7 @@ def scp(name, filename, *args)
puts "Could not find a blimp named \"#{name}\""
exit 1
end
+ box.wait_for_sshd
# Pass any extra commands along to the `scp` invocation
box.scp_file(filename, '', *ARGV[3..-1])
end

0 comments on commit bf307f6

Please sign in to comment.