Skip to content
This repository has been archived by the owner on Aug 29, 2018. It is now read-only.

Commit

Permalink
Merge pull request #293 from developercorey/master
Browse files Browse the repository at this point in the history
rhc app ssh <app>
  • Loading branch information
smarterclayton committed Feb 3, 2013
2 parents 2b8a468 + 76b704d commit 6548ce5
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 1 deletion.
40 changes: 40 additions & 0 deletions lib/rhc/commands/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,30 @@ def show(app_name)
0
end

summary "SSH into the specified application"
syntax "<app>"
argument :app, "The name of the application you want to SSH into", ["-a", "--app app"], :context => :app_context
option ["-s", "--ssh path/to/ssh"], "Path to your SSH executable"
option ["-o", "--nossh"], "Do not use system SSH executable"
option ["-d", "--dryrun"], "Don't actually execute SSH"
option ["-n", "--namespace namespace"], "Namespace of the application the cartridge belongs to", :context => :namespace_context, :required => true
def ssh(app_name)
domain = rest_client.find_domain(options.namespace)
app = domain.find_application(app_name)
ssh_command = (options.dryrun ? 'say' : 'system')
say "Please wait while we attempt an SSH connection to #{app.ssh_string.to_s}"
if options.ssh
say "Using user specified executable: #{options.ssh}"
Kernel.send(ssh_command.to_sym,"#{options.ssh} #{app.ssh_string.to_s}")
elsif has_ssh? && !options.nossh
say "Trying system command: ssh"
Kernel.send(ssh_command.to_sym, "ssh #{app.ssh_string.to_s}")
else
say "Please use the -s option to specify the path to your SSH executable, or install SSH."
end
0
end

summary "DEPRECATED use 'show <app> --state' instead"
syntax "<app> [--namespace namespace] [--app app]"
argument :app, "The name of the application you are getting information on", ["-a", "--app app"], :context => :app_context
Expand Down Expand Up @@ -433,6 +457,22 @@ def run_ping(host)
# :nocov:
end

# check the version of SSH that is installed
def ssh_version
@ssh_version ||= `ssh -V 2>&1`.strip
end

# return whether or not SSH is installed
def has_ssh?
@has_ssh ||= begin
@ssh_version = nil
ssh_version
$?.success?
rescue
false
end
end

def windows_nslookup_bug?(rest_app)
windows_nslookup = run_nslookup(rest_app.host)
windows_ping = run_ping(rest_app.host)
Expand Down
2 changes: 1 addition & 1 deletion lib/rhc/git_helpers.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'open4'
require 'open4'

module RHC
module GitHelpers
Expand Down
47 changes: 47 additions & 0 deletions spec/rhc/commands/app_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,53 @@
end
end

describe 'app ssh' do
let(:arguments) { ['app', 'ssh', 'app1', '--dryrun','--noprompt', '--config', 'test.conf', '-l', 'test@test.foo', '-p', 'password'] }

context 'when run' do
before(:each) do
@domain = rest_client.add_domain("mockdomain")
@domain.add_application("app1", "mock_type")
end
it { run_output.should match("Please wait while we attempt an SSH connection to") }
it { run_output.should match ("ssh fakeuuidfortestsapp1@127.0.0.1")}
end
end

describe 'app ssh no system ssh' do
let(:arguments) { ['app', 'ssh', 'app1', '--nossh', '--noprompt', '--config', 'test.conf', '-l', 'test@test.foo', '-p', 'password'] }

context 'when run' do
before(:each) do
@domain = rest_client.add_domain("mockdomain")
@domain.add_application("app1", "mock_type")
end
it { run_output.should match("Please use the -s option to specify the path to your SSH executable, or install SSH.") }
end
end

describe 'app ssh -s does exists' do
let(:arguments) { ['app', 'ssh', 'app1', '-s ssh', '--dryrun', '--noprompt', '--config', 'test.conf', '-l', 'test@test.foo', '-p', 'password'] }

context 'when run' do
before(:each) do
@domain = rest_client.add_domain("mockdomain")
@domain.add_application("app1", "mock_type")
end
it { run_output.should match("Using user specified executable:") }
it { run_output.should match ("ssh fakeuuidfortestsapp1@127.0.0.1")}
end
end

describe 'ssh tests' do
let(:arguments) { ['app', 'ssh', 'app1', '-s /bin/blah', '--noprompt', '--config', 'test.conf', '-l', 'test@test.foo', '-p', 'password'] }

context 'has_ssh?' do
before{ @instance.stub(:ssh_version){ raise "Fake Exception" } }
its(:has_ssh?) { should be_false }
end
end

describe 'app status' do
let(:arguments) { ['app', 'status', 'app1', '--noprompt', '--config', 'test.conf', '-l', 'test@test.foo', '-p', 'password'] }

Expand Down

0 comments on commit 6548ce5

Please sign in to comment.