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): Verify cvx status #930

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

sarunac
Copy link
Contributor

@sarunac sarunac commented Nov 18, 2024

Description

Verify the CVX server status and its corresponding peer registration status

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)

@sarunac sarunac changed the title Verify cvx status feat(anta): Verify cvx status Nov 18, 2024
Copy link

codspeed-hq bot commented Nov 18, 2024

CodSpeed Performance Report

Merging #930 will not alter performance

Comparing sarunac:verifyCVXStatus (cceba67) with main (91eac73)

Summary

✅ 8 untouched benchmarks

Copy link

sonarcloud bot commented Nov 19, 2024

Comment on lines +20 to +24
class Peer(TypedDict):
"""Class for holding CVX Peer information."""

peer_name: str
registration_state: str
Copy link
Collaborator

Choose a reason for hiding this comment

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

You probably don't need this as you have it from input models

cluster_mode: bool
role: Literal["Master", "Standby", "Disconnected"] = "Master"
peer_status: list[CVXPeers]
CVXPeers: ClassVar[type[CVXPeers]] = CVXPeers
Copy link
Collaborator

Choose a reason for hiding this comment

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

same this is not needed for new tests (we do it on refactored ones because SemVer). @carl-baillargeon to confirm

Copy link
Contributor

Choose a reason for hiding this comment

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

Correct, not needed for new tests.

Comment on lines +117 to +118
cluster_mode: true
role: Master
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 more params here than what is present in the docstring

role: Master
peer_status:
- peer_name : cvx-red-2
registration_state: Registration complete
Copy link
Collaborator

Choose a reason for hiding this comment

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

If I understand correctly this state is the default right? so could just be

peer_status:
    - peer_name : cvx-red-2
    - peer_name : cvx-red-3

?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sometimes, some switches can intentionally be left at a non-"registration complete" state in case the system is between upgrades. In these cases, I would like to provide an option to input that as part of test.

Copy link
Collaborator

Choose a reason for hiding this comment

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

you can keep the input but my point was that this input is the default so not needed.

Also according to the docstring you wrote I feel like if left on purpose in non-"registration complete" would imply failure:

 * Failure: The test will fail if any of the following conditions are met:
        - If the CVX Status is disabled
        - If the peers are not in "Registration ok" state

Maybe it should be rewritten

        - If the peers are not in the expected state

Comment on lines +174 to +178
cluster_status = command_output.get("clusterStatus")
if not (command_output.get("clusterMode") and cluster_status):
self.result.is_failure("CVX Server is not a cluster")
return False
return True
Copy link
Collaborator

Choose a reason for hiding this comment

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

feels like this could be checked in _validate_cluster_status instead

peer_cluster = cluster_status.get("peerStatus")

# Check if peer_cluster is None or not sized
if not peer_cluster or not isinstance(peer_cluster, dict):
Copy link
Collaborator

Choose a reason for hiding this comment

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

is it possible that peer_cluster is not a dict if it is not None ?

I would probably change the logic here

# get a default dict if not present and assumes valid formatted dict otherwise
peer_cluster = cluster_status.get("peerStatus", {})

Comment on lines +197 to +201
# Check cluster role
cluster_role = cluster_status.get("role")
if cluster_role != self.inputs.role:
self.result.is_failure(f"CVX Role is not valid: {cluster_role}")
return False
Copy link
Collaborator

Choose a reason for hiding this comment

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

so here you are checking the role :)

I would move the check in a different place, add in the test docstring you are doing so and

Suggested change
# Check cluster role
cluster_role = cluster_status.get("role")
if cluster_role != self.inputs.role:
self.result.is_failure(f"CVX Role is not valid: {cluster_role}")
return False
if (cluster_role := cluster_status.get("role")) != self.inputs.role:
self.result.is_failure(f"CVX Role is not valid: {cluster_role}")
return False

Comment on lines +204 to +207
for peer in self.inputs.peer_status:
if not self._validate_individual_peer(peer, peer_cluster):
continue
return True
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this is more correct

here the if..continue is useless as there is nothing else in the loop
and the last return True is possibly wrong if any peer validation was False

Suggested change
for peer in self.inputs.peer_status:
if not self._validate_individual_peer(peer, peer_cluster):
continue
return True
return all(self._validate_individual_peer(peer, peer_cluster) for peer in self.inputs.peer_status)

Comment on lines +212 to +218
Args:
peer (Peer): The peer object containing expected peer details.
peer_cluster (dict[str, Any]): The dictionary representing the peer statuses in the cluster.

Returns
-------
bool: True if the peer is valid, False otherwise.
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
Args:
peer (Peer): The peer object containing expected peer details.
peer_cluster (dict[str, Any]): The dictionary representing the peer statuses in the cluster.
Returns
-------
bool: True if the peer is valid, False otherwise.
Parameters
------------
peer
The peer object containing expected peer details.
peer_cluster:
The dictionary representing the peer statuses in the cluster.
Returns
-------
bool
True if the peer is valid, False otherwise.

role: Master
peer_status:
- peer_name : cvx-red-2
registration_state: Registration complete
Copy link
Collaborator

Choose a reason for hiding this comment

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

is the state needed? if not then lets remove it from here

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.

3 participants