def setUp(self): self.db_session.query(models.Request).delete() remove_option('throttler', '%s,%s' % (self.user_activity, self.dest_rse), session=self.db_session) remove_option('throttler', '%s,%s' % (self.all_activities, self.dest_rse), session=self.db_session) self.db_session.commit()
def dest_throttler(db_session, mock_request): config.set('throttler', 'mode', 'DEST_PER_ACT', session=db_session) set_rse_transfer_limits(mock_request.dest_rse_id, activity=mock_request.activity, max_transfers=1, strategy='fifo', session=db_session) db_session.commit() yield db_session.query(models.RSETransferLimit).filter_by( rse_id=mock_request.dest_rse_id).delete() config.remove_option('throttler', 'mode', session=db_session) db_session.commit()
def remove_option(section, option, issuer=None): """ Remove the specified section from the configuration. :param section: The name of the section. :param option: The name of the option. :param issuer: The issuer account. :returns: True/False """ kwargs = {'issuer': issuer, 'section': section, 'option': option} if not permission.has_permission(issuer=issuer, action='config_remove_option', kwargs=kwargs): raise exception.AccessDenied('%s cannot remove option %s from section %s' % (issuer, option, section)) return config.remove_option(section, option)
def remove_option(section, option, issuer=None): """ Remove the specified section from the configuration. :param section: The name of the section. :param option: The name of the option. :param issuer: The issuer account. :returns: True/False """ kwargs = {'issuer': issuer, 'section': section, 'option': option} if not permission.has_permission(issuer=issuer, action='config_remove_option', kwargs=kwargs): raise exception.AccessDenied('%s cannot remove option %s from section %s' % (issuer, option, section)) return config.remove_option(section, option)
def test_lifetime_creation_core(root_account, rse_factory, mock_scope, did_factory): """ Test the creation of a lifetime exception on the core side """ nb_datatype = 3 nb_datasets = 2 * nb_datatype yesterday = datetime.now() - timedelta(days=1) tomorrow = datetime.now() + timedelta(days=1) rse, rse_id = rse_factory.make_posix_rse() datasets = [did_factory.make_dataset() for _ in range(nb_datasets)] metadata = [str(uuid()) for _ in range(nb_datatype)] list_dids = [] for cnt, meta in enumerate(metadata): dids = [] for dataset in datasets[2 * cnt:2 * (cnt + 1)]: set_metadata(dataset['scope'], dataset['name'], 'datatype', meta) if cnt < nb_datatype - 1: set_metadata(dataset['scope'], dataset['name'], 'eol_at', yesterday) dids.append((dataset['scope'], dataset['name'])) dids.sort() list_dids.append(dids) datasets.extend([{ 'scope': mock_scope, 'name': 'dataset_%s' % str(uuid()), 'did_type': DIDType.DATASET } for _ in range(2)]) # Test with cutoff_date not defined try: config_core.remove_option('lifetime_model', 'cutoff_date') except (ConfigNotFound, NoSectionError): pass with pytest.raises(UnsupportedOperation): add_exception(datasets, root_account, pattern='wekhewfk', comments='This is a comment', expires_at=datetime.now()) # Test with cutoff_date wrongly defined config_core.set(section='lifetime_model', option='cutoff_date', value='wrong_value') config_core.get(section='lifetime_model', option='cutoff_date', default=None, use_cache=False) with pytest.raises(UnsupportedOperation): add_exception(datasets, root_account, pattern='wekhewfk', comments='This is a comment', expires_at=datetime.now()) # Test with cutoff_date properly defined tomorrow = tomorrow.strftime('%Y-%m-%d') config_core.set(section='lifetime_model', option='cutoff_date', value=tomorrow) config_core.get(section='lifetime_model', option='cutoff_date', default=None, use_cache=False) result = add_exception(datasets, root_account, pattern='wekhewfk', comments='This is a comment', expires_at=datetime.now()) # Check if the Not Existing DIDs are identified result_unknown = [(entry['scope'], entry['name']) for entry in result['unknown']] result_unknown.sort() unknown = [(entry['scope'], entry['name']) for entry in datasets[nb_datasets:nb_datasets + 2]] unknown.sort() assert result_unknown == unknown # Check if the DIDs not affected by the Lifetime Model are identified result_not_affected = [(entry['scope'], entry['name']) for entry in result['not_affected']] result_not_affected.sort() not_affected = list_dids[-1] assert result_not_affected == not_affected # Check if an exception was done for each datatype list_exceptions = list() for exception_id in result['exceptions']: dids = [(entry['scope'], entry['name']) for entry in result['exceptions'][exception_id]] dids.sort() list_exceptions.append(dids) for did in list_dids[:nb_datatype - 1]: assert did in list_exceptions