Skip to content

Commit bd2e008

Browse files
committed
run_cmd pytest
1 parent 24140e0 commit bd2e008

2 files changed

Lines changed: 32 additions & 3 deletions

File tree

aci-preupgrade-validation-script.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1278,8 +1278,8 @@ def run_cmd(cmd, splitlines=True):
12781278
return response.splitlines()
12791279
return response
12801280
except subprocess.CalledProcessError as e:
1281-
log.error("Command '%s' failed with error: %s", cmd, e.output.strip())
1282-
return None
1281+
log.error("Command '%s' failed with error: %s", cmd, str(e))
1282+
raise e
12831283

12841284

12851285
def get_credentials():
@@ -5458,7 +5458,6 @@ def get_checks(api_only, debug_function):
54585458
apic_version_md5_check,
54595459
apic_database_size_check,
54605460

5461-
54625461
# Faults
54635462
standby_apic_disk_space_check,
54645463
apic_ssd_check,

tests/test_run_cmd.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import pytest
2+
import importlib
3+
from subprocess import CalledProcessError
4+
script = importlib.import_module("aci-preupgrade-validation-script")
5+
6+
7+
@pytest.mark.parametrize(
8+
"cmd, splitlines, expected_output",
9+
[
10+
(["echo", "$'hello\nworld'"], True, ["hello", "world"]),
11+
("echo $'hello\nworld'", True, ["hello", "world"]),
12+
(["echo", "$'hello\nworld'"], False, "hello\nworld\n"),
13+
("echo $'hello\nworld'", False, "hello\nworld\n"),
14+
],
15+
)
16+
def test_run_cmds(cmd, splitlines, expected_output):
17+
result = script.run_cmd(cmd, splitlines)
18+
assert result == expected_output
19+
20+
21+
@pytest.mark.parametrize(
22+
"cmd, splitlines, expected_output",
23+
[
24+
("fake_command", True, ""),
25+
(["fake_command"], False, ""),
26+
]
27+
)
28+
def test_non_existing_command(cmd, splitlines, expected_output):
29+
with pytest.raises(CalledProcessError):
30+
script.run_cmd(cmd, splitlines)

0 commit comments

Comments
 (0)