Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ssh wait option #239

Merged
merged 1 commit into from
Feb 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions lib/tugboat/middleware/check_droplet_active.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ module Middleware
class CheckDropletActive < Base
def call(env)

if env["droplet_status"] != "active"
say "Droplet must be on for this operation to be successful.", :red
exit 1
unless env['user_droplet_ssh_wait']
if env["droplet_status"] != "active"
say "Droplet must be on for this operation to be successful.", :red
exit 1
end
end

@app.call(env)
Expand Down
32 changes: 31 additions & 1 deletion spec/cli/ssh_cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
@cli.ssh("example.com")
end

it "wait's until droplet active if -w command is given" do
it "wait's until droplet active if -w command is given and droplet already active" do
stub_request(:get, "https://api.digitalocean.com/v2/droplets?page=1&per_page=1").
with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization'=>'Bearer foo', 'Content-Type'=>'application/json', 'User-Agent'=>'Faraday v0.9.2'}).
to_return(:status => 200, :body => "", :headers => {})
Expand All @@ -43,6 +43,36 @@
eos
end

it "wait's until droplet active if -w command is given and droplet eventually active" do
stub_request(:get, "https://api.digitalocean.com/v2/droplets?page=1&per_page=1").
with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization'=>'Bearer foo', 'Content-Type'=>'application/json', 'User-Agent'=>'Faraday v0.9.2'}).
to_return(:status => 200, :body => "", :headers => {})

stub_request(:get, "https://api.digitalocean.com/v2/droplets/6918990?per_page=200").
with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization'=>'Bearer foo', 'Content-Type'=>'application/json', 'User-Agent'=>'Faraday v0.9.2'}).
to_return(
{:status => 200, :body => fixture('show_droplet_inactive'), :headers => {}},
{:status => 200, :body => fixture('show_droplet'), :headers => {}}
)

stub_request(:get, "https://api.digitalocean.com/v2/droplets?page=1&per_page=200").
to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_droplets"))
allow(Kernel).to receive(:exec).with('ssh', anything(), anything(),anything(), anything(),anything(), anything(),anything(), anything(),anything(), anything(),anything(), anything(),anything())

@cli.options = @cli.options.merge(:wait => true)

@cli.ssh("example.com")

expect($stdout.string).to eq <<-eos
Droplet fuzzy name provided. Finding droplet ID...done\e[0m, 6918990 (example.com)
Executing SSH on Droplet (example.com)...
Wait flag given, waiting for droplet to become active
..done\e[0m (2s)
Attempting SSH: baz@104.236.32.182
SShing with options: -o LogLevel=ERROR -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o IdentitiesOnly=yes -i #{Dir.home}/.ssh/id_rsa2 -p 33 baz@104.236.32.182
eos
end

it "does not allow ssh into a droplet that is inactive" do
stub_request(:get, "https://api.digitalocean.com/v2/droplets?page=1&per_page=1").
with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization'=>'Bearer foo', 'Content-Type'=>'application/json', 'User-Agent'=>'Faraday v0.9.2'}).
Expand Down