Greg Padgett has uploaded a new change for review.

Change subject: agent, broker: use base64 library to encode/decode data
......................................................................

agent, broker: use base64 library to encode/decode data

This fixes an issue caused on systems with certain locales, and makes
the code much more straightforward in general.

Change-Id: I46c3593837ff2d0c51de58fca5b9680625424baf
Signed-off-by: Greg Padgett <[email protected]>
---
M ovirt_hosted_engine_ha/agent/brokerlink.py
M ovirt_hosted_engine_ha/broker/storage_broker.py
2 files changed, 6 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-hosted-engine-ha 
refs/changes/49/18049/1

diff --git a/ovirt_hosted_engine_ha/agent/brokerlink.py 
b/ovirt_hosted_engine_ha/agent/brokerlink.py
index e437693..025181d 100644
--- a/ovirt_hosted_engine_ha/agent/brokerlink.py
+++ b/ovirt_hosted_engine_ha/agent/brokerlink.py
@@ -17,6 +17,7 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 #
 
+import base64
 import logging
 import socket
 
@@ -95,7 +96,7 @@
         """
         self._log.info("Storing blocks on storage at %s", storage_dir)
         # broker expects blocks in hex format
-        hex_data = ''.join("{0:02X}".format(ord(x)) for x in data)
+        hex_data = base64.b16encode(data)
         request = ("put-stats"
                    " storage_dir={0} service_type={1} host={2} data={3}"
                    .format(storage_dir, service_type, host, hex_data))
@@ -115,7 +116,7 @@
         # broker returns "<host 1>=<hex data 1> [<host 2>=...]"
         while tokens:
             (host, data) = tokens.pop(0).split('=', 1)
-            ret[host] = bytearray.fromhex(data)
+            ret[host] = base64.b16decode(data)
         return ret
 
     def _checked_communicate(self, request):
diff --git a/ovirt_hosted_engine_ha/broker/storage_broker.py 
b/ovirt_hosted_engine_ha/broker/storage_broker.py
index 7a7845c..7a93ab5 100644
--- a/ovirt_hosted_engine_ha/broker/storage_broker.py
+++ b/ovirt_hosted_engine_ha/broker/storage_broker.py
@@ -17,6 +17,7 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 #
 
+import base64
 import errno
 import io
 import logging
@@ -73,7 +74,7 @@
                     if f_obj:
                         f_obj.close()
 
-                hex_data = ''.join("{0:02X}".format(ord(x)) for x in data)
+                hex_data = base64.b16encode(data)
                 self._log.debug("Read for host %s: %s", host, hex_data)
                 str_list.append("{0}={1}".format(host, hex_data))
 
@@ -89,7 +90,7 @@
         self._log.info("Writing stats for service %s, host %s to file %s",
                        service_type, host, path)
 
-        byte_data = bytearray.fromhex(data)
+        byte_data = base64.b16decode(data)
         with self._storage_access_lock:
             f_obj = None
             try:


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I46c3593837ff2d0c51de58fca5b9680625424baf
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-hosted-engine-ha
Gerrit-Branch: master
Gerrit-Owner: Greg Padgett <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to