Ejegg has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/346922 )

Change subject: Add text to assertions
......................................................................

Add text to assertions

Change-Id: I0352db2bcfab288e394954a823456c04e1b3c42a
---
M processcontrol/config.py
M processcontrol/job_spec.py
M processcontrol/output_streamer.py
M processcontrol/runner.py
4 files changed, 23 insertions(+), 17 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/process-control 
refs/changes/22/346922/1

diff --git a/processcontrol/config.py b/processcontrol/config.py
index 9934806..862e083 100644
--- a/processcontrol/config.py
+++ b/processcontrol/config.py
@@ -84,7 +84,7 @@
 class MissingKeyException(Exception):
 
     def __init__(self, path):
-        message = "Missing configuration key '" + path + "'"
+        message = "Missing configuration key '{path}'".format(path=path)
         super(MissingKeyException, self).__init__(message)
 
 
@@ -108,12 +108,16 @@
         self.validate_global_config()
 
     def validate_global_config(self):
-        assert "cron_template" in self.values
-        assert "job_directory" in self.values
-        assert "output_crontab" in self.values
-        assert "output_directory" in self.values
-        assert "runner_path" in self.values
-        assert "user" in self.values
+        required_settings = (
+            "cron_template",
+            "job_directory",
+            "output_crontab",
+            "output_directory",
+            "runner_path",
+            "user",
+        )
+        for setting in required_settings:
+            assert setting in self.values, "Global config invalid: missing 
required '{setting}'".format(setting=setting)
 
 
 class JobConfiguration(Configuration):
@@ -132,19 +136,19 @@
         self.validate_job_config()
 
     def validate_job_config(self):
-        assert "name" in self.values
+        assert "name" in self.values, "Job config invalid: missing required 
'name'"
 
-        assert "command" in self.values
-        assert "\n" not in self.values["command"]
+        assert "command" in self.values, "Job config invalid: missing required 
'command'"
+        assert "\n" not in self.values["command"], "Job config invalid: 
'command' may not contain newlines"
 
         if "schedule" in self.values:
             # No tricky assignments.
-            assert "=" not in self.values["schedule"]
+            assert "=" not in self.values["schedule"], "Job config invalid: 
'schedule' may not contain the '=' character"
             # Legal cron, but I don't want to deal with it.
-            assert "@" not in self.values["schedule"]
+            assert "@" not in self.values["schedule"], "Job config invalid: 
'schedule' may not contain the '@' character"
             # No line breaks
-            assert "\n" not in self.values["schedule"]
+            assert "\n" not in self.values["schedule"], "Job config invalid: 
'schedule' may not contain newlines"
 
             # Be sure the schedule is valid.
             terms = self.values["schedule"].split()
-            assert len(terms) == 5
+            assert len(terms) == 5, "Job config invalid: 'schedule' must 
contain 5 values separated by whitespace"
diff --git a/processcontrol/job_spec.py b/processcontrol/job_spec.py
index 797a00e..93f095c 100644
--- a/processcontrol/job_spec.py
+++ b/processcontrol/job_spec.py
@@ -31,7 +31,9 @@
         self.config_path = job_path_for_slug(slug)
 
         # Validate that we're not allowing directory traversal.
-        assert os.path.dirname(os.path.realpath(self.config_path)) == 
os.path.abspath(self.global_config.get("job_directory"))
+        job_directory = 
os.path.abspath(self.global_config.get("job_directory"))
+        assert os.path.dirname(os.path.realpath(self.config_path)) == 
job_directory, \
+            "You may only run jobs with configuration files in 
'{path}'".format(path=job_directory)
 
         self.config = config.JobConfiguration(self.global_config, 
self.config_path)
 
diff --git a/processcontrol/output_streamer.py 
b/processcontrol/output_streamer.py
index 39e767b..8e6a5ac 100644
--- a/processcontrol/output_streamer.py
+++ b/processcontrol/output_streamer.py
@@ -12,7 +12,7 @@
     Makes the output file path and creates parent directory if needed
     """
     output_directory = config.GlobalConfiguration().get("output_directory")
-    assert os.access(output_directory, os.W_OK)
+    assert os.access(output_directory, os.W_OK), "Make sure directory '{path}' 
exists and is writable".format(path=output_directory)
 
     # per-job directory
     job_log_directory = output_directory + "/" + slug
diff --git a/processcontrol/runner.py b/processcontrol/runner.py
index d6a20fe..e4c3f45 100644
--- a/processcontrol/runner.py
+++ b/processcontrol/runner.py
@@ -28,7 +28,7 @@
             passwd_entry = pwd.getpwuid(int(service_user))
         else:
             passwd_entry = pwd.getpwnam(service_user)
-        assert passwd_entry.pw_uid == os.getuid()
+        assert passwd_entry.pw_uid == os.getuid(), "You must run jobs as user 
'{user}'".format(user=service_user)
 
         lock.begin(job_tag=self.job.slug)
         self.start_time = datetime.datetime.utcnow()

-- 
To view, visit https://gerrit.wikimedia.org/r/346922
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I0352db2bcfab288e394954a823456c04e1b3c42a
Gerrit-PatchSet: 1
Gerrit-Project: wikimedia/fundraising/process-control
Gerrit-Branch: master
Gerrit-Owner: Ejegg <eeggles...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to