Be a bit more persistent when connecting to VPP - retry 30 times before giving up
This commit is contained in:
@ -22,6 +22,7 @@ import os
|
|||||||
import fnmatch
|
import fnmatch
|
||||||
import logging
|
import logging
|
||||||
import socket
|
import socket
|
||||||
|
import time
|
||||||
from vpp_papi import VPPApiClient
|
from vpp_papi import VPPApiClient
|
||||||
|
|
||||||
|
|
||||||
@ -51,7 +52,7 @@ class VPPApi:
|
|||||||
self.cache_read = False
|
self.cache_read = False
|
||||||
self.lcp_enabled = False
|
self.lcp_enabled = False
|
||||||
|
|
||||||
def connect(self):
|
def connect(self, retries=30):
|
||||||
"""Connect to the VPP Dataplane, if we're not already connected"""
|
"""Connect to the VPP Dataplane, if we're not already connected"""
|
||||||
if self.connected:
|
if self.connected:
|
||||||
return True
|
return True
|
||||||
@ -67,17 +68,26 @@ class VPPApi:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
self.vpp = VPPApiClient(apifiles=jsonfiles, server_address=self.vpp_api_socket)
|
self.vpp = VPPApiClient(apifiles=jsonfiles, server_address=self.vpp_api_socket)
|
||||||
try:
|
self.logger.debug("Connecting to VPP")
|
||||||
self.logger.debug("Connecting to VPP")
|
for i in range(retries):
|
||||||
self.vpp.connect(self.clientname)
|
try:
|
||||||
except:
|
self.vpp.connect(self.clientname)
|
||||||
|
self.connected = True
|
||||||
|
break
|
||||||
|
except Exception as e:
|
||||||
|
self.logger.warning(
|
||||||
|
f"Could not connect to VPP (attempt {i+1}/{retries}): {e}"
|
||||||
|
)
|
||||||
|
time.sleep(1)
|
||||||
|
self.connected = False
|
||||||
|
if not self.connected:
|
||||||
|
self.logger.error(f"Could not connect to VPP (tried {retries} times)")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# pylint: disable=no-member
|
# pylint: disable=no-member
|
||||||
api_response = self.vpp.api.show_version()
|
api_response = self.vpp.api.show_version()
|
||||||
self.logger.info(f"VPP version is {api_response.version}")
|
self.logger.info(f"VPP version is {api_response.version}")
|
||||||
|
|
||||||
self.connected = True
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def disconnect(self):
|
def disconnect(self):
|
||||||
|
Reference in New Issue
Block a user