summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Harlow <harlowja@yahoo-inc.com>2014-09-02 13:31:18 -0700
committerJoshua Harlow <harlowja@yahoo-inc.com>2014-09-02 13:31:18 -0700
commit141caf7f3b224c0265c7bb0014b96ca08aa67193 (patch)
tree92e23f731504ee7f2d9f2f31feb76b28179ae3b9
parent128fd80cb0b27430def29bee7a8c473facd84be8 (diff)
downloadvyos-cloud-init-141caf7f3b224c0265c7bb0014b96ca08aa67193.tar.gz
vyos-cloud-init-141caf7f3b224c0265c7bb0014b96ca08aa67193.zip
Remove/adjust the verbose 'failed at attempted import of' log
Instead of using this log (which really isn't a failure) we should instead of just return the looked up locations and then if there really is an error the caller can handle the usage of the looked up locations as they choose fit.
-rw-r--r--cloudinit/distros/__init__.py8
-rw-r--r--cloudinit/importer.py21
-rw-r--r--cloudinit/mergers/__init__.py10
-rw-r--r--cloudinit/sources/__init__.py6
-rw-r--r--cloudinit/stages.py18
5 files changed, 29 insertions, 34 deletions
diff --git a/cloudinit/distros/__init__.py b/cloudinit/distros/__init__.py
index 4b41220e..9c9211fe 100644
--- a/cloudinit/distros/__init__.py
+++ b/cloudinit/distros/__init__.py
@@ -847,12 +847,10 @@ def extract_default(users, default_name=None, default_config=None):
def fetch(name):
- locs = importer.find_module(name,
- ['', __name__],
- ['Distro'])
+ locs, looked_locs = importer.find_module(name, ['', __name__], ['Distro'])
if not locs:
- raise ImportError("No distribution found for distro %s"
- % (name))
+ raise ImportError("No distribution found for distro %s (searched %s)"
+ % (name, looked_locs))
mod = importer.import_module(locs[0])
cls = getattr(mod, 'Distro')
return cls
diff --git a/cloudinit/importer.py b/cloudinit/importer.py
index a1929137..fb57253c 100644
--- a/cloudinit/importer.py
+++ b/cloudinit/importer.py
@@ -22,10 +22,6 @@
import sys
-from cloudinit import log as logging
-
-LOG = logging.getLogger(__name__)
-
def import_module(module_name):
__import__(module_name)
@@ -33,25 +29,24 @@ def import_module(module_name):
def find_module(base_name, search_paths, required_attrs=None):
- found_places = []
if not required_attrs:
required_attrs = []
# NOTE(harlowja): translate the search paths to include the base name.
- real_paths = []
+ lookup_paths = []
for path in search_paths:
real_path = []
if path:
real_path.extend(path.split("."))
real_path.append(base_name)
full_path = '.'.join(real_path)
- real_paths.append(full_path)
- for full_path in real_paths:
+ lookup_paths.append(full_path)
+ found_paths = []
+ for full_path in lookup_paths:
mod = None
try:
mod = import_module(full_path)
- except ImportError as e:
- LOG.debug("Failed at attempted import of '%s' due to: %s",
- full_path, e)
+ except ImportError:
+ pass
if not mod:
continue
found_attrs = 0
@@ -59,5 +54,5 @@ def find_module(base_name, search_paths, required_attrs=None):
if hasattr(mod, attr):
found_attrs += 1
if found_attrs == len(required_attrs):
- found_places.append(full_path)
- return found_places
+ found_paths.append(full_path)
+ return (found_paths, lookup_paths)
diff --git a/cloudinit/mergers/__init__.py b/cloudinit/mergers/__init__.py
index 650b42a9..03aa1ee1 100644
--- a/cloudinit/mergers/__init__.py
+++ b/cloudinit/mergers/__init__.py
@@ -143,12 +143,14 @@ def construct(parsed_mergers):
for (m_name, m_ops) in parsed_mergers:
if not m_name.startswith(MERGER_PREFIX):
m_name = MERGER_PREFIX + str(m_name)
- merger_locs = importer.find_module(m_name,
- [__name__],
- [MERGER_ATTR])
+ merger_locs, looked_locs = importer.find_module(m_name,
+ [__name__],
+ [MERGER_ATTR])
if not merger_locs:
msg = ("Could not find merger module named '%s' "
- "with attribute '%s'") % (m_name, MERGER_ATTR)
+ "with attribute '%s' (searched %s)") % (m_name,
+ MERGER_ATTR,
+ looked_locs)
raise ImportError(msg)
else:
mod = importer.import_module(merger_locs[0])
diff --git a/cloudinit/sources/__init__.py b/cloudinit/sources/__init__.py
index 7d52a2e6..5d58bebd 100644
--- a/cloudinit/sources/__init__.py
+++ b/cloudinit/sources/__init__.py
@@ -272,9 +272,9 @@ def list_sources(cfg_list, depends, pkg_list):
for ds_name in cfg_list:
if not ds_name.startswith(DS_PREFIX):
ds_name = '%s%s' % (DS_PREFIX, ds_name)
- m_locs = importer.find_module(ds_name,
- pkg_list,
- ['get_datasource_list'])
+ m_locs, _looked_locs = importer.find_module(ds_name,
+ pkg_list,
+ ['get_datasource_list'])
for m_loc in m_locs:
mod = importer.import_module(m_loc)
lister = getattr(mod, "get_datasource_list")
diff --git a/cloudinit/stages.py b/cloudinit/stages.py
index d29d480a..67f467f7 100644
--- a/cloudinit/stages.py
+++ b/cloudinit/stages.py
@@ -386,12 +386,12 @@ class Init(object):
potential_handlers = util.find_modules(path)
for (fname, mod_name) in potential_handlers.iteritems():
try:
- mod_locs = importer.find_module(mod_name, [''],
- ['list_types',
- 'handle_part'])
+ mod_locs, looked_locs = importer.find_module(
+ mod_name, [''], ['list_types', 'handle_part'])
if not mod_locs:
- LOG.warn(("Could not find a valid user-data handler"
- " named %s in file %s"), mod_name, fname)
+ LOG.warn("Could not find a valid user-data handler"
+ " named %s in file %s (searched %s)",
+ mod_name, fname, looked_locs)
continue
mod = importer.import_module(mod_locs[0])
mod = handlers.fixup_handler(mod)
@@ -621,11 +621,11 @@ class Modules(object):
" has an unknown frequency %s"), raw_name, freq)
# Reset it so when ran it will get set to a known value
freq = None
- mod_locs = importer.find_module(mod_name,
- ['', type_utils.obj_name(config)],
- ['handle'])
+ mod_locs, looked_locs = importer.find_module(
+ mod_name, ['', type_utils.obj_name(config)], ['handle'])
if not mod_locs:
- LOG.warn("Could not find module named %s", mod_name)
+ LOG.warn("Could not find module named %s (searched %s)",
+ mod_name, looked_locs)
continue
mod = config.fixup_module(importer.import_module(mod_locs[0]))
mostly_mods.append([mod, raw_name, freq, run_args])