]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
test/rgw: pass encoding to Key.get_content_as_string()
authorKefu Chai <kchai@redhat.com>
Mon, 6 Apr 2020 15:11:21 +0000 (23:11 +0800)
committerKefu Chai <kchai@redhat.com>
Wed, 3 Jun 2020 11:56:59 +0000 (19:56 +0800)
we assume that boto.Key.get_content_as_string() returns str instead of
bytes, and compare the return value with a string, so, to ensure that
lhs and rhs are both strings, we need to decode the returned content.

since we always store strings composed with ASCII, it's safe to use
'ascii' to decode them.

Signed-off-by: Kefu Chai <kchai@redhat.com>
(cherry picked from commit fcf4de3855f01e80b90d246529916a5915fe413d)

Conflicts:
src/test/rgw/rgw_multi/tests_az.py: trivial resolution

src/test/rgw/rgw_multi/tests.py
src/test/rgw/rgw_multi/zone_cloud.py

index 6c797e668183aab02a6278a686bae749af2c2dd8..01529c59d9d8b129ece8707757d73e53476ab0b5 100644 (file)
@@ -1011,14 +1011,14 @@ def test_multi_zone_redirect():
 
     key2 = bucket2.get_key(obj)
 
-    eq(data, key2.get_contents_as_string())
+    eq(data, key2.get_contents_as_string(encoding='ascii'))
 
     key = bucket.new_key(obj)
 
     for x in ['a', 'b', 'c', 'd']:
         data = x*512
         key.set_contents_from_string(data)
-        eq(data, key2.get_contents_as_string())
+        eq(data, key2.get_contents_as_string(encoding='ascii'))
 
     # revert config changes
     set_sync_from_all(z2, True)
@@ -1252,10 +1252,10 @@ def test_encrypted_object_sync():
     # read the encrypted objects from the second zone
     bucket2 = get_bucket(zone2, bucket_name)
     key = bucket2.get_key('testobj-sse-c', headers=sse_c_headers)
-    eq(data, key.get_contents_as_string(headers=sse_c_headers))
+    eq(data, key.get_contents_as_string(headers=sse_c_headers, encoding='ascii'))
 
     key = bucket2.get_key('testobj-sse-kms')
-    eq(data, key.get_contents_as_string())
+    eq(data, key.get_contents_as_string(encoding='ascii'))
 
 def test_bucket_index_log_trim():
     zonegroup = realm.master_zonegroup()
index e9dcc4b10ca5ea4a6edaa541500a545c640f34c3..43b1f76e0f3fc7ebfeff254c538eef6bbacacbce 100644 (file)
@@ -129,8 +129,8 @@ class CloudKey:
         self.content_language = k.content_language
 
 
-    def get_contents_as_string(self):
-        r = self.key.get_contents_as_string()
+    def get_contents_as_string(self, encoding=None):
+        r = self.key.get_contents_as_string(encoding=encoding)
 
         # the previous call changed the status of the source object, as it loaded
         # its metadata