def execute(self, conf=None, caller=None, apMon=None, logger=None): """This method is invoked by fdtcp (locally).""" # fileNameToStoreRemoteUserName - file into which AuthClient # stores name of the Grid user at the remote party, this # information is then forwarded later to # fdtd which doens't have to do the user mapping lookup again fileName = "/tmp/" + self.id + "--" + getRandomString('a', 'z', 5) if os.path.exists(fileName): raise FDTCopyException("File %s exists." % fileName) self._setUp(conf, fileName) executor = Executor(self.id, self.command, blocking=True, logger=logger) # here the Java AuthClient stores the Grid user name into the file output = executor.execute() try: remoteGridUser = open(fileName, 'r').read() os.remove(fileName) except Exception, ex: m = ("Problem handling file %s (reading remote Grid user " "name), reason: %s" % (fileName, ex)) raise FDTCopyException(m)
def _getId(self): """Transfer job / request / id will consist of hostname of the machine fdtcp is invoked on and timestamp. This id will be used in all requests to fdtd for tracking the state of the transfer job, esp. by MonALISA ApMon. Transfers at fdtd will be associated with this ID - make it as unique as possible to avoid collisions. """ h = getHostName() u = getUserName() dt = getDateTime() r = getRandomString('a', 'z', 5) id = "fdtcp-%s-%s-%s-%s" % (h, u, dt, r) return id
def testAuthClientAction(): c = \ """ [general] authClientCommand = bash authenticator/wrapper_auth.sh -p %(port)s -h %(host)s -u %(fileNameToStoreRemoteUserName)s """ f = getTempFile(c) inputOption = "--config=%s host1:/tmp/file host2:/tmp/file1" % f.name conf = ConfigFDTCopy(inputOption.split()) a = AuthClientAction("some_id", dict(port = "someport", host = "somehost")) fileNameToStoreRemoteUserName = "******" + a.id + "--" + getRandomString('a', 'z', 5) a._setUp(conf, fileNameToStoreRemoteUserName) assert a.options["port"] == "someport" c = ("bash authenticator/wrapper_auth.sh -p someport -h somehost " "-u %s" % fileNameToStoreRemoteUserName) assert a.command == c
def testAuthClientAction(): c = \ """ [general] authClientCommand = bash authenticator/wrapper_auth.sh -p %(port)s -h %(host)s -u %(fileNameToStoreRemoteUserName)s """ f = getTempFile(c) inputOption = "--config=%s host1:/tmp/file host2:/tmp/file1" % f.name conf = ConfigFDTCopy(inputOption.split()) a = AuthClientAction("some_id", dict(port="someport", host="somehost")) fileNameToStoreRemoteUserName = ("/tmp/" + a.id + "--" + getRandomString('a', 'z', 5)) a._setUp(conf, fileNameToStoreRemoteUserName) assert a.options["port"] == "someport" c = ("bash authenticator/wrapper_auth.sh -p someport -h somehost " "-u %s" % fileNameToStoreRemoteUserName) assert a.command == c
def _getId(self, srcHostName, dstHostName): """ Transfer job / request / id will consist of hostname of the machine fdtcp is invoked on and timestamp. This id will be used in all requests to fdtd for tracking the state of the transfer job, esp. by MonALISA ApMon. Transfers at fdtd will be associated with this ID - make it as unique as possible to avoid collisions. """ h = getHostName() # u = getUserName() dt = getDateTime() r = getRandomString('a', 'z', 5) template = "fdtcp-%(host)s--%(source)s-to-%(dest)s--%(datetime)s-%(randomStr)s" d = dict(host=h, source=srcHostName, dest=dstHostName, datetime=dt, randomStr=r) idT = template % d return idT
def execute(self, conf = None, caller = None, apMon = None, logger = None): """This method is invoked by fdtcp (locally).""" # fileNameToStoreRemoteUserName - file into which AuthClient stores name of the # Grid user at the remote party, this information is then forwarded later to # fdtd which doens't have to do the user mapping lookup again fileName = "/tmp/" + self.id + "--" + getRandomString('a', 'z', 5) if os.path.exists(fileName): raise FDTCopyException("File %s exists." % fileName) self._setUp(conf, fileName) executor = Executor(self.id, self.command, blocking = True, logger = logger) # here the Java AuthClient stores the Grid user name into the file output = executor.execute() try: remoteGridUser = open(fileName, 'r').read() os.remove(fileName) except Exception, ex: m = "Problem handling file %s (reading remote Grid user name), reason: %s" % (fileName, ex) raise FDTCopyException(m)
def testGetRandomString(): calculated = [] for i in range(0, 100): s = getRandomString('a', 'z', 10) assert s not in calculated calculated.append(s)