Skip to content
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

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

emilarista
Copy link

Description

Test to verify if one or more units are under or entering maintenance mode for different reasons:

  • On-boot configuration
  • Interface traffic violation
  • quiesce explicitly configured

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have run pre-commit for code linting and typing (pre-commit run)
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes (tox -e testenv)

@emilarista emilarista changed the title Feat(anta.tests): Add test for Maintenance mode feat(anta.tests): Add test for Maintenance mode Mar 6, 2025
Comment on lines +397 to +398
if not under and not entering and not causes:
self.result.is_success()
Copy link
Collaborator

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

Comment on lines 402 to 409
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)
Copy link
Collaborator

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:

Suggested change
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}'")

Comment on lines +378 to +379
under = False
entering = False
Copy link
Collaborator

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

Comment on lines +376 to +377
unitsundermaintenance = []
unitsenteringmaintenance = []
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
unitsundermaintenance = []
unitsenteringmaintenance = []
units_under_maintenance = []
units_entering_maintenance = []

Comment on lines +384 to +385
unitsundermaintenance.append(unit)
under = True
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
unitsundermaintenance.append(unit)
under = True
units_under_maintenance.append(unit)

Comment on lines +387 to +388
unitsenteringmaintenance.append(unit)
entering = True
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
unitsenteringmaintenance.append(unit)
entering = True
units_entering_maintenance.append(unit)

Comment on lines 390 to 394
causes.append("quiesce is configured")
if info["onBootMaintenance"]:
causes.append("On-boot maintenance is configured")
if info["intfsViolatingTrafficThreshold"]:
causes.append("Interface traffic threshold violation")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.")

Copy link

sonarqubecloud bot commented Mar 6, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants