Exemple #1
0
def test_insights_evaluator_attrs_incremental():
    broker = dr.Broker()
    broker[Specs.hostname] = context_wrap("www.example.com")
    broker[Specs.machine_id] = context_wrap("12345")
    broker[Specs.redhat_release] = context_wrap("Red Hat Enterprise Linux Server release 7.4 (Maipo)")
    with InsightsEvaluator(broker) as e:
        list(dr.run_incremental(components, broker=broker))
        result = e.get_response()
        assert result["system"]["hostname"] == "www.example.com"
        assert result["system"]["system_id"] == "12345"
        assert result["system"]["metadata"]["release"] == "Red Hat Enterprise Linux Server release 7.4 (Maipo)"
Exemple #2
0
def collect(manifest=default_manifest, tmp_path=None, compress=False):
    """
    This is the collection entry point. It accepts a manifest, a temporary
    directory in which to store output, and a boolean for optional compression.

    Args:
        manifest (str or dict): json document or dictionary containing the
            collection manifest. See default_manifest for an example.
        tmp_path (str): The temporary directory that will be used to create a
            working directory for storing component output as well as the final
            tar.gz if one is generated.
        compress (boolean): True to create a tar.gz and remove the original
            workspace containing output. False to leave the workspace without
            creating a tar.gz

    Returns:
        The full path to the created tar.gz or workspace.
    """

    manifest = load_manifest(manifest)
    client = manifest.get("client", {})
    plugins = manifest.get("plugins", {})

    apply_default_enabled(plugins.get("default_component_enabled", False))
    load_packages(plugins.get("packages", []))
    apply_blacklist(client.get("blacklist", {}))
    apply_configs(plugins)
    to_persist = get_to_persist(client.get("persist", set()))

    hostname = call("hostname -f", env=SAFE_ENV).strip()
    suffix = datetime.utcnow().strftime("%Y%m%d%H%M%S")
    relative_path = "insights-%s-%s" % (hostname, suffix)
    tmp_path = tmp_path or tempfile.gettempdir()
    output_path = os.path.join(tmp_path, relative_path)
    fs.ensure_path(output_path)
    fs.touch(os.path.join(output_path, "insights_archive.txt"))

    broker = dr.Broker()
    ctx = create_context(client.get("context", {}))
    broker[ctx.__class__] = ctx

    h = Hydration(output_path)
    broker.add_observer(h.make_persister(to_persist))
    list(dr.run_incremental(broker=broker))

    if compress:
        return create_archive(output_path)
    return output_path