-
Notifications
You must be signed in to change notification settings - Fork 9
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
Conversation
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.
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
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. |
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.
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" |
e20cd39
to
2f7b18c
Compare
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.
I think it's really close! Looks like the code works; I'd just suggest rearranging a few things.
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.
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.
2f7b18c
to
f43564c
Compare
@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. |
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.
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 toutils.filter_nodes_by_properties
is made; you can even mock the return value. Then you need to create and add tests totests/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.
f43564c
to
23d748f
Compare
23d748f
to
a5fcc1c
Compare
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.
Left a few comments, including ones about missing test cases. If a test case gets long, just split it into multiples.
a5fcc1c
to
a1c4ec1
Compare
@tzumainn I have addressed all your comments. |
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.
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?
3e63aa6
to
2ba1f83
Compare
45b3160
to
7a3e3e5
Compare
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.
I think this looks good! I've left a minor comment, but you can ignore it or not as you like.
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.
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.
7a3e3e5
to
d00fabc
Compare
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.
Looks good to me - thanks!
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:
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:
ListNode
command to include property filtering support.--property
argument to the parser for specifying property filters.Created test_utils.py:
Written additional test cases to verify the functionality of the utility functions:
Changes in test_node.py, test_lease.py, test_offer.py:
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
).