Skip to content

Commit

Permalink
Clients: Write deprecating warning to log rucio#7277
Browse files Browse the repository at this point in the history
  • Loading branch information
voetberg authored and bari12 committed Feb 4, 2025
1 parent a790545 commit a1eeafb
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 31 deletions.
26 changes: 14 additions & 12 deletions bin/rucio
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@

import argparse
import sys
from typing import Optional
from typing import TYPE_CHECKING, Optional

from rucio.client.commands.bin_legacy.rucio import main as main_legacy
from rucio.client.commands.command import main
from rucio.common.utils import setup_logger

if TYPE_CHECKING:
from logging import Logger


def _get_first_command(args: list[str]) -> Optional[str]:
Expand All @@ -31,15 +35,15 @@ def _get_first_command(args: list[str]) -> Optional[str]:
)


def make_warning():
base_warning = "\nWARNING: This method is being deprecated."
def make_warning(logger: "Logger") -> None:
base_warning = "This method is being deprecated."
new_command = map_legacy_command()
if new_command is not None:
warning = f"{base_warning}\nPlease replace your command with `rucio {' '.join(new_command)}`.\n"
warning = f"{base_warning} Please replace your command with `rucio {' '.join(new_command)}`"
else:
warning = base_warning + "\nPlease view rucio -h for an updated help menu.\n"
warning = base_warning + " Please view rucio -h for an updated help menu."

return warning
logger.warning(warning)


def map_legacy_command() -> Optional[list[str]]:
Expand Down Expand Up @@ -96,7 +100,7 @@ def map_legacy_command() -> Optional[list[str]]:

if __name__ == "__main__":
commands = ("-h", "--help", "--version", "account", "config", "did", "replica", "rse", "rule", "scope", "subscription", "ping", "whoami", "test-server", "lifetime-exception", "upload", "download")

logger = setup_logger(module_name=__name__)
first_command = _get_first_command(sys.argv[1:])

is_legacy = '--legacy' in sys.argv
Expand All @@ -105,19 +109,17 @@ if __name__ == "__main__":
main()

elif is_legacy:
warning = make_warning()
print(warning)
make_warning(logger)
sys.argv.pop(sys.argv.index('--legacy'))
main_legacy()

else:
warning = make_warning()
print(warning)
make_warning(logger)
try:
main_legacy()
# Make a custom warning - show the new help menu when invalid commands are called.
except argparse.ArgumentError:
print("Invalid argument(s) - %s " % sys.argv[1:])
logger.error("Invalid argument(s) - %s " % sys.argv[1:])
command = map_legacy_command()
if command is not None:
sys.argv = ["rucio"] + command + ["-h"]
Expand Down
11 changes: 7 additions & 4 deletions bin/rucio-admin
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@
import sys

from rucio.client.commands.bin_legacy.rucio_admin import main as main_legacy
from rucio.common.utils import setup_logger


def make_warning():
base_warning = "\nWARNING: This method is being deprecated."
logger = setup_logger(module_name=__name__)

base_warning = "This method is being deprecated."
args = [arg for arg in sys.argv if arg[0] != "-" or arg in ("-h", "--help", "--version")]
try:
first_command = args[1]
Expand Down Expand Up @@ -88,11 +91,11 @@ def make_warning():
except KeyError:
new_command = "-h"

warning = f"{base_warning}\nPlease replace your command with `rucio {new_command}`.\n"
warning = f"{base_warning} Please replace your command with `rucio {new_command}`"
else:
warning = base_warning + "\nPlease view rucio -h for an updated help menu.\n"
warning = base_warning + " Please view rucio -h for an updated help menu."

print(warning)
logger.warning(warning)


if __name__ == "__main__":
Expand Down
30 changes: 15 additions & 15 deletions tests/test_bin_rucio.py
Original file line number Diff line number Diff line change
Expand Up @@ -1154,7 +1154,7 @@ def test_list_blocklisted_replicas(self):
print(self.marker + cmd)
exitcode, out, err = execute(cmd)
print(out, err)
assert not err
assert "ERROR" not in err

# list-file-replicas should, by default, list replicas from blocklisted rses
cmd = 'rucio list-file-replicas {}'.format(tmp_dataset)
Expand Down Expand Up @@ -1215,7 +1215,7 @@ def test_create_rule(self):
print(self.marker + cmd)
exitcode, out, err = execute(cmd)
print(out)
assert not err
assert "ERROR" not in err
rule = out.split('\n')[-2]
assert re.match(r'^\w+$', rule)
# check if rule exist for the file
Expand Down Expand Up @@ -1256,7 +1256,7 @@ def test_create_rule_delayed(self):
print(self.marker + cmd)
exitcode, out, err = execute(cmd)
print(out, err)
assert not err
assert "ERROR" not in err
rule = out.split('\n')[-2]
cmd = "rucio rule-info {0}".format(rule)
print(self.marker + cmd)
Expand Down Expand Up @@ -1373,7 +1373,7 @@ def test_move_rule(self):
print(self.marker + cmd)
exitcode, out, err = execute(cmd)
print(out)
assert not err
assert "ERROR" not in err
rule = out.split('\n')[-2]
assert re.match(r'^\w+$', rule)

Expand All @@ -1383,7 +1383,7 @@ def test_move_rule(self):
print(self.marker + cmd)
exitcode, out, err = execute(cmd)
print(out)
assert not err
assert "ERROR" not in err
new_rule = out.split('\n')[-2] # trimming new line character

# check if rule exist for the file
Expand Down Expand Up @@ -1445,7 +1445,7 @@ def test_move_rule_with_arguments(self):
print(self.marker + cmd)
exitcode, out, err = execute(cmd)
print(out)
assert not err
assert "ERROR" not in err
rule = out.split('\n')[-2]
assert re.match(r'^\w+$', rule)
# move rule
Expand All @@ -1456,7 +1456,7 @@ def test_move_rule_with_arguments(self):
print(self.marker + cmd)
exitcode, out, err = execute(cmd)
print(out, err)
assert not err
assert "ERROR" not in err
new_rule_id = out.split('\n')[-2] # trimming new line character

# check if rule exist for the file
Expand Down Expand Up @@ -2099,21 +2099,21 @@ def test_update_rule_unset_child_rule(self):
tmp_rse = rse_name_generator()
cmd = f'rucio-admin rse add {tmp_rse}'
exitcode, out, err = execute(cmd)
assert not err
assert "ERROR" not in err

self.account_client.set_local_account_limit('root', tmp_rse, -1)

cmd = (f'rucio-admin rse set-attribute --rse {tmp_rse}'
f' --key spacetoken --value RULELOC{i}')
exitcode, out, err = execute(cmd)
assert not err
assert "ERROR" not in err

# PREPARING THE RULES
# add rule
rule_expr = "spacetoken=RULELOC0"
cmd = f"rucio add-rule {self.user}:{tmp_fname} 1 '{rule_expr}'"
exitcode, out, err = execute(cmd)
assert not err
assert "ERROR" not in err
# get the rules for the file
cmd = r"rucio list-rules {0}:{1} | grep {0}:{1} | cut -f1 -d\ ".\
format(self.user, tmp_file[5:])
Expand All @@ -2126,7 +2126,7 @@ def test_update_rule_unset_child_rule(self):
cmd = f"rucio move-rule {parentrule_id} '{new_rule_expr}'"
exitcode, out, err = execute(cmd)
childrule_id = out.split('\n')[-2]
assert err == ''
assert "ERROR" not in err

# check if new rule exists for the file
cmd = "rucio list-rules {0}:{1}".format(self.user, tmp_fname)
Expand Down Expand Up @@ -2156,21 +2156,21 @@ def test_update_rule_no_child_selfassign(self):
tmp_rse = rse_name_generator()
cmd = f'rucio-admin rse add {tmp_rse}'
exitcode, out, err = execute(cmd)
assert not err
assert "ERROR" not in err

self.account_client.set_local_account_limit('root', tmp_rse, -1)

cmd = (f'rucio-admin rse set-attribute --rse {tmp_rse}'
f' --key spacetoken --value RULELOC')
exitcode, out, err = execute(cmd)
assert not err
assert "ERROR" not in err

# PREPARING THE RULES
# add rule
rule_expr = "spacetoken=RULELOC"
cmd = f"rucio add-rule {self.user}:{tmp_fname} 1 '{rule_expr}'"
exitcode, out, err = execute(cmd)
assert not err
assert "ERROR" not in err

# get the rules for the file
cmd = r"rucio list-rules {0}:{1} | grep {0}:{1} | cut -f1 -d\ ".\
Expand Down Expand Up @@ -2353,7 +2353,7 @@ def test_admin_rse_update_unsupported_option(self):
exitcode, out, err = execute("rucio-admin rse update --setting country_name --value France --rse {}".format(self.def_rse))
print(out, err)
assert exitcode == 0
assert not err
assert "ERROR" not in err

@pytest.mark.noparallel(reason='Modify config')
def test_lifetime_cli(self):
Expand Down

0 comments on commit a1eeafb

Please sign in to comment.