def testWorkerAbortSanity(self): task = task_self() worker = task.shell("sleep 1", nodes=HOSTNAME) worker.abort() # test noop abort() on unscheduled worker worker = WorkerSsh(HOSTNAME, command="sleep 1", handler=None, timeout=None) worker.abort()
def testExplicitSshWorker(self): # init worker worker = WorkerSsh(HOSTNAME, command="/bin/echo alright", handler=None) self._task.schedule(worker) # run task self._task.resume() # test output self.assertEqual(worker.node_buffer(HOSTNAME), b"alright")
def testExplicitSshWorker(self): # init worker worker = WorkerSsh(HOSTNAME, command="/bin/echo alright", handler=None) self._task.schedule(worker) # run task self._task.resume() # test output self.assertEqual(worker.node_buffer(HOSTNAME), "alright")
def testExplicitSshWorker(self): """test simple localhost command with explicit ssh worker""" # init worker worker = WorkerSsh("localhost", command="/bin/echo alright", handler=None, timeout=5) self.assert_(worker != None) self._task.schedule(worker) # run task self._task.resume() # test output self.assertEqual(worker.node_buffer("localhost"), "alright")
def testWorkerAbortSanity(self): """test distant/ssh Worker abort() (sanity)""" task = task_self() worker = task.shell("sleep 1", nodes="localhost") worker.abort() # test noop abort() on unscheduled worker worker = WorkerSsh("localhost", command="sleep 1", handler=None, timeout=None) worker.abort()
def testExplicitSshWorkerWithOptions(self): self._task.set_info("ssh_path", "/usr/bin/ssh -C") self._task.set_info("ssh_options", "-oLogLevel=QUIET") worker = WorkerSsh(HOSTNAME, command="/bin/echo alright", handler=None) self._task.schedule(worker) # run task self._task.resume() # test output self.assertEqual(worker.node_buffer(HOSTNAME), "alright") # clear options after test task_cleanup() self.assertEqual(task_self().info("ssh_path"), None)
def testExplicitSshWorkerWithOptions(self): self._task.set_info("ssh_path", "/usr/bin/ssh -C") self._task.set_info("ssh_options", "-oLogLevel=QUIET") worker = WorkerSsh(HOSTNAME, command="/bin/echo alright", handler=None) self._task.schedule(worker) # run task self._task.resume() # test output self.assertEqual(worker.node_buffer(HOSTNAME), b"alright") # clear options after test task_cleanup() self.assertEqual(task_self().info("ssh_path"), None)
def testLocalhostExplicitSshReverseCopyDirPreserve(self): dtmp_src = make_temp_dir('src') dtmp_dst = make_temp_dir( 'testLocalhostExplicitSshReverseCopyDirPreserve') try: os.mkdir(os.path.join(dtmp_src, "lev1_a")) os.mkdir(os.path.join(dtmp_src, "lev1_b")) os.mkdir(os.path.join(dtmp_src, "lev1_a", "lev2")) worker = WorkerSsh(HOSTNAME, source=dtmp_src, dest=dtmp_dst, handler=None, timeout=30, reverse=True) self._task.schedule(worker) self._task.resume() self.assertTrue( os.path.exists( os.path.join( dtmp_dst, "%s.%s" % (os.path.basename(dtmp_src), HOSTNAME), "lev1_a", "lev2"))) finally: shutil.rmtree(dtmp_dst, ignore_errors=True) shutil.rmtree(dtmp_src, ignore_errors=True)
def testExplicitSshWorkerStdErr(self): # init worker worker = WorkerSsh(HOSTNAME, command="/bin/echo alright 1>&2", handler=None, stderr=True) self._task.schedule(worker) # run task self._task.resume() # test output self.assertEqual(worker.node_error_buffer(HOSTNAME), "alright") # Re-test with stderr=False worker = WorkerSsh(HOSTNAME, command="/bin/echo alright 1>&2", handler=None, stderr=False) self._task.schedule(worker) # run task self._task.resume() # test output self.assertEqual(worker.node_error_buffer(HOSTNAME), None)
def testLocalhostExplicitSshCopy(self): dest = make_temp_filename('testLocalhostExplicitSshCopy') try: worker = WorkerSsh(HOSTNAME, source="/etc/hosts", dest=dest, handler=None, timeout=10) self._task.schedule(worker) self._task.resume() finally: os.remove(dest)
def testWorkerNotScheduledDistant(self): """test library misusage (distant worker not scheduled)""" task = task_self() worker = WorkerSsh(HOSTNAME, command="/bin/hostname", handler=None, timeout=0) task.resume() self.assertRaises(WorkerError, worker.node_buffer, HOSTNAME)
def testLocalhostExplicitSshCopy(self): """test simple localhost copy with explicit ssh worker""" dest = "/tmp/cs-test_testLocalhostExplicitSshCopy" try: worker = WorkerSsh("localhost", source="/etc/hosts", dest=dest, handler=None, timeout=10) self._task.schedule(worker) self._task.resume() finally: os.remove(dest)
def testLocalhostExplicitSshCopy(self): dest = make_temp_filename('testLocalhostExplicitSshCopy') srcsz = os.path.getsize("/etc/hosts") try: worker = WorkerSsh(HOSTNAME, source="/etc/hosts", dest=dest, handler=None, timeout=10) self._task.schedule(worker) self._task.resume() self.assertEqual(srcsz, os.path.getsize(dest)) finally: os.remove(dest)
def testExplicitSshWorkerStdErr(self): """test simple localhost command with explicit ssh worker (stderr)""" # init worker worker = WorkerSsh("localhost", command="/bin/echo alright 1>&2", handler=None, stderr=True, timeout=5) self.assert_(worker != None) self._task.schedule(worker) # run task self._task.resume() # test output self.assertEqual(worker.node_error_buffer("localhost"), "alright") # Re-test with stderr=False worker = WorkerSsh("localhost", command="/bin/echo alright 1>&2", handler=None, stderr=False, timeout=5) self.assert_(worker != None) self._task.schedule(worker) # run task self._task.resume() # test output self.assertEqual(worker.node_error_buffer("localhost"), None)
def testLocalhostExplicitSshReverseCopy(self): dest = make_temp_dir('testLocalhostExplicitSshRCopy') try: worker = WorkerSsh(HOSTNAME, source="/etc/hosts", dest=dest, handler=None, timeout=10, reverse=True) self._task.schedule(worker) self._task.resume() self.assertEqual(worker.source, "/etc/hosts") self.assertEqual(worker.dest, dest) self.assertTrue(os.path.exists(os.path.join(dest, "hosts.%s" % HOSTNAME))) finally: shutil.rmtree(dest, ignore_errors=True)
def testLocalhostExplicitSshReverseCopy(self): """test simple localhost rcopy with explicit ssh worker""" dest = "/tmp/cs-test_testLocalhostExplicitSshRCopy" shutil.rmtree(dest, ignore_errors=True) try: os.mkdir(dest) worker = WorkerSsh("localhost", source="/etc/hosts", dest=dest, handler=None, timeout=10, reverse=True) self._task.schedule(worker) self._task.resume() self.assertEqual(worker.source, "/etc/hosts") self.assertEqual(worker.dest, dest) self.assert_(os.path.exists(os.path.join(dest, "hosts.localhost"))) finally: shutil.rmtree(dest, ignore_errors=True)
def testLocalhostExplicitSshCopyWithOptions(self): dest = make_temp_dir('testLocalhostExplicitSshCopyWithOptions') self._task.set_info("scp_path", "/usr/bin/scp -l 10") self._task.set_info("scp_options", "-oLogLevel=QUIET") try: worker = WorkerSsh(HOSTNAME, source="/etc/hosts", dest=dest, handler=None) self._task.schedule(worker) self._task.resume() self.assertEqual(self._task.max_retcode(), 0) self.assertTrue(os.path.exists(os.path.join(dest, "hosts"))) finally: os.unlink(os.path.join(dest, "hosts")) os.rmdir(dest) # clear options after test task_cleanup() self.assertEqual(task_self().info("scp_path"), None)
def testLocalhostExplicitSshCopyDir(self): dtmp_src = make_temp_dir('src') dtmp_dst = make_temp_dir('testLocalhostExplicitSshCopyDir') try: os.mkdir(os.path.join(dtmp_src, "lev1_a")) os.mkdir(os.path.join(dtmp_src, "lev1_b")) os.mkdir(os.path.join(dtmp_src, "lev1_a", "lev2")) worker = WorkerSsh(HOSTNAME, source=dtmp_src, dest=dtmp_dst, handler=None) self._task.schedule(worker) self._task.resume() path = os.path.join(dtmp_dst, os.path.basename(dtmp_src), "lev1_a", "lev2") self.assertTrue(os.path.exists(path)) finally: shutil.rmtree(dtmp_dst, ignore_errors=True) shutil.rmtree(dtmp_src, ignore_errors=True)
def testLocalhostExplicitSshReverseCopyDirPreserve(self): """test simple localhost preserve rcopy dir with explicit ssh worker""" dtmp_src = tempfile.mkdtemp("_cs-test_src") dtmp_dst = tempfile.mkdtemp( \ "_cs-test_testLocalhostExplicitSshReverseCopyDirPreserve") try: os.mkdir(os.path.join(dtmp_src, "lev1_a")) os.mkdir(os.path.join(dtmp_src, "lev1_b")) os.mkdir(os.path.join(dtmp_src, "lev1_a", "lev2")) worker = WorkerSsh("localhost", source=dtmp_src, dest=dtmp_dst, handler=None, timeout=30, reverse=True) self._task.schedule(worker) self._task.resume() self.assert_(os.path.exists(os.path.join(dtmp_dst, \ "%s.localhost" % os.path.basename(dtmp_src), "lev1_a", "lev2"))) finally: shutil.rmtree(dtmp_dst, ignore_errors=True) shutil.rmtree(dtmp_src, ignore_errors=True)
def testExplicitSshWorkerStdErr(self): # init worker worker = WorkerSsh(HOSTNAME, command="/bin/echo alright 1>&2", handler=None, stderr=True) self._task.schedule(worker) # run task self._task.resume() # test output self.assertEqual(worker.node_error_buffer(HOSTNAME), b"alright") # Re-test with stderr=False worker = WorkerSsh(HOSTNAME, command="/bin/echo alright 1>&2", handler=None, stderr=False) self._task.schedule(worker) # run task self._task.resume() # test output self.assertEqual(worker.node_error_buffer(HOSTNAME), None)