]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
use encode('utf8') instead of str()
authorKun Huang <gareth@unitedstack.com>
Wed, 24 Jul 2013 16:19:56 +0000 (00:19 +0800)
committerKun Huang <gareth@unitedstack.com>
Wed, 24 Jul 2013 18:24:33 +0000 (02:24 +0800)
It is not clear for converting a unicode to string by using str().
Instead we should use var.encode('utf8') to do this.

Change-Id: I8ce4c98f819c98e835a6d8298fe22f2fd0ca18b6

cinder/backup/drivers/ceph.py

index d9c7341946d3cb8eb2344942a53ef7a987ab4ccf..c7d2c7b8e62bbdb27d68ef95220ee2a0ec7bc56f 100644 (file)
@@ -112,9 +112,11 @@ class CephBackupDriver(BackupDriver):
             self.rbd_stripe_count = 0
             self.rbd_stripe_unit = 0
 
-        self._ceph_backup_user = str(CONF.backup_ceph_user)
-        self._ceph_backup_pool = str(CONF.backup_ceph_pool)
-        self._ceph_backup_conf = str(CONF.backup_ceph_conf)
+        _utf8 = lambda s: s if isinstance(s, str) else s.encode('utf8')
+
+        self._ceph_backup_user = _utf8(CONF.backup_ceph_user)
+        self._ceph_backup_pool = _utf8(CONF.backup_ceph_pool)
+        self._ceph_backup_conf = _utf8(CONF.backup_ceph_conf)
 
     def _validate_string_args(self, *args):
         """Ensure all args are non-None and non-empty."""