Rename gsh to polysh.
[polysh.git] / tests / tests / file_transfer.py
blob15fbb8a0374cfcf00ae112ccf0e7111964a6d265
1 # This program is free software; you can redistribute it and/or modify
2 # it under the terms of the GNU General Public License as published by
3 # the Free Software Foundation; either version 2 of the License, or
4 # (at your option) any later version.
6 # This program is distributed in the hope that it will be useful,
7 # but WITHOUT ANY WARRANTY; without even the implied warranty of
8 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 # GNU Library General Public License for more details.
11 # You should have received a copy of the GNU General Public License
12 # along with this program; if not, write to the Free Software
13 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15 # See the COPYING file for license information.
17 # Copyright (c) 2008 Guillaume Chazarain <guichaz@gmail.com>
19 import tempfile
20 import unittest
21 import pexpect
22 import subprocess
23 from polysh_tests import launch_polysh
25 def shell_output(command):
26 p = subprocess.Popen([command], shell=True, stdout=subprocess.PIPE)
27 return p.communicate()[0].strip()
29 class TestFileTransfer(unittest.TestCase):
30 def testReplicate(self):
31 tmp_dir = tempfile.mkdtemp()
32 local = tmp_dir + '/local'
33 child = launch_polysh(['localhost'] * 6)
34 child.expect('ready \(6\)> ')
35 child.sendline(':replicate')
36 child.expect('Usage: :replicate SHELL:REMOTE_PATH')
37 child.expect('ready \(6\)> ')
38 child.sendline(':replicate localhost:')
39 child.expect('No remote path given')
40 child.expect('ready \(6\)> ')
41 child.sendline(':disable')
42 child.expect('ready \(0\)> ')
43 child.sendline(':enable localhost')
44 child.expect('ready \(1\)> ')
45 child.sendline(':replicate localhost#1:/dev/null')
46 child.expect('localhost#1 is not enabled')
47 child.expect('ready \(1\)> ')
48 child.sendline(':replicate localhost:/dev/null')
49 child.expect('No other remote shell to replicate files to')
50 child.expect('ready \(1\)> ')
51 child.sendline(':enable')
52 child.expect('ready \(6\)> ')
53 child.sendline(':replicate nohost:/dev/null')
54 child.expect('nohost not found')
55 child.expect('ready \(6\)> ')
56 child.sendline(':disable localhost#5')
57 child.expect('ready \(5\)> ')
58 child.sendline("cd %s" % tmp_dir)
59 child.expect('ready \(5\)> ')
60 child.sendline('!mkdir %s' % local)
61 child.expect('ready \(5\)> ')
62 child.sendline('!yes "$(dmesg)" | head -c 20m > %s/file' % local)
63 child.expect('ready \(5\)> ')
64 child.sendline('!cd %s && sha1sum file > SHA1SUM' % local)
65 child.expect('ready \(5\)> ')
66 child.sendline(':export_vars')
67 child.expect('ready \(5\)> ')
68 child.sendline('mkdir $POLYSH_RANK')
69 child.expect('ready \(5\)> ')
70 child.sendline('cd $POLYSH_RANK')
71 child.expect('ready \(5\)> ')
72 child.sendline(':replicate l\t:%s/fil\t' % local)
73 child.expect('Done transferring 20981760 bytes')
74 child.expect('ready \(5\)> ')
75 child.sendline('sha1sum file > SHA1SUM')
76 child.expect('ready \(5\)> ')
77 cat = 'cat %s/*/SHA1SUM' % tmp_dir
78 wc_output = shell_output('%s | wc | tr -s " "' % cat)
79 self.assertEqual(wc_output, '5 10 235')
80 uniq_wc_output = shell_output('%s | uniq | wc | tr -s " "' % cat)
81 self.assertEqual(uniq_wc_output, '1 2 47')
82 child.sendline("!rm -fr '%s'" % tmp_dir)
83 child.expect('ready \(5\)> ')
84 child.sendline(':quit')
85 child.expect(pexpect.EOF)
87 def testUpload(self):
88 tmp_dir = tempfile.mkdtemp()
89 local = tmp_dir + '/local'
90 child = launch_polysh(['localhost'] * 5)
91 child.expect('ready \(5\)> ')
92 child.sendline(':upload')
93 child.expect('No local path given')
94 child.expect('ready \(5\)> ')
95 child.sendline("cd %s" % tmp_dir)
96 child.expect('ready \(5\)> ')
97 child.sendline('!mkdir %s' % local)
98 child.expect('ready \(5\)> ')
99 child.sendline('!yes "$(dmesg)" | head -c 20m > %s/file' % local)
100 child.expect('ready \(5\)> ')
101 child.sendline('!cd %s && sha1sum file > SHA1SUM' % local)
102 child.expect('ready \(5\)> ')
103 child.sendline(':export_vars')
104 child.expect('ready \(5\)> ')
105 child.sendline('mkdir $POLYSH_RANK')
106 child.expect('ready \(5\)> ')
107 child.sendline('cd $POLYSH_RANK')
108 child.expect('ready \(5\)> ')
109 child.sendline(':upload %s/fil\t' % local)
110 child.expect('Done transferring 20981760 bytes')
111 child.expect('ready \(5\)> ')
112 child.sendline('sha1sum file > SHA1SUM')
113 child.expect('ready \(5\)> ')
114 cat = 'cat %s/*/SHA1SUM' % tmp_dir
115 wc_output = shell_output('%s | wc | tr -s " "' % cat)
116 self.assertEqual(wc_output, '6 12 282')
117 uniq_wc_output = shell_output('%s | uniq | wc | tr -s " "' % cat)
118 self.assertEqual(uniq_wc_output, '1 2 47')
119 child.sendline("!rm -fr '%s'" % tmp_dir)
120 child.expect('ready \(5\)> ')
121 child.sendline(':quit')
122 child.expect(pexpect.EOF)