From 1f68b69328c961e450ac70b12f7bf073d70355d7 Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Sat, 15 May 2021 12:44:04 +0200 Subject: dhcp-server: T3544: fix FileNotFoundError on first invokation The problem of using the move() operation over render() is that render will silently create the directory tree in the background and move() does not. This means that on first boot when /run/dhcp-server does not exist, move will fail with a FileNotFoundError. Instead of using move() we render() the configuration two times, one for validating it via dhcpd -t and the other time to really apply it to the service. The performance impact should be little as the config should still be cached in the system RAM. --- src/conf_mode/dhcp_server.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src/conf_mode') diff --git a/src/conf_mode/dhcp_server.py b/src/conf_mode/dhcp_server.py index af77c6d43..0ed09e130 100755 --- a/src/conf_mode/dhcp_server.py +++ b/src/conf_mode/dhcp_server.py @@ -18,7 +18,6 @@ import os from ipaddress import ip_address from ipaddress import ip_network -from shutil import move from sys import exit from vyos.config import Config @@ -289,9 +288,9 @@ def generate(dhcp): raise ConfigError('Configuration file errors encountered - check your options!') # Now that we know that the newly rendered configuration is "good" we can - # move the temporary configuration to the "real" configuration - we could - # also render it two times but that would not be as fast as a move operation - move(tmp_file, config_file) + # render the "real" configuration + render(config_file, 'dhcp-server/dhcpd.conf.tmpl', dhcp, + formater=lambda _: _.replace(""", '"')) return None -- cgit v1.2.3