def LoadCheck(self, cfg_file, *check_ids): cfg = os.path.join(config_lib.CONFIG["Test.srcdir"], "grr", "checks", cfg_file) if check_ids: for chk_id in check_ids: checks.LoadCheckFromFile(cfg, chk_id) else: checks.LoadChecksFromFiles([cfg])
def LoadCheck(self, cfg_file, *check_ids): cfg = os.path.join(config_lib.CONFIG["Test.srcdir"], "grr", "checks", cfg_file) if check_ids: loaded = [] for chk_id in check_ids: loaded.append(checks.LoadCheckFromFile(cfg, chk_id)) return loaded else: return checks.LoadChecksFromFiles([cfg])
def LoadCheck(cls, cfg_file, *check_ids): """Loads checks from a file once per Test class. LoadCheck will read a file containing a check configuration and instantiate the checks from it. Specific checks can be selected by providing the check ids that should be loaded from the file. Checks are stored as a class attribute to prevent re-loading as each test method is set up. Args: cfg_file: A path to the file that should be read. *check_ids: A list of check ids that should be loaded from the file. Returns: The loaded check objects. """ if HostCheckTest.loaded_checks is None: HostCheckTest.loaded_checks = {} cfg = os.path.join(config.CONFIG["Test.srcdir"], "grr", "checks", cfg_file) if check_ids: key = "%s:%s" % (cfg, ",".join(check_ids)) if key in HostCheckTest.loaded_checks: return HostCheckTest.loaded_checks[key] loaded = [] for chk_id in check_ids: loaded.append(checks.LoadCheckFromFile(cfg, chk_id)) HostCheckTest.loaded_checks[key] = loaded return loaded else: key = "%s:*" % cfg_file if key in HostCheckTest.loaded_checks: return HostCheckTest.loaded_checks[key] else: result = checks.LoadChecksFromFiles([cfg]) HostCheckTest.loaded_checks[key] = result return result
def LoadCheck(cls, cfg_file, *check_ids): if HostCheckTest.loaded_checks is None: HostCheckTest.loaded_checks = {} cfg = os.path.join(config_lib.CONFIG["Test.srcdir"], "grr", "checks", cfg_file) if check_ids: key = "%s:%s" % (cfg, ",".join(check_ids)) if key in HostCheckTest.loaded_checks: return HostCheckTest.loaded_checks[key] loaded = [] for chk_id in check_ids: loaded.append(checks.LoadCheckFromFile(cfg, chk_id)) HostCheckTest.loaded_checks[key] = loaded return loaded else: key = "%s:*" % cfg_file if key in HostCheckTest.loaded_checks: return HostCheckTest.loaded_checks[key] else: result = checks.LoadChecksFromFiles([cfg]) HostCheckTest.loaded_checks[key] = result return result