From 8c9148fda19a83bb6fe9476dff34788ccfc9f639 Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Mon, 18 Jun 2012 21:07:17 -0700 Subject: 1. Fixed datasource construction (switched param order) 2. Fixed up importing of modules to handle the failure case better a. Also realized that using the import class we don't have to reimport a module via getattr, so removed that. --- cloudinit/sources/__init__.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'cloudinit') diff --git a/cloudinit/sources/__init__.py b/cloudinit/sources/__init__.py index 5842d41b..831f97ea 100644 --- a/cloudinit/sources/__init__.py +++ b/cloudinit/sources/__init__.py @@ -51,7 +51,7 @@ class DataSource(object): self.userdata_raw = None name = util.obj_name(self) if name.startswith(DS_PREFIX): - name = name[DS_PREFIX:] + name = name[len(DS_PREFIX):] self.ds_cfg = util.get_cfg_by_path(self.sys_cfg, ("datasource", name), {}) if not ud_proc: @@ -171,7 +171,7 @@ def find_source(sys_cfg, distro, paths, ds_deps, cfg_list, pkg_list): for cls in ds_list: ds = util.obj_name(cls) try: - s = cls(distro, sys_cfg, paths) + s = cls(sys_cfg, distro, paths) if s.get_data(): return (s, ds) except Exception: @@ -198,15 +198,13 @@ def list_sources(cfg_list, depends, pkg_list): if pkg: pkg_name.append(str(pkg)) pkg_name.append(ds_name) - mod = importer.import_module(".".join(pkg_name)) - if pkg: - mod = getattr(mod, ds_name, None) - if not mod: + try: + mod = importer.import_module(".".join(pkg_name)) + except RuntimeError: continue lister = getattr(mod, "get_datasource_list", None) if not lister: continue - LOG.debug("Seeing if %s matches using function %s", mod, lister) cls_matches = lister(depends) if not cls_matches: continue -- cgit v1.2.3