From 60f176e13836d77616ae07774fda2139fde790fc Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Sat, 16 Jun 2012 10:57:28 -0700 Subject: Allow the user data processor to be passed in. This could and should be useful for unit testing. --- cloudinit/sources/__init__.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'cloudinit/sources') diff --git a/cloudinit/sources/__init__.py b/cloudinit/sources/__init__.py index 46350255..5842d41b 100644 --- a/cloudinit/sources/__init__.py +++ b/cloudinit/sources/__init__.py @@ -42,7 +42,7 @@ class DataSource(object): __metaclass__ = abc.ABCMeta - def __init__(self, sys_cfg, distro, paths): + def __init__(self, sys_cfg, distro, paths, ud_proc=None): self.sys_cfg = sys_cfg self.distro = distro self.paths = paths @@ -54,11 +54,15 @@ class DataSource(object): name = name[DS_PREFIX:] self.ds_cfg = util.get_cfg_by_path(self.sys_cfg, ("datasource", name), {}) + if not ud_proc: + self.ud_proc = ud.UserDataProcessor(self.paths) + else: + self.ud_proc = ud_proc def get_userdata(self): if self.userdata is None: raw_data = self.get_userdata_raw() - self.userdata = ud.UserDataProcessor(self.paths).process(raw_data) + self.userdata = self.ud_proc.process(raw_data) return self.userdata def get_userdata_raw(self): -- cgit v1.2.3