From 326e3cc41737ccaeb302db7b34e4adfcec261ccf Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Tue, 28 Aug 2018 22:31:15 +0200 Subject: T778: harden dhcp_server.py for non existing files --- src/conf_mode/dhcp_server.py | 13 +++++++++---- 1 file changed, 9 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 cc887e28e..e03a04a4d 100755 --- a/src/conf_mode/dhcp_server.py +++ b/src/conf_mode/dhcp_server.py @@ -736,7 +736,10 @@ def verify(dhcp): return None def generate(dhcp): - if (dhcp is None) or (dhcp['disabled'] is True): + if dhcp is None: + return None + + if dhcp['disabled'] is True: print('Warning: DHCP server will be deactivated because it is disabled') return None @@ -753,11 +756,13 @@ def generate(dhcp): return None def apply(dhcp): - if (dhcp is None) or (dhcp['disabled'] is True): + if (dhcp is None) or dhcp['disabled']: # DHCP server is removed in the commit os.system('sudo systemctl stop isc-dhcp-server.service') - os.unlink(config_file) - os.unlink(daemon_config_file) + if os.path.exists(config_file): + os.unlink(config_file) + if os.path.exists(daemon_config_file): + os.unlink(daemon_config_file) else: os.system('sudo systemctl restart isc-dhcp-server.service') -- cgit v1.2.3