summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@baturin.org>2017-09-08 07:37:28 +0200
committerDaniil Baturin <daniil@baturin.org>2017-09-08 07:37:28 +0200
commit8a14d554c7de6fe0e238b55b9acf235a35714198 (patch)
tree6d44a05a23ec47112655d46748187af7e29052f3 /src
parent79f1f5a884fe7c24785ef9e6a0fb206d873663b7 (diff)
downloadvyos-1x-8a14d554c7de6fe0e238b55b9acf235a35714198.tar.gz
vyos-1x-8a14d554c7de6fe0e238b55b9acf235a35714198.zip
Separate VyOSError and ConfigError.
VyOSError is now only raised on improper config operations and internal errors, such as trying to use a function on a wrong kind of node. ConfigError should be used by scripts to indicate configuration mistakes and error conditions.
Diffstat (limited to 'src')
-rwxr-xr-xsrc/conf-mode/vyos-update-crontab.py21
1 files changed, 11 insertions, 10 deletions
diff --git a/src/conf-mode/vyos-update-crontab.py b/src/conf-mode/vyos-update-crontab.py
index ac6ae96d3..2d15de8ea 100755
--- a/src/conf-mode/vyos-update-crontab.py
+++ b/src/conf-mode/vyos-update-crontab.py
@@ -20,7 +20,8 @@ import os
import re
import sys
-from vyos.config import VyOSError, Config
+from vyos.config import Config
+from vyos.util import ConfigError
crontab_file = "/etc/cron.d/vyos-crontab"
@@ -75,34 +76,34 @@ def get_config():
def verify(tasks):
for task in tasks:
if not task["interval"] and not task["spec"]:
- raise VyOSError("Invalid task {0}: must define either interval or crontab-spec".format(task["name"]))
+ raise ConfigError("Invalid task {0}: must define either interval or crontab-spec".format(task["name"]))
if task["interval"]:
if task["spec"]:
- raise VyOSError("Invalid task {0}: cannot use interval and crontab-spec at the same time".format(task["name"]))
+ raise ConfigError("Invalid task {0}: cannot use interval and crontab-spec at the same time".format(task["name"]))
if not re.match(r"^\d+[mdh]?$", task["interval"]):
- raise(VyOSError("Invalid interval {0} in task {1}: interval should be a number optionally followed by m, h, or d".format(task["name"], task["interval"])))
+ raise(ConfigError("Invalid interval {0} in task {1}: interval should be a number optionally followed by m, h, or d".format(task["name"], task["interval"])))
else:
# Check if values are within allowed range
value, suffix = split_interval(task["interval"])
if not suffix or suffix == "m":
if value > 60:
- raise VyOSError("Invalid task {0}: interval in minutes must not exceed 60".format(task["name"]))
+ raise ConfigError("Invalid task {0}: interval in minutes must not exceed 60".format(task["name"]))
elif suffix == "h":
if value > 24:
- raise VyOSError("Invalid task {0}: interval in hours must not exceed 24".format(task["name"]))
+ raise ConfigError("Invalid task {0}: interval in hours must not exceed 24".format(task["name"]))
elif suffix == "d":
if value > 31:
- raise VyOSError("Invalid task {0}: interval in days must not exceed 31".format(task["name"]))
+ raise ConfigError("Invalid task {0}: interval in days must not exceed 31".format(task["name"]))
if not task["executable"]:
- raise VyOSError("Invalid task {0}: executable is not defined".format(task["name"]))
+ raise ConfigError("Invalid task {0}: executable is not defined".format(task["name"]))
else:
# Check if executable exists and is executable
if not (os.path.isfile(task["executable"]) and os.access(task["executable"], os.X_OK)):
- raise VyOSError("Invalid task {0}: file {1} does not exist or is not executable".format(task["name"], task["executable"]))
+ raise ConfigError("Invalid task {0}: file {1} does not exist or is not executable".format(task["name"], task["executable"]))
def generate(tasks):
crontab_header = "### Generated by vyos-update-crontab.py ###\n"
@@ -142,6 +143,6 @@ if __name__ == '__main__':
verify(c)
generate(c)
apply(c)
- except VyOSError as e:
+ except ConfigError as e:
print(e)
sys.exit(1)