|
39 | 39 | from vyos.utils.kernel import unload_kmod |
40 | 40 | from vyos.utils.kernel import list_loaded_modules |
41 | 41 | from vyos.utils.process import call |
| 42 | +from vyos.utils.process import is_systemd_service_active |
42 | 43 |
|
43 | 44 | from vyos.vpp import VPPControl |
44 | 45 | from vyos.vpp import control_host |
@@ -771,10 +772,12 @@ def apply(config): |
771 | 772 |
|
772 | 773 | if 'settings' in config and 'interface' in config.get('settings'): |
773 | 774 | # connect to VPP |
774 | | - # must be performed multiple attempts because API is not available |
775 | | - # immediately after the service restart |
776 | 775 | try: |
777 | | - vpp_control = VPPControl(attempts=20, interval=500) |
| 776 | + # Bail out early if VPP service is not running |
| 777 | + if not is_systemd_service_active(f'{service_name}.service'): |
| 778 | + raise RuntimeError('VPP service is not running or failed to start') |
| 779 | + |
| 780 | + vpp_control = VPPControl() |
778 | 781 |
|
779 | 782 | # preconfigure LCP plugin |
780 | 783 | if 'ignore_kernel_routes' in config.get('settings', {}).get('lcp', {}): |
@@ -877,7 +880,7 @@ def apply(config): |
877 | 880 | bitmask |= 1 << wid |
878 | 881 | vpp_control.set_nat_workers(bitmask) |
879 | 882 |
|
880 | | - except (VPPIOError, VPPValueError) as e: |
| 883 | + except (VPPIOError, VPPValueError, RuntimeError) as e: |
881 | 884 | # if cannot connect to VPP or an error occurred then |
882 | 885 | # we need to stop vpp service and initialize interfaces |
883 | 886 | call(f'systemctl stop {service_name}.service') |
|
0 commit comments