Skip to content

Commit

Permalink
Core: allow move_rule to override all options Fix rucio#4995
Browse files Browse the repository at this point in the history
Before the commit `move_rule` could only override two attributes of the new
rule. After the commit `move_rule` can override every field of the new rule with
the argument `override`.
  • Loading branch information
Joel Dierkes committed Nov 16, 2021
1 parent e2589ad commit 157aeb6
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 22 deletions.
3 changes: 1 addition & 2 deletions lib/rucio/api/rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,5 +318,4 @@ def move_replication_rule(rule_id, rse_expression, activity, source_replica_expr

return rule.move_rule(rule_id=rule_id,
rse_expression=rse_expression,
activity=activity,
source_replica_expression=source_replica_expression)
override={'activity': activity, 'source_replica_expression': source_replica_expression})
49 changes: 30 additions & 19 deletions lib/rucio/core/rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -1419,14 +1419,13 @@ def reduce_rule(rule_id, copies, exclude_expression=None, session=None):


@transactional_session
def move_rule(rule_id, rse_expression, activity=None, source_replica_expression=None, session=None):
def move_rule(rule_id, rse_expression, override={}, session=None):
"""
Move a replication rule to another RSE and, once done, delete the original one.
:param rule_id: Rule to be moved.
:param rse_expression: RSE expression of the new rule.
:param activity: Activity of the new rule.
:param source_replica_expression: Source-Replica-Expression of the new rule.
:param override: Dict[str, Any], Configurations to update for the new rule.
:param session: The DB Session.
:raises: RuleNotFound, RuleReplaceFailed, InvalidRSEExpression
"""
Expand All @@ -1445,22 +1444,34 @@ def move_rule(rule_id, rse_expression, activity=None, source_replica_expression=

notify = {RuleNotification.YES: 'Y', RuleNotification.CLOSE: 'C', RuleNotification.PROGRESS: 'P'}.get(rule.notification, 'N')

new_rule_id = add_rule(dids=[{'scope': rule.scope, 'name': rule.name}],
account=rule.account,
copies=rule.copies,
rse_expression=rse_expression,
grouping=grouping,
weight=rule.weight,
lifetime=lifetime,
locked=rule.locked,
subscription_id=rule.subscription_id,
source_replica_expression=source_replica_expression if source_replica_expression else rule.source_replica_expression,
activity=activity if activity else rule.activity,
notify=notify,
purge_replicas=rule.purge_replicas,
ignore_availability=rule.ignore_availability,
comment=rule.comments,
session=session)
options = {
'dids': [{'scope': rule.scope, 'name': rule.name}],
'account': rule.account,
'copies': rule.copies,
'rse_expression': rse_expression,
'grouping': grouping,
'weight': rule.weight,
'lifetime': lifetime,
'locked': rule.locked,
'subscription_id': rule.subscription_id,
'source_replica_expression': rule.source_replica_expression,
'activity': rule.activity,
'notify': notify,
'purge_replicas': rule.purge_replicas,
'ignore_availability': rule.ignore_availability,
'comment': rule.comments,
'session': session,
}

for key in override:
if key in ['dids', 'session']:
raise Exception('Not allowed to override option %s' % key)
elif key not in options:
raise Exception('Non-valid override option %s' % key)
else:
options[key] = override[key]

new_rule_id = add_rule(**options)

session.flush()

Expand Down
2 changes: 1 addition & 1 deletion lib/rucio/tests/test_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -932,7 +932,7 @@ def test_move_rule_with_arguments(self):

activity = "No User Subscriptions"
source_replica_expression = self.rse3 + "|" + self.rse1
rule_id2 = move_rule(rule_id, self.rse3, activity=activity, source_replica_expression=source_replica_expression)
rule_id2 = move_rule(rule_id, self.rse3, override={'activity': activity, 'source_replica_expression': source_replica_expression})

assert(get_rule(rule_id2)['state'] == RuleState.REPLICATING)
assert(get_rule(rule_id)['child_rule_id'] == rule_id2)
Expand Down

0 comments on commit 157aeb6

Please sign in to comment.