def update_replication_rule(rule_id, options, issuer, vo='def'): """ Update lock state of a replication rule. :param rule_id: The rule_id to lock. :param options: Options dictionary. :param issuer: The issuing account of this operation :param vo: The VO to act on. :raises: RuleNotFound if no Rule can be found. """ kwargs = {'rule_id': rule_id, 'options': options} if 'approve' in options: if not has_permission( issuer=issuer, vo=vo, action='approve_rule', kwargs=kwargs): raise AccessDenied( 'Account %s can not approve/deny this replication rule.' % (issuer)) issuer = InternalAccount(issuer, vo=vo) if options['approve']: rule.approve_rule(rule_id=rule_id, approver=issuer) else: rule.deny_rule(rule_id=rule_id, approver=issuer, reason=options.get('comment', None)) else: if not has_permission( issuer=issuer, vo=vo, action='update_rule', kwargs=kwargs): raise AccessDenied( 'Account %s can not update this replication rule.' % (issuer)) rule.update_rule(rule_id=rule_id, options=options)
def test_add_rule_with_r2d2_container_treating_and_duplicate_rule(self): """ JUDGE INJECTOR (CORE): Add a replication rule with an r2d2 container treatment and duplicate rule""" scope = 'mock' container = 'asdf.r2d2_request.2016-04-01-15-00-00.ads.' + str(uuid()) add_did(scope, container, DIDType.from_sym('CONTAINER'), 'jdoe') datasets = [] for i in range(3): files = create_files(3, scope, self.rse1_id) dataset = 'dataset_' + str(uuid()) datasets.append(dataset) add_did(scope, dataset, DIDType.from_sym('DATASET'), 'jdoe') attach_dids(scope, dataset, files, 'jdoe') attach_dids(scope, container, [{ 'scope': scope, 'name': dataset }], 'jdoe') add_rule(dids=[{ 'scope': scope, 'name': dataset }], account='jdoe', copies=1, rse_expression=self.rse1, grouping='DATASET', weight=None, lifetime=900, locked=False, subscription_id=None, ask_approval=False) rule_id = add_rule(dids=[{ 'scope': scope, 'name': container }], account='jdoe', copies=1, rse_expression=self.rse1, grouping='DATASET', weight=None, lifetime=900, locked=False, subscription_id=None, ask_approval=True)[0] approve_rule(rule_id, approver='root') assert (get_rule(rule_id)['state'] == RuleState.INJECT) rule_injector(once=True) # Check if there is a rule for each file with assert_raises(RuleNotFound): get_rule(rule_id) for dataset in datasets: assert (len( [r for r in list_rules({ 'scope': scope, 'name': dataset })]) > 0)
def test_judge_ask_approval(self): """ JUDGE INJECTOR: Test the judge when asking approval for a rule""" scope = InternalScope('mock') files = create_files(3, scope, self.rse1_id) dataset = 'dataset_' + str(uuid()) add_did(scope, dataset, DIDType.from_sym('DATASET'), self.jdoe) attach_dids(scope, dataset, files, self.jdoe) # Add a first rule to the DS rule_id = add_rule(dids=[{'scope': scope, 'name': dataset}], account=self.jdoe, copies=1, rse_expression=self.rse4, grouping='DATASET', weight=None, lifetime=None, locked=False, subscription_id=None, ask_approval=True)[0] assert(get_rule(rule_id)['state'] == RuleState.WAITING_APPROVAL) approve_rule(rule_id=rule_id, approver=self.jdoe) assert(get_rule(rule_id)['state'] == RuleState.INJECT) rule_injector(once=True) # Check if the Locks are created properly for file in files: assert(len(get_replica_locks(scope=file['scope'], name=file['name'])) == 1) assert(get_rule(rule_id)['state'] == RuleState.REPLICATING)