Example #1
0
 def testUser(self):
     child = launch_polysh(['--ssh=echo', 'machine'])
     child.expect('[^@]machine')
     child.expect(pexpect.EOF)
     child = launch_polysh(['--ssh=echo', '--user=login', 'machine'])
     child.expect('login@machine')
     child.expect(pexpect.EOF)
Example #2
0
 def testNoHosts(self):
     child = launch_polysh([])
     child.expect('error: no hosts given')
     child.expect(pexpect.EOF)
     child = launch_polysh(['--hosts-file=/dev/null'])
     child.expect('error: no hosts given')
     child.expect(pexpect.EOF)
Example #3
0
 def testUser(self):
     child = launch_polysh(['--ssh=echo', 'machine'])
     child.expect('[^@]machine')
     child.expect(pexpect.EOF)
     child = launch_polysh(['--ssh=echo', '--user=login', 'machine'])
     child.expect('login@machine')
     child.expect(pexpect.EOF)
Example #4
0
 def testNoHosts(self):
     child = launch_polysh([])
     child.expect('error: no hosts given')
     child.expect(pexpect.EOF)
     child = launch_polysh(['--hosts-file=/dev/null'])
     child.expect('error: no hosts given')
     child.expect(pexpect.EOF)
Example #5
0
 def testAbortError(self):
     child = launch_polysh(['localhost', 'unknown_host'])
     child.expect('Error talking to unknown_host')
     child.sendline(':quit')
     child.expect(pexpect.EOF)
     child = launch_polysh(['--abort-errors', 'localhost', 'unknown_host'])
     child.expect('Error talking to unknown_host')
     child.expect(pexpect.EOF)
Example #6
0
 def testAbortError(self):
     child = launch_polysh(['localhost', 'unknown_host'])
     child.expect('Error talking to unknown_host')
     child.sendline(':quit')
     child.expect(pexpect.EOF)
     child = launch_polysh(['--abort-errors', 'localhost', 'unknown_host'])
     child.expect('Error talking to unknown_host')
     child.expect(pexpect.EOF)
Example #7
0
    def testLogOutput(self):
        child = launch_polysh(['--log-file=/', 'localhost'])
        child.expect("\[Errno 21\].*'/'")
        child.expect(pexpect.EOF)
        child = launch_polysh(['--log-file=/cannot_write', 'localhost'])
        child.expect("\[Errno 13\].*'/cannot_write'")
        child.expect(pexpect.EOF)
        child = launch_polysh(['--log-file=/dev/full', 'localhost'])
        child.sendline('echo something')
        child.expect('Exception while writing log: /dev/full')
        child.expect('\[Errno 28\]')
        child.expect(pexpect.EOF)

        child = launch_polysh(['localhost'])

        def testEcho(msg):
            child.expect('ready \(1\)> ')
            child.sendline('echo %s' % msg)
            child.expect('\033\[1;36mlocalhost : \033\[1;m%s' % msg)

        testEcho('not logging')
        child.sendline(':set_log')
        testEcho('still not logging')
        child.sendline('!rm -f /tmp/polysh_test.log')
        testEcho('still not logging')
        child.sendline(':set_log /tmp/polysh_test.log')
        testEcho('now logging')
        testEcho('still logging')
        child.sendline(':set_log')
        testEcho('back to no logging')
        child.sendline(':set_log /tmp/polysh_test.lo\t')
        testEcho('appended to the log')
        child.sendline(':set_log')
        child.expect('ready \(1\)> ')
        child.sendline(':set_log /no-permission')
        child.expect("[Errno 13] .*: '/no-permission'")
        child.expect('Logging disabled')
        child.expect('ready \(1\)> ')
        child.sendeof()
        child.expect(pexpect.EOF)

        EXPECTED_LOG = """
> echo now logging
localhost : now logging
> echo still logging
localhost : still logging
> :set_log
> echo appended to the log
localhost : appended to the log
> :set_log
""".strip()
        log = file('/tmp/polysh_test.log')
        log_lines = [l for l in log.readlines() if not l.startswith('[dbg] ')]
        actual_log = ''.join(log_lines).strip()
        self.assertEqual(actual_log, EXPECTED_LOG)
        os.remove('/tmp/polysh_test.log')
Example #8
0
    def testLogOutput(self):
        child = launch_polysh(['--log-file=/', 'localhost'])
        child.expect("\[Errno 21\].*'/'")
        child.expect(pexpect.EOF)
        child = launch_polysh(['--log-file=/cannot_write', 'localhost'])
        child.expect("\[Errno 13\].*'/cannot_write'")
        child.expect(pexpect.EOF)
        child = launch_polysh(['--log-file=/dev/full', 'localhost'])
        child.sendline('echo something')
        child.expect('Exception while writing log: /dev/full')
        child.expect('\[Errno 28\]')
        child.expect(pexpect.EOF)

        child = launch_polysh(['localhost'])
        def testEcho(msg):
            child.expect('ready \(1\)> ')
            child.sendline('echo %s' % msg)
            child.expect('\033\[1;36mlocalhost : \033\[1;m%s' % msg)
        testEcho('not logging')
        child.sendline(':set_log')
        testEcho('still not logging')
        child.sendline('!rm -f /tmp/polysh_test.log')
        testEcho('still not logging')
        child.sendline(':set_log /tmp/polysh_test.log')
        testEcho('now logging')
        testEcho('still logging')
        child.sendline(':set_log')
        testEcho('back to no logging')
        child.sendline(':set_log /tmp/polysh_test.lo\t')
        testEcho('appended to the log')
        child.sendline(':set_log')
        child.expect('ready \(1\)> ')
        child.sendline(':set_log /no-permission')
        child.expect("[Errno 13] .*: '/no-permission'")
        child.expect('Logging disabled')
        child.expect('ready \(1\)> ')
        child.sendeof()
        child.expect(pexpect.EOF)

        EXPECTED_LOG="""
> echo now logging
localhost : now logging
> echo still logging
localhost : still logging
> :set_log
> echo appended to the log
localhost : appended to the log
> :set_log
""".strip()
        log = file('/tmp/polysh_test.log')
        log_lines = [l for l in log.readlines() if not l.startswith('[dbg] ')]
        actual_log = ''.join(log_lines).strip()
        self.assertEqual(actual_log, EXPECTED_LOG)
        os.remove('/tmp/polysh_test.log')
Example #9
0
 def testInitError(self):
     child = launch_polysh(['--ssh=echo message', 'localhost'])
     child.expect('message localhost')
     child.expect(pexpect.EOF)
     child = launch_polysh(['--ssh=echo The authenticity of host', 'l'])
     child.expect('Closing connection')
     child.expect('Consider manually connecting or using ssh-keyscan')
     child.expect(pexpect.EOF)
     child = launch_polysh(['--ssh=echo REMOTE HOST IDENTIFICATION '
                         'HAS CHANGED', 'l'])
     child.expect('Remote host identification has changed')
     child.expect('Consider manually connecting or using ssh-keyscan')
     child.expect(pexpect.EOF)
Example #10
0
 def testInitError(self):
     child = launch_polysh(['--ssh=echo message', 'localhost'])
     child.expect('message localhost')
     child.expect(pexpect.EOF)
     child = launch_polysh(['--ssh=echo The authenticity of host', 'l'])
     child.expect('Closing connection')
     child.expect('Consider manually connecting or using ssh-keyscan')
     child.expect(pexpect.EOF)
     child = launch_polysh(
         ['--ssh=echo REMOTE HOST IDENTIFICATION '
          'HAS CHANGED', 'l'])
     child.expect('Remote host identification has changed')
     child.expect('Consider manually connecting or using ssh-keyscan')
     child.expect(pexpect.EOF)
Example #11
0
 def testError(self):
     child = launch_polysh(['localhost', 'localhost'])
     child.expect('ready \(2\)> ')
     child.sendline('kill -9 $$')
     child.expect('Error talking to localhost')
     child.expect('Error talking to localhost')
     child.expect(pexpect.EOF)
Example #12
0
 def testListManipulation(self):
     child = launch_polysh(['localhost'])
     child.expect('ready \(1\)> ')
     child.sendline(':add localhost')
     child.expect('ready \(2\)> ')
     child.sendline(':rename $(echo newname)')
     child.expect('ready \(2\)> ')
     child.sendline('date')
     child.expect('newname')
     child.expect('newname')
     child.expect('ready \(2\)> ')
     child.sendline(':rename $EMPTY_VARIABLE')
     child.expect('ready \(2\)> ')
     child.sendline('date')
     child.expect('localhost')
     child.expect('localhost')
     child.expect('ready \(2\)> ')
     child.sendline(':rename $(echo newname)')
     child.expect('ready \(2\)> ')
     child.sendline('date')
     child.expect('newname')
     child.expect('newname')
     child.expect('ready \(2\)> ')
     child.sendline(':disable newname')
     child.sendline(':purge')
     child.sendline(':enable *')
     child.expect('ready \(1\)> ')
     child.sendline(':rename')
     child.expect('ready \(1\)> ')
     child.sendline('date')
     child.expect('localhost :')
     child.expect('ready \(1\)> ')
     child.sendeof()
     child.expect(pexpect.EOF)
Example #13
0
 def CommandCode(command, code):
     child = launch_polysh(['--command=%s' % command] +
                           ['localhost'] * 5)
     child.expect(pexpect.EOF)
     while child.isalive():
         child.wait()
     self.assertEqual(child.exitstatus, code)
Example #14
0
 def testError(self):
     child = launch_polysh(["localhost", "localhost"])
     child.expect("ready \(2\)> ")
     child.sendline("kill -9 $$")
     child.expect("Error talking to localhost")
     child.expect("Error talking to localhost")
     child.expect(pexpect.EOF)
Example #15
0
 def testListManipulation(self):
     child = launch_polysh(['localhost'])
     child.expect('ready \(1\)> ')
     child.sendline(':add localhost')
     child.expect('ready \(2\)> ')
     child.sendline(':rename $(echo newname)')
     child.expect('ready \(2\)> ')
     child.sendline('date')
     child.expect('newname')
     child.expect('newname')
     child.expect('ready \(2\)> ')
     child.sendline(':rename $EMPTY_VARIABLE')
     child.expect('ready \(2\)> ')
     child.sendline('date')
     child.expect('localhost')
     child.expect('localhost')
     child.expect('ready \(2\)> ')
     child.sendline(':rename $(echo newname)')
     child.expect('ready \(2\)> ')
     child.sendline('date')
     child.expect('newname')
     child.expect('newname')
     child.expect('ready \(2\)> ')
     child.sendline(':disable newname')
     child.sendline(':purge')
     child.sendline(':enable *')
     child.expect('ready \(1\)> ')
     child.sendline(':rename')
     child.expect('ready \(1\)> ')
     child.sendline('date')
     child.expect('localhost :')
     child.expect('ready \(1\)> ')
     child.sendeof()
     child.expect(pexpect.EOF)
Example #16
0
 def testCleanExit(self):
     child = launch_polysh(['localhost', 'localhost'])
     child.expect('ready \(2\)> ')
     child.sendeof()
     idx = child.expect(['Error talking to localhost', 'exit'])
     self.assertEqual(idx, 1)
     idx = child.expect(['Error talking to localhost', pexpect.EOF])
     self.assertEqual(idx, 1)
Example #17
0
 def testProfile(self):
     child = launch_polysh(['--profile', 'localhost'])
     child.expect('Profiling using ')
     child.expect('ready \(1\)> ')
     child.sendline(':quit')
     child.expect(' function calls in ')
     child.expect('Ordered by')
     child.expect(pexpect.EOF)
Example #18
0
 def testProfile(self):
     child = launch_polysh(['--profile', 'localhost'])
     child.expect('Profiling using ')
     child.expect('ready \(1\)> ')
     child.sendline(':quit')
     child.expect(' function calls in ')
     child.expect('Ordered by')
     child.expect(pexpect.EOF)
Example #19
0
 def testResetPrompt(self):
     child = launch_polysh(['localhost'])
     child.expect('ready \(1\)> ')
     child.sendline('bash')
     child.sendline(':reset_prompt l\t')
     child.expect('ready \(1\)> ')
     child.sendline(':quit')
     child.expect(pexpect.EOF)
Example #20
0
 def testResetPrompt(self):
     child = launch_polysh(['localhost'])
     child.expect('ready \(1\)> ')
     child.sendline('bash')
     child.sendline(':reset_prompt l\t')
     child.expect('ready \(1\)> ')
     child.sendline(':quit')
     child.expect(pexpect.EOF)
Example #21
0
 def testCleanExit(self):
     child = launch_polysh(["localhost", "localhost"])
     child.expect("ready \(2\)> ")
     child.sendeof()
     idx = child.expect(["Error talking to localhost", "exit"])
     self.assertEqual(idx, 1)
     idx = child.expect(["Error talking to localhost", pexpect.EOF])
     self.assertEqual(idx, 1)
Example #22
0
 def testPrintReadBuffer(self):
     child = launch_polysh(['--ssh=echo message; sleep'] + ['2h'] * 3)
     child.expect('waiting \(3/3\)> ')
     child.sendline(':show_read_buffer \t*')
     for i in xrange(3):
         child.expect('\033\[1;[0-9]+m2h[ #][ 12] : \033\[1;mmessage')
     child.expect('waiting \(3/3\)> ')
     child.sendintr()
     child.expect(pexpect.EOF)
Example #23
0
 def testPrintReadBuffer(self):
     child = launch_polysh(['--ssh=echo message; sleep'] + ['2h'] * 3)
     child.expect('waiting \(3/3\)> ')
     child.sendline(':show_read_buffer \t*')
     for i in xrange(3):
         child.expect('\033\[1;[0-9]+m2h[ #][ 12] : \033\[1;mmessage')
     child.expect('waiting \(3/3\)> ')
     child.sendintr()
     child.expect(pexpect.EOF)
Example #24
0
 def testReplicate(self):
     tmp_dir = tempfile.mkdtemp()
     local = tmp_dir + '/local'
     child = launch_polysh(['localhost'] * 6)
     child.expect('ready \(6\)> ')
     child.sendline(':replicate')
     child.expect('Usage: :replicate SHELL:REMOTE_PATH')
     child.expect('ready \(6\)> ')
     child.sendline(':replicate localhost:')
     child.expect('No remote path given')
     child.expect('ready \(6\)> ')
     child.sendline(':disable')
     child.expect('ready \(0\)> ')
     child.sendline(':enable localhost')
     child.expect('ready \(1\)> ')
     child.sendline(':replicate localhost#1:/dev/null')
     child.expect('localhost#1 is not enabled')
     child.expect('ready \(1\)> ')
     child.sendline(':replicate localhost:/dev/null')
     child.expect('No other remote shell to replicate files to')
     child.expect('ready \(1\)> ')
     child.sendline(':enable')
     child.expect('ready \(6\)> ')
     child.sendline(':replicate nohost:/dev/null')
     child.expect('nohost not found')
     child.expect('ready \(6\)> ')
     child.sendline(':disable localhost#5')
     child.expect('ready \(5\)> ')
     child.sendline("cd %s" % tmp_dir)
     child.expect('ready \(5\)> ')
     child.sendline('!mkdir %s' % local)
     child.expect('ready \(5\)> ')
     child.sendline('!yes "$(dmesg)" | head -c 20m > %s/file' % local)
     child.expect('ready \(5\)> ')
     child.sendline('!cd %s && sha1sum file > SHA1SUM' % local)
     child.expect('ready \(5\)> ')
     child.sendline(':export_vars')
     child.expect('ready \(5\)> ')
     child.sendline('mkdir $POLYSH_RANK')
     child.expect('ready \(5\)> ')
     child.sendline('cd $POLYSH_RANK')
     child.expect('ready \(5\)> ')
     child.sendline(':replicate l\t:%s/fil\t' % local)
     child.expect('Done transferring 20981760 bytes')
     child.expect('ready \(5\)> ')
     child.sendline('sha1sum file > SHA1SUM')
     child.expect('ready \(5\)> ')
     cat = 'cat %s/*/SHA1SUM' % tmp_dir
     wc_output = shell_output('%s | wc | tr -s " "' % cat)
     self.assertEqual(wc_output, '5 10 235')
     uniq_wc_output = shell_output('%s | uniq | wc | tr -s " "' % cat)
     self.assertEqual(uniq_wc_output, '1 2 47')
     child.sendline("!rm -fr '%s'" % tmp_dir)
     child.expect('ready \(5\)> ')
     child.sendline(':quit')
     child.expect(pexpect.EOF)
Example #25
0
 def testReplicate(self):
     tmp_dir = tempfile.mkdtemp()
     local = tmp_dir + '/local'
     child = launch_polysh(['localhost'] * 6)
     child.expect('ready \(6\)> ')
     child.sendline(':replicate')
     child.expect('Usage: :replicate SHELL:REMOTE_PATH')
     child.expect('ready \(6\)> ')
     child.sendline(':replicate localhost:')
     child.expect('No remote path given')
     child.expect('ready \(6\)> ')
     child.sendline(':disable')
     child.expect('ready \(0\)> ')
     child.sendline(':enable localhost')
     child.expect('ready \(1\)> ')
     child.sendline(':replicate localhost#1:/dev/null')
     child.expect('localhost#1 is not enabled')
     child.expect('ready \(1\)> ')
     child.sendline(':replicate localhost:/dev/null')
     child.expect('No other remote shell to replicate files to')
     child.expect('ready \(1\)> ')
     child.sendline(':enable')
     child.expect('ready \(6\)> ')
     child.sendline(':replicate nohost:/dev/null')
     child.expect('nohost not found')
     child.expect('ready \(6\)> ')
     child.sendline(':disable localhost#5')
     child.expect('ready \(5\)> ')
     child.sendline("cd %s" % tmp_dir)
     child.expect('ready \(5\)> ')
     child.sendline('!mkdir %s' % local)
     child.expect('ready \(5\)> ')
     child.sendline('!yes "$(dmesg)" | head -c 20m > %s/file' % local)
     child.expect('ready \(5\)> ')
     child.sendline('!cd %s && sha1sum file > SHA1SUM' % local)
     child.expect('ready \(5\)> ')
     child.sendline(':export_vars')
     child.expect('ready \(5\)> ')
     child.sendline('mkdir $POLYSH_RANK')
     child.expect('ready \(5\)> ')
     child.sendline('cd $POLYSH_RANK')
     child.expect('ready \(5\)> ')
     child.sendline(':replicate l\t:%s/fil\t' % local)
     child.expect('Done transferring 20981760 bytes')
     child.expect('ready \(5\)> ')
     child.sendline('sha1sum file > SHA1SUM')
     child.expect('ready \(5\)> ')
     cat = 'cat %s/*/SHA1SUM' % tmp_dir
     wc_output = shell_output('%s | wc | tr -s " "' % cat)
     self.assertEqual(wc_output, '5 10 235')
     uniq_wc_output = shell_output('%s | uniq | wc | tr -s " "' % cat)
     self.assertEqual(uniq_wc_output, '1 2 47')
     child.sendline("!rm -fr '%s'" % tmp_dir)
     child.expect('ready \(5\)> ')
     child.sendline(':quit')
     child.expect(pexpect.EOF)
Example #26
0
 def testCleanExit(self):
     child = launch_polysh(['localhost', 'localhost'])
     child.expect('ready \(2\)> ')
     child.sendeof()
     # We test for logout as this is the expected response of sending EOF to
     # a non login shell
     idx = child.expect(['Error talking to localhost', 'logout'])
     self.assertEqual(idx, 1)
     idx = child.expect(['Error talking to localhost', pexpect.EOF])
     self.assertEqual(idx, 1)
Example #27
0
 def startTestPassword(self, password_file):
     try:
         os.unlink('/tmp/polysh_test.log')
     except OSError:
         # File not found
         pass
     passwd = '--password-file=' + password_file
     child = launch_polysh([SSH_ARG, passwd, '--debug',
                         '--log-file=/tmp/polysh_test.log', '1', '2'])
     return child
Example #28
0
 def testLocalAbsPathCompletion(self):
     child = launch_polysh(['localhost'])
     child.expect('ready \(1\)> ')
     child.sendline('echo /dev/nul\t')
     child.expect('\033\[1;36mlocalhost : \033\[1;m/dev/null')
     child.expect('ready \(1\)> ')
     child.sendline('echo /sbi\t')
     child.expect('\033\[1;36mlocalhost : \033\[1;m/sbin/')
     child.expect('ready \(1\)> ')
     child.sendeof()
     child.expect(pexpect.EOF)
Example #29
0
 def testLocalAbsPathCompletion(self):
     child = launch_polysh(['localhost'])
     child.expect('ready \(1\)> ')
     child.sendline('echo /dev/nul\t')
     child.expect('\033\[1;36mlocalhost : \033\[1;m/dev/null')
     child.expect('ready \(1\)> ')
     child.sendline('echo /sbi\t')
     child.expect('\033\[1;36mlocalhost : \033\[1;m/sbin/')
     child.expect('ready \(1\)> ')
     child.sendeof()
     child.expect(pexpect.EOF)
Example #30
0
 def assertHostSyntax(self, to_expand, expanded):
     child = launch_polysh([to_expand, 'localhost'])
     child.expect('ready')
     child.sendline(':list')
     with_spaces = [e.replace('.', '\\.') + ' ' for e in expanded]
     for i in xrange(len(expanded)):
         found = child.expect(with_spaces)
         del with_spaces[found]
     child.expect('ready')
     child.sendeof()
     child.expect(pexpect.EOF)
Example #31
0
 def testMultipleCommandStdin(self):
     commands = """
     echo first
     echo next
     echo last
     """
     child = launch_polysh(['localhost'], input_data=commands)
     child.expect('localhost : first')
     child.expect('localhost : next')
     child.expect('localhost : last')
     child.expect(pexpect.EOF)
Example #32
0
 def testMultipleCommandStdin(self):
     commands = """
     echo first
     echo next
     echo last
     """
     child = launch_polysh(["localhost"], input_data=commands)
     child.expect("localhost : first")
     child.expect("localhost : next")
     child.expect("localhost : last")
     child.expect(pexpect.EOF)
Example #33
0
 def assertHostSyntax(self, to_expand, expanded):
     child = launch_polysh([to_expand, 'localhost'])
     child.expect('ready')
     child.sendline(':list')
     with_spaces = [e.replace('.', '\\.') + ' ' for e in expanded]
     for i in range(len(expanded)):
         found = child.expect(with_spaces)
         del with_spaces[found]
     child.expect('ready')
     child.sendeof()
     child.expect(pexpect.EOF)
Example #34
0
 def testPrependPrompt(self):
     child = launch_polysh(["localhost"])
     child.expect("ready \(1\)> ")
     child.sendline("sleep 1")
     child.expect("waiting \(1/1\)> ")
     child.send("echo begin-")
     child.expect("ready \(1\)> ")
     child.sendline("end")
     child.expect("begin-end")
     child.expect("ready \(1\)> ")
     child.sendeof()
     child.expect(pexpect.EOF)
Example #35
0
 def testPrependPrompt(self):
     child = launch_polysh(['localhost'])
     child.expect('ready \(1\)> ')
     child.sendline('sleep 1')
     child.expect('waiting \(1/1\)> ')
     child.send('echo begin-')
     child.expect('ready \(1\)> ')
     child.sendline('end')
     child.expect('begin-end')
     child.expect('ready \(1\)> ')
     child.sendeof()
     child.expect(pexpect.EOF)
Example #36
0
 def testReconnect(self):
     child = launch_polysh(['localhost'] * 2)
     child.expect('ready \(2\)> ')
     child.sendline(':disable localhost')
     child.sendline('exit')
     child.expect('exit\r\n')
     child.expect('ready \(0\)>')
     child.sendline(':reconnect l\t')
     child.sendline(':enable')
     child.expect('ready \(2\)> ')
     child.sendeof()
     child.expect(pexpect.EOF)
Example #37
0
 def testGoodHostsFilename(self):
     tmp_name = '/tmp/polysh_tests.%d' % (os.getpid())
     tmp = open(tmp_name, 'w', 0o600)
     print('localhost # Comment', file=tmp)
     print('# Ignore me', file=tmp)
     print('127.0.0.1', file=tmp)
     tmp.close()
     child = launch_polysh(['--hosts-file=%s' % (tmp_name)])
     child.expect('ready \(2\)> ')
     child.sendeof()
     child.expect(pexpect.EOF)
     os.remove(tmp_name)
Example #38
0
 def startTestPassword(self, password_file):
     try:
         os.unlink('/tmp/polysh_test.log')
     except OSError:
         # File not found
         pass
     passwd = '--password-file=' + password_file
     child = launch_polysh([
         SSH_ARG, passwd, '--debug', '--log-file=/tmp/polysh_test.log', '1',
         '2'
     ])
     return child
Example #39
0
 def testReconnect(self):
     child = launch_polysh(['localhost'] * 2)
     child.expect('ready \(2\)> ')
     child.sendline(':disable localhost')
     child.sendline('exit')
     child.expect('exit\r\n')
     child.expect('ready \(0\)>')
     child.sendline(':reconnect l\t')
     child.sendline(':enable')
     child.expect('ready \(2\)> ')
     child.sendeof()
     child.expect(pexpect.EOF)
Example #40
0
 def testGoodHostsFilename(self):
     tmp_name = '/tmp/polysh_tests.%d' % (os.getpid())
     tmp = open(tmp_name, 'w', 0600)
     print >> tmp, 'localhost # Comment'
     print >> tmp, '127.0.0.1'
     print >> tmp, '# Ignore me'
     print >> tmp, 'localhost.'
     tmp.close()
     child = launch_polysh(['--hosts-file=%s' % (tmp_name)])
     child.expect('ready \(3\)> ')
     child.sendeof()
     child.expect(pexpect.EOF)
     os.remove(tmp_name)
Example #41
0
 def testHole(self):
     child = launch_polysh(['--ssh=sh;:'] + ['a'] * 100)
     child.expect('ready \(100\)> ')
     child.sendline(':disable *1*')
     child.expect('ready \(81\)> ')
     child.sendline('exit')
     child.expect('ready \(0\)> ')
     child.sendline(':enable')
     child.expect('ready \(19\)> ')
     child.sendline(':purge')
     child.expect('ready \(19\)> ')
     for i in xrange(20, 101):
         child.sendline(':add a')
         child.expect('ready \(%d\)> ' % i)
     child.sendline(':quit')
     child.expect(pexpect.EOF)
Example #42
0
 def testPurge(self):
     child = launch_polysh(['localhost'] * 3)
     child.expect('ready \(3\)> ')
     child.sendline(':disable localhost#*')
     child.expect('ready \(1\)> ')
     child.sendline('kill -9 $$')
     child.expect('ready \(0\)> ')
     child.sendline(':enable')
     child.expect('ready \(2\)> ')
     child.sendline(':pur\t\t')
     child.expect('ready \(2\)> ')
     child.sendline(':list')
     child.expect('localhost#1 enabled idle:')
     child.expect('localhost#2 enabled idle:')
     child.expect('ready \(2\)> ')
     child.sendeof()
     child.expect(pexpect.EOF)
Example #43
0
 def testPurge(self):
     child = launch_polysh(['localhost'] * 3)
     child.expect('ready \(3\)> ')
     child.sendline(':disable localhost#*')
     child.expect('ready \(1\)> ')
     child.sendline('kill -9 $$')
     child.expect('ready \(0\)> ')
     child.sendline(':enable')
     child.expect('ready \(2\)> ')
     child.sendline(':pur\t\t')
     child.expect('ready \(2\)> ')
     child.sendline(':list')
     child.expect('localhost#1 enabled idle:')
     child.expect('localhost#2 enabled idle:')
     child.expect('ready \(2\)> ')
     child.sendeof()
     child.expect(pexpect.EOF)
Example #44
0
 def testSetDebug(self):
     child = launch_polysh(['localhost'])
     child.expect('ready \(1\)> ')
     child.sendline(':set_debug')
     child.expect('Expected at least a letter')
     child.sendline(':set_debug word')
     child.expect("Expected 'y' or 'n', got: word")
     child.sendline(':set_debug \ty\t\t')
     child.expect('ready \(1\)> ')
     child.sendline('echo "te""st"')
     child.expect('\[dbg\] localhost\[idle\]: state => running')
     child.expect('\[dbg\] localhost\[running\]: <== echo "te""st"')
     child.expect('\[dbg\] localhost\[running\]: ==> test')
     child.expect('\033\[1;36mlocalhost : \033\[1;mtest')
     child.expect('\[dbg\] localhost\[running\]: state => idle')
     child.expect('ready \(1\)> ')
     child.sendeof()
     child.expect(pexpect.EOF)
Example #45
0
 def testSetDebug(self):
     child = launch_polysh(['localhost'])
     child.expect('ready \(1\)> ')
     child.sendline(':set_debug')
     child.expect('Expected at least a letter')
     child.sendline(':set_debug word')
     child.expect("Expected 'y' or 'n', got: word")
     child.sendline(':set_debug \ty\t\t')
     child.expect('ready \(1\)> ')
     child.sendline('echo "te""st"')
     child.expect('\[dbg\] localhost\[idle\]: state => running')
     child.expect('\[dbg\] localhost\[running\]: <== echo "te""st"')
     child.expect('\[dbg\] localhost\[running\]: ==> test')
     child.expect('\033\[1;36mlocalhost : \033\[1;mtest')
     child.expect('\[dbg\] localhost\[running\]: state => idle')
     child.expect('ready \(1\)> ')
     child.sendeof()
     child.expect(pexpect.EOF)
Example #46
0
 def testHidePassword(self):
     child = launch_polysh(['localhost'])
     child.expect('ready \(1\)> ')
     child.sendline('# passwordnotprotected')
     child.expect('ready \(1\)> ')
     child.sendline(':set_debug y')
     child.sendline(':set_log /dev/nul\t')
     child.sendline(':hide_password')
     child.expect('Debugging disabled')
     child.expect('Logging disabled')
     child.expect('ready \(1\)> ')
     child.sendline('# passwordprotected')
     child.expect('ready \(1\)> ')
     child.sendline('echo password\t')
     child.expect('passwordnotprotected')
     child.expect('ready \(1\)> ')
     child.sendeof()
     child.expect(pexpect.EOF)
Example #47
0
 def testHidePassword(self):
     child = launch_polysh(['localhost'])
     child.expect('ready \(1\)> ')
     child.sendline('# passwordnotprotected')
     child.expect('ready \(1\)> ')
     child.sendline(':set_debug y')
     child.sendline(':set_log /dev/nul\t')
     child.sendline(':hide_password')
     child.expect('Debugging disabled')
     child.expect('Logging disabled')
     child.expect('ready \(1\)> ')
     child.sendline('# passwordprotected')
     child.expect('ready \(1\)> ')
     child.sendline('echo password\t')
     child.expect('passwordnotprotected')
     child.expect('ready \(1\)> ')
     child.sendeof()
     child.expect(pexpect.EOF)
Example #48
0
 def testLocalCommand(self):
     child = launch_polysh(['localhost'])
     child.expect('ready \(1\)> ')
     child.sendline('cat')
     child.expect('waiting \(1/1\)> ')
     child.sendline('!ech\t te""st')
     child.expect('test')
     child.sendline(':send_ctrl d')
     child.expect('ready \(1\)> ')
     child.sendline('!exit 42')
     child.expect('Child returned 42')
     child.expect('ready \(1\)> ')
     child.sendline('!python -c "import os; os.kill(os.getpid(), 9)"')
     child.expect('Child was terminated by signal 9')
     child.expect('ready \(1\)> ')
     child.sendline(':chdir /does/not/exist')
     child.expect("\[Errno 2\] .*: '/does/not/exist'")
     child.sendline(':chdir /usr/sbi\t/does/not/exist')
     child.expect('/usr/sbin')
     child.expect('ready \(1\)> ')
     child.sendeof()
     child.expect(pexpect.EOF)
Example #49
0
 def testLocalCommand(self):
     child = launch_polysh(['localhost'])
     child.expect('ready \(1\)> ')
     child.sendline('cat')
     child.expect('waiting \(1/1\)> ')
     child.sendline('!ech\t te""st')
     child.expect('test')
     child.sendline(':send_ctrl d')
     child.expect('ready \(1\)> ')
     child.sendline('!exit 42')
     child.expect('Child returned 42')
     child.expect('ready \(1\)> ')
     child.sendline('!python -c "import os; os.kill(os.getpid(), 9)"')
     child.expect('Child was terminated by signal 9')
     child.expect('ready \(1\)> ')
     child.sendline(':chdir /does/not/exist')
     child.expect("\[Errno 2\] .*: '/does/not/exist'")
     child.sendline(':chdir /usr/sbi\t/does/not/exist')
     child.expect('/usr/sbin')
     child.expect('ready \(1\)> ')
     child.sendeof()
     child.expect(pexpect.EOF)
Example #50
0
 def testUpload(self):
     tmp_dir = tempfile.mkdtemp()
     local = tmp_dir + '/local'
     child = launch_polysh(['localhost'] * 5)
     child.expect('ready \(5\)> ')
     child.sendline(':upload')
     child.expect('No local path given')
     child.expect('ready \(5\)> ')
     child.sendline("cd %s" % tmp_dir)
     child.expect('ready \(5\)> ')
     child.sendline('!mkdir %s' % local)
     child.expect('ready \(5\)> ')
     child.sendline('!yes "$(dmesg)" | head -c 20m > %s/file' % local)
     child.expect('ready \(5\)> ')
     child.sendline('!cd %s && sha1sum file > SHA1SUM' % local)
     child.expect('ready \(5\)> ')
     child.sendline(':export_vars')
     child.expect('ready \(5\)> ')
     child.sendline('mkdir $POLYSH_RANK')
     child.expect('ready \(5\)> ')
     child.sendline('cd $POLYSH_RANK')
     child.expect('ready \(5\)> ')
     child.sendline(':upload %s/fil\t' % local)
     child.expect('Done transferring 20981760 bytes')
     child.expect('ready \(5\)> ')
     child.sendline('sha1sum file > SHA1SUM')
     child.expect('ready \(5\)> ')
     cat = 'cat %s/*/SHA1SUM' % tmp_dir
     wc_output = shell_output('%s | wc | tr -s " "' % cat)
     self.assertEqual(wc_output, '6 12 282')
     uniq_wc_output = shell_output('%s | uniq | wc | tr -s " "' % cat)
     self.assertEqual(uniq_wc_output, '1 2 47')
     child.sendline("!rm -fr '%s'" % tmp_dir)
     child.expect('ready \(5\)> ')
     child.sendline(':quit')
     child.expect(pexpect.EOF)
Example #51
0
 def testUpload(self):
     tmp_dir = tempfile.mkdtemp()
     local = tmp_dir + '/local'
     child = launch_polysh(['localhost'] * 5)
     child.expect('ready \(5\)> ')
     child.sendline(':upload')
     child.expect('No local path given')
     child.expect('ready \(5\)> ')
     child.sendline("cd %s" % tmp_dir)
     child.expect('ready \(5\)> ')
     child.sendline('!mkdir %s' % local)
     child.expect('ready \(5\)> ')
     child.sendline('!yes "$(dmesg)" | head -c 20m > %s/file' % local)
     child.expect('ready \(5\)> ')
     child.sendline('!cd %s && sha1sum file > SHA1SUM' % local)
     child.expect('ready \(5\)> ')
     child.sendline(':export_vars')
     child.expect('ready \(5\)> ')
     child.sendline('mkdir $POLYSH_RANK')
     child.expect('ready \(5\)> ')
     child.sendline('cd $POLYSH_RANK')
     child.expect('ready \(5\)> ')
     child.sendline(':upload %s/fil\t' % local)
     child.expect('Done transferring 20981760 bytes')
     child.expect('ready \(5\)> ')
     child.sendline('sha1sum file > SHA1SUM')
     child.expect('ready \(5\)> ')
     cat = 'cat %s/*/SHA1SUM' % tmp_dir
     wc_output = shell_output('%s | wc | tr -s " "' % cat)
     self.assertEqual(wc_output, '6 12 282')
     uniq_wc_output = shell_output('%s | uniq | wc | tr -s " "' % cat)
     self.assertEqual(uniq_wc_output, '1 2 47')
     child.sendline("!rm -fr '%s'" % tmp_dir)
     child.expect('ready \(5\)> ')
     child.sendline(':quit')
     child.expect(pexpect.EOF)
Example #52
0
 def testInvalidCommandStdin(self):
     child = launch_polysh(["localhost", "--command=date"], input_data="uptime")
     child.expect("--command and reading from stdin are incompatible")
     child.expect(pexpect.EOF)
Example #53
0
 def testInvalidCommandStdin(self):
     child = launch_polysh(['localhost', '--command=date'],
                           input_data='uptime')
     child.expect('--command and reading from stdin are incompatible')
     child.expect(pexpect.EOF)
Example #54
0
 def testBadHostsFilename(self):
     child = launch_polysh(['--hosts-file=do not exist/at all'])
     child.expect('error')
     child.expect(pexpect.EOF)
Example #55
0
 def CommandCode(command, code):
     child = launch_polysh(["--command=%s" % command] + ["localhost"] * 5)
     child.expect(pexpect.EOF)
     while child.isalive():
         child.wait()
     self.assertEqual(child.exitstatus, code)
Example #56
0
 def testCommandNormal(self):
     child = launch_polysh(["--command=echo text", "localhost"])
     child.expect("\033\[1;36mlocalhost : \033\[1;mtext")
     child.expect(pexpect.EOF)
Example #57
0
 def start_child():
     child = launch_polysh(args)
     child.expect('ready \(%d\)> ' % (nr_localhost))
     return child
Example #58
0
 def testCommandIntr(self):
     child = launch_polysh(["--command=echo text; cat", "localhost"])
     child.expect("\033\[1;36mlocalhost : \033\[1;mtext")
     child.sendintr()
     child.expect(pexpect.EOF)
Example #59
0
 def testSimpleCommandStdin(self):
     child = launch_polysh(["localhost"], input_data="echo line")
     child.expect("localhost : line")
     child.expect(pexpect.EOF)