summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2018-08-28 22:31:15 +0200
committerChristian Poessinger <christian@poessinger.com>2018-08-28 22:32:01 +0200
commit326e3cc41737ccaeb302db7b34e4adfcec261ccf (patch)
treed5e5a7c585217df900dd7a8a5f9d286931a9c2a6 /src
parentfd1eabe72862ec364643a61cb94b21c330a385f5 (diff)
downloadvyos-1x-326e3cc41737ccaeb302db7b34e4adfcec261ccf.tar.gz
vyos-1x-326e3cc41737ccaeb302db7b34e4adfcec261ccf.zip
T778: harden dhcp_server.py for non existing files
Diffstat (limited to 'src')
-rwxr-xr-xsrc/conf_mode/dhcp_server.py13
1 files changed, 9 insertions, 4 deletions
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')