DNM testing driver agent socket

Change-Id: I69f61d7d2708be0d3d1248438db3e5b7ee6376ca
This commit is contained in:
Gregory Thiemonge 2021-04-09 08:36:29 +02:00
parent 3208f7fbca
commit 8aa1750e4c

View File

@ -14,6 +14,7 @@
import os import os
import socket import socket
import sys
import time import time
from oslo_serialization import jsonutils from oslo_serialization import jsonutils
@ -67,8 +68,12 @@ class DriverLibrary():
raise driver_exceptions.DriverAgentTimeout( raise driver_exceptions.DriverAgentTimeout(
fault_string=('The driver agent did not respond in {} ' fault_string=('The driver agent did not respond in {} '
'seconds.'.format(DRIVER_AGENT_TIMEOUT))) 'seconds.'.format(DRIVER_AGENT_TIMEOUT)))
# Give the CPU a break from polling # TODO(gthiemonge) remove time.sleep when py36 is no longer used:
time.sleep(0.01) # see note in # https://docs.python.org/3/library/socket.html#\
# socket.socket.settimeout
if sock.type & socket.SOCK_NONBLOCK:
# Give the CPU a break from polling
time.sleep(0.01)
payload_size = int(size_str) payload_size = int(size_str)
mv_buffer = memoryview(bytearray(payload_size)) mv_buffer = memoryview(bytearray(payload_size))
next_offset = 0 next_offset = 0
@ -81,8 +86,12 @@ class DriverLibrary():
raise driver_exceptions.DriverAgentTimeout( raise driver_exceptions.DriverAgentTimeout(
fault_string=('The driver agent did not respond in {} ' fault_string=('The driver agent did not respond in {} '
'seconds.'.format(DRIVER_AGENT_TIMEOUT))) 'seconds.'.format(DRIVER_AGENT_TIMEOUT)))
# Give the CPU a break from polling # TODO(gthiemonge) remove time.sleep when py36 is no longer used:
time.sleep(0.01) # see note in # https://docs.python.org/3/library/socket.html#\
# socket.socket.settimeout
if sock.type & socket.SOCK_NONBLOCK:
# Give the CPU a break from polling
time.sleep(0.01)
return jsonutils.loads(mv_buffer.tobytes()) return jsonutils.loads(mv_buffer.tobytes())
def _send(self, socket_path, data): def _send(self, socket_path, data):
@ -94,7 +103,10 @@ class DriverLibrary():
len_str = '{}\n'.format(len(json_data)).encode('utf-8') len_str = '{}\n'.format(len(json_data)).encode('utf-8')
sock.send(len_str) sock.send(len_str)
sock.sendall(json_data) sock.sendall(json_data)
start = time.time()
response = self._recv(sock) response = self._recv(sock)
end = time.time()
sys.stderr.write("_recv in {} sec\n".format(end - start))
finally: finally:
sock.close() sock.close()
return response return response
@ -216,7 +228,10 @@ class DriverLibrary():
:raises DriverError: An unexpected error occurred. :raises DriverError: An unexpected error occurred.
:returns: A HealthMonitor object or None if not found. :returns: A HealthMonitor object or None if not found.
""" """
start = time.time()
data = self._get_resource(constants.HEALTHMONITORS, healthmonitor_id) data = self._get_resource(constants.HEALTHMONITORS, healthmonitor_id)
end = time.time()
sys.stderr.write("got resource in {}\n".format(end - start))
if data: if data:
return data_models.HealthMonitor.from_dict(data) return data_models.HealthMonitor.from_dict(data)
return None return None