-
Notifications
You must be signed in to change notification settings - Fork 98
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
base_api.py: Implement operators and document them in cli help #2109
Conversation
5dad6bf
to
1d4aff3
Compare
Out of interest, would this work too? Since quotes are required anyway, we could also accept spaces around the operators. I guess it would just require a small tweak in the regex.
|
Ah also we need to make sure the previous syntax still works with e.g. |
1d4aff3
to
fd92f31
Compare
I forgot that variables might contain special characters too, just \w is not enough, i updated it, but i think still need to verify what kind of values might exist, as even new pattern might not match some special characters |
I will leave it here and create PR without spaces support, as they add additional limitations on names and values. |
fd92f31
to
5c8b797
Compare
895ad07
to
6d50193
Compare
I added also verification, for case you mentioned before:
Because many might not be aware because of our implementation details we cannot set in conditions same attribute name twice. |
6d50193
to
0139523
Compare
Right now for operators we are using "magic" suffix such as __gt, __lt and so on, which is not documented and a bit non-intuitive. We can make cli tool more intuitive with this patch, where it will hide from user this magic, until we find better mechanism to handle operators as mentioned in kernelci/kernelci-api#356 Also raise error if attribute name is used twice, as first one will be overwritten and ignored due current implementation. Signed-off-by: Denys Fedoryshchenko <denys.f@collabora.com>
0139523
to
ab63b8a
Compare
Tested locally:
|
Has this been tested with the staging API instance? I think this got merged too quickly. @JenySadadia Have you had a chance to look at this? |
Not yet. I'll test it soon. |
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.
Tested on staging.
Attributes with =
works without single quotes around.
$ ./kci node find name=checkout created=2023-07-17T11:52:31.913000
[{"id": "64b52b7fb5b4a9b8c05e0874", "kind": "node", "name": "checkout", "path": ["checkout"], "group": null, "revision": {"tree": "kernelci", "url": "https://github.com/kernelci/linux.git", "branch": "staging-mainline", "commit": "273cecedf983df3b9cc3fba85b773be154852975", "describe": "staging-mainline-20230717.0", "version": {"version": 6, "patchlevel": 5, "sublevel": null, "extra": "-rc2-1-g273cecedf983", "name": null}}, "parent": null, "state": "done", "result": null, "artifacts": {"tarball": "http://storage.staging.kernelci.org/api/linux-kernelci-staging-mainline-staging-mainline-20230717.0.tar.gz"}, "data": null, "created": "2023-07-17T11:52:31.913000", "updated": "2023-07-17T12:05:29.780000", "timeout": "2023-07-17T12:52:31.894000", "holdoff": "2023-07-17T12:03:49.144000", "owner": "staging.kernelci.org", "user_groups": []}]
However, it throws ValueError
with other operators.
$ ./kci node find name=checkout created>2023-07-17T11:52:31.913000
Traceback (most recent call last):
File "/home/jeny/kernelCI/kernelci-core_env/src/kernelci-core/./kci", line 29, in <module>
kernelci.cli.call(args.command, sys.argv[2:])
File "/home/jeny/kernelCI/kernelci-core_env/src/kernelci-core/kernelci/cli/__init__.py", line 53, in call
_COMMANDS[name](args)
File "/home/jeny/kernelCI/kernelci-core_env/src/kernelci-core/kernelci/cli/node.py", line 71, in main
sub_main("node", globals(), args)
File "/home/jeny/kernelCI/kernelci-core_env/src/kernelci-core/kernelci/cli/base.py", line 791, in sub_main
status = opts.command(configs, opts)
File "/home/jeny/kernelCI/kernelci-core_env/src/kernelci-core/kernelci/cli/base.py", line 417, in call
return func(*args, **kwargs)
File "/home/jeny/kernelCI/kernelci-core_env/src/kernelci-core/kernelci/cli/base_api.py", line 58, in __call__
return self._api_call(api, configs, args)
File "/home/jeny/kernelCI/kernelci-core_env/src/kernelci-core/kernelci/cli/node.py", line 38, in _api_call
attributes = self._split_attributes(args.attributes)
File "/home/jeny/kernelCI/kernelci-core_env/src/kernelci-core/kernelci/cli/base_api.py", line 103, in _split_attributes
raise ValueError(f"Invalid attribute {attribute}")
ValueError: Invalid attribute created
I'd suggest returning a proper error message instead of ValueError
in such case @nuclearcat
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 should also enable the support for !=
operator. But that is not implemented in the API yet.
It seems not working when I provided
|
The issue when providing the same attribute name twice is mentioned on kernelci/kernelci-api#356. Probably it would be good to have a checklist on that issue with things to do / fix before it's resolved. |
|
Because of way how conditions is implemented in kernelci-api (suffix in attribute name, __gt and etc), if you put different conditions - it will not be same attribute name anymore. |
That's true. I just recommended showing a proper error message to the user instead of returning the exception. |
Right now for operators we are using "magic" suffix such as __gt, __lt and so on, which is not documented and a bit non-intuitive. We can make cli tool more intuitive with this patch, where it will hide from user this magic, until we find better mechanism to handle operators as mentioned in kernelci/kernelci-api#356
Example tested:
Fixes: kernelci/kernelci-api#356