Skip to content

Commit c46c9c1

Browse files
committed
Add --version and --total-checks
1 parent 385fcb5 commit c46c9c1

3 files changed

Lines changed: 106 additions & 36 deletions

File tree

aci-preupgrade-validation-script.py

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5217,15 +5217,12 @@ def parse_args(args):
52175217
parser.add_argument("-t", "--tversion", action="store", type=str, help="Upgrade Target Version. Ex. 6.2(1a)")
52185218
parser.add_argument("-c", "--cversion", action="store", type=str, help="Override Current Version. Ex. 6.1(1a)")
52195219
parser.add_argument("-d", "--debug-function", action="store", type=str, help="Name of a single function to debug. Ex. 'apic_version_md5_check'")
5220-
parser.add_argument("--api-only", action="store_true", help="For built-in PUV. API Checks only. Checks using SSH are skipped.")
5221-
parser.add_argument("--no-cleanup", action="store_true", help="Skip all file cleanup after script execution.")
5220+
parser.add_argument("-a", "--api-only", action="store_true", help="For built-in PUV. API Checks only. Checks using SSH are skipped.")
5221+
parser.add_argument("-n", "--no-cleanup", action="store_true", help="Skip all file cleanup after script execution.")
5222+
parser.add_argument("-v", "--version", action="store_true", help="Show the script version.")
5223+
parser.add_argument("--total-checks", action="store_true", help="Show the total number of checks.")
52225224
parsed_args = parser.parse_args(args)
5223-
api_only = parsed_args.api_only
5224-
tversion = parsed_args.tversion
5225-
cversion = parsed_args.cversion
5226-
debug_function = parsed_args.debug_function
5227-
no_cleanup = parsed_args.no_cleanup
5228-
return api_only, tversion, cversion, debug_function, no_cleanup
5225+
return parsed_args
52295226

52305227

52315228
def prepare(api_only, arg_tversion, arg_cversion, total_checks):
@@ -5264,7 +5261,7 @@ def prepare(api_only, arg_tversion, arg_cversion, total_checks):
52645261
return inputs
52655262

52665263

5267-
def get_checks(api_only, debug_func):
5264+
def get_checks(api_only, debug_function):
52685265
api_checks = [
52695266
# General Checks
52705267
target_version_compatibility_check,
@@ -5368,8 +5365,8 @@ def get_checks(api_only, debug_func):
53685365
observer_db_size_check,
53695366

53705367
]
5371-
if debug_func:
5372-
return [check for check in api_checks + conn_checks if check.__name__ == debug_func]
5368+
if debug_function:
5369+
return [check for check in api_checks + conn_checks if check.__name__ == debug_function]
53735370
if api_only:
53745371
return api_checks
53755372
return conn_checks + api_checks
@@ -5415,12 +5412,18 @@ def wrapup(no_cleanup):
54155412
shutil.rmtree(DIR)
54165413

54175414

5418-
def main(args=None):
5419-
api_only, arg_tversion, arg_cversion, debug_func, no_cleanup = parse_args(args)
5420-
checks = get_checks(api_only, debug_func)
5421-
inputs = prepare(api_only, arg_tversion, arg_cversion, len(checks))
5415+
def main(_args=None):
5416+
args = parse_args(_args)
5417+
if args.version:
5418+
prints(SCRIPT_VERSION)
5419+
return
5420+
checks = get_checks(args.api_only, args.debug_function)
5421+
if args.total_checks:
5422+
prints("Total Number of Checks: {}".format(len(checks)))
5423+
return
5424+
inputs = prepare(args.api_only, args.tversion, args.cversion, len(checks))
54225425
run_checks(checks, inputs)
5423-
wrapup(no_cleanup)
5426+
wrapup(args.no_cleanup)
54245427

54255428

54265429
if __name__ == "__main__":

tests/test_main.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import pytest
2+
import importlib
3+
import sys
4+
5+
script = importlib.import_module("aci-preupgrade-validation-script")
6+
AciVersion = script.AciVersion
7+
8+
9+
def test_args_version(capsys):
10+
script.main(["--version"])
11+
captured = capsys.readouterr()
12+
print(captured.out)
13+
assert "{}\n".format(script.SCRIPT_VERSION) == captured.out
14+
15+
16+
@pytest.mark.parametrize("api_only", [False, True])
17+
def test_args_total_checks(capsys, api_only):
18+
args = ["--total-checks", "--api-only"] if api_only else ["--total-checks"]
19+
checks = script.get_checks(api_only=api_only, debug_function=None)
20+
script.main(args)
21+
captured = capsys.readouterr()
22+
print(captured.out)
23+
assert "Total Number of Checks: {}\n".format(len(checks)) == captured.out

tests/test_parse_args.py

Lines changed: 64 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,27 @@ def test_no_args():
1414
# To simulate the script being run without any command-line arguments,
1515
# we set `sys.argv[1:]` to an empty list when `args` is `None`.
1616
sys.argv[1:] = []
17-
api_only, tversion, cversion, debug_function, no_cleanup = script.parse_args(args=None)
18-
assert api_only is False
19-
assert tversion is None
20-
assert cversion is None
21-
assert debug_function is None
22-
assert no_cleanup is False
17+
args = script.parse_args(args=None)
18+
assert args.api_only is False
19+
assert args.tversion is None
20+
assert args.cversion is None
21+
assert args.debug_function is None
22+
assert args.no_cleanup is False
23+
assert args.version is False
24+
assert args.total_checks is False
2325

2426

2527
@pytest.mark.parametrize(
2628
"args, expected_result",
2729
[
2830
([], False),
31+
(["-a"], True),
2932
(["--api-only"], True),
3033
],
3134
)
3235
def test_api_only(args, expected_result):
33-
api_only, tversion, cversion, debug_function, no_cleanup = script.parse_args(args)
34-
assert api_only == expected_result
36+
args = script.parse_args(args)
37+
assert args.api_only == expected_result
3538

3639

3740
@pytest.mark.parametrize(
@@ -43,13 +46,14 @@ def test_api_only(args, expected_result):
4346
(["-t", "n9000-16.2(1a).bin"], "n9000-16.2(1a).bin"),
4447
(["-t", "aci-apic-dk9.6.2.1a.bin"], "aci-apic-dk9.6.2.1a.bin"),
4548
(["-t", "invalid_version"], "invalid_version"),
49+
(["--tversion", "6.2(1a)"], "6.2(1a)"),
4650
],
4751
)
4852
def test_tversion(args, expected_result):
49-
api_only, tversion, cversion, debug_function, no_cleanup = script.parse_args(args)
50-
if tversion is not None:
51-
assert isinstance(tversion, str)
52-
assert str(tversion) == str(expected_result)
53+
args = script.parse_args(args)
54+
if args.tversion is not None:
55+
assert isinstance(args.tversion, str)
56+
assert str(args.tversion) == str(expected_result)
5357

5458

5559
@pytest.mark.parametrize(
@@ -61,13 +65,14 @@ def test_tversion(args, expected_result):
6165
(["-c", "n9000-16.2(1a).bin"], "n9000-16.2(1a).bin"),
6266
(["-c", "aci-apic-dk9.6.2.1a.bin"], "aci-apic-dk9.6.2.1a.bin"),
6367
(["-c", "invalid_version"], "invalid_version"),
68+
(["--cversion", "6.2(1a)"], "6.2(1a)"),
6469
],
6570
)
6671
def test_cversion(args, expected_result):
67-
api_only, tversion, cversion, debug_function, no_cleanup = script.parse_args(args)
68-
if cversion is not None:
69-
assert isinstance(cversion, str)
70-
assert str(cversion) == str(expected_result)
72+
args = script.parse_args(args)
73+
if args.cversion is not None:
74+
assert isinstance(args.cversion, str)
75+
assert str(args.cversion) == str(expected_result)
7176

7277

7378
@pytest.mark.parametrize(
@@ -76,10 +81,49 @@ def test_cversion(args, expected_result):
7681
([], None),
7782
(["-d", "pbr_high_scale_check"], "pbr_high_scale_check"),
7883
(["-d", "made_up_func"], "made_up_func"),
84+
(["--debug-func", "pbr_high_scale_check"], "pbr_high_scale_check"),
7985
],
8086
)
8187
def test_debug_func(args, expected_result):
82-
api_only, tversion, cversion, debug_function, no_cleanup = script.parse_args(args)
83-
if debug_function is not None:
84-
assert isinstance(debug_function, str)
85-
assert str(debug_function) == str(expected_result)
88+
args = script.parse_args(args)
89+
if args.debug_function is not None:
90+
assert isinstance(args.debug_function, str)
91+
assert str(args.debug_function) == str(expected_result)
92+
93+
94+
@pytest.mark.parametrize(
95+
"args, expected_result",
96+
[
97+
([], False),
98+
(["-n"], True),
99+
(["--no-cleanup"], True),
100+
],
101+
)
102+
def test_no_cleanup(args, expected_result):
103+
args = script.parse_args(args)
104+
assert args.no_cleanup == expected_result
105+
106+
107+
@pytest.mark.parametrize(
108+
"args, expected_result",
109+
[
110+
([], False),
111+
(["-v"], True),
112+
(["--version"], True),
113+
],
114+
)
115+
def test_version(args, expected_result):
116+
args = script.parse_args(args)
117+
assert args.version == expected_result
118+
119+
120+
@pytest.mark.parametrize(
121+
"args, expected_result",
122+
[
123+
([], False),
124+
(["--total-checks"], True),
125+
],
126+
)
127+
def test_total_checks(args, expected_result):
128+
args = script.parse_args(args)
129+
assert args.total_checks == expected_result

0 commit comments

Comments
 (0)