From fe745d41ef7fd6e9d0e5292da79f0722a94ab7c8 Mon Sep 17 00:00:00 2001 From: Emanuele Giuseppe Esposito Date: Wed, 12 Jan 2022 16:04:44 +0100 Subject: print error if datasource import fails (#1170) 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 that there is an import error, 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 when used to pick the datasource to use. Signed-off-by: Emanuele Giuseppe Esposito --- cloudinit/sources/__init__.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cloudinit/sources/__init__.py b/cloudinit/sources/__init__.py index 9083f399..bd862cdd 100644 --- a/cloudinit/sources/__init__.py +++ b/cloudinit/sources/__init__.py @@ -929,6 +929,12 @@ def list_sources(cfg_list, depends, pkg_list): m_locs, _looked_locs = importer.find_module( ds_name, pkg_list, ["get_datasource_list"] ) + if not m_locs: + LOG.error( + "Could not import %s. Does the DataSource exist and " + "is it importable?", + ds_name, + ) for m_loc in m_locs: mod = importer.import_module(m_loc) lister = getattr(mod, "get_datasource_list") -- cgit v1.2.3