Skip to content
Snippets Groups Projects
Commit d772a5ee authored by Martin Barisits's avatar Martin Barisits Committed by Gerrit Code Review
Browse files

[RUCIO-940] Dataset unfreeze for power user accounts; Added events;

Change-Id: I8132f3da719194ea584b4a27a62adbba8b4306a7
parent b451fd06
No related branches found
No related tags found
No related merge requests found
...@@ -775,12 +775,18 @@ def set_status(scope, name, session=None, **kwargs): ...@@ -775,12 +775,18 @@ def set_status(scope, name, session=None, **kwargs):
if k not in statuses: if k not in statuses:
raise exception.UnsupportedStatus("The status %(k)s is not a valid data identifier status." % locals()) raise exception.UnsupportedStatus("The status %(k)s is not a valid data identifier status." % locals())
if k == 'open': if k == 'open':
query = query.filter_by(is_open=True).filter(models.DataIdentifier.did_type != DIDType.FILE) if not kwargs[k]:
values['is_open'] = False query = query.filter_by(is_open=True).filter(models.DataIdentifier.did_type != DIDType.FILE)
values['length'], values['bytes'] = session.query(func.count(models.DataIdentifierAssociation.scope), values['is_open'] = False
func.sum(models.DataIdentifierAssociation.bytes)).filter_by(scope=scope, name=name).one() values['length'], values['bytes'], values['events'] = session.query(func.count(models.DataIdentifierAssociation.scope),
# Update datasetlocks as well func.sum(models.DataIdentifierAssociation.bytes),
session.query(models.DatasetLock).filter_by(scope=scope, name=name).update({'length': values['length'], 'bytes': values['bytes']}) func.sum(models.DataIdentifierAssociation.events)).filter_by(scope=scope, name=name).one()
# Update datasetlocks as well
session.query(models.DatasetLock).filter_by(scope=scope, name=name).update({'length': values['length'], 'bytes': values['bytes']})
else:
# Set status to open only for privileged accounts
query = query.filter_by(is_open=False).filter(models.DataIdentifier.did_type != DIDType.FILE)
values['is_open'] = True
rowcount = query.update(values, synchronize_session='fetch') rowcount = query.update(values, synchronize_session='fetch')
......
...@@ -392,6 +392,10 @@ def perm_set_status(issuer, kwargs): ...@@ -392,6 +392,10 @@ def perm_set_status(issuer, kwargs):
:param kwargs: List of arguments for the action. :param kwargs: List of arguments for the action.
:returns: True if account is allowed, otherwise False :returns: True if account is allowed, otherwise False
""" """
if kwargs.get('open', False):
if issuer != 'root' and issuer not in get_special_accounts():
return False
return issuer == 'root' or issuer in get_special_accounts() or rucio.core.scope.is_scope_owner(scope=kwargs['scope'], account=issuer) return issuer == 'root' or issuer in get_special_accounts() or rucio.core.scope.is_scope_owner(scope=kwargs['scope'], account=issuer)
......
...@@ -620,3 +620,39 @@ class TestDIDClients: ...@@ -620,3 +620,39 @@ class TestDIDClients:
# Add files to dataset # Add files to dataset
files = [{'scope': tmp_scope, 'name': tmp_file, 'bytes': 1L, 'adler32': '0cc737eb'}, ] files = [{'scope': tmp_scope, 'name': tmp_file, 'bytes': 1L, 'adler32': '0cc737eb'}, ]
self.did_client.attach_dids(scope=tmp_scope, name=tmp_dataset, dids=files) self.did_client.attach_dids(scope=tmp_scope, name=tmp_dataset, dids=files)
@raises
def test_open(self):
""" DATA IDENTIFIERS (CLIENT): test to re-open data identifiers for priv account"""
tmp_rse = 'MOCK'
tmp_scope = 'mock'
# Add dataset
tmp_dataset = 'dsn_%s' % generate_uuid()
# Add file replica
tmp_file = 'file_%s' % generate_uuid()
self.replica_client.add_replica(rse=tmp_rse, scope=tmp_scope, name=tmp_file, bytes=1L, adler32='0cc737eb')
# Add dataset
self.did_client.add_dataset(scope=tmp_scope, name=tmp_dataset)
# Add files to dataset
files = [{'scope': tmp_scope, 'name': tmp_file, 'bytes': 1L, 'adler32': '0cc737eb'}, ]
self.did_client.add_files_to_dataset(scope=tmp_scope, name=tmp_dataset, files=files)
# Add a second file replica
tmp_file = 'file_%s' % generate_uuid()
self.replica_client.add_replica(tmp_rse, tmp_scope, tmp_file, 1L, '0cc737eb')
# Add files to dataset
files = [{'scope': tmp_scope, 'name': tmp_file, 'bytes': 1L, 'adler32': '0cc737eb'}, ]
self.did_client.add_files_to_dataset(scope=tmp_scope, name=tmp_dataset, files=files)
# Close dataset
with assert_raises(UnsupportedStatus):
self.did_client.set_status(scope=tmp_scope, name=tmp_dataset, close=False)
self.did_client.set_status(scope=tmp_scope, name=tmp_dataset, open=False)
# Add a third file replica
self.did_client.set_status(scope=tmp_scope, name=tmp_dataset, open=True)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment