def test_attribute_defaults(self, mode, monkeypatch): hostname = "testhost" ipaddress = "1.2.3.4" ts = Scenario() ts.add_host(hostname) ts.set_option("management_protocol", {hostname: "snmp"}) ts.set_option( "host_attributes", { hostname: { "management_address": ipaddress }, }, ) ts.apply(monkeypatch) configurator = SNMPConfigurator.management_board( hostname, ipaddress, mode=mode, ) assert configurator.description == ( "Management board - SNMP " "(Community: 'public', Bulk walk: no, Port: 161, Inline: no)")
def test_one_snmp_source(self, hostname, ipaddress, mode, config_cache, host_config): mhs = MultiHostSections() update_host_sections( mhs, make_nodes( config_cache, host_config, ipaddress, mode=mode, sources=[ SNMPConfigurator.snmp( hostname, ipaddress, mode=mode, ).make_checker(), ], ), max_cachefile_age=0, selected_raw_sections=None, host_config=host_config, ) assert len(mhs) == 1 key = HostKey(hostname, ipaddress, SourceType.HOST) assert key in mhs section = mhs[key] assert isinstance(section, SNMPHostSections) assert len(section.sections) == 1 assert section.sections[SectionName("section_name_%s" % hostname)] == [["section_content"]]
def test_attribute_defaults(self, mode, monkeypatch): hostname = "testhost" ipaddress = "1.2.3.4" Scenario().add_host(hostname).apply(monkeypatch) configurator = SNMPConfigurator.snmp(hostname, ipaddress, mode=mode) assert configurator.description == ( "SNMP (Community: 'public', Bulk walk: no, Port: 161, Inline: no)")
def do_monkeypatch_and_make_configurator(monkeypatch, plugin, hostname, ipaddress): monkeypatch.setattr( register, 'iter_all_snmp_sections', lambda: [plugin], ) Scenario().add_host(hostname).apply(monkeypatch) return SNMPConfigurator.snmp(hostname, ipaddress, mode=Mode.DISCOVERY)
def source(self, hostname, mode): return SNMPDataSource(configurator=SNMPConfigurator( hostname, "1.2.3.4", mode=mode, source_type=SourceType.HOST, id_="snmp_id", cpu_tracking_id="snmp_cpu_id", title="snmp title", ))
def test_source_requires_ipaddress(hostname, mode, monkeypatch): Scenario().add_host(hostname).apply(monkeypatch) with pytest.raises(TypeError): SNMPConfigurator.snmp(hostname, None, mode=mode)
def configurator_source(scenario, hostname, ipaddress, mode): return SNMPConfigurator.snmp(hostname, ipaddress, mode=mode)