def test_get_section_content(monkeypatch, hostname, nodes, host_entries, cluster_mapping, service_descr, expected_result): ts = Scenario() if nodes is None: ts.add_host(hostname) else: ts.add_cluster(hostname, nodes=nodes) for node in nodes or []: ts.add_host(node) config_cache = ts.apply(monkeypatch) def host_of_clustered_service(hostname, service_description): return cluster_mapping[hostname] multi_host_sections = MultiHostSections() for nodename, node_section_content in host_entries: multi_host_sections.add_or_get_host_sections( nodename, "127.0.0.1", AgentHostSections(sections={"check_plugin_name": node_section_content})) monkeypatch.setattr(ip_lookup, "lookup_ip_address", lambda h: "127.0.0.1") monkeypatch.setattr(config_cache, "host_of_clustered_service", host_of_clustered_service) section_content = multi_host_sections.get_section_content(hostname, "127.0.0.1", "check_plugin_name", False, service_description=service_descr) assert expected_result == section_content,\ "Section content: Expected '%s' but got '%s'" % (expected_result, section_content)
def test_get_section_cluster_kwargs(monkeypatch, required_sections, expected_result): _set_up(monkeypatch, "cluster", ["node2", "node1"], { "node1": "cluster", "node2": "cluster" }) node1_section_content = { "one": NODE_1, # TODO (mo): CMK-4232 # "two": NODE_1, "three": NODE_1 } node2_section_content = {"two": NODE_2, "three": NODE_2} multi_host_sections = MultiHostSections() multi_host_sections.add_or_get_host_sections( "node1", "127.0.0.1", AgentHostSections(sections=node1_section_content)) multi_host_sections.add_or_get_host_sections( "node2", "127.0.0.1", AgentHostSections(sections=node2_section_content)) kwargs = multi_host_sections.get_section_cluster_kwargs( "cluster", [PluginName(n) for n in required_sections], "_service_description") assert expected_result == kwargs,\ "Section content: Expected '%s' but got '%s'" % (expected_result, kwargs)
def test_get_parsed_section(monkeypatch, node_section_content, expected_result): _set_up(monkeypatch, "node1", None, {}) multi_host_sections = MultiHostSections() multi_host_sections.add_or_get_host_sections( "node1", "127.0.0.1", AgentHostSections(sections=node_section_content)) content = multi_host_sections.get_parsed_section("node1", "127.0.0.1", PluginName("parsed")) assert expected_result == content,\ "Section content: Expected '%s' but got '%s'" % (expected_result, content)
def test_get_section_kwargs(monkeypatch, required_sections, expected_result): _set_up(monkeypatch, "node1", None, {}) node_section_content = { "one": NODE_1, # TODO (mo): CMK-4232 # "two": NODE_1, "three": NODE_1 } multi_host_sections = MultiHostSections() multi_host_sections.add_or_get_host_sections( "node1", "127.0.0.1", AgentHostSections(sections=node_section_content)) kwargs = multi_host_sections.get_section_kwargs( "node1", "127.0.0.1", [PluginName(n) for n in required_sections]) assert expected_result == kwargs,\ "Section content: Expected '%s' but got '%s'" % (expected_result, kwargs)
def test_get_section_content(monkeypatch, hostname, nodes, host_entries, cluster_mapping, service_descr, expected_result): _set_up(monkeypatch, hostname, nodes, cluster_mapping) multi_host_sections = MultiHostSections() for nodename, node_section_content in host_entries: multi_host_sections.add_or_get_host_sections( nodename, "127.0.0.1", AgentHostSections( sections={"check_plugin_name": node_section_content})) section_content = multi_host_sections.get_section_content( hostname, "127.0.0.1", "check_plugin_name", False, service_description=service_descr) assert expected_result == section_content,\ "Section content: Expected '%s' but got '%s'" % (expected_result, section_content)