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

Apply property filters #57

Merged
merged 1 commit into from
Jun 20, 2024
Merged

Conversation

skanthed
Copy link
Collaborator

@skanthed skanthed commented May 31, 2024

This commit introduces support for filtering nodes based on properties in the node listing command and adds corresponding test cases to ensure the functionality works as expected.

Changes in utils.py:

  • Added functions to parse property filters and apply them to nodes.
    • convert_value: Converts a value string to the appropriate type (int, float, or string).
    • parse_property_filter: Parses a property filter string into a key, operator, and value.
    • node_matches_property_filters: Checks if a node matches all provided property filters.
    • filter_nodes_by_properties: Filters a list of nodes based on the provided property filters. Prints a message if no nodes match the specified properties.

Changes in node.py lease.py and offer.py:

  • Updated the ListNode command to include property filtering support.
    • Added --property argument to the parser for specifying property filters.
    • Applied property filters to the list of nodes retrieved from the client.
    • Printed a message if no nodes, lease or offer match the specified properties.

Created test_utils.py:

Written additional test cases to verify the functionality of the utility functions:

  • test_convert_value: Tests value conversion for different data types.
  • test_parse_property_filter: Tests parsing of property filter strings.
  • test_node_matches_property_filters: Tests node matching against multiple property filters.
  • test_filter_nodes_by_properties: Tests the filtering of nodes based on property filters.

Changes in test_node.py, test_lease.py, test_offer.py:

  • Added test cases to verify the functionality of property filters in node listing.
    • test_node_list_with_property_filter: Verifies node listing with a property filter (cpus>=40).
    • test_node_list_long_with_property_filter: Verifies detailed node listing with a property filter (memory_mb>=131072).

@skanthed skanthed self-assigned this May 31, 2024
Copy link
Contributor

@tzumainn tzumainn left a comment

Choose a reason for hiding this comment

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

Looks like a good start! Two broad comments I'd make here:

  • it probably makes sense to break off this logic into the utils file; this way it can be applied to any result that returns a list of properties
  • you may want a dictionary that maps property names to the types of values they have (i.e., local_gb is a number, vendor is a string). I think this will allow you to do comparision operations

@skanthed
Copy link
Collaborator Author

skanthed commented Jun 3, 2024

Sure I will remember to keep it in the utils file. All values returned within properties are in string format. However, converting some values to integers to apply conditional logic.

@skanthed skanthed requested a review from tzumainn June 5, 2024 14:50
Copy link
Contributor

@tzumainn tzumainn left a comment

Choose a reason for hiding this comment

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

I think this is a good start! The = operator works well for me; however, the > and >= operators failed:

$ openstack esi node list --property memory_mb>262144
Invalid property filter format: memory_mb

esileapclient/osc/v1/node.py Outdated Show resolved Hide resolved
esileapclient/common/utils.py Outdated Show resolved Hide resolved
esileapclient/common/utils.py Outdated Show resolved Hide resolved
@skanthed
Copy link
Collaborator Author

I think this is a good start! The = operator works well for me; however, the > and >= operators failed:

$ openstack esi node list --property memory_mb>262144
Invalid property filter format: memory_mb

@tzumainn The command openstack esi node list --long --property memory_mb>262144 fails due to how the shell interprets the > character. Without quotes, the shell may treat > as a redirection operator, causing the argument to split incorrectly. Use quotes around the --property value to ensure it is passed as a single argument:

openstack esi node list --long --property "memory_mb>262144" 

@skanthed skanthed requested a review from tzumainn June 10, 2024 17:09
@skanthed skanthed marked this pull request as ready for review June 10, 2024 17:10
Copy link
Contributor

@tzumainn tzumainn left a comment

Choose a reason for hiding this comment

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

I think it's really close! Looks like the code works; I'd just suggest rearranging a few things.

esileapclient/common/utils.py Outdated Show resolved Hide resolved
esileapclient/common/utils.py Outdated Show resolved Hide resolved
esileapclient/osc/v1/node.py Outdated Show resolved Hide resolved
esileapclient/common/utils.py Outdated Show resolved Hide resolved
Copy link
Member

@larsks larsks left a comment

Choose a reason for hiding this comment

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

I would like to see tests in this pull request. We should exercise all the valid operators as well as the behavior when there is an invalid operator.

I would also like to see the commit message updated with a description of what this change is for. Currently neither the pull request not the commit has any description.

@skanthed skanthed requested a review from tzumainn June 17, 2024 10:39
@skanthed
Copy link
Collaborator Author

@larsks @tzumainn - I have described this PR above. Please have a look.

@skanthed
Copy link
Collaborator Author

@tzumainn I have just written two test cases for now please let me know if you think I should write test different cases for every valid operator and test invalid operators too. I will do that.
In the final commit, I will provide detailed description of this PR.

Copy link
Contributor

@tzumainn tzumainn left a comment

Choose a reason for hiding this comment

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

Two broad comments!

  • We also want to add the filter to offer/lease list; I believe those already have node properties in the --long version
  • The unit tests should be done a little differently. In test_node.py you really only need to check that the call to utils.filter_nodes_by_properties is made; you can even mock the return value. Then you need to create and add tests to tests/unit/common/test_utils.py that call the utility functions directly and test the various outcomes. You'll want to test the various operators, and also the various possible inputs.

@skanthed skanthed requested review from larsks and tzumainn June 17, 2024 17:12
@skanthed
Copy link
Collaborator Author

skanthed commented Jun 17, 2024

@larsks @tzumainn I Updated the operator function as you suggested and test cases too. Once everything looks good for node list will update that in lease and offer list.

Copy link
Contributor

@tzumainn tzumainn left a comment

Choose a reason for hiding this comment

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

Left a few comments, including ones about missing test cases. If a test case gets long, just split it into multiples.

esileapclient/common/utils.py Outdated Show resolved Hide resolved
esileapclient/common/utils.py Outdated Show resolved Hide resolved
esileapclient/tests/unit/common/test_utils.py Outdated Show resolved Hide resolved
esileapclient/common/utils.py Outdated Show resolved Hide resolved
esileapclient/tests/unit/common/test_utils.py Outdated Show resolved Hide resolved
esileapclient/tests/unit/common/test_utils.py Show resolved Hide resolved
esileapclient/tests/unit/common/test_utils.py Outdated Show resolved Hide resolved
esileapclient/tests/unit/common/test_utils.py Show resolved Hide resolved
@skanthed skanthed requested a review from tzumainn June 18, 2024 16:07
@skanthed
Copy link
Collaborator Author

@tzumainn I have addressed all your comments.

Copy link
Contributor

@tzumainn tzumainn left a comment

Choose a reason for hiding this comment

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

This looks pretty good - only a few minor changes. Can you also add a description to the commit message, and add the property filtering to the lease/offer lists?

esileapclient/common/utils.py Outdated Show resolved Hide resolved
esileapclient/tests/unit/common/test_utils.py Outdated Show resolved Hide resolved
esileapclient/osc/v1/node.py Outdated Show resolved Hide resolved
@skanthed skanthed force-pushed the property-filters branch 2 times, most recently from 3e63aa6 to 2ba1f83 Compare June 18, 2024 16:41
@skanthed skanthed requested a review from tzumainn June 18, 2024 16:42
@skanthed skanthed force-pushed the property-filters branch 2 times, most recently from 45b3160 to 7a3e3e5 Compare June 19, 2024 02:23
Copy link
Member

@larsks larsks left a comment

Choose a reason for hiding this comment

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

I think this looks good! I've left a minor comment, but you can ignore it or not as you like.

esileapclient/common/utils.py Show resolved Hide resolved
esileapclient/osc/v1/node.py Outdated Show resolved Hide resolved
Copy link
Contributor

@tzumainn tzumainn left a comment

Choose a reason for hiding this comment

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

Works great from my testing! Let me know if you wanted to make the change Lars suggested.

- Add property filter parsing and conversion functions in 'utils.py'.
- Update 'ListNode' to support property filtering with improved logging.
- Add unit tests for parsing, validation, and node filtering.
@skanthed
Copy link
Collaborator Author

@tzumainn @larsks Updated with your suggestion.

Copy link
Contributor

@tzumainn tzumainn left a comment

Choose a reason for hiding this comment

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

Looks good to me - thanks!

@tzumainn tzumainn merged commit 6b3fadd into CCI-MOC:master Jun 20, 2024
6 checks passed
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