cloud-init-dev team mailing list archive
-
cloud-init-dev team
-
Mailing list archive
-
Message #00512
[Merge] lp:~harlowja/cloud-init/better-errors into lp:cloud-init
Joshua Harlow has proposed merging lp:~harlowja/cloud-init/better-errors into lp:cloud-init.
Requested reviews:
cloud init development team (cloud-init-dev)
For more details, see:
https://code.launchpad.net/~harlowja/cloud-init/better-errors/+merge/233125
Makes less noise with same benefits.
--
https://code.launchpad.net/~harlowja/cloud-init/better-errors/+merge/233125
Your team cloud init development team is requested to review the proposed merge of lp:~harlowja/cloud-init/better-errors into lp:cloud-init.
=== modified file 'cloudinit/distros/__init__.py'
--- cloudinit/distros/__init__.py 2014-08-26 18:50:11 +0000
+++ cloudinit/distros/__init__.py 2014-09-02 21:18:16 +0000
@@ -847,12 +847,10 @@
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
=== modified file 'cloudinit/importer.py'
--- cloudinit/importer.py 2014-07-15 22:09:08 +0000
+++ cloudinit/importer.py 2014-09-02 21:18:16 +0000
@@ -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 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 @@
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)
=== modified file 'cloudinit/mergers/__init__.py'
--- cloudinit/mergers/__init__.py 2014-07-15 22:09:08 +0000
+++ cloudinit/mergers/__init__.py 2014-09-02 21:18:16 +0000
@@ -143,12 +143,14 @@
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])
=== modified file 'cloudinit/sources/__init__.py'
--- cloudinit/sources/__init__.py 2014-08-26 18:50:11 +0000
+++ cloudinit/sources/__init__.py 2014-09-02 21:18:16 +0000
@@ -272,9 +272,9 @@
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")
=== modified file 'cloudinit/stages.py'
--- cloudinit/stages.py 2014-08-26 18:50:11 +0000
+++ cloudinit/stages.py 2014-09-02 21:18:16 +0000
@@ -386,12 +386,12 @@
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 @@
" 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])
Follow ups