def testCopyNodeFailure(self): # == stderr merged == self._task.set_default("stderr", False) dest = make_temp_filename(suffix='LocalhostCopyF') worker = self._task.copy("/etc/hosts", dest, nodes='unlikely-node,%s' % HOSTNAME) self._task.resume() self.assertEqual(worker.node_error_buffer("unlikely-node"), None) self.assertTrue(len(worker.node_buffer("unlikely-node")) > 2) os.unlink(dest) # == stderr separated == self._task.set_default("stderr", True) try: dest = make_temp_filename(suffix='LocalhostCopyF2') worker = self._task.copy("/etc/hosts", dest, nodes='unlikely-node,%s' % HOSTNAME) self.assert_(worker != None) # run task self._task.resume() self.assert_(worker.node_buffer("unlikely-node") is None) self.assert_(len(worker.node_error_buffer("unlikely-node")) > 2) os.unlink(dest) finally: self._task.set_default("stderr", False)
def testCopyNodeFailure(self): # == stderr merged == self._task.set_default("stderr", False) dest = make_temp_filename(suffix='LocalhostCopyF') worker = self._task.copy("/etc/hosts", dest, nodes='unlikely-node,%s' % HOSTNAME) self._task.resume() self.assertEqual(worker.node_error_buffer("unlikely-node"), None) self.assertTrue(len(worker.node_buffer("unlikely-node")) > 2) os.unlink(dest) # == stderr separated == self._task.set_default("stderr", True) try: dest = make_temp_filename(suffix='LocalhostCopyF2') worker = self._task.copy("/etc/hosts", dest, nodes='unlikely-node,%s' % HOSTNAME) # run task self._task.resume() self.assertTrue(worker.node_buffer("unlikely-node") is None) self.assertTrue(len(worker.node_error_buffer("unlikely-node")) > 2) os.unlink(dest) finally: self._task.set_default("stderr", False)
def testLocalhostCopy(self): # init worker dest = make_temp_filename(suffix='LocalhostCopy') worker = self._task.copy("/etc/hosts", dest, nodes=HOSTNAME) self.assert_(worker != None) # run task self._task.resume() os.unlink(dest)
def testCopyEvents(self): test_eh = self.__class__.TEventHandlerChecker(self) dest = make_temp_filename('testLocalhostCopyEvents') worker = self._task.copy("/etc/hosts", dest, nodes=HOSTNAME, handler=test_eh) # run task self._task.resume() os.unlink(dest) self.assertEqual(test_eh.flags, EV_START | EV_PICKUP | EV_HUP | EV_CLOSE)
def testCopyEvents(self): test_eh = self.__class__.TEventHandlerChecker(self) dest = make_temp_filename("testLocalhostCopyEvents") worker = self._task.copy("/etc/hosts", dest, nodes=HOSTNAME, handler=test_eh) self.assert_(worker != None) # run task self._task.resume() os.unlink(dest) self.assertEqual(test_eh.flags, EV_START | EV_HUP | EV_CLOSE)
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 testLocalhostCopy(self): """test simple localhost copy""" # init worker dest = make_temp_filename(suffix='LocalhostCopy') worker = self._task.copy("/etc/hosts", dest, nodes='localhost') self.assert_(worker != None) # run task self._task.resume() os.unlink(dest)
def testSshUserOptionForScp(self): ssh_user_orig = self._task.info("ssh_user") self._task.set_info("ssh_user", pwd.getpwuid(os.getuid())[0]) dest = make_temp_filename('testLocalhostCopyU') worker = self._task.copy("/etc/hosts", dest, nodes=HOSTNAME) self._task.resume() # restore original ssh_user (None) self.assertEqual(ssh_user_orig, None) self._task.set_info("ssh_user", ssh_user_orig) os.unlink(dest)
def testLocalhostExplicitSshCopy(self): """test simple localhost copy with explicit ssh worker""" dest = make_temp_filename('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 testLocalhostCopy(self): dests = [] try: for i in range(5): dest = make_temp_filename(suffix='LocalhostCopy') dests.append(dest) worker = self._task.copy("/etc/hosts", dest, nodes=HOSTNAME) self._task.resume() finally: for dest in dests: os.unlink(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 test_copy_preserve(self): """test copying with an ExecWorker (preserve=True)""" src = make_temp_file("data") past_time = 443757600 os.utime(src.name, (past_time, past_time)) dstpath = make_temp_filename() try: self.execw(nodes="localhost", handler=None, source=src.name, dest=dstpath, preserve=True) self.assertEqual(task_self().max_retcode(), 0) self.assertTrue(os.stat(dstpath).st_mtime, past_time) finally: os.unlink(dstpath)
def testLocalhostExplicitPdshCopy(self): # test simple localhost copy with explicit pdsh worker dest = make_temp_filename(suffix='LocalhostExplicitPdshCopy') try: worker = WorkerPdsh(HOSTNAME, source="/etc/hosts", dest=dest, handler=None, timeout=10) self._task.schedule(worker) self._task.resume() self.assertEqual(worker.source, "/etc/hosts") self.assertEqual(worker.dest, dest) finally: os.unlink(dest)
def test_copy_preserve(self): """test copying with an ExecWorker (preserve=True)""" src = make_temp_file(b"data") past_time = 443757600 os.utime(src.name, (past_time, past_time)) dstpath = make_temp_filename() try: self.execw(nodes='localhost', handler=None, source=src.name, dest=dstpath, preserve=True) self.assertEqual(task_self().max_retcode(), 0) self.assertTrue(os.stat(dstpath).st_mtime, past_time) finally: os.unlink(dstpath)
def testSshOptionsOptionForScp(self): ssh_options_orig = self._task.info("ssh_options") testfile = None try: testfile = make_temp_filename('testLocalhostCopyO') if os.path.exists(testfile): os.remove(testfile) self._task.set_info("ssh_options", \ "-oLogLevel=QUIET -oStrictHostKeyChecking=no -oVerifyHostKeyDNS=no") worker = self._task.copy("/etc/hosts", testfile, nodes=HOSTNAME) self._task.resume() self.assertTrue(os.path.exists(testfile)) finally: os.unlink(testfile) # restore original ssh_user (None) self.assertEqual(ssh_options_orig, None) self._task.set_info("ssh_options", ssh_options_orig)
def testSshOptionsOptionForScp(self): ssh_options_orig = self._task.info("ssh_options") testfile = None try: testfile = make_temp_filename("testLocalhostCopyO") if os.path.exists(testfile): os.remove(testfile) self._task.set_info("ssh_options", "-oLogLevel=QUIET -oStrictHostKeyChecking=no -oVerifyHostKeyDNS=no") worker = self._task.copy("/etc/hosts", testfile, nodes=HOSTNAME) self.assert_(worker != None) self._task.resume() self.assert_(os.path.exists(testfile)) finally: os.unlink(testfile) # restore original ssh_user (None) self.assertEqual(ssh_options_orig, None) self._task.set_info("ssh_options", ssh_options_orig)
def _tree_copy_file(self, target): teh = TEventHandler() srcf = make_temp_file(b'Lorem Ipsum', 'test_tree_copy_file_src') dest = make_temp_filename('test_tree_copy_file_dest') try: worker = self.task.copy(srcf.name, dest, nodes=target, handler=teh) self.task.run() self.assertEqual(teh.ev_start_cnt, 1) self.assertEqual(teh.ev_pickup_cnt, 1) self.assertEqual(teh.ev_read_cnt, 0) #self.assertEqual(teh.ev_written_cnt, 0) # FIXME self.assertEqual(teh.ev_hup_cnt, 1) self.assertEqual(teh.ev_timedout_cnt, 0) self.assertEqual(teh.ev_close_cnt, 1) with open(dest, 'r') as destf: self.assertEqual(destf.read(), 'Lorem Ipsum') finally: os.remove(dest)