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
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
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
Show more breadcrumbs
toolbox
WindEnergyToolbox
Commits
c1f7fa1e
There was a problem fetching the pipeline summary.
Commit
c1f7fa1e
authored
8 years ago
by
Mads M. Pedersen
Browse files
Options
Downloads
Patches
Plain Diff
Added requirement for sshtunnel
parent
917925ab
No related branches found
No related tags found
1 merge request
!22
Ssh client with gateway and interactive auth2
Pipeline
#
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
requirements.txt
+1
-0
1 addition, 0 deletions
requirements.txt
wetb/utils/tests/test_ssh_client.py
+26
-78
26 additions, 78 deletions
wetb/utils/tests/test_ssh_client.py
with
27 additions
and
78 deletions
requirements.txt
+
1
−
0
View file @
c1f7fa1e
...
@@ -12,6 +12,7 @@ pandas
...
@@ -12,6 +12,7 @@ pandas
tables
tables
future
future
paramiko
paramiko
sshtunnel
psutil
psutil
pbr
pbr
PyScaffold
PyScaffold
...
...
This diff is collapsed.
Click to expand it.
wetb/utils/tests/test_ssh_client.py
+
26
−
78
View file @
c1f7fa1e
...
@@ -106,89 +106,37 @@ class TestSSHClient(unittest.TestCase):
...
@@ -106,89 +106,37 @@ class TestSSHClient(unittest.TestCase):
self
.
assertEqual
(
len
(
os
.
listdir
(
tfp
+
"
tmp/input/data/
"
)),
2
)
self
.
assertEqual
(
len
(
os
.
listdir
(
tfp
+
"
tmp/input/data/
"
)),
2
)
shutil
.
rmtree
(
tfp
+
"
tmp/
"
)
shutil
.
rmtree
(
tfp
+
"
tmp/
"
)
# def test_ssh_gorm(self):
def
test_ssh_gorm
(
self
):
# if x:
if
0
or
all
:
# ssh = SSHClient('gorm.risoe.dk', 'mmpe', x.mmpe)
if
x
:
# _,out,_ = ssh.execute("hostname")
ssh
=
SSHClient
(
'
gorm.risoe.dk
'
,
'
mmpe
'
,
x
.
mmpe
)
# self.assertEqual(out.strip(), "g-000.risoe.dk")
_
,
out
,
_
=
ssh
.
execute
(
"
hostname
"
)
self
.
assertEqual
(
out
.
strip
(),
"
g-000.risoe.dk
"
)
# def test_ssh_g047(self):
# if x:
def
test_ssh_g047
(
self
):
# gateway = SSHClient('gorm.risoe.dk', 'mmpe', x.mmpe)
if
1
or
all
:
# ssh = SSHClient('g-047', "mmpe", x.mmpe, gateway=gateway)
if
x
:
# self.assertEqual(ssh.execute('hostname')[1].strip(), "g-047")
gateway
=
SSHClient
(
'
gorm.risoe.dk
'
,
'
mmpe
'
,
x
.
mmpe
)
ssh
=
SSHClient
(
'
g-047
'
,
"
mmpe
"
,
x
.
mmpe
,
gateway
=
gateway
)
self
.
assertEqual
(
ssh
.
execute
(
'
hostname
'
)[
1
].
strip
(),
"
g-047
"
)
#
def test_ssh_risoe(self):
def
test_ssh_risoe
(
self
):
#
if
x
:
if
0
or
all
:
#
if
x
:
#
ssh = SSHClient('ssh.risoe.dk', 'mmpe', interactive_auth_handler = sshrisoe_interactive_auth_handler(x.mmpe))
ssh
=
SSHClient
(
'
ssh.risoe.dk
'
,
'
mmpe
'
,
interactive_auth_handler
=
sshrisoe_interactive_auth_handler
(
x
.
mmpe
))
#
_,out,_ = ssh.execute("hostname")
_
,
out
,
_
=
ssh
.
execute
(
"
hostname
"
)
#
self.assertEqual(out.strip(), "ssh-03.risoe.dk")
self
.
assertEqual
(
out
.
strip
(),
"
ssh-03.risoe.dk
"
)
def
test_ssh_risoe_gorm
(
self
):
def
test_ssh_risoe_gorm
(
self
):
if
x
:
if
0
or
all
:
if
x
:
gateway
=
SSHClient
(
'
ssh.risoe.dk
'
,
'
mmpe
'
,
interactive_auth_handler
=
sshrisoe_interactive_auth_handler
(
x
.
mmpe
))
ssh
=
SSHClient
(
'
10.40.23.49
'
,
'
mmpe
'
,
x
.
mmpe
,
gateway
=
gateway
)
gateway
=
SSHClient
(
'
ssh.risoe.dk
'
,
'
mmpe
'
,
interactive_auth_handler
=
sshrisoe_interactive_auth_handler
(
x
.
mmpe
))
_
,
out
,
_
=
ssh
.
execute
(
"
hostname
"
)
ssh
=
SSHClient
(
'
10.40.23.49
'
,
'
mmpe
'
,
x
.
mmpe
,
gateway
=
gateway
)
self
.
assertEqual
(
out
.
strip
(),
"
g-000.risoe.dk
"
)
_
,
out
,
_
=
ssh
.
execute
(
"
hostname
"
)
self
.
assertEqual
(
out
.
strip
(),
"
g-000.risoe.dk
"
)
# def test_ssh_risoe(self):
# #logger = logging.getLogger("paramiko")
# #logger.setLevel(logging.DEBUG) # for example
# #ch = logging.StreamHandler(sys.stdout)
# #ch.setLevel(logging.DEBUG)
# #formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
# #ch.setFormatter(formatter)
# #logger.addHandler(ch)
# ssh = SSHClient('ssh.risoe.dk', 'mmpe')
# print (ssh.connect())
# return
# username = "mmpe"
#
# client = paramiko.client.SSHClient()
#
# # Any means of getting the PKey will do. This code assumes you've only got one key loaded in your active ssh-agent.
# # See also:
# # - http://docs.paramiko.org/en/1.17/api/keys.html#paramiko.pkey.PKey
# # - http://docs.paramiko.org/en/1.17/api/client.html#paramiko.client.SSHClient.connect
# my_pkey = None #paramiko.agent.Agent().get_keys()[0]
#
# try:
# client.connect(
# hostname="ssh.risoe.dk",
# port=22,
# username=username,
# look_for_keys=False,
# pkey=my_pkey
# )
# except paramiko.ssh_exception.SSHException as e:
# pass
#
# transport = client.get_transport()
#
# # Sometimes sshd is configured to use 'keyboard-interactive' instead of 'password' to implement the YubiKey challenge.
# # In that case, you can use something like this.
# # The code below assumes the server will only ask one question and expect the YubiKey OTP as an answer.
# # If there's more questions to answer, you should handle those per the docs at:
# # http://docs.paramiko.org/en/1.17/api/transport.html#paramiko.transport.Transport.auth_interactive
# #
# def interactive_handler(title, instructions, prompt_list):
# if prompt_list:
# if prompt_list[0][0]=="AD Password: ":
# return [x.mmpe]
# return [getpass.getpass(prompt_list[0][0])]
# print ("here")
# return []
# transport.auth_interactive(username, interactive_handler)
#
# #transport.auth_password(username, x.mmpe)
#
# # You should now be able to use client as the authenticated user.
# client.exec_command("echo hej")
#
if
__name__
==
"
__main__
"
:
if
__name__
==
"
__main__
"
:
#import sys;sys.argv = ['', 'Test.testName']
#import sys;sys.argv = ['', 'Test.testName']
unittest
.
main
()
unittest
.
main
()
\ No newline at end of file
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