mitogen/tests/fakessh_test.py

63 lines
1.8 KiB
Python
Raw Normal View History

2017-09-17 15:49:06 +00:00
import os
import shutil
import unittest
import mitogen.fakessh
2017-09-17 15:49:06 +00:00
import testlib
2017-09-17 15:49:06 +00:00
class RsyncTest(testlib.DockerMixin, unittest.TestCase):
def test_rsync_from_master(self):
context = self.docker_ssh_any()
2017-09-21 07:36:59 +00:00
if context.call(os.path.exists, '/tmp/data'):
context.call(shutil.rmtree, '/tmp/data')
return_code = mitogen.fakessh.run(context, self.router, [
2017-09-17 15:49:06 +00:00
'rsync', '--progress', '-vvva',
testlib.data_path('.'), 'target:/tmp/data'
])
2017-09-21 07:36:59 +00:00
assert return_code == 0
2017-09-17 15:49:06 +00:00
assert context.call(os.path.exists, '/tmp/data')
assert context.call(os.path.exists, '/tmp/data/simple_pkg/a.py')
def test_rsync_between_direct_children(self):
# master -> SSH -> has-sudo-pubkey -> rsync(.ssh) -> master ->
# has-sudo -> rsync
pubkey_acct = self.docker_ssh(
username='has-sudo-pubkey',
identity_file=testlib.data_path('docker/has-sudo-pubkey.key'),
)
nopw_acct = self.docker_ssh(
username='has-sudo-nopw',
password='y',
)
webapp_acct = self.router.sudo(
via=nopw_acct,
username='webapp',
)
dest_path = webapp_acct.call(os.path.expanduser, '~/.ssh')
if webapp_acct.call(os.path.exists, dest_path):
webapp_acct.call(shutil.rmtree, dest_path)
return_code = pubkey_acct.call(mitogen.fakessh.run, webapp_acct, args=[
'rsync', '--progress', '-vvva', '.ssh/', 'target:' + dest_path
])
assert return_code == 0
assert pubkey_acct.call(os.path.getsize, '.ssh/authorized_keys') == \
webapp_acct.call(os.path.getsize, dest_path + '/authorized_keys')
if __name__ == '__main__':
import mitogen.utils
mitogen.utils.log_to_file(level='DEBUG', io=False)
unittest.main()