Skip to content

Commit

Permalink
Rules: Listing rules includes bytes when querying by file Fix: #6348
Browse files Browse the repository at this point in the history
  • Loading branch information
voetberg committed Feb 19, 2024
1 parent 7bbdf63 commit bdecfac
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/rucio/core/rule.py
Expand Up @@ -888,15 +888,16 @@ def list_associated_rules_for_file(scope, name, *, session: "Session"):
:param session: The database session in use.
:raises: RucioException
"""

rucio.core.did.get_did(scope=scope, name=name, session=session) # Check if the did acually exists
query = session.query(models.ReplicationRule).\
query = session.query(models.ReplicationRule, models.DataIdentifier.bytes).\
with_hint(models.ReplicaLock, "INDEX(LOCKS LOCKS_PK)", 'oracle').\
join(models.ReplicaLock, models.ReplicationRule.id == models.ReplicaLock.rule_id).\
filter(models.ReplicaLock.scope == scope, models.ReplicaLock.name == name).distinct()
try:
for rule in query.yield_per(5):
yield rule.to_dict()
for rule, data_identifier_bytes in session.execute(query).yield_per(5):
d = rule.to_dict()
d['bytes'] = data_identifier_bytes
yield d
except StatementError as exc:
raise RucioException('Badly formatted input (IDs?)') from exc

Expand Down
15 changes: 15 additions & 0 deletions tests/test_rule.py
Expand Up @@ -1382,6 +1382,21 @@ def test_list_rules_by_did(self, mock_scope, did_factory, jdoe_account, rucio_cl
assert rule_id_1 in ids
assert rule_id_2 in ids

def test_list_rules_by_name(self, mock_scope, did_factory, jdoe_account, rucio_client):
""" NAME (CLIENT): List Replication Rules per NAME """
files = create_files(1, mock_scope, self.rse1_id)
dataset = did_factory.random_dataset_did()
add_did(did_type=DIDType.DATASET, account=jdoe_account, **dataset)
attach_dids(dids=files, account=jdoe_account, **dataset)

rule_id_1 = add_rule(dids=[dataset], account=jdoe_account, copies=1, rse_expression=self.rse1, grouping='NONE', weight='fakeweight', lifetime=None, locked=False, subscription_id=None)[0]
rule_id_2 = add_rule(dids=[dataset], account=jdoe_account, copies=1, rse_expression=self.rse2, grouping='NONE', weight='fakeweight', lifetime=None, locked=False, subscription_id=None)[0]
ret = rucio_client.list_associated_rules_for_file(scope=mock_scope.external, name=files[0]['name'])
ids = [rule['id'] for rule in ret]

assert rule_id_1 in ids
assert rule_id_2 in ids

def test_get_rule(self, mock_scope, did_factory, jdoe_account):
""" REPLICATION RULE (CLIENT): Get Replication Rule by id """
activity = get_schema_value('ACTIVITY')['enum'][0]
Expand Down

0 comments on commit bdecfac

Please sign in to comment.