Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mitogen
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
mitogen
Commits
3a0f0318
Commit
3a0f0318
authored
Sep 17, 2017
by
David Wilson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simple working fakessh_test.
parent
76e476dc
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
55 deletions
+31
-55
tests/fakessh_test.py
tests/fakessh_test.py
+14
-34
tests/ssh_test.py
tests/ssh_test.py
+5
-21
tests/testlib.py
tests/testlib.py
+12
-0
No files found.
tests/fakessh_test.py
View file @
3a0f0318
import
mitogen.utils
import
mitogen.fakessh
@
mitogen
.
utils
.
run_with_router
def
main
(
router
):
import
logging
mitogen
.
utils
.
log_to_file
(
level
=
logging
.
INFO
)
router
.
enable_debug
()
#mitogen.fakessh.run_with_fake_ssh(router, ['bash', '-c', 'echo $PATH'])
#mitogen.fakessh.run_with_fake_ssh(router, ['bash', '-c', 'ls -Gl $SSH_PATH'])
# k3 = router.ssh(hostname='k3')
k3
=
router
.
local
()
print
'GOT HERE'
import
os
k3
.
call
(
os
.
system
,
'hostname'
)
return
#sud = router.sudo(via=k3, username='root')
sud
=
k3
mitogen
.
fakessh
.
run_with_fake_ssh
(
sud
,
router
,
[
'rsync'
,
'--progress'
,
'-vvvr'
,
'h:/var/lib/docker'
])
#mitogen.fakessh.run_with_fake_ssh(router, ['bash', '-c', 'ssh h rsync --server . foo'])
# mitogen.fakessh.run_with_fake_ssh(router, ['bash', '-c', 'ssh k3.botanicus.net -t screen -dr'])
print
'end of t.py'
import
os
import
shutil
import
unittest
import
logging
import
mitogen.utils
import
mitogen.fakessh
@
mitogen
.
utils
.
run_with_router
def
main
(
router
):
mitogen
.
utils
.
log_to_file
(
level
=
logging
.
DEBUG
)
#router.enable_debug()
#router.enable_debug()
import
testlib
k3
=
router
.
ssh
(
hostname
=
'k3'
)
sudo
=
router
.
sudo
(
via
=
k3
,
username
=
'root'
)
mitogen
.
fakessh
.
run
(
sudo
,
router
,
[
'rsync'
,
'--progress'
,
'-r'
,
'h:/var/lib/docker'
])
class
RsyncTest
(
testlib
.
DockerMixin
,
unittest
.
TestCase
):
def
test_rsync_from_master
(
self
):
context
=
self
.
docker_ssh_any
()
context
.
call
(
shutil
.
rmtree
,
'/tmp/data'
,
ignore_errors
=
True
)
mitogen
.
fakessh
.
run
(
context
,
self
.
router
,
[
'rsync'
,
'--progress'
,
'-vvva'
,
testlib
.
data_path
(
'.'
),
'target:/tmp/data'
])
assert
context
.
call
(
os
.
path
.
exists
,
'/tmp/data'
)
assert
context
.
call
(
os
.
path
.
exists
,
'/tmp/data/simple_pkg/a.py'
)
tests/ssh_test.py
View file @
3a0f0318
...
...
@@ -26,10 +26,7 @@ class SshTest(testlib.DockerMixin, unittest.TestCase):
def
test_password_required
(
self
):
try
:
context
=
self
.
router
.
ssh
(
hostname
=
self
.
dockerized_ssh
.
host
,
port
=
self
.
dockerized_ssh
.
port
,
check_host_keys
=
False
,
context
=
self
.
docker_ssh
(
username
=
'has-sudo'
,
)
assert
0
,
'exception not thrown'
...
...
@@ -40,10 +37,7 @@ class SshTest(testlib.DockerMixin, unittest.TestCase):
def
test_password_incorrect
(
self
):
try
:
context
=
self
.
router
.
ssh
(
hostname
=
self
.
dockerized_ssh
.
host
,
port
=
self
.
dockerized_ssh
.
port
,
check_host_keys
=
False
,
context
=
self
.
docker_ssh
(
username
=
'has-sudo'
,
password
=
'badpw'
,
)
...
...
@@ -54,10 +48,7 @@ class SshTest(testlib.DockerMixin, unittest.TestCase):
assert
e
[
0
]
==
self
.
stream_class
.
password_incorrect_msg
def
test_password_specified
(
self
):
context
=
self
.
router
.
ssh
(
hostname
=
self
.
dockerized_ssh
.
host
,
port
=
self
.
dockerized_ssh
.
port
,
check_host_keys
=
False
,
context
=
self
.
docker_ssh
(
username
=
'has-sudo'
,
password
=
'y'
,
)
...
...
@@ -67,10 +58,7 @@ class SshTest(testlib.DockerMixin, unittest.TestCase):
def
test_pubkey_required
(
self
):
try
:
context
=
self
.
router
.
ssh
(
hostname
=
self
.
dockerized_ssh
.
host
,
port
=
self
.
dockerized_ssh
.
port
,
check_host_keys
=
False
,
context
=
self
.
docker_ssh
(
username
=
'has-sudo-pubkey'
,
)
assert
0
,
'exception not thrown'
...
...
@@ -80,13 +68,9 @@ class SshTest(testlib.DockerMixin, unittest.TestCase):
assert
e
[
0
]
==
self
.
stream_class
.
password_required_msg
def
test_pubkey_specified
(
self
):
context
=
self
.
router
.
ssh
(
hostname
=
self
.
dockerized_ssh
.
host
,
port
=
self
.
dockerized_ssh
.
port
,
check_host_keys
=
False
,
context
=
self
.
docker_ssh
(
username
=
'has-sudo-pubkey'
,
identity_file
=
testlib
.
data_path
(
'docker/has-sudo-pubkey.key'
),
)
sentinel
=
'i-am-mitogen-test-docker-image
\
n
'
assert
sentinel
==
context
.
call
(
plain_old_module
.
get_sentinel_value
)
tests/testlib.py
View file @
3a0f0318
...
...
@@ -76,3 +76,15 @@ class DockerMixin(RouterMixin):
def
tearDownClass
(
cls
):
cls
.
dockerized_ssh
.
close
()
super
(
DockerMixin
,
cls
).
tearDownClass
()
def
docker_ssh
(
self
,
**
kwargs
):
kwargs
.
setdefault
(
'hostname'
,
self
.
dockerized_ssh
.
host
)
kwargs
.
setdefault
(
'port'
,
self
.
dockerized_ssh
.
port
)
kwargs
.
setdefault
(
'check_host_keys'
,
False
)
return
self
.
router
.
ssh
(
**
kwargs
)
def
docker_ssh_any
(
self
,
**
kwargs
):
return
self
.
docker_ssh
(
username
=
'has-sudo-nopw'
,
password
=
'y'
,
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment