From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <pve-devel-bounces@lists.proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9])
	by lore.proxmox.com (Postfix) with ESMTPS id 697F21FF15C
	for <inbox@lore.proxmox.com>; Fri,  4 Apr 2025 18:30:49 +0200 (CEST)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
	by firstgate.proxmox.com (Proxmox) with ESMTP id 6D25F379A6;
	Fri,  4 Apr 2025 18:29:31 +0200 (CEST)
From: Gabriel Goller <g.goller@proxmox.com>
To: pve-devel@lists.proxmox.com
Date: Fri,  4 Apr 2025 18:28:41 +0200
Message-Id: <20250404162908.563060-31-g.goller@proxmox.com>
X-Mailer: git-send-email 2.39.5
In-Reply-To: <20250404162908.563060-1-g.goller@proxmox.com>
References: <20250404162908.563060-1-g.goller@proxmox.com>
MIME-Version: 1.0
X-SPAM-LEVEL: Spam detection results:  0
 AWL -0.023 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 DMARC_MISSING             0.1 Missing DMARC policy
 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
 SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_PASS               -0.001 SPF: sender matches SPF record
Subject: [pve-devel] [PATCH pve-network v2 05/19] frr: add new helpers for
 reloading frr configuration
X-BeenThere: pve-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/>
List-Post: <mailto:pve-devel@lists.proxmox.com>
List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe>
Reply-To: Proxmox VE development discussion <pve-devel@lists.proxmox.com>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: pve-devel-bounces@lists.proxmox.com
Sender: "pve-devel" <pve-devel-bounces@lists.proxmox.com>

From: Stefan Hanreich <s.hanreich@proxmox.com>

The old FRR configuration helper in the EVPN plugin defined a hash as
outfunc, which led to an error in the run_command invocation:

  Not a CODE reference at /usr/share/perl5/PVE/Tools.pm line 577.

This meant that frr-reload.py was never successfully invoked in the
first place.

The reload and restart parts of the original reload_controller_config
have been split into two functions, in order to make error handling
in the new apply function easier.

The new apply function tries to reload via frr-reload.py and if that
fails, it falls back to restarting the frr service.

Since frr-reload.py does *not* start / stop daemons that have been
added / remove to /etc/frr/daemons, we add a new parameter that can be
used to restart the frr service instead of just using frr-reload.py.

Due to completely omitting the outfunc, we now print the log of
frr-reload.py to STDOUT, so they are included in the task log for
debugging purposes.

Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
Signed-off-by: Gabriel Goller <g.goller@proxmox.com>
---
 src/PVE/Network/SDN/Frr.pm | 62 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 62 insertions(+)

diff --git a/src/PVE/Network/SDN/Frr.pm b/src/PVE/Network/SDN/Frr.pm
index 20eb4d3e405d..155cd591ea40 100644
--- a/src/PVE/Network/SDN/Frr.pm
+++ b/src/PVE/Network/SDN/Frr.pm
@@ -44,6 +44,68 @@ sub read_local_frr_config {
     }
 };
 
+my $FRR_CONFIG_FILE = "/etc/frr/frr.conf";
+
+=head3 apply()
+
+Tries to reload FRR with the frr-reload.py script from frr-pythontools. If that
+isn't installed or doesn't work it falls back to restarting the systemd frr
+service. If C<$force_restart> is set, then the FRR daemon will be restarted,
+without trying to reload it first.
+
+=cut
+
+sub apply {
+    my ($force_restart) = @_;
+
+    if (!-e $FRR_CONFIG_FILE) {
+	log_warn("$FRR_CONFIG_FILE is not present.");
+	return;
+    }
+
+    if (!$force_restart) {
+	eval { reload() };
+	return if !$@;
+
+	warn "reloading frr configuration failed: $@";
+	warn "trying to restart frr instead";
+    }
+
+    eval { restart() };
+    warn "restarting frr failed: $@" if $@;
+}
+
+sub reload {
+    my $bin_path = "/usr/lib/frr/frr-reload.py";
+
+    if (!-e $bin_path) {
+	die "missing $bin_path. Please install the frr-pythontools package";
+    }
+
+    my $err = sub {
+	my $line = shift;
+	warn "$line \n";
+    };
+
+    run_command([$bin_path, '--stdout', '--reload', $FRR_CONFIG_FILE], errfunc => $err);
+}
+
+sub restart {
+    # script invoked by the frr systemd service
+    my $bin_path = "/usr/lib/frr/frrinit.sh";
+
+    if (!-e $bin_path) {
+	die "missing $bin_path. Please install the frr package";
+    }
+
+    my $err = sub {
+	my $line = shift;
+	warn "$line \n";
+    };
+
+    run_command(['systemctl', 'restart', 'frr'], errfunc => $err);
+}
+
 =head3 to_raw_config(\%frr_config)
 
 Converts a given C<\%frr_config> to the raw config format.
-- 
2.39.5



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel