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.setdefault_host_sections( ("node1", "127.0.0.1"), AgentHostSections(sections=node1_section_content), ) multi_host_sections.setdefault_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_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 } host_key = ("node1", "127.0.0.1", SourceType.HOST) multi_host_sections = MultiHostSections() multi_host_sections.setdefault_host_sections( host_key, AgentHostSections(sections=node_section_content), ) kwargs = multi_host_sections.get_section_kwargs( host_key, [PluginName(n) for n in required_sections], ) 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.setdefault_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_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.setdefault_host_sections( (nodename, "127.0.0.1", SourceType.HOST), AgentHostSections( sections={"check_plugin_name": node_section_content}), ) section_content = multi_host_sections.get_section_content( hostname, "127.0.0.1", check_api_utils.HOST_ONLY, "check_plugin_name", False, service_description=service_descr, ) assert expected_result == section_content,\ "Section content: Expected '%s' but got '%s'" % (expected_result, section_content) section_content = multi_host_sections.get_section_content( hostname, "127.0.0.1", check_api_utils.HOST_PRECEDENCE, "check_plugin_name", False, service_description=service_descr, ) assert expected_result == section_content,\ "Section content: Expected '%s' but got '%s'" % (expected_result, section_content) section_content = multi_host_sections.get_section_content( hostname, "127.0.0.1", check_api_utils.MGMT_ONLY, "check_plugin_name", False, service_description=service_descr, ) assert section_content is None, \ "Section content: Expected 'None' but got '%s'" % (section_content,)
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.setdefault_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)