def test_keep_outdated_false(self, logger, monkeypatch): monkeypatch.setattr(time, "time", lambda c=itertools.count(1000, 50): next(c)) raw_data = AgentRawData(b"<<<another_section>>>") section_store = MockStore( "/dev/null", PersistedSections[AgentRawDataSection]( { SectionName("section"): (500, 600, []), } ), logger=logger, ) parser = AgentParser( HostName("testhost"), section_store, check_interval=42, keep_outdated=False, translation={}, encoding_fallback="ascii", simulation=False, logger=logger, ) ahs = parser.parse(raw_data, selection=NO_SELECTION) assert ahs.sections == {SectionName("another_section"): []} assert ahs.cache_info == {} assert ahs.piggybacked_raw_data == {} assert section_store.load() == {}
def test_update_with_store_and_persisting_raw_data(self, monkeypatch): monkeypatch.setattr(time, "time", lambda c=itertools.count(1000, 50): next(c)) section_store = MockStore(PersistedSections[AgentRawDataSection]({ SectionName("stored"): (0, 0, [["canned", "section"]]), })) raw_data = AgentRawData(b"<<<fresh:persist(10)>>>\nhello section") parser = AgentParser( "testhost", section_store, check_interval=0, keep_outdated=True, translation={}, encoding_fallback="ascii", simulation=False, logger=logging.getLogger("test"), ) ahs = parser.parse(raw_data, selection=NO_SELECTION) assert ahs.sections == { SectionName("fresh"): [["hello", "section"]], SectionName("stored"): [["canned", "section"]], } assert ahs.cache_info == { SectionName("stored"): (0, 0), SectionName("fresh"): (1000, -990), } assert ahs.piggybacked_raw_data == {} assert section_store.load() == PersistedSections[AgentRawDataSection]({ SectionName("stored"): (0, 0, [["canned", "section"]]), SectionName("fresh"): (1000, 10, [["hello", "section"]]), })
def test_update_store_with_newest(self, logger): section_store = MockStore( "/dev/null", PersistedSections[AgentRawDataSection]( { SectionName("section"): (0, 0, [["oldest"]]), } ), logger=logger, ) raw_data = AgentRawData(b"<<<section>>>\nnewest") parser = AgentParser( HostName("testhost"), section_store, check_interval=0, keep_outdated=True, translation={}, encoding_fallback="ascii", simulation=False, logger=logger, ) ahs = parser.parse(raw_data, selection=NO_SELECTION) assert ahs.sections == {SectionName("section"): [["newest"]]} assert ahs.cache_info == {} assert ahs.piggybacked_raw_data == {} assert section_store.load() == PersistedSections[AgentRawDataSection]( { SectionName("section"): (0, 0, [["oldest"]]), } )
def test_update_with_store_and_non_persisting_raw_data(self): section_store = MockStore(PersistedSections[AgentRawDataSection]({ SectionName("stored"): (0, 0, []), })) raw_data = AgentRawData(b"<<<fresh>>>") parser = AgentParser( "testhost", section_store, check_interval=0, keep_outdated=True, translation={}, encoding_fallback="ascii", simulation=False, logger=logging.getLogger("test"), ) ahs = parser.parse(raw_data, selection=NO_SELECTION) assert ahs.sections == { SectionName("fresh"): [], SectionName("stored"): [], } assert ahs.cache_info == {SectionName("stored"): (0, 0)} assert ahs.piggybacked_raw_data == {} assert section_store.load() == PersistedSections[AgentRawDataSection]({ SectionName("stored"): (0, 0, []), })
def test_update_with_empty_store_and_empty_raw_data(self): section_store = MockStore(PersistedSections[AgentRawDataSection]({})) raw_data = AgentRawData(b"") parser = AgentParser( "testhost", section_store, check_interval=0, keep_outdated=True, translation={}, encoding_fallback="ascii", simulation=False, logger=logging.getLogger("test"), ) ahs = parser.parse(raw_data, selection=NO_SELECTION) assert ahs.sections == {} assert ahs.cache_info == {} assert ahs.piggybacked_raw_data == {} assert section_store.load() == {}
def parser(self, hostname: HostName, store, logger): return AgentParser( hostname, store, check_interval=0, keep_outdated=True, translation={}, encoding_fallback="ascii", simulation=False, logger=logger, )
def test_update_with_empty_store_and_raw_data(self, logger): raw_data = AgentRawData(b"<<<fresh>>>") section_store = MockStore( "/dev/null", PersistedSections[AgentRawDataSection]({}), logger=logger, ) parser = AgentParser( HostName("testhost"), section_store, check_interval=0, keep_outdated=True, translation={}, encoding_fallback="ascii", simulation=False, logger=logger, ) ahs = parser.parse(raw_data, selection=NO_SELECTION) assert ahs.sections == {SectionName("fresh"): []} assert ahs.cache_info == {} assert ahs.piggybacked_raw_data == {} assert section_store.load() == {}
def _make_parser(self) -> AgentParser: check_interval = config.HostConfig.make_host_config(self.hostname).check_mk_check_interval return AgentParser( self.hostname, SectionStore[AgentRawDataSection]( self.persisted_sections_file_path, logger=self._logger, ), check_interval=check_interval, keep_outdated=self.use_outdated_persisted_sections, translation=config.get_piggyback_translations(self.hostname), encoding_fallback=config.fallback_agent_output_encoding, simulation=config.agent_simulator, logger=self._logger, )