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 <andre.zelak@windriver.com>
Change-Id: Ia1fbecebd5a0713300341717e78f12ab7a8fd6ce
This commit is contained in:
Andre Mauricio Zelak 2023-03-23 19:43:40 -03:00
parent 1154533600
commit 70c51f9da6
4 changed files with 13 additions and 25 deletions

View File

@ -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:

View File

@ -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:

View File

@ -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:

View File

@ -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