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

ceph.in: clean up and enable --foo=bar style arguments #24333

Merged
merged 14 commits into from
Nov 8, 2018

Conversation

jcsp
Copy link
Contributor

@jcsp jcsp commented Sep 28, 2018

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):

ceph osd pool create mypool 8 8 replicated

With this change, we can use a simpler form without extra unnecessary args:

ceph osd pool create mypool 8 --pool_type=replicated

In general, I would expect most people to continue using positional arguments for the mandatory arguments, and switch to keyword arguments for optional arguments.

  • Updates documentation if necessary
  • Includes tests for new functionality or reproducer for bug

@@ -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
Copy link
Member

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

Copy link
Contributor Author

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.

@liewegas
Copy link
Member

liewegas commented Oct 5, 2018

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)
Copy link
Member

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?..

Copy link
Contributor Author

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

Copy link
Member

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)?

https://docs.python.org/2/library/functions.html#raw_input

Copy link
Member

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.

Copy link
Member

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. ?

Copy link
Contributor Author

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!

Copy link
Member

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.
Copy link
Member

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?

Copy link
Contributor Author

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

@jcsp jcsp changed the title [RFC] ceph.in: clean up and enable --foo=bar style arguments ceph.in: clean up and enable --foo=bar style arguments Oct 10, 2018
@jcsp
Copy link
Contributor Author

jcsp commented Oct 10, 2018

This now has "--foo=bar" style support. This introduces a constraint that string arguments need to not start with --, so that we don't eat mistyped keyword arguments if they appear in a place where they could also be a string.

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.

@jcsp
Copy link
Contributor Author

jcsp commented Oct 10, 2018

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.

@jcsp jcsp force-pushed the wip-kwargs branch 5 times, most recently from 7e9c4ed to fe7d4ef Compare October 17, 2018 11:33
@liewegas
Copy link
Member

needs rebase

@jcsp
Copy link
Contributor Author

jcsp commented Oct 18, 2018

rebased

@liewegas liewegas requested a review from dmick October 19, 2018 13:58
@@ -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", \
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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

Copy link
Contributor Author

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

Copy link
Member

Choose a reason for hiding this comment

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

Sounds good

@tchaikov
Copy link
Contributor

2018-10-26T15:13:45.598 INFO:tasks.workunit.client.0.smithi175.stderr:/home/ubuntu/cephtest/clone.client.0/qa/workunits/cephtool/test.sh:2192: test_mon_osd_erasure_code:ceph osd erasure-code-profile set fooprofile a=b c=d e=f --force
2018-10-26T15:13:45.888 INFO:tasks.workunit.client.0.smithi175.stderr:desc={profile(<string>) [<string>...]} t=<class 'ceph_argparse.CephString'>Invalid command: Unexpected argument '--force'
2018-10-26T15:13:45.888 INFO:tasks.workunit.client.0.smithi175.stderr:osd erasure-code-profile set <name> {<profile> [<profile>...]} :  create erasure code profile <name> with [<key[=value]> ...] pairs. Add a --force at the end to overrid
e an existing profile (VERY DANGEROUS)
2018-10-26T15:13:45.889 INFO:tasks.workunit.client.0.smithi175.stderr:Error EINVAL: invalid command

http://pulpito.ceph.com/kchai-2018-10-26_14:26:38-rados-wip-kefu-testing-2018-10-25-1035-distro-basic-smithi/3186771/

@jcsp jcsp force-pushed the wip-kwargs branch 2 times, most recently from 681da6e to 55e44b1 Compare November 2, 2018 00:05
@jcsp
Copy link
Contributor Author

jcsp commented Nov 2, 2018

retest this please

John Spray added 12 commits November 2, 2018 06:57
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>
@liewegas
Copy link
Member

liewegas commented Nov 6, 2018

retest this please

John Spray added 2 commits November 7, 2018 07:02
Signed-off-by: John Spray <john.spray@redhat.com>
Signed-off-by: John Spray <john.spray@redhat.com>
@jcsp
Copy link
Contributor Author

jcsp commented Nov 7, 2018

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.

@liewegas
Copy link
Member

liewegas commented Nov 7, 2018

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", \
Copy link
Member

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?

Copy link
Member

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.

Copy link
Contributor Author

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

@jcsp
Copy link
Contributor Author

jcsp commented Nov 8, 2018

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)

@tchaikov
Copy link
Contributor

tchaikov commented Nov 8, 2018

FWIW, #24896 is supposed to address rados/test_librados_build.sh and rados/test_envlibrados_for_rocksdb.sh failures.

@liewegas liewegas merged commit 4df08eb into ceph:master Nov 8, 2018
liewegas added a commit that referenced this pull request Nov 8, 2018
* 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>
@jcsp jcsp deleted the wip-kwargs branch November 9, 2018 15:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants