def test_invalid_serialized_value_should_be_interpreted_as_change(): ts = TimestampChecker(Mock(), Mock(), 'uptime') invalid_time_pickle = 'foobar' with patch('nav.models.manage.NetboxInfo.objects.get', return_value=invalid_time_pickle): yield ts.load() assert ts.is_changed()
def _stampcheck(self, mib): stampcheck = TimestampChecker(self.agent, self.containers, INFO_VAR_NAME) yield stampcheck.load() yield stampcheck.collect([mib.get_neighbors_last_change()]) defer.returnValue(stampcheck)
def _get_stampcheck(self, mib): """Retrieves the last change timestamp of the LLDP remote table, returning a TimestampChecker instance reflecting it. """ stampcheck = TimestampChecker(self.agent, self.containers, INFO_VAR_NAME) yield stampcheck.load() yield stampcheck.collect([mib.get_remote_last_change()]) defer.returnValue(stampcheck)
def _get_timestamps(self): stampcheck = TimestampChecker(self.agent, self.containers, "uptime") old_times = yield stampcheck.load() new_times = yield stampcheck.collect([]) changed = old_times and stampcheck.is_changed(COLDBOOT_MAX_DELTA) self._logger.debug("uptime data (changed=%s): %r", changed, new_times) timestamp, ticks = new_times[0] upsince = get_upsince(timestamp, ticks) self._logger.debug( "last sysuptime reset/rollover reported by device: %s", upsince) stampcheck.save() returnValue((changed, upsince))
def test_representation_inconsistencies_should_not_matter(): """Tests that loaded and collected timestamps can be compared, even if the internal and the persisted representations may differ between being tuples and lists. The internal representation was always with tuples, but the new JSON-based db persistence converts this to lists, since tuples don't exist in JSON. """ ts = TimestampChecker(Mock(), Mock(), 'sometime') json_data = "[[1559907627.0, 28245286]]" ts.collected_times = ((1559907627.0, 28245286), ) mock_info = Mock(value=json_data) with patch('nav.models.manage.NetboxInfo.objects.get', return_value=mock_info): yield ts.load() assert not ts.is_changed(max_deviation=60)
def __init__(self, *args, **kwargs): super(Entity, self).__init__(*args, **kwargs) self.alias_mapping = {} self.entitymib = EntityMib(self.agent) self.stampcheck = TimestampChecker(self.agent, self.containers, INFO_VAR_NAME)
def test_is_changed(loaded, collected, max_deviation, expected, description): ts = TimestampChecker(Mock(), Mock(), 'sometime') ts.loaded_times = [loaded] if loaded else None ts.collected_times = [collected] assert ts.is_changed(max_deviation=max_deviation) == expected, description