Repository: dmwm/wmcore
Issue: RucioInjector checking for RSE attributes for an RSE expression

**Impact of the bug**
WMAgent

**Describe the bug**
With the changes provided by this PR: https://github.com/dmwm/WMCore/pull/10105
RucioInjector now tries to resolve the `requires_approval` attribute for every single RSE name that we are meant to create a container level rule. The problem is, central production gets the RSE name overwritten by a generic RSE expression. Such calls will of course failed to be served.

**How to reproduce it**
Pass an rse expression instead of an rse name.

**Expected behavior**
Container-level output placement has a different behaviour between central production and T0 activities, such as:
* central production does not make Tape requests; and central production always set the rse parameter to a very generic expression
* while T0 always makes a data placement against one specific RSE name.

With this in mind, we should not resolve the `requires_approval` attribute unless our rse input parameter corresponds to a single RSE. In other words, let us resolve it only for T0 output data placement. 

**Additional context and error message**
Traceback from RucioInjector component on vocms0192:
```
2020-12-03 09:18:57,737:140231927920384:INFO:RucioInjectorPoller:Starting insertContainerRules method
2020-12-03 09:18:57,931:140231927920384:ERROR:RucioInjectorPoller:<@========== WMException Start ==========@>
Exception Class: WMRucioException
Message: Error retrieving attributes for RSE: (tier=2|tier=1)&cms_type=real&rse_type=DISK. Error: RSE does not exist.
Details: RSE '(tier=2|tier=1)&cms_type=real&rse_type=DISK' cannot be found in vo 'def'
        ModuleName : WMCore.Services.Rucio.Rucio
        MethodName : requiresApproval
        ClassInstance : None
        FileName : /data/srv/wmagent/v1.4.3.patch1/sw/slc7_amd64_gcc630/cms/wmagent/1.4.3.patch1/lib/python2.7/site-packages/WMCore/Services/Rucio/Rucio.py
        ClassName : None
        LineNumber : 804
        ErrorNr : 0

Traceback: 
  File "/data/srv/wmagent/v1.4.3.patch1/sw/slc7_amd64_gcc630/cms/wmagent/1.4.3.patch1/lib/python2.7/site-packages/WMCore/Services/Rucio/Rucio.py", line 801, in requiresApproval
    attrs = self.cli.list_rse_attributes(rse)

  File "/data/srv/wmagent/v1.4.3.patch1/sw/slc7_amd64_gcc630/external/py2-rucio-clients/1.23.11/lib/python2.7/site-packages/rucio/client/rseclient.py", line 210, in list_rse_attributes
    raise exc_cls(exc_msg)

<@---------- WMException End ----------@>
Unable to check approval requirements. Will retry again in the next cycle.
```


Changed files:
src/python/WMComponent/RucioInjector/RucioInjectorPoller.py

diff --git a/src/python/WMComponent/RucioInjector/RucioInjectorPoller.py b/src/python/WMComponent/RucioInjector/RucioInjectorPoller.py
index f5752b08c..0aa7a8ce4 100644
--- a/src/python/WMComponent/RucioInjector/RucioInjectorPoller.py
+++ b/src/python/WMComponent/RucioInjector/RucioInjectorPoller.py
@@ -502,8 +502,7 @@ class RucioInjectorPoller(BaseWorkerThread):
             ruleComment = "T0 " + ruleComment
 
         # FIXME also adapt the format returned by this DAO
-        # Check for completely unsubscribed datasets
-        # in short, files in phedex, file status in "GLOBAL" or "InDBS", and subscribed=0
+        # Check for completely unsubscribed datasets that are already marked as in_phedex = 1
         unsubscribedDatasets = self.getUnsubscribedDsets.execute()
 
         # Keep a list of subscriptions to tick as subscribed in the database
@@ -536,18 +535,19 @@ class RucioInjectorPoller(BaseWorkerThread):
                 rseName = self.containerDiskRuleRSEExpr
                 if self.testRSEs:
                     rseName = rseName.replace("cms_type=real", "cms_type=test")
-            elif self.testRSEs:
-                rseName = "%s_Test" % rseName
-
-            #Checking whether we need to ask for rule approval
-            try:
-                if self.rucio.requiresApproval(rseName):
-                    ruleKwargs['ask_approval'] = True
-            except WMRucioException as exc:
-                msg = str(exc)
-                msg += "\\nUnable to check approval requirements. Will retry again in the next cycle."
-                logging.error(msg)
-                continue
+            else:
+                # then it's a T0 container placement
+                if self.testRSEs:
+                    rseName = "%s_Test" % rseName
+                #Checking whether we need to ask for rule approval
+                try:
+                    if self.rucio.requiresApproval(rseName):
+                        ruleKwargs['ask_approval'] = True
+                except WMRucioException as exc:
+                    msg = str(exc)
+                    msg += "\\nUnable to check approval requirements. Will retry again in the next cycle."
+                    logging.error(msg)
+                    continue
 
             logging.info("Creating container rule for %s against RSE %s", container, rseName)
             logging.debug("Container rule will be created with keyword args: %s", ruleKwargs)