Merge "Enhance wait_service_status function"
This commit is contained in:
commit
4b219dcbcf
|
@ -364,51 +364,62 @@ class BaseKuryrScenarioTest(manager.NetworkScenarioTest):
|
||||||
raise lib_exc.ServerFault()
|
raise lib_exc.ServerFault()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _verify_connectivity(cls, dest_ip, timeout_period, protocol, port):
|
def _verify_connectivity(cls, dest_ip, timeout_period, protocol, port,
|
||||||
udp_client_sock = None
|
expected_different_replies=1):
|
||||||
|
|
||||||
def verify_tcp(dest_ip, port, session):
|
def verify_tcp(dest_ip, port, session):
|
||||||
try:
|
try:
|
||||||
session.get("http://{0}:{1}".format(dest_ip, port),
|
resp = requests.get("http://{0}:{1}".format(dest_ip, port),
|
||||||
timeout=2)
|
timeout=2)
|
||||||
|
if resp.status_code == requests.codes.OK:
|
||||||
|
return resp
|
||||||
except Exception:
|
except Exception:
|
||||||
return False
|
return None
|
||||||
return True
|
return None
|
||||||
|
|
||||||
def verify_udp(dest_ip, port, udp_client_sock):
|
def verify_udp(dest_ip, port):
|
||||||
|
udp_client_sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||||
|
udp_client_sock.settimeout(5.0)
|
||||||
udp_client_sock.sendto("Hi Server, howRU?".encode(),
|
udp_client_sock.sendto("Hi Server, howRU?".encode(),
|
||||||
(dest_ip, port))
|
(dest_ip, port))
|
||||||
try:
|
try:
|
||||||
udp_client_sock.recvfrom(512)
|
data, addr = udp_client_sock.recvfrom(1024)
|
||||||
except socket.timeout:
|
except socket.timeout:
|
||||||
return False
|
return None
|
||||||
return True
|
return data
|
||||||
|
|
||||||
if protocol == "TCP":
|
if protocol == "TCP":
|
||||||
session = requests.Session()
|
session = requests.Session()
|
||||||
iter_func = partial(verify_tcp, session=session)
|
iter_func = partial(verify_tcp, session=session)
|
||||||
elif protocol == "UDP":
|
elif protocol == "UDP":
|
||||||
udp_client_sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
iter_func = verify_udp
|
||||||
udp_client_sock.settimeout(5.0)
|
|
||||||
iter_func = partial(verify_udp, udp_client_sock=udp_client_sock)
|
|
||||||
else:
|
else:
|
||||||
LOG.warning("Unsupported protocol %s, returning", protocol)
|
LOG.warning("Unsupported protocol %s, returning", protocol)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
start = time.time()
|
start = time.time()
|
||||||
|
unique_resps = set()
|
||||||
while time.time() - start < timeout_period:
|
while time.time() - start < timeout_period:
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
if iter_func(dest_ip, port):
|
unique_resps.add(iter_func(dest_ip, port))
|
||||||
|
unique_resps.discard(None)
|
||||||
|
if len(unique_resps) == expected_different_replies:
|
||||||
|
LOG.info('We received %d replies from prot=%s;%s:%d - '
|
||||||
|
'connectivity was veified!',
|
||||||
|
expected_different_replies, protocol, dest_ip, port)
|
||||||
return True
|
return True
|
||||||
LOG.warning('No initial traffic is passing through.')
|
LOG.info('Connectivity not verified yet, we received so far %d '
|
||||||
|
'replies from prot=%s;%s:%d', len(unique_resps),
|
||||||
|
protocol, dest_ip, port)
|
||||||
LOG.error("Can't connect to %s:%d", dest_ip, port)
|
LOG.error("Can't connect to %s:%d", dest_ip, port)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def wait_service_status(cls, service_ip, timeout_period,
|
def wait_service_status(cls, service_ip, timeout_period, protocol="TCP",
|
||||||
protocol="TCP", port=80):
|
port=80, num_of_back_ends=1):
|
||||||
if cls._verify_connectivity(service_ip, timeout_period,
|
if cls._verify_connectivity(
|
||||||
protocol, port):
|
service_ip, timeout_period, protocol, port,
|
||||||
|
expected_different_replies=num_of_back_ends):
|
||||||
LOG.info('Service responding...')
|
LOG.info('Service responding...')
|
||||||
else:
|
else:
|
||||||
LOG.error("Can't connect service's IP %s", service_ip)
|
LOG.error("Can't connect service's IP %s", service_ip)
|
||||||
|
@ -466,7 +477,7 @@ class BaseKuryrScenarioTest(manager.NetworkScenarioTest):
|
||||||
cls.service_name = service_name
|
cls.service_name = service_name
|
||||||
cls.wait_service_status(cls.service_ip,
|
cls.wait_service_status(cls.service_ip,
|
||||||
CONF.kuryr_kubernetes.lb_build_timeout,
|
CONF.kuryr_kubernetes.lb_build_timeout,
|
||||||
protocol, port)
|
protocol, port, num_of_back_ends=pod_num)
|
||||||
actual_be = cls.wait_ep_members_status(
|
actual_be = cls.wait_ep_members_status(
|
||||||
cls.service_name, namespace,
|
cls.service_name, namespace,
|
||||||
CONF.kuryr_kubernetes.lb_build_timeout)
|
CONF.kuryr_kubernetes.lb_build_timeout)
|
||||||
|
|
Loading…
Reference in New Issue