From 5037ab577ab2744035160b2d506ab5b0e7524818 Mon Sep 17 00:00:00 2001 From: Cyril Roelandt Date: Tue, 29 Jan 2019 03:28:26 +0100 Subject: [PATCH] Python3: fix test/unit/obj/test_replicator.py Change-Id: Ib494a974ac41f4c23c7a1125470d532c36d6f7c6 --- swift/obj/replicator.py | 6 ++--- test/unit/obj/test_replicator.py | 42 ++++++++++++++++---------------- tox.ini | 1 + 3 files changed, 25 insertions(+), 24 deletions(-) diff --git a/swift/obj/replicator.py b/swift/obj/replicator.py index 9dc7c925e2..81cb531e63 100644 --- a/swift/obj/replicator.py +++ b/swift/obj/replicator.py @@ -90,13 +90,13 @@ class Stats(object): total.suffix_hash = self.suffix_hash + other.suffix_hash total.suffix_sync = self.suffix_sync + other.suffix_sync - all_failed_ips = (set(self.failure_nodes.keys() + - other.failure_nodes.keys())) + all_failed_ips = (set(list(self.failure_nodes.keys()) + + list(other.failure_nodes.keys()))) for ip in all_failed_ips: self_devs = self.failure_nodes.get(ip, {}) other_devs = other.failure_nodes.get(ip, {}) this_ip_failures = {} - for dev in set(self_devs.keys() + other_devs.keys()): + for dev in set(list(self_devs.keys()) + list(other_devs.keys())): this_ip_failures[dev] = ( self_devs.get(dev, 0) + other_devs.get(dev, 0)) total.failure_nodes[ip] = this_ip_failures diff --git a/test/unit/obj/test_replicator.py b/test/unit/obj/test_replicator.py index acc664aab3..781a3de177 100644 --- a/test/unit/obj/test_replicator.py +++ b/test/unit/obj/test_replicator.py @@ -344,7 +344,7 @@ class TestObjectReplicator(unittest.TestCase): f = open(os.path.join(df._datadir, normalize_timestamp(time.time()) + '.data'), 'wb') - f.write('1234567890') + f.write(b'1234567890') f.close() ohash = hash_path('a', 'c', 'o') data_dir = ohash[-3:] @@ -408,7 +408,7 @@ class TestObjectReplicator(unittest.TestCase): f = open(os.path.join(df._datadir, normalize_timestamp(time.time()) + '.data'), 'wb') - f.write('1234567890') + f.write(b'1234567890') f.close() ohash = hash_path('a', 'c', 'o') data_dir = ohash[-3:] @@ -842,7 +842,7 @@ class TestObjectReplicator(unittest.TestCase): ts = next(self.ts) df = self.df_mgr.get_diskfile('sda', '0', 'a', 'c', 'o', policy) with df.create() as w: - w.write('asdf') + w.write(b'asdf') w.put({'X-Timestamp': ts.internal}) w.commit(ts) expected_suffix_paths.append(os.path.dirname(df._datadir)) @@ -850,7 +850,7 @@ class TestObjectReplicator(unittest.TestCase): ts = next(self.ts) df = self.df_mgr.get_diskfile('sda', '1', 'a', 'c', 'o', policy) with df.create() as w: - w.write('asdf') + w.write(b'asdf') w.put({'X-Timestamp': ts.internal}) w.commit(ts) expected_suffix_paths.append(os.path.dirname(df._datadir)) @@ -925,7 +925,7 @@ class TestObjectReplicator(unittest.TestCase): ts = next(self.ts) df = self.df_mgr.get_diskfile('sda', '1', 'a', 'c', 'o', policy) with df.create() as w: - w.write('asdf') + w.write(b'asdf') w.put({'X-Timestamp': ts.internal}) w.commit(ts) handoff_suffix_paths.append(os.path.dirname(df._datadir)) @@ -1043,7 +1043,7 @@ class TestObjectReplicator(unittest.TestCase): policy=POLICIES.legacy) ts = next(self.ts) with df.create() as w: - w.write('asdf') + w.write(b'asdf') w.put({'X-Timestamp': ts.internal}) w.commit(ts) # pre-flight and post sync request for both other primaries @@ -1125,7 +1125,7 @@ class TestObjectReplicator(unittest.TestCase): f = open(os.path.join(df._datadir, normalize_timestamp(time.time()) + '.data'), 'wb') - f.write('1234567890') + f.write(b'1234567890') f.close() ohash = hash_path('a', 'c', 'o') data_dir = ohash[-3:] @@ -1155,7 +1155,7 @@ class TestObjectReplicator(unittest.TestCase): f = open(os.path.join(df._datadir, normalize_timestamp(time.time()) + '.data'), 'wb') - f.write('1234567890') + f.write(b'1234567890') f.close() ohash = hash_path('a', 'c', 'o') data_dir = ohash[-3:] @@ -1206,7 +1206,7 @@ class TestObjectReplicator(unittest.TestCase): ts = normalize_timestamp(time.time()) f = open(os.path.join(df._datadir, ts + '.data'), 'wb') - f.write('1234567890') + f.write(b'1234567890') f.close() ohash = hash_path('a', 'c', 'o') whole_path_from = storage_directory(self.objects, 1, ohash) @@ -1232,7 +1232,7 @@ class TestObjectReplicator(unittest.TestCase): f = open(os.path.join(df._datadir, normalize_timestamp(time.time()) + '.data'), 'wb') - f.write('1234567890') + f.write(b'1234567890') f.close() ohash = hash_path('a', 'c', 'o') data_dir = ohash[-3:] @@ -1261,7 +1261,7 @@ class TestObjectReplicator(unittest.TestCase): f = open(os.path.join(df._datadir, normalize_timestamp(time.time()) + '.data'), 'wb') - f.write('1234567890') + f.write(b'1234567890') f.close() ohash = hash_path('a', 'c', 'o') data_dir = ohash[-3:] @@ -1297,7 +1297,7 @@ class TestObjectReplicator(unittest.TestCase): f = open(os.path.join(df._datadir, normalize_timestamp(time.time()) + '.data'), 'wb') - f.write('1234567890') + f.write(b'1234567890') f.close() ohash = hash_path('a', 'c', 'o') data_dir = ohash[-3:] @@ -1332,7 +1332,7 @@ class TestObjectReplicator(unittest.TestCase): f = open(os.path.join(df._datadir, normalize_timestamp(time.time()) + '.data'), 'wb') - f.write('1234567890') + f.write(b'1234567890') f.close() ohash = hash_path('a', 'c', 'o') data_dir = ohash[-3:] @@ -1367,7 +1367,7 @@ class TestObjectReplicator(unittest.TestCase): f = open(os.path.join(df._datadir, normalize_timestamp(time.time()) + '.data'), 'wb') - f.write('1234567890') + f.write(b'1234567890') f.close() ohash = hash_path('a', 'c', 'o') data_dir = ohash[-3:] @@ -1443,7 +1443,7 @@ class TestObjectReplicator(unittest.TestCase): ts = normalize_timestamp(time.time()) f = open(os.path.join(df._datadir, ts + '.data'), 'wb') - f.write('0') + f.write(b'0') f.close() ohash = hash_path('a', 'c', 'o') whole_path_from = storage_directory(self.objects, 1, ohash) @@ -1491,7 +1491,7 @@ class TestObjectReplicator(unittest.TestCase): ts = normalize_timestamp(time.time()) mkdirs(df._datadir) f = open(os.path.join(df._datadir, ts + '.data'), 'wb') - f.write('0') + f.write(b'0') f.close() ohash = hash_path('a', 'c', 'o') whole_path_from = storage_directory(self.objects, 1, ohash) @@ -1539,7 +1539,7 @@ class TestObjectReplicator(unittest.TestCase): mkdirs(df._datadir) ts = normalize_timestamp(time.time()) f = open(os.path.join(df._datadir, ts + '.data'), 'wb') - f.write('0') + f.write(b'0') f.close() ohash = hash_path('a', 'c', 'o') whole_path_from = storage_directory(self.objects, 1, ohash) @@ -1580,7 +1580,7 @@ class TestObjectReplicator(unittest.TestCase): mkdirs(df._datadir) ts = normalize_timestamp(time.time()) f = open(os.path.join(df._datadir, ts + '.data'), 'wb') - f.write('0') + f.write(b'0') f.close() ohash = hash_path('a', 'c', 'o') whole_path_from = storage_directory(self.objects, 1, ohash) @@ -1681,7 +1681,7 @@ class TestObjectReplicator(unittest.TestCase): f = open(os.path.join(df._datadir, normalize_timestamp(time.time()) + '.data'), 'wb') - f.write('1234567890') + f.write(b'1234567890') f.close() ohash = hash_path('a', 'c', 'o') data_dir = ohash[-3:] @@ -2070,7 +2070,7 @@ class TestObjectReplicator(unittest.TestCase): f = open(os.path.join(df._datadir, normalize_timestamp(time.time()) + '.data'), 'wb') - f.write('1234567890') + f.write(b'1234567890') f.close() mock_procs = [] @@ -2106,7 +2106,7 @@ class TestObjectReplicator(unittest.TestCase): f = open(os.path.join(df._datadir, normalize_timestamp(time.time()) + '.data'), 'wb') - f.write('1234567890') + f.write(b'1234567890') f.close() mock_procs = [] diff --git a/tox.ini b/tox.ini index 7cebc03537..a6cd6e8dbc 100644 --- a/tox.ini +++ b/tox.ini @@ -85,6 +85,7 @@ commands = test/unit/container/test_auditor.py \ test/unit/container/test_replicator.py \ test/unit/container/test_sync_store.py \ + test/unit/obj/test_replicator.py \ test/unit/obj/test_server.py \ test/unit/proxy/controllers/test_info.py}