Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
W
WindEnergyToolbox
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Admin message
The Gitlab server is succesfully updated to version 17.10.3
Show more breadcrumbs
shfe1
WindEnergyToolbox
Commits
8ef952ee
Commit
8ef952ee
authored
8 years ago
by
Mads M. Pedersen
Browse files
Options
Downloads
Patches
Plain Diff
extracted class interactive_auth_handler in test_ssh_client.py
parent
2ccdb635
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
wetb/utils/cluster_tools/ssh_client.py
+4
-5
4 additions, 5 deletions
wetb/utils/cluster_tools/ssh_client.py
wetb/utils/tests/test_ssh_client.py
+18
-27
18 additions, 27 deletions
wetb/utils/tests/test_ssh_client.py
with
22 additions
and
32 deletions
wetb/utils/cluster_tools/ssh_client.py
+
4
−
5
View file @
8ef952ee
...
...
@@ -142,12 +142,11 @@ class SSHClient(object):
else
:
self
.
client
=
paramiko
.
SSHClient
()
self
.
client
.
set_missing_host_key_policy
(
paramiko
.
AutoAddPolicy
())
if
self
.
interactive_auth_handler
:
transport
=
self
.
client
.
get_transport
()
transport
.
auth_interactive
(
self
.
username
,
self
.
interactive_handler
)
else
:
try
:
self
.
client
.
connect
(
self
.
host
,
self
.
port
,
username
=
self
.
username
,
password
=
self
.
password
,
pkey
=
self
.
key
,
timeout
=
self
.
TIMEOUT
)
except
paramiko
.
ssh_exception
.
SSHException
as
e
:
transport
=
self
.
client
.
get_transport
()
transport
.
auth_interactive
(
self
.
username
,
self
.
interactive_auth_handler
)
...
...
This diff is collapsed.
Click to expand it.
wetb/utils/tests/test_ssh_client.py
+
18
−
27
View file @
8ef952ee
...
...
@@ -23,7 +23,17 @@ import logging
import
getpass
class
sshrisoe_interactive_auth_handler
(
object
):
def
__init__
(
self
,
password
):
self
.
password
=
password
def
__call__
(
self
,
title
,
instructions
,
prompt_list
):
if
prompt_list
:
if
prompt_list
[
0
][
0
]
==
"
AD Password:
"
:
return
[
self
.
password
]
return
[
getpass
.
getpass
(
prompt_list
[
0
][
0
])]
return
[]
tfp
=
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
'
test_files/
'
)
all
=
0
class
TestSSHClient
(
unittest
.
TestCase
):
...
...
@@ -111,35 +121,16 @@ class TestSSHClient(unittest.TestCase):
# ssh = SSHClient('g-047', "mmpe", x.mmpe, gateway=gateway)
# self.assertEqual(ssh.execute('hostname')[1].strip(), "g-047")
# def test_ssh_risoe(self):
# if x:
# class sshrisoe_interactive_auth_handler(object):
# def __init__(self, password):
# self.password = password
#
# def __call__(self, title, instructions, prompt_list):
# if prompt_list:
# if prompt_list[0][0]=="AD Password: ":
# return [self.password]
# return [getpass.getpass(prompt_list[0][0])]
# return []
#
# ssh = SSHClient('ssh.risoe.dk', 'mmpe', interactive_auth_handler = sshrisoe_interactive_auth_handler(x.mmpe))
# _,out,_ = ssh.execute("hostname")
# self.assertEqual(out.strip(), "ssh-03.risoe.dk")
def
test_ssh_risoe
(
self
):
if
x
:
ssh
=
SSHClient
(
'
ssh.risoe.dk
'
,
'
mmpe
'
,
interactive_auth_handler
=
sshrisoe_interactive_auth_handler
(
x
.
mmpe
))
_
,
out
,
_
=
ssh
.
execute
(
"
hostname
"
)
self
.
assertEqual
(
out
.
strip
(),
"
ssh-03.risoe.dk
"
)
def
test_ssh_risoe_gorm
(
self
):
if
x
:
class
sshrisoe_interactive_auth_handler
(
object
):
def
__init__
(
self
,
password
):
self
.
password
=
password
def
__call__
(
self
,
title
,
instructions
,
prompt_list
):
if
prompt_list
:
if
prompt_list
[
0
][
0
]
==
"
AD Password:
"
:
return
[
self
.
password
]
return
[
getpass
.
getpass
(
prompt_list
[
0
][
0
])]
return
[]
gateway
=
SSHClient
(
'
ssh.risoe.dk
'
,
'
mmpe
'
,
interactive_auth_handler
=
sshrisoe_interactive_auth_handler
(
x
.
mmpe
))
ssh
=
SSHClient
(
'
gorm.risoe.dk
'
,
'
mmpe
'
,
x
.
mmpe
,
gateway
=
gateway
)
_
,
out
,
_
=
ssh
.
execute
(
"
hostname
"
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment