def testIndexes(self): test_data = helpers.readResource('filter_cloud_multipart.yaml') ud_proc = ud.UserDataProcessor(self.getCloudPaths()) message = ud_proc.process(test_data) start_count = count_messages(message) self.assertTrue(start_count > 0) # This file should have the following # indexes -> amount mapping in it expected_counts = { 2: 2, 3: 2, 1: 2, 0: 1, 4: 1, 7: 0, -1: 0, 100: 0, # None should just give all back None: start_count, # Non ints should be ignored 'c': start_count, # Strings should be converted '1': 2, } self.assertCounts(message, expected_counts)
def __init__(self, sys_cfg, distro, paths, ud_proc=None): self.sys_cfg = sys_cfg self.distro = distro self.paths = paths self.userdata = None self.metadata = {} self.userdata_raw = None self.vendordata = None self.vendordata_raw = None # find the datasource config name. # remove 'DataSource' from classname on front, and remove 'Net' on end. # Both Foo and FooNet sources expect config in cfg['sources']['Foo'] name = type_utils.obj_name(self) if name.startswith(DS_PREFIX): name = name[len(DS_PREFIX):] if name.endswith('Net'): name = name[0:-3] self.ds_cfg = util.get_cfg_by_path(self.sys_cfg, ("datasource", name), {}) if not self.ds_cfg: self.ds_cfg = {} if not ud_proc: self.ud_proc = ud.UserDataProcessor(self.paths) else: self.ud_proc = ud_proc
def testNoneIndex(self): test_data = helpers.readResource('filter_cloud_multipart.yaml') ud_proc = ud.UserDataProcessor(self.getCloudPaths()) message = ud_proc.process(test_data) start_count = count_messages(message) self.assertTrue(start_count > 0) filtered_message = launch_index.Filter(None).apply(message) self.assertTrue(self.equivalentMessage(message, filtered_message))
def testConfigEmailIndex(self): test_data = helpers.readResource('filter_cloud_multipart_1.email') ud_proc = ud.UserDataProcessor(self.getCloudPaths()) message = ud_proc.process(test_data) self.assertTrue(count_messages(message) > 0) # This file should have the following # indexes -> amount mapping in it expected_counts = { 2: 1, -1: 0, None: 1, } self.assertCounts(message, expected_counts)
def __init__(self, sys_cfg, distro, paths, ud_proc=None): self.sys_cfg = sys_cfg self.distro = distro self.paths = paths self.userdata = None self.metadata = {} self.userdata_raw = None self.vendordata = None self.vendordata_raw = None self.ds_cfg = util.get_cfg_by_path( self.sys_cfg, ("datasource", self.dsname), {}) if not self.ds_cfg: self.ds_cfg = {} if not ud_proc: self.ud_proc = ud.UserDataProcessor(self.paths) else: self.ud_proc = ud_proc
def __init__(self, sys_cfg, distro, paths, ud_proc=None): self.sys_cfg = sys_cfg self.distro = distro self.paths = paths self.userdata = None self.metadata = {} self.userdata_raw = None self.vendordata = None self.vendordata_raw = None # Default: generate network config on new instance id (first boot). self.update_events = {'network': {EventType.BOOT_NEW_INSTANCE}} self.ds_cfg = util.get_cfg_by_path(self.sys_cfg, ("datasource", self.dsname), {}) if not self.ds_cfg: self.ds_cfg = {} if not ud_proc: self.ud_proc = ud.UserDataProcessor(self.paths) else: self.ud_proc = ud_proc
def test_string_in_userdata(self): msg = '#cloud-config\napt_update: True\n' ud_proc = ud.UserDataProcessor(self.getCloudPaths()) message = ud_proc.process(msg) self.assertTrue(count_messages(message) == 1)