File tree Expand file tree Collapse file tree 1 file changed +16
-2
lines changed Expand file tree Collapse file tree 1 file changed +16
-2
lines changed Original file line number Diff line number Diff line change 1818
1919from ssh_utilities import Connection
2020import getpass
21+ import socket
2122
2223logging .basicConfig (stream = sys .stderr )
2324log = logging .getLogger (__name__ )
@@ -34,6 +35,18 @@ class TestSSHPath(TestCase):
3435
3536 def setUp (self ):
3637
38+ def get_ip ():
39+ s = socket .socket (socket .AF_INET , socket .SOCK_DGRAM )
40+ try :
41+ # doesn't even have to be reachable
42+ s .connect (('10.255.255.255' , 1 ))
43+ IP = s .getsockname ()[0 ]
44+ except Exception :
45+ IP = '127.0.0.1'
46+ finally :
47+ s .close ()
48+ return IP
49+
3750 self .user = os .environ .get ("USER" , "rynik" )
3851 self .home = os .environ .get ("HOME" , Path .home ())
3952 self .os = os .name
@@ -46,14 +59,15 @@ def setUp(self):
4659 #else:
4760 # c = Connection.open(self.user, "127.0.0.1", ssh_key_file=None,
4861 # ssh_password="12345678", server_name="test")
62+ localhost = get_ip ()
4963 user = getpass .getuser ()
5064 Connection .add_hosts ({
5165 "user" : user ,
52- "hostname" : " localhost" ,
66+ "hostname" : localhost ,
5367 "identityfile" : "~/.ssh/id_rsa"
5468 })
5569 print (Connection .available_hosts )
56- c = Connection .get (" localhost" , local = False )
70+ c = Connection .get (localhost , local = False )
5771
5872 self .p = c .pathlib .Path ("/tmp" )
5973
You can’t perform that action at this time.
0 commit comments