Antoni Segura Puimedon has uploaded a new change for review.

Change subject: drv_name: Make drv_name support unicode types
......................................................................

drv_name: Make drv_name support unicode types

Our json serialization and de-serialization for both the hooks and
persistence add unicode text to the flows of our codebase.

Before we would only have "foo". Now we have as well u"foo".
In order to make it work in unicode we also need to provide for real
unicode characters u"トトロ".

Change-Id: Ic705eaaad22fb1ed56bca3363a3559ee1b13d63f
Signed-off-by: Antoni S. Puimedon <[email protected]>
---
M lib/vdsm/ipwrapper.py
M tests/ipwrapperTests.py
2 files changed, 8 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/71/35471/1

diff --git a/lib/vdsm/ipwrapper.py b/lib/vdsm/ipwrapper.py
index 89280e7..828d395 100644
--- a/lib/vdsm/ipwrapper.py
+++ b/lib/vdsm/ipwrapper.py
@@ -277,6 +277,7 @@
     """Returns the driver used by a device.
     Throws IOError ENODEV for non existing devices.
     Throws IOError EOPNOTSUPP for non supported devices, i.g., loopback."""
+    encoded_name = devName.encode('utf-8')
     ETHTOOL_GDRVINFO = 0x00000003  # ETHTOOL Get driver info command
     SIOCETHTOOL = 0x8946  # Ethtool interface
     DRVINFO_FORMAT = '= I 32s 32s 32s 32s 32s 12s 5I'
@@ -284,7 +285,7 @@
     buff = array.array('c', b'\0' * struct.calcsize(DRVINFO_FORMAT))
     cmd = struct.pack('= I', ETHTOOL_GDRVINFO)
     buff[0:len(cmd)] = array.array('c', cmd)
-    data = struct.pack(IFREQ_FORMAT, devName, *buff.buffer_info())
+    data = struct.pack(IFREQ_FORMAT, encode_name, *buff.buffer_info())
     with closing(socket.socket(socket.AF_INET, socket.SOCK_DGRAM)) as sock:
         fcntl.ioctl(sock, SIOCETHTOOL, data)
     (cmd, driver, version, fw_version, businfo, _, _, n_priv_flags, n_stats,
diff --git a/tests/ipwrapperTests.py b/tests/ipwrapperTests.py
index 89d6a0c..7dd43d5 100644
--- a/tests/ipwrapperTests.py
+++ b/tests/ipwrapperTests.py
@@ -191,18 +191,24 @@
 
 class TestDrvinfo(TestCaseBase):
     _bridge = tcTests._Bridge()
+    _unicode_bridge = tcTests._Bridge()
 
     @ValidateRunningAsRoot
     def setUp(self):
         tcTests._checkDependencies()
         self._bridge.addDevice()
+        self._unicode_bridge.devName = 'test-トトロ'
+        self._unicode_bridge.addDevice()
 
     def tearDown(self):
         self._bridge.delDevice()
+        self._unicode_bridge.delDevice()
 
     def testBridgeEthtoolDrvinfo(self):
         self.assertEqual(ipwrapper.drv_name(self._bridge.devName),
                          ipwrapper.LinkType.BRIDGE)
+        self.assertEqual(ipwrapper.drv_name(self._unicode_bridge.devName),
+                         ipwrapper.LinkType.BRIDGE)
 
     def testTogglePromisc(self):
         ipwrapper.getLink(self._bridge.devName).promisc = True


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

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

Reply via email to