Skip to content

Commit

Permalink
Rules: Correct rule for file query to include bytes #6348
Browse files Browse the repository at this point in the history
  • Loading branch information
voetberg committed Mar 14, 2024
1 parent 1fc0c97 commit f7088ef
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/rucio/core/rule.py
Expand Up @@ -1084,10 +1084,10 @@ def list_associated_rules_for_file(
: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
stmt = select(
models.ReplicationRule
models.ReplicationRule,
models.DataIdentifier.bytes
).distinct(
).join(
models.ReplicaLock,
Expand All @@ -1100,8 +1100,10 @@ def list_associated_rules_for_file(
)

try:
for result in session.execute(stmt).yield_per(5):
yield result[0].to_dict()
for result, data_identifier_bytes in session.execute(stmt).yield_per(5):
d = result[0].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 @@ -1381,6 +1381,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 f7088ef

Please sign in to comment.