DNM testing driver agent socket
Change-Id: I69f61d7d2708be0d3d1248438db3e5b7ee6376ca
This commit is contained in:
parent
3208f7fbca
commit
8aa1750e4c
@ -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,6 +68,10 @@ 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)))
|
||||||
|
# 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
|
# Give the CPU a break from polling
|
||||||
time.sleep(0.01)
|
time.sleep(0.01)
|
||||||
payload_size = int(size_str)
|
payload_size = int(size_str)
|
||||||
@ -81,6 +86,10 @@ 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)))
|
||||||
|
# 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
|
# Give the CPU a break from polling
|
||||||
time.sleep(0.01)
|
time.sleep(0.01)
|
||||||
return jsonutils.loads(mv_buffer.tobytes())
|
return jsonutils.loads(mv_buffer.tobytes())
|
||||||
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user