Skip to content

Commit c67a0e9

Browse files
committed
Clients: Write deprecating warning to log rucio#7277
1 parent 8a52a93 commit c67a0e9

File tree

3 files changed

+36
-31
lines changed

3 files changed

+36
-31
lines changed

bin/rucio

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,14 @@
1515

1616
import argparse
1717
import sys
18-
from typing import Optional
18+
from typing import TYPE_CHECKING, Optional
1919

2020
from rucio.client.commands.bin_legacy.rucio import main as main_legacy
2121
from rucio.client.commands.command import main
22+
from rucio.common.utils import setup_logger
23+
24+
if TYPE_CHECKING:
25+
from logging import Logger
2226

2327

2428
def _get_first_command(args: list[str]) -> Optional[str]:
@@ -31,15 +35,15 @@ def _get_first_command(args: list[str]) -> Optional[str]:
3135
)
3236

3337

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

42-
return warning
46+
logger.warning(warning)
4347

4448

4549
def map_legacy_command() -> Optional[list[str]]:
@@ -96,7 +100,7 @@ def map_legacy_command() -> Optional[list[str]]:
96100

97101
if __name__ == "__main__":
98102
commands = ("-h", "--help", "--version", "account", "config", "did", "replica", "rse", "rule", "scope", "subscription", "ping", "whoami", "test-server", "lifetime-exception", "upload", "download")
99-
103+
logger = setup_logger(module_name=__name__)
100104
first_command = _get_first_command(sys.argv[1:])
101105

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

107111
elif is_legacy:
108-
warning = make_warning()
109-
print(warning)
112+
make_warning(logger)
110113
sys.argv.pop(sys.argv.index('--legacy'))
111114
main_legacy()
112115

113116
else:
114-
warning = make_warning()
115-
print(warning)
117+
make_warning(logger)
116118
try:
117119
main_legacy()
118120
# Make a custom warning - show the new help menu when invalid commands are called.
119121
except argparse.ArgumentError:
120-
print("Invalid argument(s) - %s " % sys.argv[1:])
122+
logger.error("Invalid argument(s) - %s " % sys.argv[1:])
121123
command = map_legacy_command()
122124
if command is not None:
123125
sys.argv = ["rucio"] + command + ["-h"]

bin/rucio-admin

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,13 @@
1515
import sys
1616

1717
from rucio.client.commands.bin_legacy.rucio_admin import main as main_legacy
18+
from rucio.common.utils import setup_logger
1819

1920

2021
def make_warning():
21-
base_warning = "\nWARNING: This method is being deprecated."
22+
logger = setup_logger(module_name=__name__)
23+
24+
base_warning = "This method is being deprecated."
2225
args = [arg for arg in sys.argv if arg[0] != "-" or arg in ("-h", "--help", "--version")]
2326
try:
2427
first_command = args[1]
@@ -88,11 +91,11 @@ def make_warning():
8891
except KeyError:
8992
new_command = "-h"
9093

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

95-
print(warning)
98+
logger.warning(warning)
9699

97100

98101
if __name__ == "__main__":

tests/test_bin_rucio.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,7 +1154,7 @@ def test_list_blocklisted_replicas(self):
11541154
print(self.marker + cmd)
11551155
exitcode, out, err = execute(cmd)
11561156
print(out, err)
1157-
assert not err
1157+
assert "ERROR" not in err
11581158

11591159
# list-file-replicas should, by default, list replicas from blocklisted rses
11601160
cmd = 'rucio list-file-replicas {}'.format(tmp_dataset)
@@ -1215,7 +1215,7 @@ def test_create_rule(self):
12151215
print(self.marker + cmd)
12161216
exitcode, out, err = execute(cmd)
12171217
print(out)
1218-
assert not err
1218+
assert "ERROR" not in err
12191219
rule = out.split('\n')[-2]
12201220
assert re.match(r'^\w+$', rule)
12211221
# check if rule exist for the file
@@ -1256,7 +1256,7 @@ def test_create_rule_delayed(self):
12561256
print(self.marker + cmd)
12571257
exitcode, out, err = execute(cmd)
12581258
print(out, err)
1259-
assert not err
1259+
assert "ERROR" not in err
12601260
rule = out.split('\n')[-2]
12611261
cmd = "rucio rule-info {0}".format(rule)
12621262
print(self.marker + cmd)
@@ -1373,7 +1373,7 @@ def test_move_rule(self):
13731373
print(self.marker + cmd)
13741374
exitcode, out, err = execute(cmd)
13751375
print(out)
1376-
assert not err
1376+
assert "ERROR" not in err
13771377
rule = out.split('\n')[-2]
13781378
assert re.match(r'^\w+$', rule)
13791379

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

13891389
# check if rule exist for the file
@@ -1445,7 +1445,7 @@ def test_move_rule_with_arguments(self):
14451445
print(self.marker + cmd)
14461446
exitcode, out, err = execute(cmd)
14471447
print(out)
1448-
assert not err
1448+
assert "ERROR" not in err
14491449
rule = out.split('\n')[-2]
14501450
assert re.match(r'^\w+$', rule)
14511451
# move rule
@@ -1456,7 +1456,7 @@ def test_move_rule_with_arguments(self):
14561456
print(self.marker + cmd)
14571457
exitcode, out, err = execute(cmd)
14581458
print(out, err)
1459-
assert not err
1459+
assert "ERROR" not in err
14601460
new_rule_id = out.split('\n')[-2] # trimming new line character
14611461

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

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

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

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

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

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

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

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

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

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

0 commit comments

Comments
 (0)