Repository: rucio/rucio

Issue:
Wrong cms RSE name pattern used when attaching dids
Motivation
----------
in lib/rucio/common/schema/cms.py the RSE Name pattern is 

`^T[0-3]_[A-Z]{2}((_[A-Za-z0-9]+)+)$`

while the pattern for the rse property of ATTACHMENT is

`^([A-Z0-9]+([_-][A-Z0-9]+)*)$`

as a result when we add replicas to a CMS RSE whose name is not all in capitals (e.g. T1_UK_RAL_Buffer):
  * if we use `add_replicas` and the `attach_dids` it works fine
  * if we use `attach_dids` directly it fails with `InvalidObject`

Modification
------------
Just put the same regexp for the two patterns (PR coming)




Discussion:
Created PR #1902 
Maybe we may want to test it on the CERN server before merging.
Hi Andrea,
You created this PR against the next branch (Thus it is treated as a feature). This will then only go in the Rucio 1.19.0 release in February 2019. Is this fine? Otherwise please re-create as a patch.
See https://github.com/rucio/rucio/blob/master/CONTRIBUTING.rst
Hi Martin, 
ok sorry. I'm recreating the PR.
Created #1904
That's against the **hotfix** branch 😄
I'll create the two PRs for **master** and **next**. 
Although I just saw you based your development off the **hotfix** branch (instead of master). It's not super clean to merge it like that. It would probably work fine, but we should stick to the normal workflow here.
I'm really sorry.. I've read the doc too quickly and understood patches go in hotfix (I do not know how, since is clearly stated). I'll recreate 2 PR one for next and one for master (both from a branch based on master, if I understand correctly)
Hi Andrea, no worries. The workflow we have is sadly not very simple for somebody new, since it is somewhat different than most projects do it, so I can understand the confusion. Just ping me on Slack if you have any question about the setup. 😄 

Resolving patch:
diff --git a/lib/rucio/common/schema/cms.py b/lib/rucio/common/schema/cms.py
--- a/lib/rucio/common/schema/cms.py
+++ b/lib/rucio/common/schema/cms.py
@@ -269,7 +269,7 @@
                              "name": NAME,
                              "rse": {"description": "RSE name",
                                      "type": ["string", "null"],
-                                     "pattern": "^([A-Z0-9]+([_-][A-Z0-9]+)*)$"},
+                                     "pattern": "^T[0-3]_[A-Z]{2}((_[A-Za-z0-9]+)+)$"},
                              "dids": DIDS},
               "required": ["dids"],
               "additionalProperties": False}


Test patch:
diff --git a/lib/rucio/tests/test_schema_cms.py b/lib/rucio/tests/test_schema_cms.py
old mode 100755
new mode 100644
--- a/lib/rucio/tests/test_schema_cms.py
+++ b/lib/rucio/tests/test_schema_cms.py
@@ -125,7 +125,6 @@ def test_dids(self):
 
     def test_scopes(self):
         """ CMS SCHEMA (COMMON): Test CMS scopes"""
-
         validate_schema('scope', 'cms')
         validate_schema('scope', 'user.ewv')
         validate_schema('scope', 'user.ewv2')
@@ -138,3 +137,37 @@ def test_scopes(self):
             validate_schema('scope', 'higgs')  # Not user.higgs
         with assert_raises(InvalidObject):
             validate_schema('scope', 'csm')  # Anagram
+
+    def test_attachment(self):
+        """ CMS SCHEMA (COMMON): Test CMS attachment"""
+
+        # no need to re-test did pattrens
+        dids = [{
+            'scope': 'cms', 'name': '/store/mc/Fall10/DYToMuMu_M-20_TuneZ2_7TeV-pythia6/AODSIM/START38_V12-v1/0003/C0F3344F-6EC8-DF11-8ED6-E41F13181020.root'
+        }]
+
+        dataset = '/DoubleMu/aburgmei-Run2012A_22Jan2013_v1_RHembedded_trans1_tau121_ptelec1_17elec2_8_v4/USER#1f1eee22-cdee-0f1b-271b-77a7f559e7dd'
+
+        scope = 'cms'
+
+        # RSE pattern is defined independently so we want to re-test
+        good_rses = [None, 'T2_FR_GRIF_LLR', 'T1_IT_CNAF_Disk']
+        bad_rses = ['T2_FR_GRIF-LLR', 'T4_FR_GRIF_LLR']
+
+        with assert_raises(InvalidObject):   # missing dids
+            validate_schema('attachment', {'rse': 'T1_FR_CCIN2P3'})
+
+        args = {'dids': dids}
+        validate_schema('attachment', args)
+        args['scope'] = scope
+        args['name'] = dataset
+        validate_schema('attachment', args)
+
+        for rse in good_rses:
+            args['rse'] = rse
+            validate_schema('attachment', args)
+
+        for rse in bad_rses:
+            args['rse'] = rse
+            with assert_raises(InvalidObject):
+                validate_schema('attachment', args)