def test_did_set_metadata_bulk_single(testdid): """ DID (CORE) : Test setting metadata in bulk with a single key-value pair """ skip_without_json() testkey = 'testkey' testmeta = {testkey: 'testvalue'} set_metadata_bulk(meta=testmeta, recursive=False, **testdid) meta = get_metadata(plugin="ALL", **testdid) print('Metadata:', meta) assert testkey in meta and meta[testkey] == testmeta[testkey]
def test_did_set_metadata_bulk_multi(testdid): """ DID (CORE) : Test setting metadata in bulk with multiple key-values """ skip_without_json() testkeys = list(map(lambda i: 'testkey' + str(i), range(3))) testmeta = {key: key + 'value' for key in testkeys} # let two keys have the same value testmeta[testkeys[1]] = testmeta[testkeys[0]] set_metadata_bulk(meta=testmeta, recursive=False, **testdid) meta = get_metadata(plugin="ALL", **testdid) print('Metadata:', meta) for testkey in testkeys: assert testkey in meta and meta[testkey] == testmeta[testkey]
def set_metadata_bulk(scope, name, meta, issuer, recursive=False, vo='def'): """ Add metadata to data did. :param scope: The scope name. :param name: The data identifier name. :param meta: the key-values. :param issuer: The issuer account. :param recursive: Option to propagate the metadata update to content. :param vo: The VO to act on. """ kwargs = {'scope': scope, 'name': name, 'meta': meta, 'issuer': issuer} for key in meta: if key in RESERVED_KEYS: raise rucio.common.exception.AccessDenied( 'Account %s can not change the value of the metadata key %s to data identifier %s:%s' % (issuer, key, scope, name)) if not rucio.api.permission.has_permission( issuer=issuer, vo=vo, action='set_metadata_bulk', kwargs=kwargs): raise rucio.common.exception.AccessDenied( 'Account %s can not add metadata to data identifier %s:%s' % (issuer, scope, name)) scope = InternalScope(scope, vo=vo) return did.set_metadata_bulk(scope=scope, name=name, meta=meta, recursive=recursive)