-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
ceph.in: clean up and enable --foo=bar style arguments #24333
Conversation
src/pybind/ceph_argparse.py
Outdated
@@ -851,30 +853,20 @@ def matchnum(args, signature, partial=False): | |||
return matchcnt | |||
|
|||
|
|||
def get_next_arg(desc, args): | |||
def _get_next_arg(desc, args): | |||
''' | |||
Get either the value matching key 'desc.name' or the next arg in |
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 guess this comment changes with the reduced function too
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.
Yeah -- I think actually I'll remove this function entirely, the part where it considers one of the args being a list seems to be redundant as we're always parsing a simple list of strings from the CLI.
Can/do we allow "--foo bar" style too? (i.e., space instead of =) |
src/ceph.in
Outdated
@@ -600,12 +599,6 @@ def new_style_command(parsed_args, cmdargs, target, sigdict, inbuf, verbose): | |||
# Non interactive mode | |||
ret, outbuf, outs = do_command(parsed_args, target, cmdargs, sigdict, inbuf, verbose) | |||
else: | |||
# Interactive mode (ceph cli) |
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.
how do we get to remove this? Is readline support now builtin?..
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.
Is just importing readline meant to have an effect? It seems like e.g. pressing the up arrow to see last command already doesn't work, so I'm not sure what it was meant to be doing
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.
It had been the case that, when raw_input() was used, "import readline" made it support line-editing-and-recall features. Perhaps the port to Py3 lost that behavior (as raw_input disappeared too)?
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.
confusingly, both Py2 and Py3 pre-import readline for me, and thus raw_input() on py2 and input() on py3 have the recall behavior. odd that you don't observe it with ceph CLI. Digging.
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.
https://gist.github.com/dmick/90b43cb15464417870147d953d7a2412 works as I'd expect for me with py2 and py3. ?
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.
Huh, yeah, that snippet does show importing readline having the side effect on raw_input, which is presumably why it was in ceph.in. I'll reinstate it. Thanks for setting me straight!
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.
(my "pre-import" comment was about the IDE, which of course makes sense since it also supports commandline editing)
src/ceph.in
Outdated
""" | ||
Consume generic arguments from the start of the ``args`` | ||
list. Call this first to handle arguments that are not | ||
part of a server-side command's parameters. |
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 know it's hard to describe this, but...the 'generic args' are server-side too. hm. Maybe just call them "generic args that are not part of the 'argdesc' parameters" as a signpost?
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'll update this comment
This now has "--foo=bar" style support. This introduces a constraint that string arguments need to not start with There were a few CephString instances for --yes-i-really-mean-it etc, so I've made them all CephChoices, and added a special case for those strings when talking to an old daemon. |
I still have one annoying failure for the test that invokes "osd reweight-by-utilization --no-increasing" with the expectation that the parser will skip over the numeric arguments and match --no-increasing to the first string arg -- this doesn't work with the new code because --no-increasing just looks like a bogus keyword argument, so I'm inclined to change the rules to say that positional arguments have to be in order, rather than allowing this "skip through args until you find one that's a match for the type" case. |
7e9c4ed
to
fe7d4ef
Compare
needs rebase |
rebased |
src/mgr/MgrCommands.h
Outdated
@@ -108,14 +108,14 @@ COMMAND("osd test-reweight-by-pg " \ | |||
|
|||
COMMAND("osd destroy " \ | |||
"name=id,type=CephOsdName " \ | |||
"name=sure,type=CephString,req=False", | |||
"name=sure,type=CephChoices,strings=--force|--yes-i-really-mean-it,req=false", \ |
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.
Does this mean you can do
ceph osd destroy osd.123 --sure=--force
? It seems like what we maybe want instead is a new option,
name=force,type=CephBool,default=False
Then we'd update the code to look for the new field, and leave the optional positional one there for 2+ releases for backward compatibility?
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 agree with wanting to introduce a CephBool type, but I think it can come later? The CephChoices style is consistent with other commands that already used that for the confirmation flag.
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 agree with wanting to introduce a CephBool type, but I think it can come later? The CephChoices style is consistent with other commands that already used that for the confirmation flag.
I'm kind of hoping that nobody would actually use the weird --sure=--force
style, and/or the cleaned up CephBool thing would happen before releasing Nautilus
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 agree with wanting to introduce a CephBool type, but I think it can come later? The CephChoices style is consistent with other commands that already used that for the confirmation flag.
I'm kind of hoping that nobody would actually use the weird --sure=--force
style, and/or the cleaned up CephBool thing would happen before releasing Nautilus
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.
Sounds good
|
681da6e
to
55e44b1
Compare
retest this please |
Signed-off-by: John Spray <john.spray@redhat.com>
This was introduced for the now-removed ceph-rest-api gateway. It enabled limiting certain commands to be CLI-only or rest-only, but in practice almost everything just said "cli,rest" here. Now that ceph-rest-api is gone, let's remove this field. The CLI client code already tolerated the absence of this field, so older CLI clients will not mind. Signed-off-by: John Spray <john.spray@redhat.com>
Get this pyflakes-clean ahead of making changes for keyword arguments. Signed-off-by: John Spray <john.spray@redhat.com>
Add some docstrings to functions, remove some dead code and places where e.g. dicts were used unncessary. Signed-off-by: John Spray <john.spray@redhat.com>
This is a simple implementation that treats anything that matches the "--X=Y" pattern as separate from positional arguments. This works well for optional arguments. Mandatory arguments still need to be specified positionally, or the parsing code will think the command's argument description has not been satisfied. Signed-off-by: John Spray <john.spray@redhat.com>
This had existed in a disabled state (by having an empty string for the cli/rest field in the command definition) for a long time. Now that that field is gone, we don't have a concept of "disabled" commands any more, so let's just clean up this loose end. Signed-off-by: John Spray <john.spray@redhat.com>
Signed-off-by: John Spray <john.spray@redhat.com>
...so that arg parsing can rely on strings satisfying a "doesn't start with --" convention. Signed-off-by: John Spray <john.spray@redhat.com>
This relied on a behaviour where positional arguments could be omitted if the subsequent argument was of a different type. This was pretty weird, and in any case the reweight-by-utilization command is likely to go away soon. Signed-off-by: John Spray <john.spray@redhat.com>
This replaces use of CephChoices for cases like --yes-i-really-really-mean-it. It's a relatively invasive change, because both client and server need to handle backward compatibility: - Clients are easy, they just cope with the server's use of CephChoices/CephString with a few special case strings to recognise --yes-i-really-mean-it and similar - Servers are harder, they have to convert CephBool arguments into a similar CephChoices argument that older clients will understand. This involves propagating feature flags into some code paths that couldn't see them before. Signed-off-by: John Spray <john.spray@redhat.com>
Signed-off-by: John Spray <john.spray@redhat.com>
Signed-off-by: John Spray <john.spray@redhat.com>
retest this please |
Signed-off-by: John Spray <john.spray@redhat.com>
Signed-off-by: John Spray <john.spray@redhat.com>
teuthology run here: http://pulpito.ceph.com/jspray-2018-11-02_14:40:18-rados-wip-kwargs-distro-basic-smithi/ test_python.sh failure was because of a lingering --yes-i-really-mean-it in the application_enable path through librados. I've updated it, but that is also going to show up for anyone who is using an old librados with a newer Ceph cluster -- we shouldn't really have been hardcoding that CLI syntax into librados :-/ Other librados test failures were from old style --yes-i-really-mean-it instances in the test code. |
retest this please |
"name=sure,type=CephString,req=False", | ||
"name=force,type=CephBool,req=false " | ||
// backward compat synonym for --force | ||
"name=yes_i_really_mean_it,type=CephBool,req=false", \ |
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.
What if, instead, we simply s/sure/force/, and s/CephString/CephBool/. Then the compat code would only need to rewrite CephBool to CephString in the general case, and the code for each of these commands in the mon would need to tolerate getting either a boolean or a "--yes-i-really-mean-it" style string (it already does the latter). I think that would make it so that the librados test case code would only need s/sure/force/? And we would end up with only one field defined here in MonCommands. We would lose the CephChoices that would tell you the magic force argument on older clients in ceph -h, but that is small and maybe even a good thing anyway?
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.
Oh, I see... this way lets you still do --yes-i-really-mean-it on the new code while also making it a non-positional flag.
In that case, I think the checks in the mon need to be adjusted so that they tolerate a string being passed for the compat field. Probably a helper like bool cmdmap_compat_confirm(cmdmap, "force", "yes_i_really_mean_it") or something would make this easier and capture all of the compat hackery.
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 particular command definition already had both --force and --yes-i-really-mean-it, the two lines here are just synonym flags rather than anything related to CephBool vs. CephChoices
Rerun with fixes: http://pulpito.ceph.com/jspray-2018-11-08_09:46:03-rados-wip-kwargs-distro-basic-smithi/ Looks good so far (failures in rados/test_librados_build.sh and rados/test_envlibrados_for_rocksdb.sh are unrelated to this) |
FWIW, #24896 is supposed to address |
* refs/pull/24333/head: test: update librados tests for CLI arg syntax librados: update for CLI arg format change pybind: update python callers of force flags mon: convert remaining confirmation flags to CephBool ceph_argparse: introduce CephBool arguments test: remove quirky argparse case mgr,mon: use CephChoices for confirmation flags test: add cases for CLI's --key=val style mon: remove dead "cluster_snap" command pybind: enable --keyword=arguments in ceph_argparse ceph.in: some cleanups ceph.in: misc cleanups common: remove unused 'avail' field from commands mon: fix help string for `osd crush rule create-replicated` Reviewed-by: Sage Weil <sage@redhat.com>
Currently, our CLI only provides positional arguments -- if there are lots of optional fields for an operation, we can only specify a field by specifying all the optional fields before it too. That's awkward, and it's hard to be sure you've got all your values in the order you intended.
For example, specifying "pool_type" on a created pool, previously we had to know the right order of args, and also specify the pgp_num field (because it comes before pool type in the command definition):
With this change, we can use a simpler form without extra unnecessary args:
In general, I would expect most people to continue using positional arguments for the mandatory arguments, and switch to keyword arguments for optional arguments.