def test_check_plugin_name_and_version(self): template = {"plugin_name": "vanilla", "hadoop_version": "2.6.0"} self.assertTrue(utils.check_plugin_name_and_version(template, None, ["2.6.0"])) self.assertTrue(utils.check_plugin_name_and_version(template, ["vanilla"], None)) self.assertTrue(utils.check_plugin_name_and_version(template, ["vanilla"], ["2.6.0"])) self.assertTrue(utils.check_plugin_name_and_version(template, ["vanilla"], ["vanilla.2.6.0"])) self.assertFalse(utils.check_plugin_name_and_version(template, ["hdp"], ["2.6.0"]))
def test_check_plugin_name_and_version(self): template = {"plugin_name": "vanilla", "hadoop_version": "2.6.0"} self.assertTrue(utils.check_plugin_name_and_version( template, None, ["2.6.0"])) self.assertTrue(utils.check_plugin_name_and_version( template, ["vanilla"], None)) self.assertTrue(utils.check_plugin_name_and_version( template, ["vanilla"], ["2.6.0"])) self.assertTrue(utils.check_plugin_name_and_version( template, ["vanilla"], ["vanilla.2.6.0"])) self.assertFalse(utils.check_plugin_name_and_version( template, ["hdp"], ["2.6.0"]))
def process_files(dirname, files): node_groups = [] clusters = [] plugin_name = get_plugin_name() try: for fname in files: if os.path.splitext(fname)[1] == ".json": fpath = os.path.join(dirname, fname) with open(fpath, "r") as fp: try: template = json.load(fp) except ValueError as e: LOG.warning("Error processing {path}, {reason}".format(path=fpath, reason=e)) raise Handled("error processing files") # If this file doesn't contain basic fields, skip it. # If we are filtering on plugin and version make # sure the file is one that we want if not u.check_basic_fields(template) or ( not u.check_plugin_name_and_version(template, plugin_name, CONF.command.plugin_version) ): continue # Look through the sections in CONF and register # options for this template if we find a section # related to the template (ie, plugin, version, name) section = add_config_section_for_template(template) LOG.debug("Using config section {section} " "for {path}".format(section=section, path=fpath)) # Attempt to resolve substitutions using the config section substitute_config_values(get_configs(section), template, fpath) file_entry = {"template": template, "path": fpath} if u.is_node_group(template): # JSON validator try: ng_validator.validate(template) except jsonschema.ValidationError as e: LOG.warning("Validation for {path} failed, " "{reason}".format(path=fpath, reason=e)) raise Handled("node group template validation failed") node_groups.append(file_entry) LOG.debug("Added {path} to node group " "template files".format(path=fpath)) else: clusters.append(file_entry) LOG.debug("Added {path} to cluster template " "files".format(path=fpath)) except Handled as e: log_skipping_dir(dirname, e.message) node_groups = [] clusters = [] except Exception as e: log_skipping_dir(dirname, "unhandled exception, {reason}".format(reason=e)) node_groups = [] clusters = [] return node_groups, clusters
def process_files(dirname, files): node_groups = [] clusters = [] plugin_name = get_plugin_name() try: for fname in files: if os.path.splitext(fname)[1] == ".json": fpath = os.path.join(dirname, fname) with open(fpath, 'r') as fp: try: data = fp.read() template = json.loads(data) except ValueError as e: LOG.warning( _LW("Error processing {path}, " "{reason}").format(path=fpath, reason=e)) raise Handled("error processing files") # If this file doesn't contain basic fields, skip it. # If we are filtering on plugin and version make # sure the file is one that we want if not u.check_basic_fields(template) or ( not u.check_plugin_name_and_version( template, plugin_name, CONF.command.plugin_version)): continue # Look through the sections in CONF and register # options for this template if we find a section # related to the template (ie, plugin, version, name) section = add_config_section_for_template(template) LOG.debug("Using config section {section} " "for {path}".format(section=section, path=fpath)) # Attempt to resolve substitutions using the config section substitute_config_values(get_configs(section), template, fpath) file_entry = {'template': template, 'path': fpath} if u.is_node_group(template): # JSON validator try: ng_validator.validate(template) except jsonschema.ValidationError as e: LOG.warning( _LW("Validation for {path} failed, " "{reason}").format(path=fpath, reason=e)) raise Handled( "node group template validation failed") node_groups.append(file_entry) LOG.debug("Added {path} to node group " "template files".format(path=fpath)) else: clusters.append(file_entry) LOG.debug("Added {path} to cluster template " "files".format(path=fpath)) except Handled as e: log_skipping_dir(dirname, str(e)) node_groups = [] clusters = [] except Exception as e: log_skipping_dir(dirname, "unhandled exception, {reason}".format(reason=e)) node_groups = [] clusters = [] return node_groups, clusters