From: Cliff Rosson Date: 2013-05-15T06:07:29+09:00 Subject: Re: PROBLEMS CREATING AN SSH TUNNEL --047d7b16381f4f923d04dcb40586 Content-Type: text/plain; charset=ISO-8859-1 Can you just ssh directly in your code and deal with errors? require 'rubygems' require 'net/ssh' require 'net/ssh/telnet' class SSH attr_accessor :errors def initialize(creds) begin @ssh_session = Net::SSH.start(creds[:host], creds[:user], :password => creds[:password], :keys => []) @ssh = Net::SSH::Telnet.new("Session" => @ssh_session, "Prompt" => creds[:prompt]) @errors = false rescue Exception => e @errors = e end end def cmd(command) @ssh.cmd(command) end def close @ssh.close end end ssh = SSH.new(:host => "host.com", :username => "billy", :password => "123", :prompt => /./) unless ssh.errors ssh.cmd("pwd") end ssh.close On Tue, May 14, 2013 at 1:56 PM, Clem Rock wrote: > Hey - there thanks for getting back to me on this and sorry for the long > reply. I've been out sick in the last few days. > > I do not want to deal with mocking an ssh tunnel because I want the test > to be 100% a real test. I want to make sure the communication between > my code and the server to be 100% real. I want to be able to detect > any changes that come back from the sabrix server transactions. > > Also, I'm not even sure how I'd mock out an ssh tunnel connection in the > first place. Really, it seems like I'd be mocking the response from > the sabrix server. > > Thanks for your help so far. > > > > > > tamouse mailing lists wrote in post #1108163: > > On Tue, May 7, 2013 at 12:28 PM, Clem Rock wrote: > >> for some reason. I've tried about every solution out there but can't > >> sleep(1) #sleep just a tad to let everything start up > >> def teardown > >> -- > >> Posted via http://www.ruby-forum.com/. > > > > Just off the top of my head, instead of doing the setup and tear down, > > perhaps pass the test code into a method as a block that does that > > stuff, and mock the Net::SSH stuff? > > -- > Posted via http://www.ruby-forum.com/. > > -- vizualize.me/cliffrosson --047d7b16381f4f923d04dcb40586 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
Can you just ssh directly in your code and deal with error= s?

require 'rubygems'
require = 9;net/ssh'
require 'net/ssh/telnet'

class SSH
=A0 attr_accessor :errors
=A0=A0
=A0 def initialize(creds)
=A0 =A0 begin
=A0 =A0 =A0 = @ssh_session =3D Net::SSH.start(creds[:host], creds[:user], :password =3D&g= t; creds[:password], :keys =3D> [])
=A0 =A0 =A0 @ssh =3D Net::SSH::Telnet.new("Session" =3D> = @ssh_session, "Prompt" =3D> creds[:prompt])
=A0 =A0 = =A0 @errors =3D false
=A0 =A0 rescue Exception =3D> e
=A0 =A0 =A0 @errors =3D e
=A0 =A0 end
=A0 end
=A0=A0
=A0 def cmd(c= ommand)
=A0 =A0 @ssh.cmd(command)
=A0 end
=A0= =A0
=A0 def close
=A0 =A0 @ssh.close
=A0 end<= /div>
=A0 =A0=A0
end

ssh =3D SSH.new(:host =3D> "host.com", :username =3D> "billy", :password= =3D> "123", :prompt =3D> /./)
unless ssh.errors<= /div>
=A0 ssh.cmd("pwd")
end
ssh.close
<= div>


On Tue, May 14, 2013 at 1:56 PM, Clem Rock <lists@ruby-forum.com= > wrote:
Hey - there thanks for getting back to me on= this and sorry for the long
reply. =A0I've been out sick in the last few days.

I do not want to deal with mocking an ssh tunnel because I want the test to be 100% a real test. =A0 I want to make sure the communication between my code and the server to be 100% real. =A0 I want to be able to detect
any changes that come back from the sabrix server transactions.

Also, I'm not even sure how I'd mock out an ssh tunnel connection i= n the
first place. =A0 Really, it seems like I'd be mocking the response from=
the sabrix server.

Thanks for your help so far.





tamouse mailing lists wrote in post #1108163:
> On Tue, May 7, 2013 at 12:28 PM, Clem Rock <lists@ruby-forum.com> wrote:
>> for some reason. =A0 I've tried about = every solution out there but can't
>> =A0 =A0 sleep(1) #sleep just a tad to let = everything start up
>> =A0 def teardown
>> --
>> Posted via http://www.ruby-forum.com/.
>
> Just off the top of my head, instead of doing the setup and tear down,=
> perhaps pass the test code into a method as a block that does that
> stuff, and mock the Net::SSH stuff?

--
Posted via http://= www.ruby-forum.com/.




--
=
vizualiz= e.me/cliffrosson
--047d7b16381f4f923d04dcb40586--