Eduardo has uploaded a new change for review.

Change subject: Encode '=' in Task._dump().
......................................................................

Encode '=' in Task._dump().

"For a reason unknown (to me), task.py does not use pickle to
persist its data to file. We cannot fix that without breaking
backward-compatibility."
Danken, circa 2012.

Change-Id: I735d28974d3953aafaf4b5e5f1a25363d22b50c3
Signed-off-by: Eduardo <[email protected]>
---
M vdsm/storage/task.py
1 file changed, 17 insertions(+), 8 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/28/13128/1

diff --git a/vdsm/storage/task.py b/vdsm/storage/task.py
index cf32723..5f589aa 100644
--- a/vdsm/storage/task.py
+++ b/vdsm/storage/task.py
@@ -64,6 +64,7 @@
 getProcPool = oop.getGlobalProcPool
 
 KEY_SEPARATOR = "="
+KEY_SEPARATOR_ENCODED = "_eq_"
 TASK_EXT = ".task"
 JOB_EXT = ".job"
 RESOURCE_EXT = ".resource"
@@ -77,6 +78,14 @@
 TASK_METADATA_VERSION = 1
 
 ROLLBACK_SENTINEL = "rollback sentinel"
+
+
+def _eq_encode(s):
+    return s.replace(KEY_SEPARATOR, KEY_SEPARATOR_ENCODED)
+
+
+def _eq_decode(s):
+    return s.replace(KEY_SEPARATOR_ENCODED, KEY_SEPARATOR)
 
 
 class State:
@@ -605,8 +614,8 @@
                                     " '%s'", filename, line)
                     continue
 
-                field = parts[0].strip()
-                value = parts[1].strip()
+                field = _eq_decode(parts[0].strip())
+                value = _eq_decode(parts[1].strip())
                 if field not in fields:
                     cls.log.warning("Task._loadMetaFile: %s - ignoring field"
                                     " %s in line '%s'", filename, field, line)
@@ -624,13 +633,13 @@
         for field in fields:
             try:
                 value = unicode(getattr(obj, field))
-                if KEY_SEPARATOR in field or KEY_SEPARATOR in value:
-                    raise ValueError("field and value cannot include %s "
-                                     "character" % KEY_SEPARATOR)
-                lines.append("%s %s %s" % (field, KEY_SEPARATOR, value))
-            except Exception:
-                cls.log.warning("Task._dump: object %s skipping field %s" %
+            except AttributeError:
+                cls.log.warning("Task._dump: object %s field %s not found" %
                                 (obj, field), exc_info=True)
+            else:
+                field = _eq_encode(field)
+                value = _eq_encode(value)
+                lines.append("%s %s %s" % (field, KEY_SEPARATOR, value))
         return lines
 
     @classmethod


--
To view, visit http://gerrit.ovirt.org/13128
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I735d28974d3953aafaf4b5e5f1a25363d22b50c3
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Eduardo <[email protected]>
_______________________________________________
vdsm-patches mailing list
[email protected]
https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches

Reply via email to