By doing this, we allow the error messages to be more useful. When an import
of a class fails because of a missing module dependency, it would have fail
that way for example:
$ nova-manage
Traceback (most recent call last):
File "./bin/nova-manage", line 84, in <module>
from nova import image
File "/home/jd/Work/src/nova/nova/image/__init__.py", line 22, in <module>
from nova.image import glance
File "/home/jd/Work/src/nova/nova/image/glance.py", line 42, in <module>
GlanceClient = utils.import_class('glance.client.Client')
File "/home/jd/Work/src/nova/nova/utils.py", line 66, in import_class
raise exception.ClassNotFound(class_name=class_str)
nova.exception.ClassNotFound: Class Client could not be found
This does not help the user, since it indicates the class Client cannot be
found, even if it is actually found but fail to import.
With this commit, the error message is better:
nova-manage
Traceback (most recent call last):
File "./bin/nova-manage", line 84, in <module>
from nova import image
File "/home/jd/Work/src/nova/nova/image/__init__.py", line 22, in <module>
from nova.image import glance
File "/home/jd/Work/src/nova/nova/image/glance.py", line 42, in <module>
GlanceClient = utils.import_class('glance.client.Client')
File "/home/jd/Work/src/nova/nova/utils.py", line 66, in import_class
raise exception.ClassNotFound(class_name=class_str, exception=exc)
nova.exception.ClassNotFound: Class Client could not be found: No module named kombu.connection
This helps to know that in this kombu is missing.
It would probably even better to rename ClassNotFound to
ClassCannotBeImported or something like that too.
Change-Id: I4100d931a0a825fa0729d5467d2f9268fdd2a261
Signed-off-by: Julien Danjou <julien.danjou@enovance.com>
* Adds a run_as_root parameter to utils.execute, that prefixes your command with FLAG.root_helper (which defaults to 'sudo')
* Turns all sudo calls into run_as_root=True calls
* Update fakes accordingly
* Replaces usage of "sudo -E" and "addl_env" parameter into passing environment in the command (allows it to be compatible with alternative sudo_helpers)
* Additionally, forces close_fds=True on all utils.execute calls, since it's a more secure default
Anywhere "except:" occurs, I tried to replace it with an explicit except on
known error types. If none were known, Except was used.
In the process I've been able to unearth a few evasive bugs and clean up some
adjacent code.