Browse Source

DNM testing driver agent socket

Change-Id: I69f61d7d2708be0d3d1248438db3e5b7ee6376ca
changes/59/785559/1
Gregory Thiemonge 4 months ago
parent
commit
513d8dce24
  1. 23
      octavia_lib/api/drivers/driver_lib.py

23
octavia_lib/api/drivers/driver_lib.py

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

Loading…
Cancel
Save