Note: This is a beta release of Red Hat Bugzilla 5.0. The data contained within is a snapshot of the live data so any changes you make will not be reflected in the production Bugzilla. Also email is disabled so feel free to test any aspect of the site that you want. File any problems you find or give feedback here.
Bug 1357495 - ipa command provides stack trace when provided with single hypen commands
Summary: ipa command provides stack trace when provided with single hypen commands
Keywords:
Status: NEW
Alias: None
Product: Red Hat Enterprise Linux 8
Classification: Red Hat
Component: ipa
Version: 8.0
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: rc
: ---
Assignee: IPA Maintainers
QA Contact: Kaleem
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2016-07-18 11:41 UTC by Abhijeet Kasurde
Modified: 2019-03-25 16:50 UTC (History)
4 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed:
Type: Bug


Attachments (Terms of Use)

Description Abhijeet Kasurde 2016-07-18 11:41:24 UTC
Description of problem:
If user provides commands such as following, then ipa command provides stack trace instead of error message to user.


# ipa -verbose
Traceback (most recent call last):
  File "/usr/bin/ipa", line 32, in <module>
    cli.run(api)
  File "/usr/lib/python2.7/site-packages/ipalib/cli.py", line 1346, in run
    api.log.exception('%s: %s', e.__class__.__name__, str(e))
AttributeError: 'API' object has no attribute 'log'

# ipa -ver
Traceback (most recent call last):
  File "/usr/bin/ipa", line 32, in <module>
    cli.run(api)
  File "/usr/lib/python2.7/site-packages/ipalib/cli.py", line 1346, in run
    api.log.exception('%s: %s', e.__class__.__name__, str(e))
AttributeError: 'API' object has no attribute 'log'

# ipa -e aa 
Traceback (most recent call last):
  File "/usr/bin/ipa", line 32, in <module>
    cli.run(api)
  File "/usr/lib/python2.7/site-packages/ipalib/cli.py", line 1346, in run
    api.log.exception('%s: %s', e.__class__.__name__, str(e))
AttributeError: 'API' object has no attribute 'log'


Version-Release number of selected component (if applicable):
ipa-server-4.2.0-15.el7_2.17.x86_64

How reproducible:
100%

Steps to Reproduce:
1. ipa -verbose # or
2. ipa -e aa # or
3. ipa -ver 

Actual results:
IPA command provides stack traces

Expected results:
IPA command should provide user friendly information about unknown command

Comment 2 Martin Bašti 2016-07-22 10:30:15 UTC
Upstream ticket:
https://fedorahosted.org/freeipa/ticket/6115

Comment 3 Petr Vobornik 2017-04-06 16:05:42 UTC
IdM team doesn't have capacity to fix this bug for RHEL 7.4. Moving to next RHEL version. Fixing the bug there will depend on capacity of FreeIPA upstream. Without sufficient  justification there is a chance that it will be moved again later.

Comment 5 Rob Crittenden 2018-05-11 17:15:43 UTC
Single options are fine. The problem in this case is different.


# ipa -verbose

This is option -v, option -e and rbose as an environment variable without an = sign which is invalid.

# ipa -ver

Virtually the same, just with r as the environment.

# ipa -e aa 

Same, aa as an environment variable and no value.

I think the log failure is masking the actual error.

We see a different error in master:

UnboundLocalError: local variable 'value' referenced before assignment
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/ipalib/cli.py", line 1403, in run
    (_options, argv) = api.bootstrap_with_global_options(context='cli')
  File "/usr/lib/python3.6/site-packages/ipalib/plugable.py", line 594, in bootstrap_with_global_options
    overrides[str(key.strip())] = value.strip()
UnboundLocalError: local variable 'value' referenced before assignment
an internal error has occurred

value is unreferenced because it is obtained via:

(key, value) = item.split('=', 1)

Since there is no = there is no value so it blows up.

I think this will fix it:

--- ipalib/plugable.py
@@ -585,13 +585,18 @@
             assert type(options.env) is list
             for item in options.env:
                 try:
-                    (key, value) = item.split('=', 1)
+                    values = item.split('=', 1)
                 except ValueError:
                     # FIXME: this should raise an IPA exception with an
                     # error code.
                     # --Jason, 2008-10-31
                     pass
-                overrides[str(key.strip())] = value.strip()
+                if len(values) == 2:
+                    (key, value) = values
+                    overrides[str(key.strip())] = value.strip()
+                else:
+                    raise errors.OptionError(_('Unable to parse option {item}'
+                                      .format(item=item)))
         for key in ('conf', 'debug', 'verbose', 'prompt_all', 'interactive',
             'fallback', 'delegate'):
             value = getattr(options, key, None)

The only problem with the exception is that it isn't clear what is actually wrong. For example for the case of -verbose the error is:

Unable to parse option rbose


Note You need to log in before you can comment on or make changes to this bug.