Repository: dmwm/wmcore
Issue: RucioInjector trying to close blocks injected into PhEDEx

**Impact of the bug**
WMAgent

**Describe the bug**
Sigh, from my testbed agent, it looks like I missed the datatier check on the `closeBlocks()` method. Which means, RucioInjector might try to close blocks that have actually being injected into PhEDEx, see:
```
2020-04-15 01:42:04,886:140658649351936:ERROR:RucioInjectorPoller:Failed to close block: /RelValQCD_FlatPt_15_3000HS_13/CMSSW_10_6_1_patch1-SC_ReDigi_Harvest_Agent133_Val_Alanv11-v11/GEN-SIM#af031cd3-55d5-44be-aedc-743feca2704d. Will retry again later.
```

It's not a terrible thing, because eventually PhEDExInjector will close those blocks and they won't be retried by RucioInjector. Yet, unneeded data service calls and other issues.

**How to reproduce it**
standard agent deployment with RucioInjector enabled

**Expected behavior**
The component should apply the same rules as specified by its configuration parameter:
```
config.RucioInjector.listTiersToInject = []
```
and only try to close blocks for data tiers that are listed in that parameter.

**Additional context and error message**
none

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 b01fefed5..d27fd697d 100644
--- a/src/python/WMComponent/RucioInjector/RucioInjectorPoller.py
+++ b/src/python/WMComponent/RucioInjector/RucioInjectorPoller.py
@@ -347,6 +347,8 @@ class RucioInjectorPoller(BaseWorkerThread):
         ### FIXME the data format returned by this DAO
         for location in migratedBlocks:
             for container in migratedBlocks[location]:
+                if not self._isContainerTierAllowed(container, checkRulesList=False):
+                    continue
                 for block in migratedBlocks[location][container]:
                     if self.rucio.closeBlockContainer(block):
                         self.setBlockClosed.execute(block)
@@ -368,17 +370,21 @@ class RucioInjectorPoller(BaseWorkerThread):
         logging.info("Starting deleteBlocks methods --> IMPLEMENT-ME!!!")
 
     # TODO: this will likely go away once the phedex to rucio migration is over
-    def _isContainerTierAllowed(self, containerName):
+    def _isContainerTierAllowed(self, containerName, checkRulesList=True):
         """
-        Performs a couple of checks on the container datatier, such as:
-          * is the datatier supposed to be injected by this component
-          * is the datatier supposed to get rules created by this component
+        It compares the container datatier name to check whether the component
+        should inject data for it or not.
+        In addition to that, it can also evaluate whether it's allowed to create
+        rules for such datatier or not.
+        :param containerName: string with the name of the container
+        :param checkRulesList: boolean to check or not against the list of tiers
+          to be skipped in the rule creation
         :return: True if the component can proceed with this container, False otherwise
         """
         endTier = containerName.rsplit('/', 1)[1]
         if endTier not in self.listTiersToInject:
             return False
-        if endTier in self.skipRulesForTiers:
+        if checkRulesList and endTier in self.skipRulesForTiers:
             return False
         return True