Repository: dmwm/wmcore
Issue: Tier0 agent fails using the last WMCore version 1.4.7.patch2.

**Impact of the bug**
Not able to create a new version of T0 agent based on WMCore 1.4.7.patch2. Last stable T0 version used in production node is with 1.4.5.patch2

**Describe the bug**
Following the requested by WMCore team to move to the last stable version, we founded that Tier0 shows an error in the component Tier0Feeder. While this component is only for Tier0, after doing some investigation, we founded inside the traceback the following error message:
`2021-04-21 04:05:34,680:140355232098048:INFO:Rucio:./WMCore Rucio initialization parameters: {'auth_type': None, 'account': 'wmcore_transferor', 'timeout': 600, 'ca_cert': None, 'rucio_host': None, 'auth_host': None, 'creds': None, 'user_ag
ent': 'wmcore-client'}
2021-04-21 04:05:34,714:140355232098048:ERROR:RunConfigAPI:Cannot authenticate.
Details: Cannot authenticate to account wmcore_transferor with given credentials
`
We don’t use the wmcore_trasnferor account within the code in T0, but the traceback shows that the error might be in the following file:
`/data/tier0/srv/wmagent/2.2.4/sw.jamadova/slc7_amd64_gcc630/cms/t0/2.2.4/lib/python2.7/site-packages/WMCore/WMSpec/Steps/Fetchers/PileupFetcher.py", line 38, in __init__
    self.rucio = Rucio(self.rucioAcct)`

Checking the historical behavior of that file, shows that is hardcoded to use the account wmcore_transferor. We managed to create a stable version of a T0 release using WMCore 1.4.6.pre5 and everything works as expected with that version and a replay was deployed using that version without issues. But using WMCore 1.4.6.pre6 or more actual releases, Tier0Feeder fails with the same error message as showed before. Checking the differences of both releases (1.4.6.pre5 vs 1.4.6.pre6) for that file shows that the lines `if usingRucio():else:` might be involved 
**How to reproduce it**
Create a T0 release based on WMCore versions higher than 1.4.6.pre5

**Expected behavior**
Be able to authenticate with the correct account.

**Additional context and error message**

```2021-04-21 04:05:13,522:140355232098048:INFO:LogDB:<LogDB(url=http://admin:couch@localhost:5984/t0_logdb, identifier=vocms0500.cern.ch, agent=1)>
2021-04-21 04:05:13,522:140355232098048:INFO:BaseWorkerThread:Worker thread <T0Component.Tier0Feeder.Tier0FeederPoller.Tier0FeederPoller object at 0x7fa70a1ffb50> started
2021-04-21 04:05:34,680:140355232098048:INFO:Rucio:./WMCore Rucio initialization parameters: {'auth_type': None, 'account': 'wmcore_transferor', 'timeout': 600, 'ca_cert': None, 'rucio_host': None, 'auth_host': None, 'creds': None, 'user_ag
ent': 'wmcore-client'}
2021-04-21 04:05:34,714:140355232098048:ERROR:RunConfigAPI:Cannot authenticate.
Details: Cannot authenticate to account wmcore_transferor with given credentials
Traceback (most recent call last):
  File "/data/tier0/srv/wmagent/2.2.4/sw.jamadova/slc7_amd64_gcc630/cms/t0/2.2.4/lib/python2.7/site-packages/T0/RunConfig/RunConfigAPI.py", line 749, in configureRunStream
    wmbsHelper.createSubscription(wmSpec.getTask(taskName), fileset, alternativeFilesetClose = True)
  File "/data/tier0/srv/wmagent/2.2.4/sw.jamadova/slc7_amd64_gcc630/cms/t0/2.2.4/lib/python2.7/site-packages/WMCore/WorkQueue/WMBSHelper.py", line 261, in createSubscription
    self._createSubscriptionsInWMBS(task, fileset, alternativeFilesetClose)
  File "/data/tier0/srv/wmagent/2.2.4/sw.jamadova/slc7_amd64_gcc630/cms/t0/2.2.4/lib/python2.7/site-packages/WMCore/WorkQueue/WMBSHelper.py", line 276, in _createSubscriptionsInWMBS
    self.createSandbox()
  File "/data/tier0/srv/wmagent/2.2.4/sw.jamadova/slc7_amd64_gcc630/cms/t0/2.2.4/lib/python2.7/site-packages/WMCore/WorkQueue/WMBSHelper.py", line 212, in createSandbox
    sandboxCreator.makeSandbox(self.cachepath, self.wmSpec)
  File "/data/tier0/srv/wmagent/2.2.4/sw.jamadova/slc7_amd64_gcc630/cms/t0/2.2.4/lib/python2.7/site-packages/WMCore/WMRuntime/SandboxCreator.py", line 108, in makeSandbox
    fetcherInstances = list(map(getFetcher, fetcherNames))
  File "/data/tier0/srv/wmagent/2.2.4/sw.jamadova/slc7_amd64_gcc630/cms/t0/2.2.4/lib/python2.7/site-packages/WMCore/WMSpec/Steps/StepFactory.py", line 196, in getFetcher
    return _FetcherFactory.loadObject(fetcherName)
  File "/data/tier0/srv/wmagent/2.2.4/sw.jamadova/slc7_amd64_gcc630/cms/t0/2.2.4/lib/python2.7/site-packages/WMCore/WMFactory.py", line 61, in loadObject
    classinstance = obj()
  File "/data/tier0/srv/wmagent/2.2.4/sw.jamadova/slc7_amd64_gcc630/cms/t0/2.2.4/lib/python2.7/site-packages/WMCore/WMSpec/Steps/Fetchers/PileupFetcher.py", line 38, in __init__
    self.rucio = Rucio(self.rucioAcct)
  File "/data/tier0/srv/wmagent/2.2.4/sw.jamadova/slc7_amd64_gcc630/cms/t0/2.2.4/lib/python2.7/site-packages/WMCore/Services/Rucio/Rucio.py", line 144, in __init__
    user_agent=self.rucioParams['user_agent'])
  File "/data/tier0/srv/wmagent/2.2.4/sw.jamadova/slc7_amd64_gcc630/external/py2-rucio-clients/1.24.2.post1/lib/python2.7/site-packages/rucio/client/client.py", line 84, in __init__
    super(Client, self).__init__(rucio_host=rucio_host, auth_host=auth_host, account=account, ca_cert=ca_cert, auth_type=auth_type, creds=creds, timeout=timeout, user_agent=user_agent, vo=vo)
  File "/data/tier0/srv/wmagent/2.2.4/sw.jamadova/slc7_amd64_gcc630/external/py2-rucio-clients/1.24.2.post1/lib/python2.7/site-packages/rucio/client/accountclient.py", line 51, in __init__
    super(AccountClient, self).__init__(rucio_host, auth_host, account, ca_cert, auth_type, creds, timeout, user_agent, vo=vo)
  File "/data/tier0/srv/wmagent/2.2.4/sw.jamadova/slc7_amd64_gcc630/external/py2-rucio-clients/1.24.2.post1/lib/python2.7/site-packages/rucio/client/accountlimitclient.py", line 47, in __init__
    auth_type, creds, timeout, user_agent, vo=vo)
  File "/data/tier0/srv/wmagent/2.2.4/sw.jamadova/slc7_amd64_gcc630/external/py2-rucio-clients/1.24.2.post1/lib/python2.7/site-packages/rucio/client/metaclient.py", line 46, in __init__
    super(MetaClient, self).__init__(rucio_host, auth_host, account, ca_cert, auth_type, creds, timeout, user_agent, vo=vo)
  File "/data/tier0/srv/wmagent/2.2.4/sw.jamadova/slc7_amd64_gcc630/external/py2-rucio-clients/1.24.2.post1/lib/python2.7/site-packages/rucio/client/pingclient.py", line 36, in __init__
    super(PingClient, self).__init__(rucio_host, auth_host, account, ca_cert, auth_type, creds, timeout, user_agent, vo=vo)
  File "/data/tier0/srv/wmagent/2.2.4/sw.jamadova/slc7_amd64_gcc630/external/py2-rucio-clients/1.24.2.post1/lib/python2.7/site-packages/rucio/client/replicaclient.py", line 49, in __init__
    super(ReplicaClient, self).__init__(rucio_host, auth_host, account, ca_cert, auth_type, creds, timeout, user_agent, vo=vo)
  File "/data/tier0/srv/wmagent/2.2.4/sw.jamadova/slc7_amd64_gcc630/external/py2-rucio-clients/1.24.2.post1/lib/python2.7/site-packages/rucio/client/requestclient.py", line 38, in __init__
    auth_type, creds, timeout, user_agent, vo=vo)
  File "/data/tier0/srv/wmagent/2.2.4/sw.jamadova/slc7_amd64_gcc630/external/py2-rucio-clients/1.24.2.post1/lib/python2.7/site-packages/rucio/client/rseclient.py", line 48, in __init__
    auth_type, creds, timeout, user_agent, vo=vo)
  File "/data/tier0/srv/wmagent/2.2.4/sw.jamadova/slc7_amd64_gcc630/external/py2-rucio-clients/1.24.2.post1/lib/python2.7/site-packages/rucio/client/scopeclient.py", line 47, in __init__
    super(ScopeClient, self).__init__(rucio_host, auth_host, account, ca_cert, auth_type, creds, timeout, user_agent, vo=vo)
  File "/data/tier0/srv/wmagent/2.2.4/sw.jamadova/slc7_amd64_gcc630/external/py2-rucio-clients/1.24.2.post1/lib/python2.7/site-packages/rucio/client/didclient.py", line 60, in __init__
    auth_type, creds, timeout, user_agent, vo=vo)
  File "/data/tier0/srv/wmagent/2.2.4/sw.jamadova/slc7_amd64_gcc630/external/py2-rucio-clients/1.24.2.post1/lib/python2.7/site-packages/rucio/client/ruleclient.py", line 45, in __init__
    super(RuleClient, self).__init__(rucio_host, auth_host, account, ca_cert, auth_type, creds, timeout, dq2_wrapper, vo=vo)
  File "/data/tier0/srv/wmagent/2.2.4/sw.jamadova/slc7_amd64_gcc630/external/py2-rucio-clients/1.24.2.post1/lib/python2.7/site-packages/rucio/client/subscriptionclient.py", line 40, in __init__
    super(SubscriptionClient, self).__init__(rucio_host, auth_host, account, ca_cert, auth_type, creds, timeout, user_agent, vo=vo)
  File "/data/tier0/srv/wmagent/2.2.4/sw.jamadova/slc7_amd64_gcc630/external/py2-rucio-clients/1.24.2.post1/lib/python2.7/site-packages/rucio/client/lockclient.py", line 45, in __init__
    auth_type, creds, timeout, user_agent, vo=vo)
  File "/data/tier0/srv/wmagent/2.2.4/sw.jamadova/slc7_amd64_gcc630/external/py2-rucio-clients/1.24.2.post1/lib/python2.7/site-packages/rucio/client/configclient.py", line 45, in __init__
    super(ConfigClient, self).__init__(rucio_host, auth_host, account, ca_cert, auth_type, creds, timeout, user_agent, vo=vo)
  File "/data/tier0/srv/wmagent/2.2.4/sw.jamadova/slc7_amd64_gcc630/external/py2-rucio-clients/1.24.2.post1/lib/python2.7/site-packages/rucio/client/touchclient.py", line 42, in __init__
    super(TouchClient, self).__init__(rucio_host, auth_host, account, ca_cert, auth_type, creds, timeout, user_agent, vo=vo)
  File "/data/tier0/srv/wmagent/2.2.4/sw.jamadova/slc7_amd64_gcc630/external/py2-rucio-clients/1.24.2.post1/lib/python2.7/site-packages/rucio/client/importclient.py", line 36, in __init__
    auth_type, creds, timeout, user_agent, vo=vo)
  File "/data/tier0/srv/wmagent/2.2.4/sw.jamadova/slc7_amd64_gcc630/external/py2-rucio-clients/1.24.2.post1/lib/python2.7/site-packages/rucio/client/exportclient.py", line 36, in __init__
    auth_type, creds, timeout, user_agent, vo=vo)
  File "/data/tier0/srv/wmagent/2.2.4/sw.jamadova/slc7_amd64_gcc630/external/py2-rucio-clients/1.24.2.post1/lib/python2.7/site-packages/rucio/client/credentialclient.py", line 36, in __init__
    auth_type, creds, timeout, user_agent, vo=vo)
  File "/data/tier0/srv/wmagent/2.2.4/sw.jamadova/slc7_amd64_gcc630/external/py2-rucio-clients/1.24.2.post1/lib/python2.7/site-packages/rucio/client/diracclient.py", line 39, in __init__
    auth_type, creds, timeout, user_agent, vo=vo)
  File "/data/tier0/srv/wmagent/2.2.4/sw.jamadova/slc7_amd64_gcc630/external/py2-rucio-clients/1.24.2.post1/lib/python2.7/site-packages/rucio/client/baseclient.py", line 311, in __init__
    self.__authenticate()
  File "/data/tier0/srv/wmagent/2.2.4/sw.jamadova/slc7_amd64_gcc630/external/py2-rucio-clients/1.24.2.post1/lib/python2.7/site-packages/rucio/client/baseclient.py", line 985, in __authenticate
    self.__get_token()
  File "/data/tier0/srv/wmagent/2.2.4/sw.jamadova/slc7_amd64_gcc630/external/py2-rucio-clients/1.24.2.post1/lib/python2.7/site-packages/rucio/client/baseclient.py", line 877, in __get_token
    if not self.__get_token_x509():
  File "/data/tier0/srv/wmagent/2.2.4/sw.jamadova/slc7_amd64_gcc630/external/py2-rucio-clients/1.24.2.post1/lib/python2.7/site-packages/rucio/client/baseclient.py", line 707, in __get_token_x509
    raise exc_cls(exc_msg)

CannotAuthenticate: Cannot authenticate.
Details: Cannot authenticate to account wmcore_transferor with given credentials
2021-04-21 04:05:34,721:140355232098048:ERROR:Tier0FeederPoller:Can't configure for run 338714 and stream Calibration
Traceback (most recent call last):
  File "/data/tier0/srv/wmagent/2.2.4/sw.jamadova/slc7_amd64_gcc630/cms/t0/2.2.4/lib/python2.7/site-packages/T0Component/Tier0Feeder/Tier0FeederPoller.py", line 198, in algorithm
    self.dqmUploadProxy)
  File "/data/tier0/srv/wmagent/2.2.4/sw.jamadova/slc7_amd64_gcc630/cms/t0/2.2.4/lib/python2.7/site-packages/T0/RunConfig/RunConfigAPI.py", line 761, in configureRunStream
    raise RuntimeError("Problem in configureRunStream() database transaction !")
RuntimeError: Problem in configureRunStream() database transaction !
2021-04-21 04:05:34,920:140355232098048:INFO:Rucio:WMCore Rucio initialization parameters: {'auth_type': None, 'account': 'wmcore_transferor', 'timeout': 600, 'ca_cert': None, 'rucio_host': None, 'auth_host': None, 'creds': None, 'user_agent': 'wmcore-client'}
2021-04-21 04:05:34,945:140355232098048:ERROR:RunConfigAPI:Cannot authenticate.
Details: Cannot authenticate to account wmcore_transferor with given credentials
Traceback (most recent call last):
 ```


Changed files:
src/python/WMCore/WMSpec/Steps/Fetchers/PileupFetcher.py

diff --git a/src/python/WMCore/WMSpec/Steps/Fetchers/PileupFetcher.py b/src/python/WMCore/WMSpec/Steps/Fetchers/PileupFetcher.py
index 76de290e4..3e292a8a8 100644
--- a/src/python/WMCore/WMSpec/Steps/Fetchers/PileupFetcher.py
+++ b/src/python/WMCore/WMSpec/Steps/Fetchers/PileupFetcher.py
@@ -15,7 +15,6 @@ import logging
 from json import JSONEncoder
 import WMCore.WMSpec.WMStep as WMStep
 from WMCore.Services.DBS.DBSReader import DBSReader
-from WMCore.Services.PhEDEx.PhEDEx import PhEDEx
 from WMCore.Services.Rucio.Rucio import Rucio
 from WMCore.WMSpec.Steps.Fetchers.FetcherInterface import FetcherInterface
 
@@ -35,7 +34,7 @@ class PileupFetcher(FetcherInterface):
         super(PileupFetcher, self).__init__()
         # FIXME: find a way to pass the Rucio account name to this fetcher module
         self.rucioAcct = "wmcore_transferor"
-        self.rucio = Rucio(self.rucioAcct)
+        self.rucio = None
 
     def _queryDbsAndGetPileupConfig(self, stepHelper, dbsReader):
         """
@@ -78,6 +77,8 @@ class PileupFetcher(FetcherInterface):
         :param blockDict: dictionary with DBS summary info
         :return: update blockDict in place
         """
+        # initialize Rucio here to avoid this authentication on T0-WMAgent
+        self.rucio = Rucio(self.rucioAcct)
         blockReplicas = self.rucio.getPileupLockedAndAvailable(dset, account=self.rucioAcct)
         for blockName, blockLocation in viewitems(blockReplicas):
             try: