Skip to content

Commit 280b309

Browse files
authored
Update host-check rc and summary string for case of no errors/failures but warnings (#36)
* Added tests for new error codes * updated changelog * . * autoformatted * comment updates * NamedTuple * formatting * Same exit code * review comments * changed changelog * changed changelog * changed changelog * date
1 parent fa33fa3 commit 280b309

File tree

3 files changed

+374
-77
lines changed

3 files changed

+374
-77
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55

66
The v1 release supports Cisco IOS-XR release versions from 7.7.1 to 7.10.1.
77

8+
### v1.1.14 (2023-11-27)
9+
10+
- `host-check` now summarizes failures and warnings separately. When testing both XR platforms, a failure for either is now treated as a failure overall.
11+
812
### v1.1.13 (2023-10-11)
913

1014
- Modify Linux kernel version check to require kernel version 4.6 or higher.

scripts/host-check

Lines changed: 114 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ from typing import (
6767
# Globals
6868
# -----------------------------------------------------------------------------
6969

70+
71+
# Exit codes
72+
EXIT_SUCCESS = 0
73+
EXIT_ERROR = 1
74+
75+
7076
INOTIFY_RECOMMENDED = 64000
7177
INOTIFY_PER_CONTAINER = 4000
7278

@@ -319,12 +325,13 @@ class CheckState(enum.Enum):
319325
# 'success' check states
320326
SUCCESS = "success"
321327
NEUTRAL = "neutral"
322-
# 'failure' check states
328+
# 'warning' check states
323329
WARNING = "warning"
330+
# 'failure' check states
324331
SKIPPED = "skipped"
325332
FAILED = "failed"
326333
# Check state for when the check fails to run/errors
327-
# Note: this is neither 'success' nor 'failure'
334+
# Note: this is not 'success', 'warning' or 'failure'
328335
ERROR = "error"
329336

330337
def is_failure(self) -> bool:
@@ -335,7 +342,6 @@ class CheckState(enum.Enum):
335342
return self in [
336343
CheckState.FAILED,
337344
CheckState.SKIPPED,
338-
CheckState.WARNING,
339345
]
340346

341347

@@ -1597,20 +1603,29 @@ def perform_checks(checks: List[Check]) -> Mapping[str, CheckState]:
15971603
return results
15981604

15991605

1606+
class ExtraResults(NamedTuple):
1607+
"""The results of any extra checks."""
1608+
1609+
supported: Set[str]
1610+
not_supported: Set[str]
1611+
errored: Set[str]
1612+
warned: Set[str]
1613+
1614+
16001615
def run_if_extra_checks(
16011616
extra_checks: Optional[List[str]] = None,
1602-
) -> Tuple[Set[str], Set[str], Set[str]]:
1617+
) -> ExtraResults:
16031618
"""
1604-
Run the specified extra checks, printing the results and returning the
1605-
checks that succeeded, failed and errored.
1619+
Run the specified extra checks, printing the results.
16061620
:param extra_checks:
16071621
List of extra checks to perform.
16081622
:returns:
1609-
Tuple of the checks that: succeeded, failed and errored.
1623+
NamedTuple of sets of checks that succeeded, failed, errored and warned.
16101624
"""
16111625
extras_supported = set()
16121626
extras_not_supported = set()
16131627
extras_errored = set()
1628+
extras_warned = set()
16141629

16151630
if extra_checks:
16161631
print("") # insert a newline
@@ -1623,40 +1638,49 @@ def run_if_extra_checks(
16231638
extras_not_supported.add(extra_check)
16241639
elif any(c is CheckState.ERROR for c in extra_results.values()):
16251640
extras_errored.add(extra_check)
1641+
elif any(c is CheckState.WARNING for c in extra_results.values()):
1642+
extras_warned.add(extra_check)
16261643
else:
16271644
extras_supported.add(extra_check)
16281645

1629-
return extras_supported, extras_not_supported, extras_errored
1646+
return ExtraResults(
1647+
extras_supported,
1648+
extras_not_supported,
1649+
extras_errored,
1650+
extras_warned,
1651+
)
16301652

16311653

1632-
def print_extra_checks_summary(
1633-
extras_supported: Set[str],
1634-
extras_not_supported: Set[str],
1635-
extras_errored: Set[str],
1636-
) -> None:
1654+
def print_extra_checks_summary(extra_results: ExtraResults) -> None:
16371655
"""
16381656
Print a summary of the extra checks that passed and failed.
1639-
:param extras_supported:
1640-
The checks that were successful.
1641-
:param extras_not_supported:
1642-
The checks that were not successful.
1643-
:param extras_errored:
1644-
The checks that errored/failed to run.
1657+
:param extras_results:
1658+
The results of the extra checks.
16451659
"""
16461660
print(f"{DASHED_LINE}")
1647-
if extras_supported:
1648-
print("Extra checks passed: " + ", ".join(sorted(extras_supported)))
1649-
if extras_not_supported:
1661+
if extra_results.supported:
1662+
print(
1663+
"Extra checks passed: "
1664+
+ ", ".join(sorted(extra_results.supported))
1665+
)
1666+
if extra_results.not_supported:
1667+
print(
1668+
"Extra checks failed: "
1669+
+ ", ".join(sorted(extra_results.not_supported))
1670+
)
1671+
if extra_results.errored:
16501672
print(
1651-
"Extra checks failed: " + ", ".join(sorted(extras_not_supported))
1673+
"Extra checks errored: " + ", ".join(sorted(extra_results.errored))
1674+
)
1675+
if extra_results.warned:
1676+
print(
1677+
"Extra checks warned: " + ", ".join(sorted(extra_results.warned))
16521678
)
1653-
if extras_errored:
1654-
print("Extra checks errored: " + ", ".join(sorted(extras_errored)))
16551679

16561680

16571681
def run_checks_specific_platform(
16581682
platform: str, extra_checks: List[str]
1659-
) -> bool:
1683+
) -> int:
16601684
"""
16611685
Run checks for the given platform (including the base checks that are
16621686
required for all platforms).
@@ -1666,19 +1690,18 @@ def run_checks_specific_platform(
16661690
:param extra_checks:
16671691
A list of the extra checks.
16681692
:return:
1669-
Whether all checks that were performed succeeded.
1693+
EXIT_SUCCESS if all checks were successful
1694+
EXIT_ERROR if there are any failures, warnings or errors (including
1695+
extra checks)
16701696
"""
16711697

16721698
print_heading(f"Platform checks - {platform}")
16731699
plat_results = perform_checks(BASE_CHECKS + PLATFORM_CHECKS_MAP[platform])
16741700
plat_failure = any(check.is_failure() for check in plat_results.values())
16751701
plat_error = any(c is CheckState.ERROR for c in plat_results.values())
1702+
plat_warning = any(c is CheckState.WARNING for c in plat_results.values())
16761703

1677-
(
1678-
extras_supported,
1679-
extras_not_supported,
1680-
extras_errored,
1681-
) = run_if_extra_checks(extra_checks)
1704+
extra_results = run_if_extra_checks(extra_checks)
16821705

16831706
# Print a summary of what is and is not supported
16841707
print(f"\n{DOUBLE_DASHED_LINE}")
@@ -1688,29 +1711,44 @@ def run_checks_specific_platform(
16881711
print(
16891712
"!! One or more platform checks could not be performed, see errors above !!"
16901713
)
1714+
elif plat_warning:
1715+
print(
1716+
"!! One or more platform checks resulted in a warning, see warnings above !!"
1717+
)
16911718
else:
16921719
print(f"Host environment set up correctly for {platform}")
16931720
if extra_checks:
1694-
print_extra_checks_summary(
1695-
extras_supported, extras_not_supported, extras_errored
1696-
)
1721+
print_extra_checks_summary(extra_results)
16971722
print(f"{DOUBLE_DASHED_LINE}")
16981723

1699-
return not (
1700-
plat_failure or plat_error or extras_not_supported or extras_errored
1701-
)
1724+
if (
1725+
plat_failure
1726+
or plat_error
1727+
or extra_results.not_supported
1728+
or extra_results.errored
1729+
or plat_warning
1730+
or extra_results.warned
1731+
):
1732+
rc = EXIT_ERROR
1733+
else:
1734+
rc = EXIT_SUCCESS
1735+
1736+
return rc
17021737

17031738

1704-
def run_checks_all_platforms(extra_checks: List[str]) -> bool:
1739+
def run_checks_all_platforms(extra_checks: List[str]) -> int:
17051740
"""
17061741
Run checks for all platforms and report which platforms are supported.
17071742
17081743
:return:
1709-
Whether at least one XR platform is supported.
1744+
EXIT_SUCCESS if all checks were successful
1745+
EXIT_ERROR if there are any failures, warnings or errors (including
1746+
extra tests)
17101747
"""
17111748
platforms_supported: Set[str] = set()
17121749
platforms_not_supported: Set[str] = set()
17131750
platforms_errored: Set[str] = set()
1751+
platforms_warned: Set[str] = set()
17141752

17151753
print_heading("Platform checks")
17161754
print_subheading("base checks")
@@ -1727,14 +1765,14 @@ def run_checks_all_platforms(extra_checks: List[str]) -> bool:
17271765
result is CheckState.ERROR for result in base_and_plat_results
17281766
):
17291767
platforms_errored.add(platform)
1768+
elif any(
1769+
result is CheckState.WARNING for result in base_and_plat_results
1770+
):
1771+
platforms_warned.add(platform)
17301772
else:
17311773
platforms_supported.add(platform)
17321774

1733-
(
1734-
extras_supported,
1735-
extras_not_supported,
1736-
extras_errored,
1737-
) = run_if_extra_checks(extra_checks)
1775+
extra_results = run_if_extra_checks(extra_checks)
17381776

17391777
# Print a summary of what is and is not supported
17401778
print(f"\n{DOUBLE_DASHED_LINE}")
@@ -1744,21 +1782,43 @@ def run_checks_all_platforms(extra_checks: List[str]) -> bool:
17441782
)
17451783
if platforms_not_supported:
17461784
print(
1747-
"XR platforms NOT supported: "
1785+
"!! XR platforms NOT supported: "
17481786
+ ", ".join(sorted(platforms_not_supported))
1787+
+ " !!"
17491788
)
17501789
if platforms_errored:
17511790
print(
1752-
"!! One or more platform checks could not be performed, see errors above !!"
1791+
"!! One or more platform checks could not be performed for XR platforms: !!"
1792+
+ "\n "
1793+
+ ",\n ".join(sorted(platforms_errored))
1794+
+ "\n See errors above."
1795+
)
1796+
if platforms_warned:
1797+
print(
1798+
"!! One or more platform checks resulted in a warning for XR platforms: !!"
1799+
+ "\n "
1800+
+ ",\n ".join(sorted(platforms_warned))
1801+
+ "\n See warnings above."
17531802
)
1803+
17541804
# Print the result of any extra checks
17551805
if extra_checks:
1756-
print_extra_checks_summary(
1757-
extras_supported, extras_not_supported, extras_errored
1758-
)
1806+
print_extra_checks_summary(extra_results)
17591807
print(f"{DOUBLE_DASHED_LINE}")
17601808

1761-
return len(platforms_supported) > 0
1809+
if (
1810+
platforms_not_supported
1811+
or platforms_errored
1812+
or extra_results.not_supported
1813+
or extra_results.errored
1814+
or platforms_warned
1815+
or extra_results.warned
1816+
):
1817+
rc = EXIT_ERROR
1818+
else:
1819+
rc = EXIT_SUCCESS
1820+
1821+
return rc
17621822

17631823

17641824
def parse_args(argv: List[str]) -> argparse.Namespace:
@@ -1786,12 +1846,10 @@ def parse_args(argv: List[str]) -> argparse.Namespace:
17861846
def main(argv: List[str]) -> NoReturn:
17871847
args = parse_args(argv)
17881848
if args.platform:
1789-
success = run_checks_specific_platform(
1790-
args.platform, args.extra_checks
1791-
)
1849+
rc = run_checks_specific_platform(args.platform, args.extra_checks)
17921850
else:
1793-
success = run_checks_all_platforms(args.extra_checks)
1794-
sys.exit(0 if success else 1)
1851+
rc = run_checks_all_platforms(args.extra_checks)
1852+
sys.exit(rc)
17951853

17961854

17971855
if __name__ == "__main__":

0 commit comments

Comments
 (0)