def testCopyTo(self): client = PSSHClient(['localhost', 'localhost']) client.connect() tasks = client.copy_to('/tmp/a', '/tmp/b') self.assertIsNotNone(tasks, "failed to copy to") output = [] tasks.wait(output) # , "failed to copy to") for item in output: print item['hostname'], item['exit_code'] print item['stdout'] print item['stderr'] print item['exception']
def testCancel(self): client = PSSHClient(['localhost', 'localhost']) client.connect() tasks = client.exec_command("ls -la; sleep 10; ls") self.assertIsNotNone(tasks, "failed to exec_command") tasks.cancel() output = [] print tasks.wait(output) for item in output: print item['hostname'], item['exit_code'] print item['stdout'] print item['stderr'] print item['exception']
def testConnect(self): client = PSSHClient(['localhost', 'localhost']) client.connect() self.assertEqual(len(client._connections), 2, "failed to connect") client.close() self.assertIsNone(client._connections, "failed to reset connection") client.close() client.connect() self.assertEqual(len(client._connections), 2, "failed to connect") self.assertRaises(RuntimeError, client.connect)
def testExecLs(self): client = PSSHClient(['localhost', 'localhost']) client.connect() tasks = client.exec_command("ls -la") self.assertIsNotNone(tasks, "failed to exec_command") self.assertTrue(tasks.wait(), "failed to exec_command") output = [] self.assertTrue(tasks.wait(output), "failed to exec_command") for item in output: print item['hostname'], item['exit_code'] print item['stdout'] print item['stderr'] tasks = client.exec_command("ls") self.assertIsNotNone(tasks, "failed to exec_command") self.assertTrue(tasks.wait(), "failed to exec_command") output = [] self.assertTrue(tasks.wait(output), "failed to exec_command") for item in output: print item['hostname'], item['exit_code'] print item['stdout'] print item['stderr']