2017-09-16 10:06:08 +00:00
|
|
|
|
2017-09-17 15:49:06 +00:00
|
|
|
import os
|
|
|
|
import shutil
|
2017-11-11 22:59:38 +00:00
|
|
|
|
2017-11-12 12:42:27 +00:00
|
|
|
import unittest2
|
2017-09-16 10:06:08 +00:00
|
|
|
|
|
|
|
import mitogen.fakessh
|
|
|
|
|
2017-09-17 15:49:06 +00:00
|
|
|
import testlib
|
2017-09-16 10:06:08 +00:00
|
|
|
|
|
|
|
|
2018-11-03 13:28:37 +00:00
|
|
|
class RsyncTest(testlib.DockerMixin, testlib.TestCase):
|
2018-04-16 13:28:07 +00:00
|
|
|
@unittest2.skip('broken')
|
2017-09-17 15:49:06 +00:00
|
|
|
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
|
|
|
|
2017-11-11 23:08:08 +00:00
|
|
|
self.assertEqual(return_code, 0)
|
|
|
|
self.assertTrue(context.call(os.path.exists, '/tmp/data'))
|
|
|
|
self.assertTrue(context.call(os.path.exists, '/tmp/data/simple_pkg/a.py'))
|
2017-09-16 10:06:08 +00:00
|
|
|
|
2018-04-16 13:28:07 +00:00
|
|
|
@unittest2.skip('broken')
|
2017-09-21 11:16:30 +00:00
|
|
|
def test_rsync_between_direct_children(self):
|
2018-04-16 13:24:39 +00:00
|
|
|
# master -> SSH -> mitogen__has_sudo_pubkey -> rsync(.ssh) -> master ->
|
|
|
|
# mitogen__has_sudo -> rsync
|
2017-09-21 11:16:30 +00:00
|
|
|
|
|
|
|
pubkey_acct = self.docker_ssh(
|
2018-04-16 13:24:39 +00:00
|
|
|
username='mitogen__has_sudo_pubkey',
|
|
|
|
identity_file=testlib.data_path('docker/mitogen__has_sudo_pubkey.key'),
|
2017-09-21 11:16:30 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
nopw_acct = self.docker_ssh(
|
2018-04-16 13:24:39 +00:00
|
|
|
username='mitogen__has_sudo_nopw',
|
|
|
|
password='has_sudo_nopw_password',
|
2017-09-21 11:16:30 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
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
|
|
|
|
])
|
|
|
|
|
2017-11-11 23:08:08 +00:00
|
|
|
self.assertEqual(return_code, 0)
|
|
|
|
self.assertEqual(
|
|
|
|
pubkey_acct.call(os.path.getsize, '.ssh/authorized_keys'),
|
|
|
|
webapp_acct.call(os.path.getsize, dest_path + '/authorized_keys'),
|
|
|
|
)
|
2017-09-21 11:16:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2017-11-12 12:42:27 +00:00
|
|
|
unittest2.main()
|