コード例 #1
0
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()))
コード例 #2
0
ファイル: test_specs.py プロジェクト: zerodayz/insights-core
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)
コード例 #3
0
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
コード例 #4
0
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)
コード例 #5
0
ファイル: test_specs.py プロジェクト: xiangce/insights-core
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, [])
コード例 #6
0
ファイル: test_specs.py プロジェクト: zerodayz/insights-core
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)
コード例 #7
0
ファイル: test_specs.py プロジェクト: zerodayz/insights-core
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