Skip to content

Commit 6442f5e

Browse files
voetbergrdimaio
authored andcommitted
Client: Add command to route to list_datasets_per_rse rucio#7801
1 parent 8769257 commit 6442f5e

File tree

3 files changed

+35
-7
lines changed

3 files changed

+35
-7
lines changed

bin/rucio

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ def map_legacy_command() -> Optional[list[str]]:
5454
command_map = {
5555
"list-file-replicas": ["replica", "list", "file"],
5656
"list-dataset-replicas": ["replica", "list", "dataset"],
57+
"list-datasets-rse": ["replica", "list", "dataset", "--rse"],
5758
"add-dataset": ["did", "add", "--type dataset"],
5859
"add-container": ["did", "add", "--type container"],
5960
"attach": ["did", "content", "add"],

lib/rucio/cli/replica.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,17 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14+
from typing import TYPE_CHECKING, Optional
15+
1416
import click
1517

16-
from rucio.cli.bin_legacy.rucio import list_dataset_replicas, list_file_replicas, list_suspicious_replicas
18+
from rucio.cli.bin_legacy.rucio import list_dataset_replicas, list_datasets_rse, list_file_replicas, list_suspicious_replicas
1719
from rucio.cli.bin_legacy.rucio_admin import declare_bad_file_replicas, declare_temporary_unavailable_replicas, quarantine_replicas, set_tombstone
1820
from rucio.cli.utils import Arguments
1921

22+
if TYPE_CHECKING:
23+
from collections.abc import Sequence
24+
2025

2126
@click.group()
2227
def replica():
@@ -60,13 +65,18 @@ def list_(ctx, dids, protocols, all_states, pfns, domain, link, missing, metalin
6065

6166
@replica_list.command("dataset")
6267
@click.argument("dids", nargs=-1)
68+
@click.option("--rse", default=None, help="RSE name to use a filter")
6369
@click.option("--deep", default=False, is_flag=True, help="Make a deep check, checking the contents of datasets in datasets")
6470
@click.option("--csv", help="Write output to comma separated values", is_flag=True, default=False)
6571
@click.pass_context
66-
def list_dataset(ctx, dids, deep, csv):
67-
"""List dataset replicas"""
68-
args = Arguments({"no_pager": ctx.obj.no_pager, "dids": dids, "deep": deep, "csv": csv})
69-
list_dataset_replicas(args, ctx.obj.client, ctx.obj.logger, ctx.obj.console, ctx.obj.spinner)
72+
def list_dataset(ctx, dids: Optional["Sequence[str]"], rse: Optional[str], deep: bool, csv: bool):
73+
"""List dataset replicas, or view all datasets at a RSE"""
74+
if rse is None:
75+
args = Arguments({"no_pager": ctx.obj.no_pager, "dids": dids, "deep": deep, "csv": csv})
76+
list_dataset_replicas(args, ctx.obj.client, ctx.obj.logger, ctx.obj.console, ctx.obj.spinner)
77+
else:
78+
args = Arguments({"no_pager": ctx.obj.no_pager, "rse": rse})
79+
list_datasets_rse(args, ctx.obj.client, ctx.obj.logger, ctx.obj.console, ctx.obj.spinner)
7080

7181

7282
@replica.command("remove")

tests/test_cli_client_structure.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,9 +437,9 @@ def test_lifetime_exception(rucio_client, mock_scope):
437437

438438

439439
@pytest.mark.dirty
440-
def test_replica(mock_scope, rucio_client):
440+
def test_replica(mock_scope, rucio_client, did_factory, rse_factory):
441441
mock_did = tempfile.NamedTemporaryFile()
442-
mock_rse = "MOCK-POSIX"
442+
mock_rse, _ = rse_factory.make_posix_rse()
443443

444444
scope = mock_scope.external
445445
name = mock_did.name.split("/")[-1]
@@ -471,6 +471,23 @@ def test_replica(mock_scope, rucio_client):
471471
assert exitcode == 0
472472
assert "ERROR" not in err
473473

474+
# Check the dataset commands
475+
476+
dids = did_factory.upload_test_dataset(rse_name=mock_rse, scope=scope, size=1, nb_files=1)
477+
dataset_name = dids[0]['dataset_name']
478+
479+
cmd = f"rucio replica list dataset {scope}:{dataset_name} --deep"
480+
exitcode, out, err = execute(cmd)
481+
assert exitcode == 0
482+
assert "ERROR" not in err
483+
assert dataset_name in out
484+
485+
cmd = f"rucio replica list dataset --rse {mock_rse}"
486+
exitcode, out, err = execute(cmd)
487+
assert exitcode == 0
488+
assert "ERROR" not in err
489+
assert all([dataset in out for dataset in rucio_client.list_datasets_per_rse(mock_rse)])
490+
474491

475492
@pytest.mark.dirty
476493
def test_replica_state(mock_scope, rucio_client):

0 commit comments

Comments
 (0)