Fix unhandled exception when querying ptp status

Attempting to query the status of a non-existant ptp instance or
clockClass could result in an unhandled key error exception on the
ptptracking daemon.

Added logic to handle this case on the server and report the error to
the client.

Test plan:
PASS: Build and deploy notificationservice-base and
notificationclient-base
PASS: Test v1 and v2 status pulls, subscribe, list and delete.

Closes-bug: 1997995

Signed-off-by: Cole Walker <cole.walker@windriver.com>
Change-Id: I3bfe111dbd79475720ea1e710be2a23f45763ae6
This commit is contained in:
Cole Walker 2022-11-25 15:37:10 -05:00
parent dffee68f5b
commit 3123d63cfb
2 changed files with 15 additions and 6 deletions

View File

@ -65,6 +65,9 @@ class ResourceAddressController(object):
LOG.warning("Client side error:{0},{1}".format(type(ex), str(ex)))
# raise ex
abort(400)
except TypeError as ex:
LOG.error("Resource {0} not found on {1}".format(self.resource_address, nodename))
abort(404)
except HTTPServerError as ex:
LOG.error("Server side error:{0},{1}".format(type(ex), str(ex)))
# raise ex

View File

@ -127,7 +127,7 @@ class PtpWatcherDefault:
resource_path = constants.SOURCE_SYNC_SYNC_STATE
if resource_path == constants.SOURCE_SYNC_GNSS_SYNC_STATUS:
self.watcher.gnsstracker_context_lock.acquire()
if optional:
if optional and self.watcher.gnsstracker_context.get(optional):
sync_state = \
self.watcher.gnsstracker_context[optional].get(
'sync_state', GnssState.Failure_Nofix)
@ -137,7 +137,7 @@ class PtpWatcherDefault:
lastStatus[optional] = self._build_event_response(
resource_path, last_event_time, resource_address,
sync_state)
else:
elif not optional:
for config in self.daemon_context['GNSS_INSTANCES']:
sync_state = \
self.watcher.gnsstracker_context[config].get(
@ -148,10 +148,12 @@ class PtpWatcherDefault:
lastStatus[config] = self._build_event_response(
resource_path, last_event_time,
resource_address, sync_state)
else:
lastStatus = None
self.watcher.gnsstracker_context_lock.release()
elif resource_path == constants.SOURCE_SYNC_PTP_CLOCK_CLASS:
self.watcher.ptptracker_context_lock.acquire()
if optional:
if optional and self.watcher.ptptracker_context.get(optional):
clock_class = \
self.watcher.ptptracker_context[optional].get(
'clock_class', '248')
@ -162,7 +164,7 @@ class PtpWatcherDefault:
resource_path, last_clock_class_event_time,
resource_address, clock_class,
constants.VALUE_TYPE_METRIC)
else:
elif not optional:
for config in self.daemon_context['PTP4L_INSTANCES']:
clock_class = \
self.watcher.ptptracker_context[config].get(
@ -175,10 +177,12 @@ class PtpWatcherDefault:
resource_path, last_clock_class_event_time,
resource_address, clock_class,
constants.VALUE_TYPE_METRIC)
else:
lastStatus = None
self.watcher.ptptracker_context_lock.release()
elif resource_path == constants.SOURCE_SYNC_PTP_LOCK_STATE:
self.watcher.ptptracker_context_lock.acquire()
if optional:
if optional and self.watcher.ptptracker_context.get(optional):
sync_state = \
self.watcher.ptptracker_context[optional].get(
'sync_state', PtpState.Freerun)
@ -188,7 +192,7 @@ class PtpWatcherDefault:
lastStatus[optional] = self._build_event_response(
resource_path, last_event_time, resource_address,
sync_state)
else:
elif not optional:
for config in self.daemon_context['PTP4L_INSTANCES']:
sync_state = \
self.watcher.ptptracker_context[config].get(
@ -199,6 +203,8 @@ class PtpWatcherDefault:
lastStatus[config] = self._build_event_response(
resource_path, last_event_time,
resource_address, sync_state)
else:
lastStatus = None
self.watcher.ptptracker_context_lock.release()
elif resource_path == constants.SOURCE_SYNC_OS_CLOCK: