r5476 - trunk/cumin/python/cumin/grid

tmckay at fedoraproject.org tmckay at fedoraproject.org
Wed Sep 26 19:02:13 UTC 2012


Author: tmckay
Date: 2012-09-26 19:02:12 +0000 (Wed, 26 Sep 2012)
New Revision: 5476

Modified:
   trunk/cumin/python/cumin/grid/job.py
Log:
Extra checks for edits on readonly job attributes
BZ837037


Modified: trunk/cumin/python/cumin/grid/job.py
===================================================================
--- trunk/cumin/python/cumin/grid/job.py	2012-09-26 12:06:17 UTC (rev 5475)
+++ trunk/cumin/python/cumin/grid/job.py	2012-09-26 19:02:12 UTC (rev 5476)
@@ -873,25 +873,15 @@
         
         self.update_enabled = False
 
-    def do_get_items(self, session):
-        ads = self.ads.get(session)
-
-        if len(ads):
-            # we just returned from a submit
-            # Don't think this code is ever called, since process_cancel
-            # below clears self.ads and is called at the end of process_submit.
-            # Never saw the debugger hit a breakpoint here... tmckay 7/22/2011
-            cls = self.app.model.job_meta_data
-            return [self.gen_item(x, ads[x]["value"], cls, path=self.ads.path,
-                                  dtype=ads[x]["type"], error=ads[x],
-                                  orig=ads[x]["orig"]) for x in ads]
-
+    def do_get_items(self, session, setpath=True):
         items, error = super(JobAdsEditor, self).do_get_items(session)
         if error:
             items = []
 
-        for item in items:
-            item["path"] = self.ads.path
+        # Avoid an extra pass if we don't need it
+        if setpath:
+            for item in items:
+                item["path"] = self.ads.path
         return items, error
 
     def process_cancel(self, session):
@@ -930,7 +920,7 @@
         ads = self.ads.get(session)
 
         just_ads = dict()
-        for field in ads:
+        for field in ads:            
             ads[field]["error"] = None
             try:
                 fval = ads[field]["value"]
@@ -990,6 +980,26 @@
                 if fval != orig:
                     just_ads[unicode(field)] = fval
 
+        # Use the full job add data to find out which 
+        # ads are writable.  This info is not available
+        # in the POST request data.
+        if just_ads:
+            items, error = self.do_get_items(session, setpath=False)
+            if error:
+                msg = (hasattr(error, "args") and \
+                           len(error.args) > 0 and error.args[0]) or ""
+                if not msg:
+                    msg = "Unable to get Job information at this time"
+                session.add_notice(Notice("Job edit failed: %s" % msg))
+                just_ads = []
+            else:    
+                writables = dict()
+                for item in items:
+                    n = item["name"]
+                    if n in just_ads:
+                        p = "property" in item and item["property"] or None
+                        writables[n] = not p or p.writable
+
         # Process all cases, including errors, becase we
         # want to see a banner for errors we detect.
         id = self.frame.id.get(session)
@@ -999,6 +1009,8 @@
 
         task = self.frame.set_ad_task
         for field in just_ads:
+            if not writables[field]:
+                ads[field]["error"] = "Attribute is not writable"
             task.invoke(session, scheduler, job_id, field, 
                         str(just_ads[field]), ads[field]["error"],
                         submission)



More information about the cumin-developers mailing list