Repository: dmwm/wmcore
Issue: [MS] Input data placement for primary + parents must be done with grouping=ALL

**Impact of the bug**
MSTransferor

**Describe the bug**
With the changes pushed in in: https://github.com/dmwm/WMCore/pull/11143

we no longer pick a single RSE as the final destination, but instead rely on Rucio to decide which RSE to use out of an expression (logical OR of RSEs). This logic is fine, however, we must define the rule grouping to `ALL`, otherwise we could end up with parent blocks in an RSE different than the primary, leaving that workqueue element stuck.

**How to reproduce it**
Inject one of the test templates that require parent dataset.

**Expected behavior**
When a workflow has primary AND parent, we must define the Rucio rule with `grouping=ALL`, to ensure that primary and all its relevant parents will be under the same RSE.

**Additional context and error message**
From the testbed MSTransferor logs:
```
2022-05-19 12:44:47,305:INFO:MSTransferor: Creating rule for workflow amaltaro_ReReco_Parents_May2022_Val_220519_123725_5652 with 16 DIDs in container /NoBPTX/Run2018D-12Nov2019_UL2018-v1/MINIAOD, RSEs: T2_CH_CERN|T1_US_FNAL_Disk, groupin
g: DATASET
...
2022-05-19 12:44:47,364:WARNING:Rucio: Resolving duplicate rules and separating every DID in a new rule...
2022-05-19 12:44:48,277:INFO:MSTransferor: Transfer requests successful for amaltaro_ReReco_Parents_May2022_Val_220519_123725_5652. Summary: [{'campaignName': 'May2022_Val',
  'completion': [0.0],
  'dataType': 'primary',
  'dataset': '/NoBPTX/Run2018D-12Nov2019_UL2018-v1/MINIAOD',
  'transferIDs': ['3d41f229531f4828aab4a888de14bebf',
                  '0c2dedbbbf3b4f50af016aa164154c9d',
                  '3c82c4aff2b44fc78d2e1facedeeaf6f',
                  '9eb0d2a2cc9942848f4ccb688eb6ccae',
                  'bfd413087cea4e649106c10dcc8e72d7',
                  'a8be0a5ae0a24643bfe0eadc9369cdfa',
                  'dcd1e7db1c1d428990722b8c1b83e84f',
                  '8753e1a4fdc74740b29bf4adabab63a3',
                  '5a953bcbca184ddbb4f377010badbf36',
                  '085ae92efe734c4d98342fbcbb0d4d52',
                  '945fb737fe61418b8b723db2c1bab6ef',
                  'ee5cb5a0c1ae42d78ab150dd68ef8625',
                  '8f96ca5cc816427aa7d561131891c8e7',
                  'a90303b7ee1e4035aabc49d7e8421667',
                  '2ea8b054d35248a9a0c69c61e9fba6fa',
                  'e6e077403af54df7bcbc1a1f1c37998b']}]
```

Changed files:
test/python/WMCore_t/MicroService_t/MSTransferor_t/DataStructs_t/Workflow_t.py, src/python/WMCore/MicroService/MSTransferor/DataStructs/Workflow.py

diff --git a/src/python/WMCore/MicroService/MSTransferor/DataStructs/Workflow.py b/src/python/WMCore/MicroService/MSTransferor/DataStructs/Workflow.py
index 0d7787bae..c385534f2 100644
--- a/src/python/WMCore/MicroService/MSTransferor/DataStructs/Workflow.py
+++ b/src/python/WMCore/MicroService/MSTransferor/DataStructs/Workflow.py
@@ -10,7 +10,7 @@ from future.utils import viewitems, viewvalues, listvalues
 from copy import copy, deepcopy
 from WMCore.DataStructs.LumiList import LumiList
 from WMCore.MicroService.Tools.Common import getMSLogger
-from WMCore.Services.Rucio.Rucio import GROUPING_DSET
+from WMCore.Services.Rucio.Rucio import GROUPING_DSET, GROUPING_ALL
 
 
 class Workflow(object):
@@ -419,4 +419,6 @@ class Workflow(object):
 
         :return: a string with the required DID grouping
         """
+        if self.getParentDataset():
+            return GROUPING_ALL
         return GROUPING_DSET
diff --git a/test/python/WMCore_t/MicroService_t/MSTransferor_t/DataStructs_t/Workflow_t.py b/test/python/WMCore_t/MicroService_t/MSTransferor_t/DataStructs_t/Workflow_t.py
index 587912426..346a859a2 100644
--- a/test/python/WMCore_t/MicroService_t/MSTransferor_t/DataStructs_t/Workflow_t.py
+++ b/test/python/WMCore_t/MicroService_t/MSTransferor_t/DataStructs_t/Workflow_t.py
@@ -326,6 +326,26 @@ class WorkflowTest(unittest.TestCase):
                                                "DbsUrl": "a_dbs_url"})
             self.assertEqual(wflowObj.getWorkflowGroup(), "relval")
 
+    def testGetRucioGrouping(self):
+        """
+        Test the `getRucioGrouping` method, which is supposed to return
+        a basic string with the Rucio grouping for this template (static
+        output).
+        """
+        parentDset = "/rereco/parent-dataset/tier"
+        rerecoSpec = {"RequestType": "ReReco",
+                      "InputDataset": "/rereco/input-dataset/tier",
+                      "Campaign": "any-campaign",
+                      "RequestName": "whatever_name",
+                      "DbsUrl": "a_dbs_url",
+                      "SiteWhitelist": ["CERN", "FNAL", "DESY"],
+                      "SiteBlacklist": ["FNAL"]}
+        wflow = Workflow(rerecoSpec['RequestName'], rerecoSpec)
+        self.assertEqual(wflow.getRucioGrouping(), "DATASET")
+
+        wflow.setParentDataset(parentDset)
+        self.assertEqual(wflow.getRucioGrouping(), "ALL")
+
 
 if __name__ == '__main__':
     unittest.main()