Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cloudinit/importer.py: print a meaningful message if import fails
Sometimes an import might fail for different reasons: the string is wrongly typed, or the module has a dependency that is not installed in python. We should print what the error is about, otherwise it might be really difficult to understand what is the root cause of this issue. Currently, cloud-init just ignores the error and continues. This can have fatal consequences, especially when used to pick the datasource to use. For example, we can have a missing/misspelled datasource file: $ ls cloudinit/sources/DataSourceInexistent.py ls: cannot access 'cloudinit/sources/DataSourceInexistent.py': No such file or directory $ python >>> __import__("cloudinit.sources.DataSourceInexistent") and in this case cloud-init should also print "No module named 'cloudinit.sources.DataSourceInexistent'" If instead the datasource exists but uses a dependency that is not installed (for example netifaces for DataSourceVMware): $ ls cloudinit/sources/DataSourceVMWare.py cloudinit/sources/DataSourceVMWare.py $ python >>> __import__("cloudinit.sources.DataSourceVMware") then cloud-init should print "No module named 'netifaces'" In order to not add unnecessary logging and modify existing tests, add the logging as optional and use it only in cloudinit/sources/__init__.py, to handle the cases explained above. Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
- Loading branch information