def post(self): """ Attach DIDs to DIDs .. :quickref: Attachements; Attach DIDs to DIDs. """ # To be moved in a common processor attachments, ignore_duplicate = [], False try: json_data = loads(request.data) if type(json_data) is dict: attachments = json_data.get('attachments') ignore_duplicate = json_data.get('ignore_duplicate') elif type(json_data) is list: attachments = json_data except ValueError: return generate_http_error_flask( 400, 'ValueError', 'Cannot decode json parameter list') try: attach_dids_to_dids(attachments=attachments, ignore_duplicate=ignore_duplicate, issuer=request.environ.get('issuer')) except DataIdentifierNotFound, error: return generate_http_error_flask(404, 'DataIdentifierNotFound', error.args[0][0])
def post(self): """ Attach DIDs to DIDs .. :quickref: Attachements; Attach DIDs to DIDs. """ parameters = json_parse((dict, list)) if isinstance(parameters, list): attachments = parameters ignore_duplicate = False else: assert isinstance(parameters, dict) attachments = param_get(parameters, 'attachments') ignore_duplicate = param_get(parameters, 'ignore_duplicate', default=False) try: attach_dids_to_dids(attachments=attachments, ignore_duplicate=ignore_duplicate, issuer=request.environ.get('issuer'), vo=request.environ.get('vo')) except DataIdentifierNotFound as error: return generate_http_error_flask(404, error) except (DuplicateContent, DataIdentifierAlreadyExists, UnsupportedOperation, FileAlreadyExists) as error: return generate_http_error_flask(409, error) except AccessDenied as error: return generate_http_error_flask(401, error) except FileConsistencyMismatch as error: return generate_http_error_flask(412, error) return 'Created', 201
def test_api_did(self): """ DID (API): Test external representation of DIDs """ # add some dids add_did(self.scope_name, 'ext_parent', 'container', issuer='root', account=self.account_name, **self.vo) add_did(self.scope_name, 'ext_child', 'dataset', issuer='root', account=self.account_name, **self.vo) attachment = {'scope': self.scope_name, 'name': 'ext_parent', 'dids': [{'scope': self.scope_name, 'name': 'ext_child', 'type': 'DATASET'}]} attach_dids_to_dids([attachment], issuer='root', **self.vo) # test scope_list out = scope_list(self.scope_name, recursive=True, **self.vo) out = list(out) assert_not_equal(0, len(out)) parent_found = False for did in out: assert_equal(did['scope'], self.scope_name) if did['parent'] is not None: parent_found = True assert_equal(did['parent']['scope'], self.scope_name) assert_true(parent_found) # test get_did add_did_to_followed(self.scope_name, 'ext_parent', self.account_name, **self.vo) out = get_users_following_did('ext_parent', self.scope_name, **self.vo) out = list(out) assert_not_equal(0, len(out)) for user in out: assert_equal(user['user'], self.account_name)
def POST(self): # To be moved in a common processor attachments, ignore_duplicate = [], False try: json_data = loads(data()) if type(json_data) is dict: attachments = json_data.get('attachments') ignore_duplicate = json_data.get('ignore_duplicate') elif type(json_data) is list: attachments = json_data except ValueError: raise generate_http_error(400, 'ValueError', 'Cannot decode json parameter list') try: attach_dids_to_dids(attachments=attachments, ignore_duplicate=ignore_duplicate, issuer=ctx.env.get('issuer')) except DataIdentifierNotFound as error: raise generate_http_error(404, 'DataIdentifierNotFound', error.args[0]) except DuplicateContent as error: raise generate_http_error(409, 'DuplicateContent', error.args[0]) except DataIdentifierAlreadyExists as error: raise generate_http_error(409, 'DataIdentifierAlreadyExists', error.args[0]) except AccessDenied as error: raise generate_http_error(401, 'AccessDenied', error.args[0]) except UnsupportedOperation as error: raise generate_http_error(409, 'UnsupportedOperation', error.args[0]) except RucioException as error: raise generate_http_error(500, error.__class__.__name__, error.args[0]) except Exception as error: print(format_exc()) raise InternalError(error) raise Created()
def test_api_did(self): """ DID (API): Test external representation of DIDs """ # add some dids ext_parent = did_name_generator('container') ext_child = did_name_generator('dataset') add_did(self.scope_name, ext_parent, 'container', issuer='root', account=self.account_name, **self.vo) add_did(self.scope_name, ext_child, 'dataset', issuer='root', account=self.account_name, **self.vo) attachment = { 'scope': self.scope_name, 'name': ext_parent, 'dids': [{ 'scope': self.scope_name, 'name': ext_child, 'type': 'DATASET' }] } attach_dids_to_dids([attachment], issuer='root', **self.vo) # test scope_list out = scope_list(self.scope_name, recursive=True, **self.vo) out = list(out) assert 0 != len(out) parent_found = False for did in out: assert did['scope'] == self.scope_name if did['parent'] is not None: parent_found = True assert did['parent']['scope'] == self.scope_name assert parent_found # test get_did add_did_to_followed(self.scope_name, ext_parent, self.account_name, **self.vo) out = get_users_following_did(ext_parent, self.scope_name, **self.vo) out = list(out) assert 0 != len(out) for user in out: assert user['user'] == self.account_name
def post(self): """ Attach DIDs to DIDs .. :quickref: Attachements; Attach DIDs to DIDs. """ # To be moved in a common processor attachments, ignore_duplicate = [], False try: json_data = loads(request.data) if type(json_data) is dict: attachments = json_data.get('attachments') ignore_duplicate = json_data.get('ignore_duplicate') elif type(json_data) is list: attachments = json_data except ValueError: return generate_http_error_flask( 400, 'ValueError', 'Cannot decode json parameter list') try: attach_dids_to_dids(attachments=attachments, ignore_duplicate=ignore_duplicate, issuer=request.environ.get('issuer')) except DataIdentifierNotFound as error: return generate_http_error_flask(404, 'DataIdentifierNotFound', error.args[0]) except DuplicateContent as error: return generate_http_error_flask(409, 'DuplicateContent', error.args[0]) except DataIdentifierAlreadyExists as error: return generate_http_error_flask(409, 'DataIdentifierAlreadyExists', error.args[0]) except AccessDenied as error: return generate_http_error_flask(401, 'AccessDenied', error.args[0]) except UnsupportedOperation as error: return generate_http_error_flask(409, 'UnsupportedOperation', error.args[0]) except RucioException as error: return generate_http_error_flask(500, error.__class__.__name__, error.args[0]) except Exception as error: print format_exc() return error, 500 return "Created", 201
def POST(self): # To be moved in a common processor attachments, ignore_duplicate = [], False try: json_data = loads(data()) if type(json_data) is dict: attachments = json_data.get('attachments') ignore_duplicate = json_data.get('ignore_duplicate') elif type(json_data) is list: attachments = json_data except ValueError: raise generate_http_error(400, 'ValueError', 'Cannot decode json parameter list') try: attach_dids_to_dids(attachments=attachments, ignore_duplicate=ignore_duplicate, issuer=ctx.env.get('issuer')) except DataIdentifierNotFound, error: raise generate_http_error(404, 'DataIdentifierNotFound', error.args[0][0])
def test_api_replica(self): """ REPLICA (API): Test external representation of replicas """ did = 'ext_' + str(generate_uuid()) pfn = 'srm://mock2.com:8443/srm/managerv2?SFN=/rucio/tmpdisk/rucio_tests/%s/%s' % (self.scope_name, generate_uuid()) add_replicas(self.rse2_name, files=[{'scope': self.scope_name, 'name': did, 'bytes': 100, 'pfn': pfn}], issuer='root', **self.vo) add_did(self.scope_name, 'ext_parent_2', 'dataset', issuer='root', account=self.account_name, **self.vo) attachment = {'scope': self.scope_name, 'name': 'ext_parent_2', 'dids': [{'scope': self.scope_name, 'name': did}]} attach_dids_to_dids([attachment], issuer='root', **self.vo) out = get_did_from_pfns([pfn], self.rse2_name, **self.vo) out = list(out) assert_not_equal(0, len(out)) did_found = False for p in out: for key in p: if p[key]['name'] == did: did_found = True assert_equal(self.scope_name, p[key]['scope']) assert_true(did_found) out = list_replicas(dids=[{'scope': self.scope_name, 'name': did}], resolve_parents=True, **self.vo) out = list(out) assert_not_equal(0, len(out)) parents_found = False for rep in out: assert_equal(rep['scope'], self.scope_name) if 'parents' in rep: parents_found = True for parent in rep['parents']: assert_in(self.scope_name, parent) if self.multi_vo: assert_not_in(self.scope.internal, parent) assert_true(parents_found)
def test_api_replica(self): """ REPLICA (API): Test external representation of replicas """ did = did_name_generator('file') did_parent = did_name_generator('dataset') pfn = 'srm://mock2.com:8443/srm/managerv2?SFN=/rucio/tmpdisk/rucio_tests/%s/%s' % ( self.scope_name, generate_uuid()) add_replicas(self.rse2_name, files=[{ 'scope': self.scope_name, 'name': did, 'bytes': 100, 'pfn': pfn }], issuer='root', **self.vo) add_did(self.scope_name, did_parent, 'dataset', issuer='root', account=self.account_name, **self.vo) attachment = { 'scope': self.scope_name, 'name': did_parent, 'dids': [{ 'scope': self.scope_name, 'name': did }] } attach_dids_to_dids([attachment], issuer='root', **self.vo) out = get_did_from_pfns([pfn], self.rse2_name, **self.vo) out = list(out) assert 0 != len(out) did_found = False for p in out: for key in p: if p[key]['name'] == did: did_found = True assert self.scope_name == p[key]['scope'] assert did_found out = list_replicas(dids=[{ 'scope': self.scope_name, 'name': did }], resolve_parents=True, **self.vo) out = list(out) assert 0 != len(out) parents_found = False for rep in out: assert rep['scope'] == self.scope_name if 'parents' in rep: parents_found = True for parent in rep['parents']: assert self.scope_name in parent if self.multi_vo: assert self.scope.internal not in parent assert parents_found