Repository: rucio/rucio

Issue:
`import rucio.core.rule` fails with missing section
The work in #339 caused a regression if the `permission` section does not exist.  From the logs:

```
mod_wsgi (pid=18803): Exception occurred processing WSGI script '/usr/lib/python2.7/site-packages/rucio/web/rest/did.py'.
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/rucio/web/rest/did.py", line 22, in <module>
    from rucio.api.did import (add_did, add_dids, list_content, list_content_history,
  File "/usr/lib/python2.7/site-packages/rucio/api/did.py", line 19, in <module>
    from rucio.core import did, naming_convention, meta as meta_core
  File "/usr/lib/python2.7/site-packages/rucio/core/did.py", line 35, in <module>
    import rucio.core.rule
  File "/usr/lib/python2.7/site-packages/rucio/core/rule.py", line 2888, in <module>
    def archive_localgroupdisk_datasets(scope, name, session=None):
  File "/usr/lib/python2.7/site-packages/rucio/common/policy.py", line 78, in policy_filter
    policy = get_policy()
  File "/usr/lib/python2.7/site-packages/rucio/common/policy.py", line 40, in get_policy
    policy = config_get('permission', 'policy')
  File "/usr/lib/python2.7/site-packages/rucio/common/config.py", line 30, in config_get
    return __CONFIG.get(section, option)
  File "/usr/lib64/python2.7/ConfigParser.py", line 607, in get
    raise NoSectionError(section)
NoSectionError: No section: 'permission'
```

Seems that this exception type is simply not caught.


Discussion:

Resolving patch:
diff --git a/lib/rucio/core/did.py b/lib/rucio/core/did.py
--- a/lib/rucio/core/did.py
+++ b/lib/rucio/core/did.py
@@ -1157,6 +1157,16 @@ def set_metadata(scope, name, key, value, type=None, did=None,
             session.query(models.DataIdentifier).filter_by(scope=scope, name=name).update({'expired_at': expired_at}, synchronize_session='fetch')
         except TypeError as error:
             raise exception.InvalidValueForKey(error)
+    elif key in ['guid', 'events']:
+        rowcount = session.query(models.DataIdentifier).filter_by(scope=scope, name=name, did_type=DIDType.FILE).update({key: value}, synchronize_session=False)
+        if not rowcount:
+            raise exception.UnsupportedOperation('%(key)s for %(scope)s:%(name)s cannot be updated' % locals())
+        session.query(models.DataIdentifierAssociation).filter_by(child_scope=scope, child_name=name, child_type=DIDType.FILE).update({key: value}, synchronize_session=False)
+        if key == 'events':
+            for parent_scope, parent_name in session.query(models.DataIdentifierAssociation.scope, models.DataIdentifierAssociation.name).filter_by(child_scope=scope, child_name=name):
+                events = session.query(func.sum(models.DataIdentifierAssociation.events)).filter_by(scope=parent_scope, name=parent_name).one()
+                session.query(models.DataIdentifier).filter_by(scope=parent_scope, name=parent_name).update({'events': events}, synchronize_session=False)
+
     elif key == 'adler32':
         rowcount = session.query(models.DataIdentifier).filter_by(scope=scope, name=name, did_type=DIDType.FILE).update({key: value}, synchronize_session=False)
         if not rowcount:


Test patch: