
Disable PTP v1 subscription and get current status and return an appropriated error message. Test Plan: PASS: Build notificationclient-base and notificationserver-base-v2 docker images With both ptptracking v1 and v2 enabled and running both client versions: Using V1 client: PASS: Get current PTP locking state PASS: Make a v1 type subscription PASS: Verify the subscription can be retrieved PASS: Get current PTP locking state PASS: Delete existing subscription Using v2 client: PASS: Get current /sync/sync-status/sync-state PASS: Try to get an invalid resource address PASS: Try to get current v1 type PTP locking state PASS: Make a v2 type subscription PASS: Verify the subscription can be retrived PASS: Delete existing subscription PASS: Try to add a v1 type subscription and check it fails PASS: Verify the v1 type subscription cannot be retrieved With only ptptracking v1 enabled repeat the tests with V1 client. And with only ptptracking v2 enabled repeat the tests with V2 client. Task: 47699 Story: 2010538 Signed-off-by: Andre Mauricio Zelak <andre.zelak@windriver.com> Change-Id: Ia1fbecebd5a0713300341717e78f12ab7a8fd6ce
96 lines
3.2 KiB
Python
96 lines
3.2 KiB
Python
#
|
|
# Copyright (c) 2020-2022 Wind River Systems, Inc.
|
|
#
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
#
|
|
|
|
from pecan import expose, rest, route, abort
|
|
from webob.exc import HTTPException, HTTPServerError
|
|
|
|
from wsme import types as wtypes
|
|
from wsmeext.pecan import wsexpose
|
|
|
|
import logging
|
|
import oslo_messaging
|
|
|
|
from notificationclientsdk.common.helpers import log_helper
|
|
from notificationclientsdk.services.ptp import PtpService
|
|
from notificationclientsdk.exception import client_exception
|
|
|
|
from sidecar.repository.notification_control import notification_control
|
|
|
|
LOG = logging.getLogger(__name__)
|
|
log_helper.config_logger(LOG)
|
|
|
|
|
|
class CurrentStateController(rest.RestController):
|
|
def __init__(self):
|
|
pass
|
|
|
|
@expose('json')
|
|
def get(self):
|
|
try:
|
|
service_nodenames = \
|
|
notification_control.list_of_service_nodenames()
|
|
LOG.debug('List of service nodes: %s' % service_nodenames)
|
|
if len(service_nodenames) == 0:
|
|
LOG.warning('No PTP service available yet')
|
|
abort(404)
|
|
|
|
# Starting with residing node, try querying the announced locations
|
|
# since the notification app may have moved to another node
|
|
nodename = notification_control.get_residing_nodename()
|
|
ptpservice = PtpService(notification_control)
|
|
|
|
while len(service_nodenames) > 0:
|
|
try:
|
|
LOG.debug('Querying nodename: %s' % nodename)
|
|
ptpstatus = ptpservice.query(nodename)
|
|
LOG.debug('Got ptpstatus: %s' % ptpstatus)
|
|
if ptpstatus == {}:
|
|
raise client_exception.ResourceNotAvailable('PTP',
|
|
nodename)
|
|
# response.status = 200
|
|
return ptpstatus
|
|
except client_exception.NodeNotAvailable as ex:
|
|
LOG.warning("{0}".format(str(ex)))
|
|
service_nodenames.remove(nodename)
|
|
if len(service_nodenames) > 0:
|
|
nodename = service_nodenames[0]
|
|
except Exception:
|
|
raise # break
|
|
|
|
LOG.warning('No PTP service available')
|
|
abort(404)
|
|
|
|
except client_exception.ResourceNotAvailable as ex:
|
|
LOG.warning("{0}".format(str(ex)))
|
|
abort(404)
|
|
except oslo_messaging.exceptions.MessagingTimeout as ex:
|
|
LOG.warning("Resource is not reachable:{0}".format(str(ex)))
|
|
abort(404)
|
|
except HTTPException as ex:
|
|
LOG.warning("Client side error:{0},{1}".format(type(ex), str(ex)))
|
|
# raise ex
|
|
abort(400)
|
|
except HTTPServerError as ex:
|
|
LOG.error("Server side error:{0},{1}".format(type(ex), str(ex)))
|
|
# raise ex
|
|
abort(500)
|
|
except Exception as ex:
|
|
LOG.error("Exception:{0}@{1}".format(type(ex), str(ex)))
|
|
abort(500)
|
|
|
|
|
|
class PtpController(rest.RestController):
|
|
def __init__(self):
|
|
pass
|
|
|
|
@wsexpose(wtypes.text)
|
|
def get(self):
|
|
return 'ptp'
|
|
|
|
|
|
route(PtpController, 'CurrentState', CurrentStateController())
|
|
route(PtpController, 'currentstate', CurrentStateController())
|