Ejemplo n.º 1
0
    def test_fetch_from_io_non_empty(self, monkeypatch: MonkeyPatch, fetcher: SNMPFetcher) -> None:
        table = [["1"]]
        monkeypatch.setattr(
            snmp_table,
            "get_snmp_table",
            lambda *_, **__: table,
        )
        section_name = SectionName("pim")
        monkeypatch.setattr(
            fetcher,
            "sections",
            {
                section_name: SectionMeta(
                    checking=True,
                    disabled=False,
                    redetect=False,
                    fetch_interval=None,
                ),
            },
        )

        assert fetcher.fetch(Mode.INVENTORY) == result.OK({})  # 'pim' is not an inventory section
        assert fetcher.fetch(Mode.CHECKING) == result.OK({section_name: [table]})

        monkeypatch.setattr(
            snmp,
            "gather_available_raw_section_names",
            lambda *_, **__: {SectionName("pim")},
        )
        assert fetcher.fetch(Mode.DISCOVERY) == result.OK({section_name: [table]})
Ejemplo n.º 2
0
 def test_fetch_from_io_partially_empty(
     self, monkeypatch: MonkeyPatch, fetcher: SNMPFetcher
 ) -> None:
     section_name = SectionName("pum")
     monkeypatch.setattr(
         fetcher,
         "sections",
         {
             section_name: SectionMeta(
                 checking=True,
                 disabled=False,
                 redetect=False,
                 fetch_interval=None,
             ),
         },
     )
     table = [["1"]]
     monkeypatch.setattr(
         snmp_table,
         "get_snmp_table",
         lambda tree, **__: table
         if tree.base == fetcher.plugin_store[section_name].trees[0].base
         else [],
     )
     assert fetcher.fetch(Mode.CHECKING) == result.OK({section_name: [table, []]})
Ejemplo n.º 3
0
 def test_mode_checking_not_do_status_data_inventory(
         self, monkeypatch: MonkeyPatch, fetcher: SNMPFetcher) -> None:
     monkeypatch.setattr(fetcher, "do_status_data_inventory", False)
     monkeypatch.setattr(
         snmp,
         "gather_available_raw_section_names",
         lambda *_, **__: fetcher._get_detected_sections(Mode.CHECKING),
     )
     assert fetcher.fetch(Mode.CHECKING) == result.OK({})
Ejemplo n.º 4
0
 def test_mode_checking_do_status_data_inventory(
     self, set_sections: List[List[str]], monkeypatch: MonkeyPatch, fetcher: SNMPFetcher
 ) -> None:
     table = set_sections
     monkeypatch.setattr(fetcher, "do_status_data_inventory", True)
     monkeypatch.setattr(
         snmp,
         "gather_available_raw_section_names",
         lambda *_, **__: fetcher._get_detected_sections(Mode.CHECKING),
     )
     assert fetcher.fetch(Mode.CHECKING) == result.OK({SectionName("pim"): [table]})
Ejemplo n.º 5
0
 def test_fetch_from_io_empty(self, monkeypatch: MonkeyPatch, fetcher: SNMPFetcher) -> None:
     monkeypatch.setattr(
         snmp_table,
         "get_snmp_table",
         lambda *_, **__: [],
     )
     monkeypatch.setattr(
         snmp,
         "gather_available_raw_section_names",
         lambda *_, **__: {SectionName("pam")},
     )
     assert fetcher.fetch(Mode.DISCOVERY) == result.OK({SectionName("pam"): [[]]})
Ejemplo n.º 6
0
 def test_fetch_reading_cache_in_discovery_mode(self, fetcher: SNMPFetcher) -> None:
     assert isinstance(fetcher.file_cache, StubFileCache)  # For mypy
     assert fetcher.file_cache.cache == b"cached_section"
     assert fetcher.fetch(Mode.DISCOVERY) == result.OK(b"cached_section")