def set_dids_metadata_bulk(dids, issuer, recursive=False, vo='def'): """ Add metadata to a list of data identifiers. :param issuer: The issuer account. :param dids: A list of dids including metadata. :param recursive: Option to propagate the metadata update to content. :param vo: The VO to act on. """ for entry in dids: kwargs = { 'scope': entry['scope'], 'name': entry['name'], 'meta': entry['meta'], 'issuer': issuer } 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, entry['scope'], entry['name'])) entry['scope'] = InternalScope(entry['scope'], vo=vo) meta = entry['meta'] 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, entry['scope'], entry['name'])) return did.set_dids_metadata_bulk(dids=dids, recursive=recursive)
def test_set_dids_metadata_bulk_multi(did_factory): """ DID (CORE) : Test setting metadata in bulk with multiple key-values on multiple dids""" skip_without_json() nb_dids = 5 dids = [did_factory.make_dataset() for _ in range(nb_dids)] for did in dids: testkeys = list(map(lambda i: 'testkey' + generate_uuid(), range(3))) testmeta = {key: key + 'value' for key in testkeys} did['meta'] = testmeta print(dids) set_dids_metadata_bulk(dids=dids, recursive=False) for did in dids: testmeta = did['meta'] print('Metadata:', testmeta) meta = get_metadata(plugin="ALL", scope=did['scope'], name=did['name']) print('Metadata:', meta) for testkey in testmeta: assert testkey in meta and meta[testkey] == testmeta[testkey]