From 70c51f9da6e0d1a5a47a4b0a9b513aa15a372d1e Mon Sep 17 00:00:00 2001 From: Andre Mauricio Zelak Date: Thu, 23 Mar 2023 19:43:40 -0300 Subject: [PATCH] Disable PTP v1 API in V2 server 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 Change-Id: Ia1fbecebd5a0713300341717e78f12ab7a8fd6ce --- .../common/helpers/subscription_helper.py | 8 ++++++ .../sidecar/controllers/v1/resource/ptp.py | 3 +++ .../sidecar/controllers/v1/subscriptions.py | 2 ++ .../trackingfunctionsdk/services/daemon.py | 25 ------------------- 4 files changed, 13 insertions(+), 25 deletions(-) diff --git a/notificationclient-base/docker/notificationclient-sidecar/notificationclientsdk/common/helpers/subscription_helper.py b/notificationclient-base/docker/notificationclient-sidecar/notificationclientsdk/common/helpers/subscription_helper.py index 21b29f8..133d27d 100644 --- a/notificationclient-base/docker/notificationclient-sidecar/notificationclientsdk/common/helpers/subscription_helper.py +++ b/notificationclient-base/docker/notificationclient-sidecar/notificationclientsdk/common/helpers/subscription_helper.py @@ -40,6 +40,14 @@ def notify(subscriptioninfo, notification, timeout=2, retry=3): response = requests.post(url, data=data, headers=headers, timeout=timeout) response.raise_for_status() + if notification == {}: + if hasattr(subscriptioninfo, 'ResourceType'): + resource = "{'ResourceType':'" + \ + subscriptioninfo.ResourceType + "'}" + elif hasattr(subscriptioninfo, 'ResourceAddress'): + _, _, resource, _, _ = parse_resource_address( + subscriptioninfo.ResourceAddress) + raise client_exception.InvalidResource(resource) result = True return response except client_exception.InvalidResource as ex: diff --git a/notificationclient-base/docker/notificationclient-sidecar/sidecar/controllers/v1/resource/ptp.py b/notificationclient-base/docker/notificationclient-sidecar/sidecar/controllers/v1/resource/ptp.py index 7171cd0..c893cf8 100644 --- a/notificationclient-base/docker/notificationclient-sidecar/sidecar/controllers/v1/resource/ptp.py +++ b/notificationclient-base/docker/notificationclient-sidecar/sidecar/controllers/v1/resource/ptp.py @@ -47,6 +47,9 @@ class CurrentStateController(rest.RestController): 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: diff --git a/notificationclient-base/docker/notificationclient-sidecar/sidecar/controllers/v1/subscriptions.py b/notificationclient-base/docker/notificationclient-sidecar/sidecar/controllers/v1/subscriptions.py index 962c22f..b7e365e 100644 --- a/notificationclient-base/docker/notificationclient-sidecar/sidecar/controllers/v1/subscriptions.py +++ b/notificationclient-base/docker/notificationclient-sidecar/sidecar/controllers/v1/subscriptions.py @@ -73,6 +73,8 @@ class SubscriptionsControllerV1(rest.RestController): abort(400) except client_exception.InvalidEndpoint: abort(400) + except client_exception.InvalidResource as ex: + abort(400, str(ex)) except client_exception.NodeNotAvailable: abort(404) except client_exception.ResourceNotAvailable: diff --git a/notificationservice-base-v2/docker/ptptrackingfunction/trackingfunctionsdk/services/daemon.py b/notificationservice-base-v2/docker/ptptrackingfunction/trackingfunctionsdk/services/daemon.py index 799f744..b0a2694 100644 --- a/notificationservice-base-v2/docker/ptptrackingfunction/trackingfunctionsdk/services/daemon.py +++ b/notificationservice-base-v2/docker/ptptrackingfunction/trackingfunctionsdk/services/daemon.py @@ -254,31 +254,6 @@ class PtpWatcherDefault: constants.SOURCE_SYNC_SYNC_STATE), sync_state) LOG.debug("query_status: {}".format(lastStatus)) - else: - # Request is for PTP v1 notification - # PTP v1 only supports single instance ptp - instance = self.daemon_context['PTP4L_INSTANCES'][0] - if len(self.daemon_context['PTP4L_INSTANCES']) > 1: - LOG.warning("Multiple ptp4l instances configured, " - "retrieving status for %s" % instance) - self.watcher.ptptracker_context_lock.acquire() - sync_state = self.watcher.ptptracker_context[instance].get( - 'sync_state', PtpState.Freerun) - last_event_time = \ - self.watcher.ptptracker_context[instance].get( - 'last_event_time', time.time()) - lastStatus[constants.PTP_V1_KEY] = { - 'ResourceType': ResourceType.TypePTP, - 'EventData': { - 'State': sync_state - }, - 'ResourceQualifier': { - 'NodeName': self.watcher.node_name - }, - 'EventTimestamp': last_event_time - } - self.watcher.ptptracker_context_lock.release() - LOG.warning("query_status PTP v1: {}".format(lastStatus)) return lastStatus