-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(anta.tests): Add test for Maintenance mode #1067
base: main
Are you sure you want to change the base?
Conversation
if not under and not entering and not causes: | ||
self.result.is_success() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you already set is_success at the beginning so you don't need this. you can just return
anta/tests/system.py
Outdated
message = "" | ||
if under: | ||
message += f"Units under maintenance: '{unitsundermaintenance}'. " | ||
if entering: | ||
message += f"Units entering maintenance: '{unitsenteringmaintenance}'. " | ||
if len(causes) > 0: | ||
message += f"Possible causes: '{causes}'" | ||
self.result.is_failure(message) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we have a list os messages so yuo can do instead:
message = "" | |
if under: | |
message += f"Units under maintenance: '{unitsundermaintenance}'. " | |
if entering: | |
message += f"Units entering maintenance: '{unitsenteringmaintenance}'. " | |
if len(causes) > 0: | |
message += f"Possible causes: '{causes}'" | |
self.result.is_failure(message) | |
if units_under_maintenance: | |
self.result.is_failure(f"Units under maintenance: '{', '.join(units_under_maintenance)}'.") | |
if units_entering_maintenance: | |
self.result.is_failure(f"Units entering maintenance: '{', '.join(units_entering_maintenance)}'.") | |
if len(causes) > 0: | |
self.result.is_failure(f"Possible causes: '{', '.join(causes}'") |
under = False | ||
entering = False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you don't need the flags as you just need to check if the lists are empty or not
unitsundermaintenance = [] | ||
unitsenteringmaintenance = [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unitsundermaintenance = [] | |
unitsenteringmaintenance = [] | |
units_under_maintenance = [] | |
units_entering_maintenance = [] |
unitsundermaintenance.append(unit) | ||
under = True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unitsundermaintenance.append(unit) | |
under = True | |
units_under_maintenance.append(unit) |
unitsenteringmaintenance.append(unit) | ||
entering = True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unitsenteringmaintenance.append(unit) | |
entering = True | |
units_entering_maintenance.append(unit) |
anta/tests/system.py
Outdated
causes.append("quiesce is configured") | ||
if info["onBootMaintenance"]: | ||
causes.append("On-boot maintenance is configured") | ||
if info["intfsViolatingTrafficThreshold"]: | ||
causes.append("Interface traffic threshold violation") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
causes.append("quiesce is configured") | |
if info["onBootMaintenance"]: | |
causes.append("On-boot maintenance is configured") | |
if info["intfsViolatingTrafficThreshold"]: | |
causes.append("Interface traffic threshold violation") | |
causes.append("quiesce is configured.") | |
if info["onBootMaintenance"]: | |
causes.append("On-boot maintenance is configured.") | |
if info["intfsViolatingTrafficThreshold"]: | |
causes.append("Interface traffic threshold violation.") |
|
Description
Test to verify if one or more units are under or entering maintenance mode for different reasons:
Checklist:
pre-commit run
)tox -e testenv
)