Bug 1311730

Summary: oo-admin-ctl-cartridge gives no error with incorrect ids syntax
Product: OpenShift Online Reporter: Timothy Williams <tiwillia>
Component: UnknownAssignee: Rory Thrasher <rthrashe>
Status: CLOSED EOL QA Contact: Meng Bo <bmeng>
Severity: low Docs Contact:
Priority: unspecified    
Version: 2.xCC: aos-bugs, jokerman, mmccomas, rthrashe, xtian
Target Milestone: ---   
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2018-03-09 19:52:42 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:

Description Timothy Williams 2016-02-24 20:33:28 UTC
Description of problem:
Running the following command is incorrect syntax and will return nothing rather than an error:

  oo-admin-ctl-cartridge -c list -ids 000000000000

Version-Release number of selected component (if applicable):
2.2

How reproducible:
Always

Steps to Reproduce:
1. Run the following command to get a valid cartridge ID:
	oo-admin-ctl-cartridge -c list --all
2. Run the following command to get information just on that cartridge:
	oo-admin-ctl-cartridge -c list --ids 000000000000
3. Run the same command, with only one '-' before 'ids':
	oo-admin-ctl-cartridge -c list -ids 000000000000

Actual results:
Nothing is returned

Expected results:
An error is returned for the incorrect syntax.

Additional info:

Comment 1 Rory Thrasher 2016-05-06 23:06:47 UTC
So this is an interesting "feature" of ruby's optionparser: short style arguments are NOT disabled unless there are two long style arguments that start with the same letter.


So whats actually happening here is that running....

# oo-admin-ctl-cartridge -c list -ids 000000000000

...is actually using -i to get to --ids, and then is passing in ds as the first (and only, since its comma separated) id value.  The script will then check for carts that have an id that matches 'ds', and its no surprise that it comes up empty.  Note that this works the same way in ALL of our scripts.  We can't disable the short style options without editing the optionparser code, so anywhere that we only define a long option, unless theres a second long option that starts with the same letter, the short option is present.  So running `oo-admin-ctl-cartridge -c list -ds 00000000000` will actually get -d as the option and do a --dry-run, even though -d isn't specified as an option.



So basically theres only one real option to fix it.  We should go ahead and add the short style option (-i) for every long style option that will implicitly have a short style option.  I'm not sure how many oo-admin-commands attempt to use long style only options, but most that I've seen also use the short-style options.


Tim - what are your thoughts on going through all the oo commands and making sure we define and document the implied short style options where applicable?

Comment 2 Timothy Williams 2016-05-09 16:08:23 UTC
Well, there does not appear to be any way to configure optionParser to only support explicitly defined short options, it appears that the only option is to go through and define/document the short style options.

This bug is pretty low priority though, in my opinion. Its just confusing when the incorrect syntax is used and nothing is returned.

Comment 3 Rory Thrasher 2016-05-09 18:09:16 UTC
Right.  Thats what I was going for - explicitly define the short options (in addition to the long options) in the code (which will change the --help text) and then update the man pages.

Should be relatively easy to get done.

Comment 4 openshift-github-bot 2016-05-23 20:30:45 UTC
Commits pushed to master at https://github.com/openshift/origin-server

https://github.com/openshift/origin-server/commit/3b5dcf0807f398182a93a27fd54fd77468ffbfef
Bug1311730: Fixing short-form optparse options

Bug 1311730
BZ: https://bugzilla.redhat.com/show_bug.cgi?id=1311730

Errors were being seen when command line tools using the 'optparse' libary.
Using long-form only options with a single dash was resulting in odd returns,
but no errors.  This is because optparse automatically infers a short-form
option for long-form options that have a unique starting letter.  So '--ids' has
an implied short-form of '-i'.  This meant that running a command with '-ids'
would actually use '-i' and pass in "ds" as an ID value.  This commit takes
several cases where this happens and explicitely defines the short-form options
in the relevant scripts and man pages, which should reduce confusion on why
certain options may not error out as expected.

Also updates an old man page to reflect the current options.

https://github.com/openshift/origin-server/commit/feaf88b7923a7db76a3eb215e929014aea4601fe
Merge pull request #6388 from thrasher-redhat/bug1311730

Merged by openshift-bot

Comment 5 openshift-github-bot 2016-06-13 20:44:39 UTC
Commit pushed to master at https://github.com/openshift/origin-server

https://github.com/openshift/origin-server/commit/27b3d2564ab016b3aad9f03446c8295ea96b9f71
Update oo-admin-regenerate-gear-metadata man page

Bug 1311730
BZ: https://bugzilla.redhat.com/show_bug.cgi?id=1311730

The options for oo-admin-regenerate previously had an implied short option of
'-n' for '--no-accept-node'.  A previous PR defined the '-n' option in the
command's help options, however the man page was not updated.  The '-n' option
has been added to the man page as well now.

Comment 6 Rory Thrasher 2016-06-13 20:48:18 UTC
QA,

Can we check that these short-form options are shown in both the man page and --help options for the following commands?

1. oo-admin-broker-auth should now list the '-r' option for '--rekey' and the '-v' option for the '--verbose' options.

2. oo-admin-ctl-cartridge should now list the '-d' option for '--dry-run', the '-r' option for '--raw', the '-i' option for '--ids', the '-p' option for '--profile', the '-b' option for '--broker', the '-f' option for '--force', and the '-o' option for '--obsolete'.

3. oo-app-info should now list the '-r' option for '--raw'.

4. oo-admin-cartridge should now list '-a' for '--action', '-R' for '--recursive', '-m' for '--mco', and '-f' for '--force'.

5. oo-admin-regenerate-gear-metadata should list '-n' for '--no-accept-node'.

Thank you.

Comment 7 Meng Bo 2016-12-14 07:18:12 UTC
Checked on devenv_5831
The -r for oo-app-info displays as wrong format.
The -m for oo-admin-cartridge is missing.
Please see the details below.


# oo-admin-ctl-cartridge --help
    -c, --command COMMAND            A command to execute
    -b, --broker PATH                The path to the broker
                                      (default /var/www/openshift/broker/config/environment)
    -r, --raw                        Dump all cartridge information as JSON
    -f, --force                      Replace with new version even if unchanged
    -o, --obsolete                   Force activation of obsolete cartridges
    -a, --active                     Show only active cartridges
        --activate                   Mark imported or updated cartridges as active.
    -d, --dry-run                    Show the results of the update without changing anything.
    -n, --name NAMES                 Comma-delimited cartridge names.
        --all                        Display all information
    -q                               Display only ids
    -i, --ids IDS                    ID for a cartridge version to activate or deactivate (comma-delimited).
        --node NODE                  With import-node, server-identity for a node to import from.
    -p, --profile PROFILES           With import-profile, profile to import from (may be comma-separated list).
    -u, --url URL                    URL of a cartrige manifest to import.
    -h, --help                       Show this message


# oo-admin-broker-auth --help
-r|--rekey [uuid]
    Rekey an individual gear
-v|--verbose
    Show debugging information


# oo-app-info --help
        --raw                        r
                                     Print raw data structure without formatting.


# oo-admin-cartridge --help
    -a, --action ACTION              one of <install|list|erase>
        --mco                        Issue action via mcollective agent
    -R, --recursive                  Source is assumed to point to a directory containing cartridge directories
    -f, --force                      Force erase of cartridge


# oo-admin-regenerate-gear-metadata --help
    -n, --no-accept-node             Don't run accept node