Commit Graph

9 Commits

Author SHA1 Message Date
Matthew Booth a785ad3441 Allow wrapping of closures
get_wrapped_function() assumes that any function which is a closure is a
decorator, and therefore has a function argument. This assumption fails
when the function is just a regular closure, and we end up falling
through and returning None.

Change-Id: I18da02d83fd9884e2e8c2173acf124140bd43525
2017-07-20 10:07:52 +01:00
Andrew Laski 997bec1bb9 Replace safe_utils.getcallargs with inspect.getcallargs
safe_utils.getcallargs was written to support python2.6 which did not
have inspect.getcallargs.  Now that support for python2.6 has been
dropped it should be replaced with inspect.getcallargs.

Change-Id: Idf5b9a7f4d10b81b1be9aed26505e3acaa6f7e24
2015-12-11 10:15:37 -05:00
Andrew Laski 1b757c328d Fix wrap_exception to get all arguments for payload
The wrap_exception decorator that attempts to send a notification when
exceptions occur was not sending all the arguments it was intending to.
It relies on getcallargs to get the arguments and argument names for the
called method but if the method has another decorator on it getcallargs
pulls information for the decorator rather than the decorated method.
This pulls the decorated method with get_wrapped_function and then calls
getcallargs.

get_wrapped_function was moved to safeutils because utils.py can't be
imported by exception.py without a circular import.

A few tests were updated to include the id on the instance object used.
This was done because serialization of the object includes the
instance.name field which assumes that id is set to populate the
CONF.instance_name_template.  When id is not set it triggers a lazy load
which fails in the test environment.

Change-Id: I87d8691a2aae6f3555177364f3c40a490a6f7591
Closes-bug: 1525282
2015-12-11 10:11:08 -05:00
Andrew Laski 2910d75b28 Fix use of safeutils.getcallargs
The getcallargs method was written under the assumption that self was
not passed in as an argument even if the function being introspected
took self as an argument.  Since safeutils.getcallargs is modeled on
inspect.getcallargs which does require self to be passed in the wrong
interface was being provided.

The initial user of getcallargs was therefore calling it incorrectly and
this usage was copied to other places.  However this led to strange
failures when someone attempted to call the method correctly.  So this
patch fixes callers of getcallargs, and removes some code from the
implementation that is not necessary once the usage is fixed.

Change-Id: I86eb59a2280961b809c1b4680012fab9566d60db
Closes-Bug: 1524990
2015-12-10 17:32:36 -05:00
Matt Riedemann 8b24bf766d Set autodoc_index_modules=True so tox -e docs builds module docs again
Commit bd7e62f796 disabled the
autodoc_index_modules flag for building docs but it wasn't really
necessary, that change was just to get the module index out of the main
docs page.

We want to autodoc the modules so we can view the actual module index in
the tox -d docs build results, which also tells us if we have correct
ReST format in doc strings.

Notes
-----

1. Several doc string blocks have to be fixed as part of this to get
   the docs tox job to pass.
2. A docstring in vhdutilsv2 is updated to remove the math directive
   since that requires the sphinx.ext.pngmath extension which requires
   latex and dvipng packages from the distro - which is overkill for
   what the docstring was actually doing with the math directive.
3. We exclude autodoc for tests since we don't really care about
   docstrings on unit tests.
4. We exclude the nova.wsgi.nova-* modules since those won't build with
   autodoc since they can't be imported (there is no
   nova/wsgi/__init__.py module). We could arguably add the __init__.py
   but it's not really necessary for what those scripts are used for.
5. The sphinx.ext.ifconfig extension is removed since there are no docs
   that use the ifconfig directive.
6. Update the developer docs to explicitly point out that graphviz must
   be installed prior to running tox -e docs.
7. Hide doc/source/api/autoindex.rst from the toctree so that we don't
   regress the point of commit bd7e62f796.
8. unused_docs and exclude_trees options are removed from conf.py since
   they are deprecated in Sphinx 1.2.3:

   https://github.com/sphinx-doc/sphinx/blob/1.2.3/sphinx/config.py#L54
9. Fix imports for moved libvirt volume options.

Closes-Bug: #1471934

Change-Id: I946e2f89f2c9fc70e870faaf84e4a8b0fc703344
2015-07-30 17:11:47 -07:00
Andrew Laski 34e089d229 Avoid indexing into an empty list in getcallargs
If a method signature has no named arguments, either empty or
(*args, **kwargs), then inspect.getargspec() will return an empty list
for argnames.  In that case we should not try to compare against the
first element of that list.

Also updates the docstring for getcallargs to specify a limitation of
the method.

Change-Id: I68af587fe91310a68bb5c37b80d3f00f5d45dd16
2015-04-10 13:10:16 -04:00
Joe Gordon 855fe98ef4 Fix and Gate on E265
pep8 E265 makes sure block comment start with '# '. Fix and gate on this
new rule as it helps improve comment readability.

In the few cases where the comment was just commented out code, remove
the comment.

Change-Id: Iea1c445df8ddc2b6c17a4ab697ad756eef2f91fa
2014-07-24 08:11:00 -04:00
liu-sheng 74f953a1d7 Remove vi modelines
We don't need to have the vi modelines in each source file,
it can be set in a user's vimrc if required.

Also a check is added to hacking to detect if they are re-added.

Change-Id: I347307a5145b2760c69085b6ca850d6a9137ffc6
Closes-Bug: #1229324
2014-02-03 14:19:44 +00:00
Sandy Walsh 1d5154ed0d Remove parameters containing passwords from Notifications.
compute.manager methods often takes password parameters in methods
that are wrapped with exception handlers and notifiers. What can
happen is these passwords will get bundled up and sent outside of
the system.

This patch will strip out any parameter with *_pass* in the name.

The side effect of this is that all notification will have the
error parameters in the 'args' part of the notification payload.
Previously only the positional args were in the 'args' part and
keyword args were placed in the payload directly.

This may affect consumers of the error notifications.

Change-Id: I2e7822eb5416d315ceb690f739e4dba9d52a7954
2013-03-05 16:27:29 -04:00