Skip to content
Snippets Groups Projects
Commit b10f9dfa authored by Erik Reid's avatar Erik Reid
Browse files

no changes if new netconf timestamp is same

parent 6c8ae704
No related branches found
No related tags found
No related merge requests found
......@@ -399,3 +399,18 @@ def snmp_community_string(netconf_config):
if me in allowed_network:
return community.xpath('./name/text()')[0]
return None
def netconf_changed_timestamp(netconf_config):
'''
<configuration changed-seconds="1549049195" changed-localtime="2019-02-01 19:26:35 UTC">
return the last change timestamp published by the config document
:param netconf_config: netconf lxml etree document
:return: an epoch timestamp (integer number of seconds) or None
'''
for ts in netconf_config.xpath('/configuration/@changed-seconds'):
if re.match(r'^\d+$', ts):
return int(ts)
logger = logging.getLogger(__name__)
logger.warning('no valid timestamp found in netconf configuration')
return None
......@@ -311,39 +311,63 @@ def reload_router_config(self, hostname):
'message': 'loading router netconf data'
})
# get the timestamp for the current netconf data
current_netconf_timestamp = None
netconf_doc = load_netconf_data(hostname)
if netconf_doc:
current_netconf_timestamp \
= juniper.netconf_changed_timestamp(netconf_doc)
logger.debug(
'current netconf timestamp: %r' % current_netconf_timestamp)
# load new netconf data
netconf_refresh_config.apply(args=[hostname])
netconf_doc = load_netconf_data(hostname)
if netconf_doc is None:
raise InventoryTaskError(
'no netconf data available for %r' % hostname)
'failure loading netconf data for %r' % hostname)
# return if new timestamp is the same as the original timestamp
new_netconf_timestamp = juniper.netconf_changed_timestamp(netconf_doc)
assert new_netconf_timestamp, \
'no timestamp available for new netconf data'
if new_netconf_timestamp == current_netconf_timestamp:
logger.debug('no netconf change timestamp change, aborting')
logger.debug('<<< reload_router_config')
return {
'task': 'reload_router_config',
'hostname': hostname,
'message': 'OK (no change)'
}
# clear cached classifier responses for this router, and
# refresh peering data
self.update_state(
state=states.STARTED,
meta={
'task': 'reload_router_config',
'hostname': hostname,
'message': 'refreshing peers & clearing cache'
})
refresh_ix_public_peers(hostname, netconf_doc)
refresh_vpn_rr_peers(hostname, netconf_doc)
clear_cached_classifier_responses(hostname)
# load snmp indexes
community = juniper.snmp_community_string(netconf_doc)
if not community:
raise InventoryTaskError(
'error extracting community string for %r' % hostname)
else:
self.update_state(
state=states.STARTED,
meta={
'task': 'reload_router_config',
'hostname': hostname,
'message': 'refreshing peers'
'message': 'refreshing snmp interface indexes'
})
refresh_ix_public_peers(hostname, netconf_doc)
refresh_vpn_rr_peers(hostname, netconf_doc)
community = juniper.snmp_community_string(netconf_doc)
if not community:
raise InventoryTaskError(
'error extracting community string for %r' % hostname)
else:
self.update_state(
state=states.STARTED,
meta={
'task': 'reload_router_config',
'hostname': hostname,
'message': 'refreshing snmp interface indexes'
})
snmp_refresh_interfaces.apply(args=[hostname, community])
# TODO: move this out of else? (i.e. clear even if netconf fails?)
clear_cached_classifier_responses(hostname)
snmp_refresh_interfaces.apply(args=[hostname, community])
logger.debug('<<< reload_router_config')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment