def test_pylint_modules(): base_path = pylint_cmk.get_test_dir() f = file(base_path + "/cmk-modules.py", "w") for path in pylint_cmk.ordered_module_files(): pylint_cmk.add_file(f, path) f.close() exit_code = pylint_cmk.run_pylint(base_path, cleanup_test_dir=True) assert exit_code == 0, "PyLint found an error in modules"
def _compile_bakery_plugins(pylint_test_dir): with open(pylint_test_dir + "/cmk_bakery_plugins.py", "w") as f: pylint_cmk.add_file( f, os.path.realpath(os.path.join(cmc_path(), "cmk_base/cee/agent_bakery_plugins.py"))) # This pylint warning is incompatible with our "concatenation technology". f.write("# pylint: disable=reimported,wrong-import-order,wrong-import-position\n") # Also add bakery plugins for path in pylint_cmk.check_files(os.path.join(cmc_path(), "agents/bakery")): pylint_cmk.add_file(f, path)
def test_pylint_checks(): base_path = pylint_cmk.get_test_dir() f = file(base_path + "/cmk-checks.py", "w") # add the modules for path in pylint_cmk.ordered_module_files(): pylint_cmk.add_file(f, path) # Now add the checks for path in pylint_cmk.check_files(repo_path() + "/checks"): pylint_cmk.add_file(f, path) # Also add inventory plugins for path in pylint_cmk.check_files(repo_path() + "/inventory"): pylint_cmk.add_file(f, path) # Also add bakery plugins for path in pylint_cmk.check_files(os.path.realpath(repo_path() + "/../cmc/agents/bakery")): pylint_cmk.add_file(f, path) f.close() exit_code = pylint_cmk.run_pylint(base_path, cleanup_test_dir=True) assert exit_code == 0, "PyLint found an error in checks, inventory " \ "or agent bakery plugins"
def test_pylint_checks(): base_path = pylint_cmk.get_test_dir() f = file(base_path + "/cmk-checks.py", "w") # add the modules for path in pylint_cmk.ordered_module_files(): pylint_cmk.add_file(f, path) # Now add the checks for path in pylint_cmk.check_files(repo_path() + "/checks"): pylint_cmk.add_file(f, path) # Also add inventory plugins for path in pylint_cmk.check_files(repo_path() + "/inventory"): pylint_cmk.add_file(f, path) # Also add bakery plugins for path in pylint_cmk.check_files(cmc_path() + "/agents/bakery"): pylint_cmk.add_file(f, path) f.close() exit_code = pylint_cmk.run_pylint(base_path, cleanup_test_dir=True) assert exit_code == 0, "PyLint found an error in checks, inventory " \ "or agent bakery plugins"
def test_pylint_web(): base_path = pylint_cmk.get_test_dir() # Make compiled files import eachother by default sys.path.insert(0, base_path) modules = glob.glob(cmk_path() + "/web/htdocs/*.py") \ + glob.glob(cmc_path() + "/web/htdocs/*.py") \ + glob.glob(cme_path() + "/web/htdocs/*.py") for module in modules: print("Copy %s to test directory" % module) f = open(base_path + "/" + os.path.basename(module), "w") pylint_cmk.add_file(f, module) f.close() # Move the whole plugins code to their modules, then # run pylint only on the modules for plugin_dir in get_web_plugin_dirs(): files = get_plugin_files(plugin_dir) for plugin_file, plugin_base in files: plugin_path = plugin_base + "/" + plugin_file if plugin_file.startswith('.'): continue elif plugin_dir in ["icons", "perfometer"]: module_name = "views" elif plugin_dir == "pages": module_name = "modules" else: module_name = plugin_dir print("[%s] add %s" % (module_name, plugin_path)) module = file(base_path + "/" + module_name + ".py", "a") pylint_cmk.add_file(module, plugin_path) module.close() exit_code = pylint_cmk.run_pylint(base_path, cleanup_test_dir=True) assert exit_code == 0, "PyLint found an error in the web code"
def test_pylint_web(): base_path = pylint_cmk.get_test_dir() # Make compiled files import eachother by default sys.path.insert(0, base_path) modules = glob.glob(cmk_path() + "/web/htdocs/*.py") \ + glob.glob(cmc_path() + "/web/htdocs/*.py") for module in modules: print("Copy %s to test directory" % module) f = open(base_path + "/" + os.path.basename(module), "w") pylint_cmk.add_file(f, module) f.close() # Move the whole plugins code to their modules, then # run pylint only on the modules for plugin_dir in get_web_plugin_dirs(): files = get_plugin_files(plugin_dir) for plugin_file, plugin_base in files: plugin_path = plugin_base +"/"+plugin_file if plugin_file.startswith('.'): continue elif plugin_dir in ["icons","perfometer"]: module_name = "views" elif plugin_dir == "pages": module_name = "modules" else: module_name = plugin_dir print("[%s] add %s" % (module_name, plugin_path)) module = file(base_path + "/" + module_name + ".py", "a") pylint_cmk.add_file(module, plugin_path) module.close() exit_code = pylint_cmk.run_pylint(base_path, cleanup_test_dir=True) assert exit_code == 0, "PyLint found an error in the web code"
def _compile_check_and_inventory_plugins(pylint_test_dir): with open(pylint_test_dir + "/cmk_checks.py", "w") as f: # Fake data structures where checks register (See cmk/base/checks.py) f.write(""" # -*- encoding: utf-8 -*- check_info = {} check_includes = {} precompile_params = {} check_default_levels = {} factory_settings = {} check_config_variables = [] snmp_info = {} snmp_scan_functions = {} active_check_info = {} special_agent_info = {} inv_info = {} # Inventory plugins inv_export = {} # Inventory export hooks def inv_tree_list(path): return inv_tree(path, []) def inv_tree(path, default_value=None): if default_value is not None: node = default_value else: node = {} return node """) # add the modules # These pylint warnings are incompatible with our "concatenation technology". f.write( "# pylint: disable=reimported,ungrouped-imports,wrong-import-order,wrong-import-position,redefined-outer-name\n" ) pylint_cmk.add_file(f, repo_path() + "/cmk/base/check_api.py") pylint_cmk.add_file(f, repo_path() + "/cmk/base/inventory_plugins.py") # Now add the checks for path in pylint_cmk.check_files(repo_path() + "/checks"): pylint_cmk.add_file(f, path) # Now add the inventory plugins for path in pylint_cmk.check_files(repo_path() + "/inventory"): pylint_cmk.add_file(f, path)
def _compile_check_and_inventory_plugins(pylint_test_dir): for idx, f_name in enumerate(pylint_cmk.check_files(repo_path() + "/checks")): with stand_alone_template(pylint_test_dir + "/cmk_checks_%s.py" % idx) as file_handle: pylint_cmk.add_file(file_handle, f_name) with stand_alone_template(pylint_test_dir + "/cmk_checks.py") as file_handle: pylint_cmk.add_file(file_handle, repo_path() + "/cmk/base/inventory_plugins.py") for path in pylint_cmk.check_files(repo_path() + "/inventory"): pylint_cmk.add_file(file_handle, path)
def _compile_check_and_inventory_plugins(pylint_test_dir): with open(pylint_test_dir + "/cmk_checks.py", "w") as f: # Fake data structures where checks register (See cmk/base/checks.py) f.write(""" # -*- encoding: utf-8 -*- check_info = {} check_includes = {} precompile_params = {} check_default_levels = {} factory_settings = {} check_config_variables = [] snmp_info = {} snmp_scan_functions = {} active_check_info = {} special_agent_info = {} inv_info = {} # Inventory plugins inv_export = {} # Inventory export hooks def inv_tree_list(path): return inv_tree(path, []) def inv_tree(path, default_value=None): if default_value is not None: node = default_value else: node = {} return node """) disable_pylint = [ 'chained-comparison', 'consider-iterating-dictionary', 'consider-using-dict-comprehension', 'consider-using-in', 'function-redefined', 'no-else-break', 'no-else-continue', 'no-else-return', 'pointless-string-statement', 'redefined-outer-name', 'reimported', 'simplifiable-if-expression', 'ungrouped-imports', 'unnecessary-comprehension', 'unused-variable', 'useless-object-inheritance', 'wrong-import-order', 'wrong-import-position', ] # add the modules # These pylint warnings are incompatible with our "concatenation technology". f.write("# pylint: disable=%s\n" % ','.join(disable_pylint)) pylint_cmk.add_file(f, repo_path() + "/cmk/base/check_api.py") pylint_cmk.add_file(f, repo_path() + "/cmk/base/inventory_plugins.py") # Now add the checks for path in sorted(pylint_cmk.check_files(repo_path() + "/checks"), key=lambda check: (not check.endswith(".include"), check)): pylint_cmk.add_file(f, path) # Now add the inventory plugins for path in pylint_cmk.check_files(repo_path() + "/inventory"): pylint_cmk.add_file(f, path)