Commit 4807d19e authored by Lu Xu's avatar Lu Xu 👀

software/ors-amarisoft: fix ncclient waiting notification forever

The Ncclient does not have a timeout for taking notifications, causing it to wait indefinitely. This can result in the connection being lost while the waiting process is still ongoing.
parent b0c37a4a
...@@ -44,7 +44,7 @@ md5sum = 0450e9fa50844e4d6e51d608625c57f6 ...@@ -44,7 +44,7 @@ md5sum = 0450e9fa50844e4d6e51d608625c57f6
[ru_lopcomm_ncclient_common.py] [ru_lopcomm_ncclient_common.py]
_update_hash_filename_ = ru/lopcomm/ncclient_common.py _update_hash_filename_ = ru/lopcomm/ncclient_common.py
md5sum = 6f8d0592cc4b0b695cea5a0c25aafc4e md5sum = b3504313d232c2505a8c252ae9109c62
[ru_lopcomm_stats.jinja2.py] [ru_lopcomm_stats.jinja2.py]
_update_hash_filename_ = ru/lopcomm/stats.jinja2.py _update_hash_filename_ = ru/lopcomm/stats.jinja2.py
......
...@@ -103,24 +103,24 @@ class LopcommNetconfClient: ...@@ -103,24 +103,24 @@ class LopcommNetconfClient:
sub = self.conn.create_subscription() sub = self.conn.create_subscription()
self.logger.info('Subscription to %s successful' % (self.address,)) self.logger.info('Subscription to %s successful' % (self.address,))
def get_notification(self): def get_notification(self):
result = None self.logger.debug('Waiting for notification from %s...' % (self.address,))
while result == None: result = self.conn.take_notification(block=True, timeout=120)
self.logger.debug('Waiting for notification from %s...' % (self.address,)) if result:
result = self.conn.take_notification(block=True) self.logger.debug('Got new notification from %s...' % (self.address,))
if result: result_in_xml = result._raw
self.logger.debug('Got new notification from %s...' % (self.address,)) data_dict = xmltodict.parse(result_in_xml)
result_in_xml = result._raw if 'alarm-notif' in data_dict['notification']:
data_dict = xmltodict.parse(result_in_xml) self.json_logger.info('', extra={'data': json.dumps(data_dict)})
if 'alarm-notif' in data_dict['notification']: elif 'supervision-notification' in data_dict['notification']:
self.json_logger.info('', extra={'data': json.dumps(data_dict)}) self.supervision_json_logger.info('', extra={'data': json.dumps(data_dict)})
elif 'supervision-notification' in data_dict['notification']: elif 'netconf-session-start' in data_dict['notification'] or 'netconf-session-end' in data_dict['notification']:
self.supervision_json_logger.info('', extra={'data': json.dumps(data_dict)}) self.ncsession_json_logger.info('', extra={'data': json.dumps(data_dict)})
elif 'netconf-session-start' in data_dict['notification'] or 'netconf-session-end' in data_dict['notification']: elif any(event in data_dict['notification'] for event in ['install-event', 'activation-event', 'download-event']):
self.ncsession_json_logger.info('', extra={'data': json.dumps(data_dict)}) self.software_json_logger.info('', extra={'data': json.dumps(data_dict)})
elif any(event in data_dict['notification'] for event in ['install-event', 'activation-event', 'download-event']): else:
self.software_json_logger.info('', extra={'data': json.dumps(data_dict)}) self.cfg_json_logger.info('', extra={'data': json.dumps(data_dict)})
else: else:
self.cfg_json_logger.info('', extra={'data': json.dumps(data_dict)}) raise TimeoutError
def edit_config(self, config_files): def edit_config(self, config_files):
for config_file in config_files: for config_file in config_files:
with open(config_file) as f: with open(config_file) as f:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment