Skip to content
This repository was archived by the owner on Aug 15, 2025. It is now read-only.

Commit 9878852

Browse files
committed
Add method wait_for_vpp_api for the interface class
Add method 'wait_for_vpp_api()' for the interface class to be sure that VPP API is available before we can do interface operations
1 parent dfda2c7 commit 9878852

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

python/vyos/vpp/interface/gre.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ def delete(self):
117117
a = GREInterface(ifname='gre0', source_address='192.0.2.1', remote='203.0.113.25')
118118
a.delete()
119119
"""
120+
self.wait_for_vpp_api()
120121
return self.vpp.api.gre_tunnel_add_del(
121122
is_add=False, tunnel={'src': self.src_address, 'dst': self.dst_address}
122123
)
@@ -128,6 +129,8 @@ def kernel_add(self):
128129
a = GREInterface(ifname='gre0', source_address='192.0.2.1', remote='203.0.113.25')
129130
a.kernel_add()
130131
"""
132+
# Wait for VPP API to be ready
133+
self.wait_for_vpp_api()
131134
self.vpp.lcp_pair_add(self.ifname, self.kernel_interface, 'tun')
132135

133136
def kernel_delete(self):
@@ -137,4 +140,5 @@ def kernel_delete(self):
137140
a = GREInterface(ifname='gre0', source_address='192.0.2.1', remote='203.0.113.25')
138141
a.kernel_delete()
139142
"""
143+
self.wait_for_vpp_api()
140144
self.vpp.lcp_pair_del(self.ifname, self.kernel_interface)

python/vyos/vpp/interface/interface.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
# with this program; if not, write to the Free Software Foundation, Inc.,
1616
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
1717

18+
import time
1819
from vyos.vpp import VPPControl
1920

2021

@@ -47,3 +48,27 @@ def get_state(self):
4748
"""
4849
if_index = self.vpp.get_sw_if_index(self.ifname)
4950
return self.vpp.api.sw_interface_dump(sw_if_index=if_index)[0]['flags']
51+
52+
def wait_for_vpp_api(self, retries=10, delay=1):
53+
"""
54+
Waits for the VPP API to become available.
55+
56+
Args:
57+
retries (int): Number of times to retry checking the API readiness.
58+
delay (int): Time in seconds to wait between retries.
59+
60+
Raises:
61+
RuntimeError: If the VPP API is not ready after the specified retries.
62+
"""
63+
for attempt in range(retries):
64+
try:
65+
# Attempt to connect to the VPP API or call a test method
66+
if self.vpp.api.show_version():
67+
print("VPP API is ready.")
68+
return
69+
else:
70+
raise RuntimeError("VPP API is not connected.")
71+
except Exception as e:
72+
print(f"Attempt {attempt + 1}/{retries}: VPP API not ready - {e}")
73+
time.sleep(delay)
74+
raise RuntimeError("VPP API did not become ready within the expected time.")

0 commit comments

Comments
 (0)