Ejemplo n.º 1
0
    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() == {}
Ejemplo n.º 2
0
    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"]]),
            }
        )
Ejemplo n.º 3
0
    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"]]),
        })
Ejemplo n.º 4
0
    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, []),
        })
Ejemplo n.º 5
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() == {}
Ejemplo n.º 6
0
    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() == {}