def post(self, account, rse_expression): """ Create or update an account limit. .. :quickref: GlobalAccountLimit; Create/update global account limits. :param account: Account name. :param rse_expression: RSE name. :status 201: Successfully created or updated. :status 401: Invalid auth token. :status 404: RSE not found. :status 404: Account not found """ parameters = json_parameters() bytes_param = param_get(parameters, 'bytes') try: set_global_account_limit( account=account, rse_expression=rse_expression, bytes_=bytes_param, issuer=request.environ.get('issuer'), vo=request.environ.get('vo'), ) except AccessDenied as error: return generate_http_error_flask(401, error) except (RSENotFound, AccountNotFound) as error: return generate_http_error_flask(404, error) return 'Created', 201
def post(self, account, rse_expression): """ --- summary: Create or update a global account limit tags: - Account Limit parameters: - name: account in: path description: The account for the accountlimit. schema: type: string style: simple - name: rse_expression in: path description: The rse expression for the accountlimit. schema: type: string style: simple requestBody: content: 'application/json': schema: type: object required: - bytes properties: bytes: description: The new limit in bytes. type: integer responses: 201: description: OK content: application/json: schema: type: string enum: ['Created'] 401: description: Invalid Auth Token 404: description: No RSE or account found for the given id. """ parameters = json_parameters() bytes_param = param_get(parameters, 'bytes') try: set_global_account_limit( account=account, rse_expression=rse_expression, bytes_=bytes_param, issuer=request.environ.get('issuer'), vo=request.environ.get('vo'), ) except AccessDenied as error: return generate_http_error_flask(401, error) except (RSENotFound, AccountNotFound) as error: return generate_http_error_flask(404, error) return 'Created', 201
def POST(self, account, rse_expression): """ Create or update an account limit. HTTP Success: 201 Created HTTP Error: 400 Bad Request 401 Unauthorized 404 Not Found 500 Internal Error :param X-Rucio-Auth-Account: Account identifier. :param X-Rucio-Auth-Token: As an 32 character hex string. :param account: Account name. :param rse_expression: RSE expression. """ json_data = data() try: parameter = loads(json_data) except ValueError: raise generate_http_error( 400, 'ValueError', 'cannot decode json parameter dictionary') try: bytes = parameter['bytes'] except KeyError as exception: if exception.args[0] == 'type': raise generate_http_error(400, 'KeyError', '%s not defined' % str(exception)) except TypeError: raise generate_http_error(400, 'TypeError', 'body must be a json dictionary') try: set_global_account_limit(account=account, rse_expression=rse_expression, bytes=bytes, issuer=ctx.env.get('issuer'), vo=ctx.env.get('vo')) except AccessDenied as exception: raise generate_http_error(401, 'AccessDenied', exception.args[0]) except RSENotFound as exception: raise generate_http_error(404, 'RSENotFound', exception.args[0]) except AccountNotFound as exception: raise generate_http_error(404, 'AccountNotFound', exception.args[0]) except Exception as exception: print(format_exc()) raise InternalError(exception) raise Created()
def post(self, account, rse_expression): """ Create or update an account limit. .. :quickref: GlobalAccountLimit; Create/update global account limits. :param account: Account name. :param rse_expression: RSE name. :status 201: Successfully created or updated. :status 401: Invalid auth token. :status 404: RSE not found. :status 404: Account not found """ json_data = request.data try: parameter = loads(json_data) except ValueError: return generate_http_error_flask( 400, 'ValueError', 'cannot decode json parameter dictionary') try: bytes = parameter['bytes'] except KeyError as error: if error.args[0] == 'type': return generate_http_error_flask(400, 'KeyError', '%s not defined' % str(error)) raise except TypeError: return generate_http_error_flask(400, 'TypeError', 'body must be a json dictionary') try: set_global_account_limit(account=account, rse_expression=rse_expression, bytes=bytes, issuer=request.environ.get('issuer'), vo=request.environ.get('vo')) except AccessDenied as error: return generate_http_error_flask(401, 'AccessDenied', error.args[0]) except RSENotFound as error: return generate_http_error_flask(404, 'RSENotFound', error.args[0]) except AccountNotFound as error: return generate_http_error_flask(404, 'AccountNotFound', error.args[0]) except Exception as error: print(format_exc()) return str(error), 500 return 'Created', 201
def test_api_account_limit(self): """ ACCOUNT_LIMIT (API): Test external representation of account limits """ # Add mock account limits rse_expr = '{}|{}'.format(self.rse_name, self.rse2_name) api_acc_lim.set_local_account_limit(self.account_name, self.rse_name, 10000, issuer='root', **self.vo) api_acc_lim.set_global_account_limit(self.account_name, rse_expr, 20000, issuer='root', **self.vo) out = api_acc_lim.get_local_account_limits(self.account_name, **self.vo) assert_in(self.rse_name, out) assert_not_in(self.rse_id, out) out = api_acc_lim.get_local_account_limit(self.account_name, self.rse_name, **self.vo) assert_in(self.rse_name, out) assert_not_in(self.rse_id, out) out = api_acc_lim.get_global_account_limits(self.account_name, **self.vo) assert_in(rse_expr, out) if self.multi_vo: assert_not_in('vo={}&({})'.format(self.vo['vo'], rse_expr), out) out = api_acc_lim.get_global_account_limit(self.account_name, rse_expr, **self.vo) assert_in(rse_expr, out) if self.multi_vo: assert_not_in('vo={}&({})'.format(self.vo['vo'], rse_expr), out) out = api_acc_lim.get_local_account_usage(self.account_name, self.rse_name, issuer='root', **self.vo) out = list(out) assert_not_equal(0, len(out)) assert_in(self.rse_id, [usage['rse_id'] for usage in out if 'rse_id' in usage]) for usage in out: if 'rse_id' in usage: assert_in('rse', usage) if usage['rse_id'] == self.rse_id: assert_equal(self.rse_name, usage["rse"]) out = api_acc_lim.get_global_account_usage(self.account_name, rse_expr, issuer='root', **self.vo) out = list(out) assert_not_equal(0, len(out)) assert_in(rse_expr, [usage['rse_expression'] for usage in out if 'rse_expression' in usage])
def test_api_account_limit(self): """ ACCOUNT_LIMIT (API): Test external representation of account limits """ # Add mock account limits rse_expr = '{}|{}'.format(self.rse_name, self.rse2_name) api_acc_lim.set_local_account_limit(self.account_name, self.rse_name, 10000, issuer='root', **self.vo) api_acc_lim.set_global_account_limit(self.account_name, rse_expr, 20000, issuer='root', **self.vo) out = api_acc_lim.get_local_account_limits(self.account_name, **self.vo) assert self.rse_name in out assert self.rse_id not in out out = api_acc_lim.get_local_account_limit(self.account_name, self.rse_name, **self.vo) assert self.rse_name in out assert self.rse_id not in out out = api_acc_lim.get_global_account_limits(self.account_name, **self.vo) assert rse_expr in out if self.multi_vo: assert 'vo={}&({})'.format(self.vo['vo'], rse_expr) not in out out = api_acc_lim.get_global_account_limit(self.account_name, rse_expr, **self.vo) assert rse_expr in out if self.multi_vo: assert 'vo={}&({})'.format(self.vo['vo'], rse_expr) not in out out = api_acc_lim.get_local_account_usage(self.account_name, self.rse_name, issuer='root', **self.vo) out = list(out) assert 0 != len(out) assert self.rse_id in [usage['rse_id'] for usage in out if 'rse_id' in usage] for usage in out: if 'rse_id' in usage: assert 'rse' in usage if usage['rse_id'] == self.rse_id: assert self.rse_name == usage["rse"] out = api_acc_lim.get_global_account_usage(self.account_name, rse_expr, issuer='root', **self.vo) out = list(out) assert 0 != len(out) assert rse_expr in [usage['rse_expression'] for usage in out if 'rse_expression' in usage]