You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
add async notification support in active-active topo; refactor code for ycable tasks for change events (sonic-net#327)
Signed-off-by: vaibhav-dahiya [email protected]
This PR adds an enhancement to ycabled when if and whenever a notification arrives from SoC or server that it is going to be serviced. The notification can come at anytime and hence it must be listened to or awaited by the client at all times. For this we use asyncio lib and avail the async functionality in python.
the added code defines a GracefulRestartClient class that can be used to send requests to a gRPC server for graceful restart. The class has three async methods: send_request, receive_response, and notify_graceful_restart_start.
send_request method retrieves tor from request_queue, creates a request with the ToR, and sends it to the server using the stub's NotifyGracefulRestartStart method. It then reads the response from the server and prints the details of the response.
receive_response method retrieves response from response_queue, prints/puts the the response in DB, sleeps for the period mentioned in the response, and then puts the tor of the response back in the request_queue
We follow the existing ycabled pattern and instantiate the task_worker which contains all these tasks in a seperate thread
Description
Motivation and Context
How Has This Been Tested?
UT and using this server to validate
helper_logger.log_notice("Async client received from direct read period port = {}: period = {} index = {} guid = {} notifytype {} msgtype = {}".format(self.port, response.period, index, response.guid, response.notifytype, response.msgtype))
4034
+
helper_logger.log_debug("Async Debug only :{} {}".format(dir(response_stream), dir(response)))
4035
+
index=index+1
4036
+
ifresponse==grpc.aio.EOF:
4037
+
break
4038
+
helper_logger.log_notice("Async client finished loop from direct read period port:{} ".format(self.port))
4039
+
index=index+1
4040
+
exceptgrpc.RpcErrorase:
4041
+
helper_logger.log_notice("Async client port = {} exception occured because of {} ".format(self.port, e.code()))
4042
+
4043
+
awaitself.response_queue.put(response)
4044
+
4045
+
asyncdefprocess_response(self):
4046
+
whileTrue:
4047
+
response=awaitself.response_queue.get()
4048
+
helper_logger.log_debug("Async recieved a response from {} {}".format(self.port, response))
0 commit comments