def get_account_usage(account, rse, issuer): """ Get the account usage and connect it with (if available) the account limits of the account. :param account: The account to read. :param rse: The rse to read (If none, get all). :param issuer: The issuer account. :returns: List of dicts {'rse_id', 'bytes_used', 'files_used', 'bytes_limit'} """ rse_id = None if rse: rse_id = get_rse_id(rse=rse) kwargs = {'account': account, 'rse': rse, 'rse_id': rse_id} if not rucio.api.permission.has_permission( issuer=issuer, action='get_account_usage', kwargs=kwargs): raise rucio.common.exception.AccessDenied( 'Account %s can not list account usage.' % (issuer)) account = InternalAccount(account) if not account_exists(account=account): raise rucio.common.exception.AccountNotFound( 'Account %s does not exist' % (account)) return [ api_update_return_dict(d) for d in account_limit_core.get_account_usage(account=account, rse_id=rse_id) ]
def test_abacus_account(self): """ ABACUS (ACCOUNT): Test update of account usage """ self.session.query(models.UpdatedAccountCounter).delete() # pylint: disable=no-member self.session.query(models.AccountUsage).delete() # pylint: disable=no-member self.session.commit() # pylint: disable=no-member # Upload files -> account usage should increase self.files = [{ 'did_scope': self.scope.external, 'did_name': 'file_' + generate_uuid(), 'path': file_generator(size=self.file_sizes), 'rse': self.rse, 'lifetime': -1 } for i in range(0, 2)] self.upload_client.upload(self.files) [os.remove(file['path']) for file in self.files] account.run(once=True) account_usage = get_account_usage(account=self.account, rse_id=self.rse_id)[0] assert_equal(account_usage['bytes'], len(self.files) * self.file_sizes) assert_equal(account_usage['files'], len(self.files)) # Update and check the account history with the core method update_account_counter_history(account=self.account, rse_id=self.rse_id) usage_history = get_usage_history(rse_id=self.rse_id, account=self.account) assert_equal(usage_history[-1]['bytes'], len(self.files) * self.file_sizes) assert_equal(usage_history[-1]['files'], len(self.files)) # Check the account history with the client usage_history = self.account_client.get_account_usage_history( rse=self.rse, account=self.account.external) assert_equal(usage_history[-1]['bytes'], len(self.files) * self.file_sizes) assert_equal(usage_history[-1]['files'], len(self.files)) # Delete rules -> account usage should decrease cleaner.run(once=True) account.run(once=True) # set account limit because return value of get_account_usage differs if a limit is set or not set_account_limit(account=self.account, rse_id=self.rse_id, bytes=10) account_usages = get_account_usage(account=self.account, rse_id=self.rse_id)[0] assert_equal(account_usages['bytes'], 0) assert_equal(account_usages['files'], 0)
def get_account_usage(account, rse, issuer): """ Get the account usage and connect it with (if available) the account limits of the account. :param account: The account to read. :param rse: The rse to read (If none, get all). :param issuer: The issuer account. :returns: List of dicts {'rse_id', 'bytes_used', 'files_used', 'bytes_limit'} """ kwargs = {'account': account, 'rse': rse} if not rucio.api.permission.has_permission(issuer=issuer, action='get_account_usage', kwargs=kwargs): raise rucio.common.exception.AccessDenied('Account %s can not list account usage.' % (issuer)) if not account_exists(account=account): raise rucio.common.exception.AccountNotFound('Account %s does not exist' % (account)) rse_id = None if rse: rse_id = get_rse_id(rse=rse) return account_limit_core.get_account_usage(account=account, rse_id=rse_id)