Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Reverting wait_for_ssh command #75

Merged
merged 2 commits into from

3 participants

@kohsuke

scp and ssh commands now wait for SSH to come online, like they were before.

As we discussed in IRC (and can be seen in the commit message), if the user aborted with Ctrl+C, report what we are doing so that the operator error can be discovered more efficiently.

kohsuke added some commits
@kohsuke kohsuke Revisiting 8b38008
(04:25:26 PM) rtyler: kohsuke: so `blimpy ssh` is going to return immediately now?
(04:25:41 PM) kohsuke: yes, it fails if ssh fails
(04:26:09 PM) ***rtyler is a bit confused
(04:26:14 PM) rtyler: this seems like a big UX change then
(04:26:21 PM) ***rtyler should read more carefully
(04:27:13 PM) kohsuke: Yes, modifying a test case made me wonder if there's a better way to do it
(04:28:00 PM) kohsuke: (though in practice you wouldn't see any change as "blimpy provision" does wait for ssh to come online)
(04:28:13 PM) rtyler: but a `blimpy ssh` won't log me into the machine?
(04:28:51 PM) kohsuke: I think just reporting ">> Connecting: SHIPNAME..." if the first attempt fails would be sufficient
(04:29:25 PM) kohsuke: The "gotcha" that made me write that patch is that my first attempt to use blimpy failed miserably at "blimpy ssh"
(04:29:51 PM) kohsuke: because it was trying a wrong user name, and I couldn't Ctrl+C it because of another bug that since then I fixed
(04:30:11 PM) rtyler: with aws and openstack it connects multiple times, usually the machine isn't accepting ssh connections right away
(04:30:14 PM) rtyler: especially on a fresh image
(04:30:25 PM) kohsuke: yes, I understand why you wrote it the way you did the first place
(04:31:17 PM) rtyler: heh
(04:31:21 PM) rtyler: alright
(04:32:05 PM) kohsuke: Let me change it to ">> Connecting: user@SHIPNAME:port" with dots added over time,
(04:32:15 PM) kohsuke: and if it's killed by SIGINT I'll run ssh one last time but without -q
(04:32:22 PM) kohsuke: so you see the error message
(04:32:41 PM) kohsuke: does that sound OK to you?
(04:34:30 PM) rtyler: that does sound good

It turns out some mode of failure includes ssh hanging (such as trying a
wrong port), so silently re-running SSH again wasn't very wise. Instead,
show the command line needed to let the user run the ssh command by
himself.
c3fe15f
@kohsuke kohsuke Revert "Fixing the unit test failure"
This reverts commit 8827307.
6d1e587
@buildhive

R. Tyler Croy » blimpy #80 FAILURE
Looks like there's a problem with this pull request
(what's this?)

@rtyler rtyler merged commit bf307f6 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 29, 2013
  1. @kohsuke

    Revisiting 8b38008

    kohsuke authored
    (04:25:26 PM) rtyler: kohsuke: so `blimpy ssh` is going to return immediately now?
    (04:25:41 PM) kohsuke: yes, it fails if ssh fails
    (04:26:09 PM) ***rtyler is a bit confused
    (04:26:14 PM) rtyler: this seems like a big UX change then
    (04:26:21 PM) ***rtyler should read more carefully
    (04:27:13 PM) kohsuke: Yes, modifying a test case made me wonder if there's a better way to do it
    (04:28:00 PM) kohsuke: (though in practice you wouldn't see any change as "blimpy provision" does wait for ssh to come online)
    (04:28:13 PM) rtyler: but a `blimpy ssh` won't log me into the machine?
    (04:28:51 PM) kohsuke: I think just reporting ">> Connecting: SHIPNAME..." if the first attempt fails would be sufficient
    (04:29:25 PM) kohsuke: The "gotcha" that made me write that patch is that my first attempt to use blimpy failed miserably at "blimpy ssh"
    (04:29:51 PM) kohsuke: because it was trying a wrong user name, and I couldn't Ctrl+C it because of another bug that since then I fixed
    (04:30:11 PM) rtyler: with aws and openstack it connects multiple times, usually the machine isn't accepting ssh connections right away
    (04:30:14 PM) rtyler: especially on a fresh image
    (04:30:25 PM) kohsuke: yes, I understand why you wrote it the way you did the first place
    (04:31:17 PM) rtyler: heh
    (04:31:21 PM) rtyler: alright
    (04:32:05 PM) kohsuke: Let me change it to ">> Connecting: user@SHIPNAME:port" with dots added over time,
    (04:32:15 PM) kohsuke: and if it's killed by SIGINT I'll run ssh one last time but without -q
    (04:32:22 PM) kohsuke: so you see the error message
    (04:32:41 PM) kohsuke: does that sound OK to you?
    (04:34:30 PM) rtyler: that does sound good
    
    It turns out some mode of failure includes ssh hanging (such as trying a
    wrong port), so silently re-running SSH again wasn't very wise. Instead,
    show the command line needed to let the user run the ssh command by
    himself.
Commits on Mar 30, 2013
  1. @kohsuke

    Revert "Fixing the unit test failure"

    kohsuke authored
    This reverts commit 8827307.
This page is out of date. Refresh to see the latest.
View
6 features/cli/scp.feature
@@ -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
3  features/cli/ssh.feature
@@ -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:
"""
View
1  features/step_definitions/cli_steps.rb
@@ -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
26 lib/blimpy/box.rb
@@ -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
26 lib/blimpy/cli.rb
@@ -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
Something went wrong with that request. Please try again.