def _create_new_broker(path=None): """ Create a broker and populate it by evaluating the path with all registered datasources. Args: path (str): path to the archive or directory to analyze. ``None`` will analyze the current system. """ datasources = dr.get_components_of_type(datasource) def make_broker(ctx): broker = dr.Broker() broker[ctx.__class__] = ctx if isinstance(ctx, SerializedArchiveContext): h = Hydration(ctx.root) broker = h.hydrate(broker=broker) dr.run(datasources, broker=broker) del broker[ctx.__class__] return broker if path: if os.path.isdir(path): ctx = create_context(path) yield (path, make_broker(ctx)) else: with extract(path) as e: ctx = create_context(e.tmp_dir) yield (e.tmp_dir, make_broker(ctx)) else: yield (os.curdir, make_broker(HostContext()))
def test_glob_max(max_globs): too_many = glob_file(max_globs + "/tmp_*_glob") hn = HostContext() broker = dr.Broker() broker[HostContext] = hn with pytest.raises(ContentException): too_many(broker)
def test_spec_factory(): hn = HostContext() broker = dr.Broker() broker[HostContext] = hn broker = dr.run(dr.get_dependency_graph(dostuff), broker) assert dostuff in broker, broker.tracebacks assert broker[Stuff.smpl_file].content == file_content
def main(): args = parse_args() logging.basicConfig(level=logging.DEBUG if args.verbose else logging.WARN) ctx = HostContext() broker = dr.Broker() broker[HostContext] = ctx out_path = args.output dr.load_components("insights.specs.default") dr.load_components("insights.specs.insights_archive") dr.load_components("insights.specs.sos_archive") dr.load_components("insights.parsers") dr.load_components("insights.combiners") for path in args.plugins: dr.load_components(path) graphs = dr.get_subgraphs(dr.COMPONENTS[dr.GROUPS.single]) worker_args = [(broker, g, out_path) for g in graphs] if args.parallel: run_parallel(worker_args) else: run_serial(worker_args)
def test_get_running_commands(): broker = dr.Broker() broker[HostContext] = HostContext() with pytest.raises(Exception): default_specs._get_running_commands(broker, 'not_a_list') with pytest.raises(Exception): default_specs._get_running_commands(broker, [])
def test_line_terminators(): add_filter(Stuff.smpl_file, "def test") hn = HostContext() broker = dr.Broker() broker[HostContext] = hn broker = dr.run(dr.get_dependency_graph(dostuff), broker) content = broker[Stuff.smpl_file].content assert all("def test" in l for l in content), content assert not any(l.endswith("\n") for l in content)
def test_spec_factory(): add_filter(Stuff.smpl_cmd_list_of_lists, " hello ") hn = HostContext() broker = dr.Broker() broker[HostContext] = hn broker = dr.run(dr.get_dependency_graph(dostuff), broker) assert dostuff in broker, broker.tracebacks assert broker[Stuff.smpl_file].content == file_content assert not any(l.endswith("\n") for l in broker[Stuff.smpl_file].content) assert "hello" in broker[Stuff.smpl_cmd_list_of_lists].content[0] assert len(broker[Stuff.smpl_cmd_list_of_lists].content) == 1