Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch 6348 list rules keyerror #6377

Merged
merged 1 commit into from Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 10 additions & 5 deletions lib/rucio/core/rule.py
Expand Up @@ -1084,24 +1084,29 @@ 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,
models.ReplicationRule.id == models.ReplicaLock.rule_id
).join(
models.DataIdentifier,
and_(models.ReplicationRule.scope == models.DataIdentifier.scope,
models.ReplicationRule.name == models.DataIdentifier.name)
).with_hint(
models.ReplicaLock, 'INDEX(LOCKS LOCKS_PK)', 'oracle'
).where(
and_(models.ReplicaLock.scope == scope,
models.ReplicaLock.name == name)
)

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