Repository: dmwm/wmcore
Issue: Resubmission workflows fail to get assigned with Trust* flags enabled

**Impact of the bug**
ReqMgr2

**Describe the bug**
With this PR:
https://github.com/dmwm/WMCore/pull/9770

we have added a validation of the workflow configuration in order to allow or not its assignment with the Trust* flags enabled.
The problem is that the validation doesn't happen on the high level workflow description (workflow json/dictionary), but it happens on the workload attributes. The workload gets truncated when ACDCs are created, which means that the task with InputDataset and/or MCPileup dataset might no longer be there...

**How to reproduce it**
Create an ACDC for a workflow with InputDataset, and enable TrustSitelists flag. Or create a merge ACDC workflow with TrustPUSitelists enabled.

**Expected behavior**
Ideally, we should not validate those Trust flags against `Resubmission` workflows. However, an ACDC workflow keeps the original request type, so calling `workload.requestType()` would not return `Resubmission`. I need to check what are our other options here...

**Additional context and error message**
Error from reqmgr2 logs:
```
[03/Jul/2020:07:42:50]  Error for request args {u'SoftTimeout': 129600, u'BlockCloseMaxEvents': 25000000, 'DeleteFromSource': False, u'MaxMergeEvents': 100000000, u'CustodialSites': [], u'Override': {u'eos-lfn-prefix': u'root://eoscms.cer
n.ch//eos/cms/store/logs/prod/recent/TESTBED'}, u'ProcessingString': 'SC_ReDigi_Harvest_HG2007_Val_Alanv12', 'NonCustodialGroup': 'DataOps', u'TrustSitelists': False, 'ChainParentageMap': {}, 'CustodialGroup': 'DataOps', u'UnmergedLFNBase
': '/store/unmerged', u'CustodialSubType': 'Replica', u'TrustPUSitelists': True, u'GracePeriod': 300, u'MergedLFNBase': '/store/backfill/1', 'HardTimeout': 129900, u'BlockCloseMaxWaitTime': 66400, u'MaxMergeSize': 4294967296, u'Acquisitio
nEra': {u'DigiFullPU_2017PU': u'CMSSW_10_6_1_patch2', u'QCDForPF_13TeV_TuneCUETP8M1_2017PU_GenSimFull': u'CMSSW_10_6_1_patch1', u'RecoFullPU_2017PU': u'CMSSW_10_6_1_patch3'}, u'NonCustodialSubType': 'Replica', u'NonCustodialSites': [], u'
MinMergeSize': 2147483648, u'SiteWhitelist': [u'T1_US_FNAL', u'T2_CH_CERN'], u'BlockCloseMaxSize': 5000000000000, u'ProcessingVersion': 11, u'Dashboard': 'integration', u'Team': 'testbed-vocms0193', 'AllowOpportunistic': False, u'AutoAppr
oveSubscriptionSites': [], u'BlockCloseMaxFiles': 500, u'SiteBlacklist': [], u'SubscriptionPriority': 'Low', u'RequestStatus': 'assigned', 'MaxWaitTime': 86400}: Traceback (most recent call last):
  File "/data/srv/beHG2007g/sw/slc7_amd64_gcc630/cms/reqmgr2/1.3.6.pre5/lib/python2.7/site-packages/WMCore/ReqMgr/Service/Request.py", line 444, in _handleAssignmentStateTransition
    workload.updateArguments(request_args)
  File "/data/srv/beHG2007g/sw/slc7_amd64_gcc630/cms/reqmgr2/1.3.6.pre5/lib/python2.7/site-packages/WMCore/WMSpec/WMWorkload.py", line 1928, in updateArguments
    pileupFlag=strToBool(kwargs["TrustPUSitelists"]))
  File "/data/srv/beHG2007g/sw/slc7_amd64_gcc630/cms/reqmgr2/1.3.6.pre5/lib/python2.7/site-packages/WMCore/WMSpec/WMWorkload.py", line 1878, in setTrustLocationFlag
    raise RuntimeError(msg)
RuntimeError: Setting TrustPUSitelists=True for workflows without pileup dataset is forbidden!

[03/Jul/2020:07:42:50]  SERVER REST ERROR WMCore.ReqMgr.DataStructs.RequestError.InvalidSpecParameterValue 821107c30142870903a5fd72eae3e6aa (Invalid spec parameter value: Setting TrustPUSitelists=True for workflows without pileup dataset 
is forbidden!)
```


Changed files:
src/python/WMCore/WMSpec/WMWorkload.py

diff --git a/src/python/WMCore/WMSpec/WMWorkload.py b/src/python/WMCore/WMSpec/WMWorkload.py
index 98f6a21d6..9dc74b6b4 100644
--- a/src/python/WMCore/WMSpec/WMWorkload.py
+++ b/src/python/WMCore/WMSpec/WMWorkload.py
@@ -1861,19 +1861,25 @@ class WMWorkloadHelper(PersistencyHelper):
 
     def setTrustLocationFlag(self, inputFlag=False, pileupFlag=False):
         """
-        _setTrustLocationFlag_
-
         Set the input and the pileup flags in the top level tasks
         indicating that site lists should be used as location data
 
         The input data flag has to be set only for top level tasks, otherwise
         it affects where secondary jobs are meant to run.
         The pileup flag has to be set for all the tasks in the workload.
+
+        Validate these parameters to make sure they are only set for workflows
+        that require those type of input datasets (ACDCs are not validated)
         """
-        if inputFlag is True and not self.listInputDatasets():
+        isACDCWorkflow = False
+        for task in self.taskIterator():
+            if task.getInputACDC():
+                isACDCWorkflow = True
+
+        if inputFlag is True and isACDCWorkflow is False and not self.listInputDatasets():
             msg = "Setting TrustSitelists=True for workflows without input dataset is forbidden!"
             raise RuntimeError(msg)
-        if pileupFlag is True and not self.listPileupDatasets():
+        if pileupFlag is True and isACDCWorkflow is False and not self.listPileupDatasets():
             msg = "Setting TrustPUSitelists=True for workflows without pileup dataset is forbidden!"
             raise RuntimeError(msg)
         for task in self.getAllTasks(cpuOnly=True):