Browse Source

Merge "py3: (mostly) port probe tests"

tags/2.23.0
Zuul 1 month ago
parent
commit
5cb53838a6

+ 9
- 9
test/probe/common.py View File

@@ -164,7 +164,7 @@ def add_ring_devs_to_ipport2server(ring, server_type, ipport2server,
164 164
     # We'll number the servers by order of unique occurrence of:
165 165
     #   IP, if servers_per_port > 0 OR there > 1 IP in ring
166 166
     #   ipport, otherwise
167
-    unique_ip_count = len(set(dev['ip'] for dev in ring.devs if dev))
167
+    unique_ip_count = len({dev['ip'] for dev in ring.devs if dev})
168 168
     things_to_number = {}
169 169
     number = 0
170 170
     for dev in filter(None, ring.devs):
@@ -244,7 +244,7 @@ def get_ring(ring_name, required_replicas, required_devices,
244 244
         if p.returncode:
245 245
             raise unittest.SkipTest('unable to connect to rsync '
246 246
                                     'export %s (%s)' % (rsync_export, cmd))
247
-        for line in stdout.splitlines():
247
+        for line in stdout.decode().splitlines():
248 248
             if line.rsplit(None, 1)[-1] == dev['device']:
249 249
                 break
250 250
         else:
@@ -295,11 +295,11 @@ def kill_orphans():
295 295
 class Body(object):
296 296
 
297 297
     def __init__(self, total=3.5 * 2 ** 20):
298
-        self.length = total
298
+        self.length = int(total)
299 299
         self.hasher = md5()
300 300
         self.read_amount = 0
301
-        self.chunk = uuid4().hex * 2 ** 10
302
-        self.buff = ''
301
+        self.chunk = uuid4().hex.encode('ascii') * 2 ** 10
302
+        self.buff = b''
303 303
 
304 304
     @property
305 305
     def etag(self):
@@ -320,9 +320,9 @@ class Body(object):
320 320
     def __iter__(self):
321 321
         return self
322 322
 
323
-    def next(self):
323
+    def __next__(self):
324 324
         if self.buff:
325
-            rv, self.buff = self.buff, ''
325
+            rv, self.buff = self.buff, b''
326 326
             return rv
327 327
         if self.read_amount >= self.length:
328 328
             raise StopIteration()
@@ -331,8 +331,8 @@ class Body(object):
331 331
         self.hasher.update(rv)
332 332
         return rv
333 333
 
334
-    def __next__(self):
335
-        return next(self)
334
+    # for py2 compat:
335
+    next = __next__
336 336
 
337 337
 
338 338
 class ProbeTest(unittest.TestCase):

+ 3
- 3
test/probe/test_account_get_fake_responses_match.py View File

@@ -56,7 +56,7 @@ class TestAccountGetFakeResponsesMatch(ReplProbeTest):
56 56
             raise Exception("Unexpected status %s\n%s" %
57 57
                             (resp.status, resp.read()))
58 58
 
59
-        response_headers = dict(resp.getheaders())
59
+        response_headers = {h.lower(): v for h, v in resp.getheaders()}
60 60
         response_body = resp.read()
61 61
         resp.close()
62 62
         return response_headers, response_body
@@ -98,8 +98,8 @@ class TestAccountGetFakeResponsesMatch(ReplProbeTest):
98 98
             fake_acct, headers={'Accept': 'application/xml'})
99 99
 
100 100
         # the account name is in the XML response
101
-        real_body = re.sub('AUTH_\w{4}', 'AUTH_someaccount', real_body)
102
-        fake_body = re.sub('AUTH_\w{4}', 'AUTH_someaccount', fake_body)
101
+        real_body = re.sub(br'AUTH_\w{4}', b'AUTH_someaccount', real_body)
102
+        fake_body = re.sub(br'AUTH_\w{4}', b'AUTH_someaccount', fake_body)
103 103
 
104 104
         self.assertEqual(real_body, fake_body)
105 105
         self.assertEqual(real_headers['content-type'],

+ 1
- 1
test/probe/test_container_failures.py View File

@@ -130,7 +130,7 @@ class TestContainerFailures(ReplProbeTest):
130 130
         onode = onodes[0]
131 131
         db_files = []
132 132
         for onode in onodes:
133
-            node_id = (onode['port'] - 6000) / 10
133
+            node_id = (onode['port'] - 6000) // 10
134 134
             device = onode['device']
135 135
             hash_str = hash_path(self.account, container)
136 136
             server_conf = readconf(self.configs['container-server'][node_id])

+ 30
- 29
test/probe/test_container_merge_policy_index.py View File

@@ -68,7 +68,7 @@ class TestContainerMergePolicyIndex(ReplProbeTest):
68 68
         self.brain.stop_handoff_half()
69 69
         self.brain.put_container()
70 70
         self.brain.put_object(headers={'x-object-meta-test': 'custom-meta'},
71
-                              contents='VERIFY')
71
+                              contents=b'VERIFY')
72 72
         self.brain.start_handoff_half()
73 73
         # make sure we have some manner of split brain
74 74
         container_part, container_nodes = self.container_ring.get_nodes(
@@ -78,9 +78,9 @@ class TestContainerMergePolicyIndex(ReplProbeTest):
78 78
             metadata = direct_client.direct_head_container(
79 79
                 node, container_part, self.account, self.container_name)
80 80
             head_responses.append((node, metadata))
81
-        found_policy_indexes = \
82
-            set(metadata['X-Backend-Storage-Policy-Index'] for
83
-                node, metadata in head_responses)
81
+        found_policy_indexes = {
82
+            metadata['X-Backend-Storage-Policy-Index']
83
+            for node, metadata in head_responses}
84 84
         self.assertGreater(
85 85
             len(found_policy_indexes), 1,
86 86
             'primary nodes did not disagree about policy index %r' %
@@ -116,9 +116,9 @@ class TestContainerMergePolicyIndex(ReplProbeTest):
116 116
             metadata = direct_client.direct_head_container(
117 117
                 node, container_part, self.account, self.container_name)
118 118
             head_responses.append((node, metadata))
119
-        found_policy_indexes = \
120
-            set(metadata['X-Backend-Storage-Policy-Index'] for
121
-                node, metadata in head_responses)
119
+        found_policy_indexes = {
120
+            metadata['X-Backend-Storage-Policy-Index']
121
+            for node, metadata in head_responses}
122 122
         self.assertEqual(len(found_policy_indexes), 1,
123 123
                          'primary nodes disagree about policy index %r' %
124 124
                          head_responses)
@@ -144,7 +144,7 @@ class TestContainerMergePolicyIndex(ReplProbeTest):
144 144
                     orig_policy_index))
145 145
         # verify that the object data read by external client is correct
146 146
         headers, data = self._get_object_patiently(expected_policy_index)
147
-        self.assertEqual('VERIFY', data)
147
+        self.assertEqual(b'VERIFY', data)
148 148
         self.assertEqual('custom-meta', headers['x-object-meta-test'])
149 149
 
150 150
     def test_reconcile_delete(self):
@@ -165,9 +165,9 @@ class TestContainerMergePolicyIndex(ReplProbeTest):
165 165
             metadata = direct_client.direct_head_container(
166 166
                 node, container_part, self.account, self.container_name)
167 167
             head_responses.append((node, metadata))
168
-        found_policy_indexes = \
169
-            set(metadata['X-Backend-Storage-Policy-Index'] for
170
-                node, metadata in head_responses)
168
+        found_policy_indexes = {
169
+            metadata['X-Backend-Storage-Policy-Index']
170
+            for node, metadata in head_responses}
171 171
         self.assertGreater(
172 172
             len(found_policy_indexes), 1,
173 173
             'primary nodes did not disagree about policy index %r' %
@@ -208,15 +208,14 @@ class TestContainerMergePolicyIndex(ReplProbeTest):
208 208
             metadata = direct_client.direct_head_container(
209 209
                 node, container_part, self.account, self.container_name)
210 210
             head_responses.append((node, metadata))
211
-        new_found_policy_indexes = \
212
-            set(metadata['X-Backend-Storage-Policy-Index'] for node,
213
-                metadata in head_responses)
214
-        self.assertEqual(len(new_found_policy_indexes), 1,
211
+        node_to_policy = {
212
+            node['port']: metadata['X-Backend-Storage-Policy-Index']
213
+            for node, metadata in head_responses}
214
+        policies = set(node_to_policy.values())
215
+        self.assertEqual(len(policies), 1,
215 216
                          'primary nodes disagree about policy index %r' %
216
-                         dict((node['port'],
217
-                               metadata['X-Backend-Storage-Policy-Index'])
218
-                              for node, metadata in head_responses))
219
-        expected_policy_index = new_found_policy_indexes.pop()
217
+                         node_to_policy)
218
+        expected_policy_index = policies.pop()
220 219
         self.assertEqual(orig_policy_index, expected_policy_index)
221 220
         # validate object fully deleted
222 221
         for policy_index in found_policy_indexes:
@@ -257,7 +256,7 @@ class TestContainerMergePolicyIndex(ReplProbeTest):
257 256
         manifest_data = []
258 257
 
259 258
         def write_part(i):
260
-            body = 'VERIFY%0.2d' % i + '\x00' * 1048576
259
+            body = b'VERIFY%0.2d' % i + b'\x00' * 1048576
261 260
             part_name = 'manifest_part_%0.2d' % i
262 261
             manifest_entry = {
263 262
                 "path": "/%s/%s" % (self.container_name, part_name),
@@ -310,7 +309,8 @@ class TestContainerMergePolicyIndex(ReplProbeTest):
310 309
                 'bytes': data['size_bytes'],
311 310
                 'name': data['path'],
312 311
             }
313
-        direct_manifest_data = map(translate_direct, manifest_data)
312
+        direct_manifest_data = [translate_direct(item)
313
+                                for item in manifest_data]
314 314
         headers = {
315 315
             'x-container-host': ','.join('%s:%s' % (n['ip'], n['port']) for n
316 316
                                          in self.container_ring.devs),
@@ -320,11 +320,12 @@ class TestContainerMergePolicyIndex(ReplProbeTest):
320 320
             'X-Backend-Storage-Policy-Index': wrong_policy.idx,
321 321
             'X-Static-Large-Object': 'True',
322 322
         }
323
+        body = utils.json.dumps(direct_manifest_data).encode('ascii')
323 324
         for node in nodes:
324 325
             direct_client.direct_put_object(
325 326
                 node, part, self.account, self.container_name,
326 327
                 direct_manifest_name,
327
-                contents=utils.json.dumps(direct_manifest_data),
328
+                contents=body,
328 329
                 headers=headers)
329 330
             break  # one should do it...
330 331
 
@@ -347,8 +348,8 @@ class TestContainerMergePolicyIndex(ReplProbeTest):
347 348
         self.assertEqual(metadata['x-static-large-object'].lower(), 'true')
348 349
         self.assertEqual(int(metadata['content-length']),
349 350
                          sum(part['size_bytes'] for part in manifest_data))
350
-        self.assertEqual(body, ''.join('VERIFY%0.2d' % i + '\x00' * 1048576
351
-                                       for i in range(20)))
351
+        self.assertEqual(body, b''.join(b'VERIFY%0.2d' % i + b'\x00' * 1048576
352
+                                        for i in range(20)))
352 353
 
353 354
         # and regular upload should work now too
354 355
         client.put_object(self.url, self.token, self.container_name,
@@ -375,7 +376,7 @@ class TestContainerMergePolicyIndex(ReplProbeTest):
375 376
         self.brain.start_primary_half()
376 377
         # write some target data
377 378
         client.put_object(self.url, self.token, self.container_name, 'target',
378
-                          contents='this is the target data')
379
+                          contents=b'this is the target data')
379 380
 
380 381
         # write the symlink
381 382
         self.brain.stop_handoff_half()
@@ -401,7 +402,7 @@ class TestContainerMergePolicyIndex(ReplProbeTest):
401 402
         self.assertEqual(metadata['x-symlink-target'],
402 403
                          '%s/target' % self.container_name)
403 404
         self.assertEqual(metadata['content-type'], 'application/symlink')
404
-        self.assertEqual(body, '')
405
+        self.assertEqual(body, b'')
405 406
         # ... although in the wrong policy
406 407
         object_ring = POLICIES.get_object_ring(int(wrong_policy), '/etc/swift')
407 408
         part, nodes = object_ring.get_nodes(
@@ -423,7 +424,7 @@ class TestContainerMergePolicyIndex(ReplProbeTest):
423 424
         # now the symlink works
424 425
         metadata, body = client.get_object(self.url, self.token,
425 426
                                            self.container_name, 'symlink')
426
-        self.assertEqual(body, 'this is the target data')
427
+        self.assertEqual(body, b'this is the target data')
427 428
         # and it's in the correct policy
428 429
         object_ring = POLICIES.get_object_ring(int(policy), '/etc/swift')
429 430
         part, nodes = object_ring.get_nodes(
@@ -469,7 +470,7 @@ class TestContainerMergePolicyIndex(ReplProbeTest):
469 470
 
470 471
         # hopefully memcache still has the new policy cached
471 472
         self.brain.put_object(headers={'x-object-meta-test': 'custom-meta'},
472
-                              contents='VERIFY')
473
+                              contents=b'VERIFY')
473 474
         # double-check object correctly written to new policy
474 475
         conf_files = []
475 476
         for server in Manager(['container-reconciler']).servers:
@@ -546,7 +547,7 @@ class TestContainerMergePolicyIndex(ReplProbeTest):
546 547
 
547 548
         # verify that the object data read by external client is correct
548 549
         headers, data = self._get_object_patiently(int(new_policy))
549
-        self.assertEqual('VERIFY', data)
550
+        self.assertEqual(b'VERIFY', data)
550 551
         self.assertEqual('custom-meta', headers['x-object-meta-test'])
551 552
 
552 553
 

+ 14
- 14
test/probe/test_container_sync.py View File

@@ -113,7 +113,7 @@ class TestContainerSync(BaseTestContainerSync):
113 113
 
114 114
         resp_headers, body = client.get_object(self.url, self.token,
115 115
                                                dest_container, object_name)
116
-        self.assertEqual(body, 'test-body')
116
+        self.assertEqual(body, b'test-body')
117 117
         self.assertIn('x-object-meta-test', resp_headers)
118 118
         self.assertEqual('put_value', resp_headers['x-object-meta-test'])
119 119
 
@@ -136,7 +136,7 @@ class TestContainerSync(BaseTestContainerSync):
136 136
         # verify that metadata changes were sync'd
137 137
         resp_headers, body = client.get_object(self.url, self.token,
138 138
                                                dest_container, object_name)
139
-        self.assertEqual(body, 'test-body')
139
+        self.assertEqual(body, b'test-body')
140 140
         self.assertIn('x-object-meta-test', resp_headers)
141 141
         self.assertEqual('post_value', resp_headers['x-object-meta-test'])
142 142
         self.assertEqual('image/jpeg', resp_headers['content-type'])
@@ -180,7 +180,7 @@ class TestContainerSync(BaseTestContainerSync):
180 180
 
181 181
         # upload a segment to source
182 182
         segment_name = 'segment-%s' % uuid.uuid4()
183
-        segment_data = 'segment body'  # it's ok for first segment to be small
183
+        segment_data = b'segment body'  # it's ok for first segment to be small
184 184
         segment_etag = client.put_object(
185 185
             self.url, self.token, segs_container, segment_name,
186 186
             segment_data)
@@ -270,7 +270,7 @@ class TestContainerSync(BaseTestContainerSync):
270 270
         Manager(['container-sync']).once()
271 271
         _junk, body = client.get_object(self.url, self.token,
272 272
                                         dest_container, object_name)
273
-        self.assertEqual(body, 'test-body')
273
+        self.assertEqual(body, b'test-body')
274 274
 
275 275
     def test_sync_lazy_dkey(self):
276 276
         # Create synced containers, but with no key at dest
@@ -297,7 +297,7 @@ class TestContainerSync(BaseTestContainerSync):
297 297
         Manager(['container-sync']).once()
298 298
         _junk, body = client.get_object(self.url, self.token,
299 299
                                         dest_container, object_name)
300
-        self.assertEqual(body, 'test-body')
300
+        self.assertEqual(body, b'test-body')
301 301
 
302 302
     def test_sync_with_stale_container_rows(self):
303 303
         source_container, dest_container = self._setup_synced_containers()
@@ -351,7 +351,7 @@ class TestContainerSync(BaseTestContainerSync):
351 351
         # verify sync'd object has same content and headers
352 352
         dest_headers, body = client.get_object(self.url, self.token,
353 353
                                                dest_container, object_name)
354
-        self.assertEqual(body, 'new-test-body')
354
+        self.assertEqual(body, b'new-test-body')
355 355
         mismatched_headers = []
356 356
         for k in ('etag', 'content-length', 'content-type', 'x-timestamp',
357 357
                   'last-modified'):
@@ -381,7 +381,7 @@ class TestContainerSync(BaseTestContainerSync):
381 381
         # verify that the remote object did not change
382 382
         resp_headers, body = client.get_object(self.url, self.token,
383 383
                                                dest_container, object_name)
384
-        self.assertEqual(body, 'new-test-body')
384
+        self.assertEqual(body, b'new-test-body')
385 385
 
386 386
 
387 387
 class TestContainerSyncAndSymlink(BaseTestContainerSync):
@@ -413,7 +413,7 @@ class TestContainerSyncAndSymlink(BaseTestContainerSync):
413 413
 
414 414
         # upload a target to source
415 415
         target_name = 'target-%s' % uuid.uuid4()
416
-        target_body = 'target body'
416
+        target_body = b'target body'
417 417
         client.put_object(
418 418
             self.url, self.token, tgt_container, target_name,
419 419
             target_body)
@@ -432,7 +432,7 @@ class TestContainerSyncAndSymlink(BaseTestContainerSync):
432 432
         resp_headers, symlink_body = client.get_object(
433 433
             self.url, self.token, source_container, symlink_name,
434 434
             query_string='symlink=get')
435
-        self.assertEqual('', symlink_body)
435
+        self.assertEqual(b'', symlink_body)
436 436
         self.assertIn('x-symlink-target', resp_headers)
437 437
 
438 438
         # verify symlink behavior
@@ -453,7 +453,7 @@ class TestContainerSyncAndSymlink(BaseTestContainerSync):
453 453
         resp_headers, symlink_body = client.get_object(
454 454
             dest_account['url'], dest_account['token'], dest_container,
455 455
             symlink_name, query_string='symlink=get')
456
-        self.assertEqual('', symlink_body)
456
+        self.assertEqual(b'', symlink_body)
457 457
         self.assertIn('x-symlink-target', resp_headers)
458 458
 
459 459
         # attempt to GET the target object via symlink will fail because
@@ -480,7 +480,7 @@ class TestContainerSyncAndSymlink(BaseTestContainerSync):
480 480
         resp_headers, symlink_body = client.get_object(
481 481
             dest_account['url'], dest_account['token'], dest_container,
482 482
             symlink_name, query_string='symlink=get')
483
-        self.assertEqual('', symlink_body)
483
+        self.assertEqual(b'', symlink_body)
484 484
         self.assertIn('x-symlink-target', resp_headers)
485 485
 
486 486
         # verify GET of target object via symlink now succeeds
@@ -511,7 +511,7 @@ class TestContainerSyncAndSymlink(BaseTestContainerSync):
511 511
 
512 512
         # upload a target to source
513 513
         target_name = 'target-%s' % uuid.uuid4()
514
-        target_body = 'target body'
514
+        target_body = b'target body'
515 515
         client.put_object(tgt_account['url'], tgt_account['token'],
516 516
                           tgt_container, target_name, target_body)
517 517
 
@@ -531,7 +531,7 @@ class TestContainerSyncAndSymlink(BaseTestContainerSync):
531 531
         resp_headers, symlink_body = client.get_object(
532 532
             self.url, self.token, source_container, symlink_name,
533 533
             query_string='symlink=get')
534
-        self.assertEqual('', symlink_body)
534
+        self.assertEqual(b'', symlink_body)
535 535
         self.assertIn('x-symlink-target', resp_headers)
536 536
         self.assertIn('x-symlink-target-account', resp_headers)
537 537
 
@@ -553,7 +553,7 @@ class TestContainerSyncAndSymlink(BaseTestContainerSync):
553 553
         resp_headers, symlink_body = client.get_object(
554 554
             self.url, self.token, dest_container,
555 555
             symlink_name, query_string='symlink=get')
556
-        self.assertEqual('', symlink_body)
556
+        self.assertEqual(b'', symlink_body)
557 557
         self.assertIn('x-symlink-target', resp_headers)
558 558
         self.assertIn('x-symlink-target-account', resp_headers)
559 559
 

+ 2
- 2
test/probe/test_empty_device_handoff.py View File

@@ -69,7 +69,7 @@ class TestEmptyDevice(ReplProbeTest):
69 69
         # Create container/obj (goes to two primary servers and one handoff)
70 70
         client.put_object(self.url, self.token, container, obj, 'VERIFY')
71 71
         odata = client.get_object(self.url, self.token, container, obj)[-1]
72
-        if odata != 'VERIFY':
72
+        if odata != b'VERIFY':
73 73
             raise Exception('Object GET did not return VERIFY, instead it '
74 74
                             'returned: %s' % repr(odata))
75 75
 
@@ -87,7 +87,7 @@ class TestEmptyDevice(ReplProbeTest):
87 87
 
88 88
         # Indirectly through proxy assert we can get container/obj
89 89
         odata = client.get_object(self.url, self.token, container, obj)[-1]
90
-        if odata != 'VERIFY':
90
+        if odata != b'VERIFY':
91 91
             raise Exception('Object GET did not return VERIFY, instead it '
92 92
                             'returned: %s' % repr(odata))
93 93
         # Restart those other two container/obj primary servers

+ 3
- 3
test/probe/test_object_async_update.py View File

@@ -14,7 +14,7 @@
14 14
 # See the License for the specific language governing permissions and
15 15
 # limitations under the License.
16 16
 
17
-from io import StringIO
17
+from io import BytesIO
18 18
 from unittest import main, SkipTest
19 19
 from uuid import uuid4
20 20
 
@@ -82,7 +82,7 @@ class TestObjectAsyncUpdate(ReplProbeTest):
82 82
             self.assertEqual(err.http_status, 503)
83 83
 
84 84
         # Assert handoff device has a container replica
85
-        another_cnode = self.container_ring.get_more_nodes(cpart).next()
85
+        another_cnode = next(self.container_ring.get_more_nodes(cpart))
86 86
         direct_client.direct_get_container(
87 87
             another_cnode, cpart, self.account, container)
88 88
 
@@ -143,7 +143,7 @@ class TestUpdateOverrides(ReplProbeTest):
143 143
                                       self.policy.name})
144 144
 
145 145
         int_client.upload_object(
146
-            StringIO(u'stuff'), self.account, 'c1', 'o1', headers)
146
+            BytesIO(b'stuff'), self.account, 'c1', 'o1', headers)
147 147
 
148 148
         # Run the object-updaters to be sure updates are done
149 149
         Manager(['object-updater']).once()

+ 6
- 6
test/probe/test_object_conditional_requests.py View File

@@ -40,7 +40,7 @@ class TestPutIfNoneMatchRepl(ReplProbeTest):
40 40
         self.brain.put_container()
41 41
         self.brain.stop_primary_half()
42 42
         # put object to only 1 of 3 primaries
43
-        self.brain.put_object(contents='VERIFY')
43
+        self.brain.put_object(contents=b'VERIFY')
44 44
         self.brain.start_primary_half()
45 45
 
46 46
         # Restart services and attempt to overwrite
@@ -64,16 +64,16 @@ class TestPutIfNoneMatchRepl(ReplProbeTest):
64 64
         # ...and verify the object was not overwritten
65 65
         _headers, body = client.get_object(
66 66
             self.url, self.token, self.container_name, self.object_name)
67
-        self.assertEqual(body, 'VERIFY')
67
+        self.assertEqual(body, b'VERIFY')
68 68
 
69 69
     def test_content_length_nonzero(self):
70
-        self._do_test('OVERWRITE')
70
+        self._do_test(b'OVERWRITE')
71 71
 
72 72
     def test_content_length_zero(self):
73
-        self._do_test('')
73
+        self._do_test(b'')
74 74
 
75 75
     def test_chunked(self):
76
-        self._do_test(chunker('OVERWRITE'))
76
+        self._do_test(chunker(b'OVERWRITE'))
77 77
 
78 78
     def test_chunked_empty(self):
79
-        self._do_test(chunker(''))
79
+        self._do_test(chunker(b''))

+ 10
- 7
test/probe/test_object_failures.py View File

@@ -78,7 +78,7 @@ class TestObjectFailures(ReplProbeTest):
78 78
         container = 'container-%s' % uuid4()
79 79
         obj = 'object-%s' % uuid4()
80 80
         onode, opart, data_file = self._setup_data_file(container, obj,
81
-                                                        'VERIFY')
81
+                                                        b'VERIFY')
82 82
         # Stash the on disk data for future comparison - this may not equal
83 83
         # 'VERIFY' if for example the proxy has crypto enabled
84 84
         backend_data = direct_client.direct_get_object(
@@ -105,7 +105,7 @@ class TestObjectFailures(ReplProbeTest):
105 105
         container = 'container-range-%s' % uuid4()
106 106
         obj = 'object-range-%s' % uuid4()
107 107
         onode, opart, data_file = self._setup_data_file(container, obj,
108
-                                                        'RANGE')
108
+                                                        b'RANGE')
109 109
         # Stash the on disk data for future comparison - this may not equal
110 110
         # 'VERIFY' if for example the proxy has crypto enabled
111 111
         backend_data = direct_client.direct_get_object(
@@ -137,7 +137,8 @@ class TestObjectFailures(ReplProbeTest):
137 137
     def run_quarantine_zero_byte_get(self):
138 138
         container = 'container-zbyte-%s' % uuid4()
139 139
         obj = 'object-zbyte-%s' % uuid4()
140
-        onode, opart, data_file = self._setup_data_file(container, obj, 'DATA')
140
+        onode, opart, data_file = self._setup_data_file(
141
+            container, obj, b'DATA')
141 142
         metadata = read_metadata(data_file)
142 143
         unlink(data_file)
143 144
 
@@ -155,7 +156,8 @@ class TestObjectFailures(ReplProbeTest):
155 156
     def run_quarantine_zero_byte_head(self):
156 157
         container = 'container-zbyte-%s' % uuid4()
157 158
         obj = 'object-zbyte-%s' % uuid4()
158
-        onode, opart, data_file = self._setup_data_file(container, obj, 'DATA')
159
+        onode, opart, data_file = self._setup_data_file(
160
+            container, obj, b'DATA')
159 161
         metadata = read_metadata(data_file)
160 162
         unlink(data_file)
161 163
 
@@ -173,7 +175,8 @@ class TestObjectFailures(ReplProbeTest):
173 175
     def run_quarantine_zero_byte_post(self):
174 176
         container = 'container-zbyte-%s' % uuid4()
175 177
         obj = 'object-zbyte-%s' % uuid4()
176
-        onode, opart, data_file = self._setup_data_file(container, obj, 'DATA')
178
+        onode, opart, data_file = self._setup_data_file(
179
+            container, obj, b'DATA')
177 180
         metadata = read_metadata(data_file)
178 181
         unlink(data_file)
179 182
 
@@ -217,7 +220,7 @@ class TestECObjectFailures(ECProbeTest):
217 220
 
218 221
         # PUT object, should go to primary nodes
219 222
         client.put_object(self.url, self.token, container_name,
220
-                          object_name, contents='object contents')
223
+                          object_name, contents=b'object contents')
221 224
 
222 225
         # get our node lists
223 226
         opart, onodes = self.object_ring.get_nodes(
@@ -226,7 +229,7 @@ class TestECObjectFailures(ECProbeTest):
226 229
         # sanity test
227 230
         odata = client.get_object(self.url, self.token, container_name,
228 231
                                   object_name)[-1]
229
-        self.assertEqual('object contents', odata)
232
+        self.assertEqual(b'object contents', odata)
230 233
 
231 234
         # make all fragments non-durable
232 235
         for node in onodes:

+ 11
- 11
test/probe/test_object_handoff.py View File

@@ -53,9 +53,9 @@ class TestObjectHandoff(ReplProbeTest):
53 53
         kill_server((onode['ip'], onode['port']), self.ipport2server)
54 54
 
55 55
         # Create container/obj (goes to two primary servers and one handoff)
56
-        client.put_object(self.url, self.token, container, obj, 'VERIFY')
56
+        client.put_object(self.url, self.token, container, obj, b'VERIFY')
57 57
         odata = client.get_object(self.url, self.token, container, obj)[-1]
58
-        if odata != 'VERIFY':
58
+        if odata != b'VERIFY':
59 59
             raise Exception('Object GET did not return VERIFY, instead it '
60 60
                             'returned: %s' % repr(odata))
61 61
 
@@ -73,7 +73,7 @@ class TestObjectHandoff(ReplProbeTest):
73 73
 
74 74
         # Indirectly through proxy assert we can get container/obj
75 75
         odata = client.get_object(self.url, self.token, container, obj)[-1]
76
-        if odata != 'VERIFY':
76
+        if odata != b'VERIFY':
77 77
             raise Exception('Object GET did not return VERIFY, instead it '
78 78
                             'returned: %s' % repr(odata))
79 79
 
@@ -139,13 +139,13 @@ class TestObjectHandoff(ReplProbeTest):
139 139
                 port_num = node['replication_port']
140 140
             except KeyError:
141 141
                 port_num = node['port']
142
-            node_id = (port_num - 6000) / 10
142
+            node_id = (port_num - 6000) // 10
143 143
             Manager(['object-replicator']).once(number=node_id)
144 144
         try:
145 145
             another_port_num = another_onode['replication_port']
146 146
         except KeyError:
147 147
             another_port_num = another_onode['port']
148
-        another_num = (another_port_num - 6000) / 10
148
+        another_num = (another_port_num - 6000) // 10
149 149
         Manager(['object-replicator']).once(number=another_num)
150 150
 
151 151
         # Assert the first container/obj primary server now has container/obj
@@ -231,9 +231,9 @@ class TestObjectHandoff(ReplProbeTest):
231 231
                 port_num = node['replication_port']
232 232
             except KeyError:
233 233
                 port_num = node['port']
234
-            node_id = (port_num - 6000) / 10
234
+            node_id = (port_num - 6000) // 10
235 235
             Manager(['object-replicator']).once(number=node_id)
236
-        another_node_id = (another_port_num - 6000) / 10
236
+        another_node_id = (another_port_num - 6000) // 10
237 237
         Manager(['object-replicator']).once(number=another_node_id)
238 238
 
239 239
         # Assert primary node no longer has container/obj
@@ -261,9 +261,9 @@ class TestObjectHandoff(ReplProbeTest):
261 261
         kill_server((onode['ip'], onode['port']), self.ipport2server)
262 262
 
263 263
         # Create container/obj (goes to two primaries and one handoff)
264
-        client.put_object(self.url, self.token, container, obj, 'VERIFY')
264
+        client.put_object(self.url, self.token, container, obj, b'VERIFY')
265 265
         odata = client.get_object(self.url, self.token, container, obj)[-1]
266
-        if odata != 'VERIFY':
266
+        if odata != b'VERIFY':
267 267
             raise Exception('Object GET did not return VERIFY, instead it '
268 268
                             'returned: %s' % repr(odata))
269 269
 
@@ -318,9 +318,9 @@ class TestObjectHandoff(ReplProbeTest):
318 318
 
319 319
         # Create container/obj (goes to all three primaries)
320 320
         obj = 'object-%s' % uuid4()
321
-        client.put_object(self.url, self.token, container, obj, 'VERIFY')
321
+        client.put_object(self.url, self.token, container, obj, b'VERIFY')
322 322
         odata = client.get_object(self.url, self.token, container, obj)[-1]
323
-        if odata != 'VERIFY':
323
+        if odata != b'VERIFY':
324 324
             raise Exception('Object GET did not return VERIFY, instead it '
325 325
                             'returned: %s' % repr(odata))
326 326
 

+ 5
- 5
test/probe/test_object_metadata_replication.py View File

@@ -13,7 +13,7 @@
13 13
 # implied.
14 14
 # See the License for the specific language governing permissions and
15 15
 # limitations under the License.
16
-from io import StringIO
16
+from io import BytesIO
17 17
 import unittest
18 18
 
19 19
 import os
@@ -134,9 +134,9 @@ class Test(ReplProbeTest):
134 134
         modified = Timestamp(metadata['x-timestamp']).isoformat
135 135
         self.assertEqual(listing['last_modified'], modified)
136 136
 
137
-    def _put_object(self, headers=None, body=u'stuff'):
137
+    def _put_object(self, headers=None, body=b'stuff'):
138 138
         headers = headers or {}
139
-        self.int_client.upload_object(StringIO(body), self.account,
139
+        self.int_client.upload_object(BytesIO(body), self.account,
140 140
                                       self.container_name,
141 141
                                       self.object_name, headers)
142 142
 
@@ -232,12 +232,12 @@ class Test(ReplProbeTest):
232 232
         self.brain.put_container()
233 233
 
234 234
         # put object
235
-        self._put_object(headers={'Content-Type': 'foo'}, body=u'older')
235
+        self._put_object(headers={'Content-Type': 'foo'}, body=b'older')
236 236
 
237 237
         # put newer object to first server subset
238 238
         self.brain.stop_primary_half()
239 239
         self.container_brain.stop_primary_half()
240
-        self._put_object(headers={'Content-Type': 'bar'}, body=u'newer')
240
+        self._put_object(headers={'Content-Type': 'bar'}, body=b'newer')
241 241
         metadata = self._get_object_metadata()
242 242
         etag = metadata['etag']
243 243
         self.brain.start_primary_half()

+ 2
- 2
test/probe/test_object_partpower_increase.py View File

@@ -51,8 +51,8 @@ class TestPartPowerIncrease(ProbeTest):
51 51
 
52 52
         self.devices = [
53 53
             self.device_dir('object', {'ip': ip, 'port': port, 'device': ''})
54
-            for ip, port in set((dev['ip'], dev['port'])
55
-                                for dev in self.object_ring.devs)]
54
+            for ip, port in {(dev['ip'], dev['port'])
55
+                             for dev in self.object_ring.devs}]
56 56
 
57 57
     def tearDown(self):
58 58
         # Keep a backup copy of the modified .builder file

+ 19
- 13
test/probe/test_reconstructor_rebuild.py View File

@@ -24,6 +24,7 @@ import shutil
24 24
 import random
25 25
 import os
26 26
 import time
27
+import six
27 28
 
28 29
 from swift.common.direct_client import DirectClientException
29 30
 from test.probe.common import ECProbeTest
@@ -38,10 +39,10 @@ from swiftclient import client, ClientException
38 39
 class Body(object):
39 40
 
40 41
     def __init__(self, total=3.5 * 2 ** 20):
41
-        self.total = total
42
+        self.total = int(total)
42 43
         self.hasher = md5()
43 44
         self.size = 0
44
-        self.chunk = 'test' * 16 * 2 ** 10
45
+        self.chunk = b'test' * 16 * 2 ** 10
45 46
 
46 47
     @property
47 48
     def etag(self):
@@ -50,21 +51,21 @@ class Body(object):
50 51
     def __iter__(self):
51 52
         return self
52 53
 
53
-    def next(self):
54
+    def __next__(self):
54 55
         if self.size > self.total:
55 56
             raise StopIteration()
56 57
         self.size += len(self.chunk)
57 58
         self.hasher.update(self.chunk)
58 59
         return self.chunk
59 60
 
60
-    def __next__(self):
61
-        return next(self)
61
+    # for py2 compat
62
+    next = __next__
62 63
 
63 64
 
64 65
 class TestReconstructorRebuild(ECProbeTest):
65 66
 
66 67
     def _make_name(self, prefix):
67
-        return '%s%s' % (prefix, uuid.uuid4())
68
+        return ('%s%s' % (prefix, uuid.uuid4())).encode()
68 69
 
69 70
     def setUp(self):
70 71
         super(TestReconstructorRebuild, self).setUp()
@@ -131,10 +132,13 @@ class TestReconstructorRebuild(ECProbeTest):
131 132
                 {'X-Backend-Fragment-Preferences': json.dumps([])})
132 133
         # node dict has unicode values so utf8 decode our path parts too in
133 134
         # case they have non-ascii characters
135
+        if six.PY2:
136
+            acc, con, obj = (s.decode('utf8') for s in (
137
+                self.account, self.container_name, self.object_name))
138
+        else:
139
+            acc, con, obj = self.account, self.container_name, self.object_name
134 140
         headers, data = direct_client.direct_get_object(
135
-            node, part, self.account.decode('utf8'),
136
-            self.container_name.decode('utf8'),
137
-            self.object_name.decode('utf8'), headers=req_headers,
141
+            node, part, acc, con, obj, headers=req_headers,
138 142
             resp_chunk_size=64 * 2 ** 20)
139 143
         hasher = md5()
140 144
         for chunk in data:
@@ -402,7 +406,7 @@ class TestReconstructorRebuild(ECProbeTest):
402 406
         opart, onodes = self.object_ring.get_nodes(
403 407
             self.account, self.container_name, self.object_name)
404 408
         delete_at = int(time.time() + 3)
405
-        contents = 'body-%s' % uuid.uuid4()
409
+        contents = ('body-%s' % uuid.uuid4()).encode()
406 410
         headers = {'x-delete-at': delete_at}
407 411
         client.put_object(self.url, self.token, self.container_name,
408 412
                           self.object_name, headers=headers, contents=contents)
@@ -418,15 +422,17 @@ class TestReconstructorRebuild(ECProbeTest):
418 422
         # wait for the delete_at to pass, and check that it thinks the object
419 423
         # is expired
420 424
         timeout = time.time() + 5
425
+        err = None
421 426
         while time.time() < timeout:
422 427
             try:
423 428
                 direct_client.direct_head_object(
424 429
                     post_fail_node, opart, self.account, self.container_name,
425 430
                     self.object_name, headers={
426 431
                         'X-Backend-Storage-Policy-Index': int(self.policy)})
427
-            except direct_client.ClientException as err:
428
-                if err.http_status != 404:
432
+            except direct_client.ClientException as client_err:
433
+                if client_err.http_status != 404:
429 434
                     raise
435
+                err = client_err
430 436
                 break
431 437
             else:
432 438
                 time.sleep(0.1)
@@ -454,7 +460,7 @@ class TestReconstructorRebuild(ECProbeTest):
454 460
 class TestReconstructorRebuildUTF8(TestReconstructorRebuild):
455 461
 
456 462
     def _make_name(self, prefix):
457
-        return '%s\xc3\xa8-%s' % (prefix, uuid.uuid4())
463
+        return b'%s\xc3\xa8-%s' % (prefix.encode(), str(uuid.uuid4()).encode())
458 464
 
459 465
 
460 466
 if __name__ == "__main__":

+ 1
- 1
test/probe/test_reconstructor_revert.py View File

@@ -132,7 +132,7 @@ class TestReconstructorRevert(ECProbeTest):
132 132
 
133 133
         # fire up reconstructor on handoff nodes only
134 134
         for hnode in hnodes:
135
-            hnode_id = (hnode['port'] - 6000) / 10
135
+            hnode_id = (hnode['port'] - 6000) // 10
136 136
             self.reconstructor.once(number=hnode_id)
137 137
 
138 138
         # first three primaries have data again

+ 43
- 30
test/probe/test_sharder.py View File

@@ -19,6 +19,7 @@ import shutil
19 19
 import uuid
20 20
 
21 21
 from nose import SkipTest
22
+import six
22 23
 
23 24
 from swift.common import direct_client, utils
24 25
 from swift.common.manager import Manager
@@ -65,8 +66,8 @@ class BaseTestContainerSharding(ReplProbeTest):
65 66
                            'container-server configs')
66 67
 
67 68
         skip_reasons = []
68
-        auto_shard = all([config_true_value(c.get('auto_shard', False))
69
-                          for c in cont_configs])
69
+        auto_shard = all(config_true_value(c.get('auto_shard', False))
70
+                         for c in cont_configs)
70 71
         if not auto_shard:
71 72
             skip_reasons.append(
72 73
                 'auto_shard must be true in all container_sharder configs')
@@ -83,7 +84,7 @@ class BaseTestContainerSharding(ReplProbeTest):
83 84
                  MAX_SHARD_CONTAINER_THRESHOLD))
84 85
 
85 86
         def skip_check(reason_list, option, required):
86
-            values = set([int(c.get(option, required)) for c in cont_configs])
87
+            values = {int(c.get(option, required)) for c in cont_configs}
87 88
             if values != {required}:
88 89
                 reason_list.append('%s must be %s' % (option, required))
89 90
 
@@ -259,8 +260,8 @@ class BaseTestContainerSharding(ReplProbeTest):
259 260
 
260 261
     def assert_dict_contains(self, expected_items, actual_dict):
261 262
         ignored = set(expected_items) ^ set(actual_dict)
262
-        filtered_actual = dict((k, actual_dict[k])
263
-                               for k in actual_dict if k not in ignored)
263
+        filtered_actual = {k: actual_dict[k]
264
+                           for k in actual_dict if k not in ignored}
264 265
         self.assertEqual(expected_items, filtered_actual)
265 266
 
266 267
     def assert_shard_ranges_contiguous(self, expected_number, shard_ranges,
@@ -268,8 +269,8 @@ class BaseTestContainerSharding(ReplProbeTest):
268 269
         if shard_ranges and isinstance(shard_ranges[0], ShardRange):
269 270
             actual_shard_ranges = sorted(shard_ranges)
270 271
         else:
271
-            actual_shard_ranges = sorted([ShardRange.from_dict(d)
272
-                                          for d in shard_ranges])
272
+            actual_shard_ranges = sorted(ShardRange.from_dict(d)
273
+                                         for d in shard_ranges)
273 274
         self.assertLengthEqual(actual_shard_ranges, expected_number)
274 275
         if expected_number:
275 276
             with annotate_failure('Ranges %s.' % actual_shard_ranges):
@@ -300,7 +301,7 @@ class BaseTestContainerSharding(ReplProbeTest):
300 301
                          [sr.state for sr in shard_ranges])
301 302
 
302 303
     def assert_total_object_count(self, expected_object_count, shard_ranges):
303
-        actual = sum([sr['object_count'] for sr in shard_ranges])
304
+        actual = sum(sr['object_count'] for sr in shard_ranges)
304 305
         self.assertEqual(expected_object_count, actual)
305 306
 
306 307
     def assert_container_listing(self, expected_listing):
@@ -309,7 +310,8 @@ class BaseTestContainerSharding(ReplProbeTest):
309 310
         self.assertIn('x-container-object-count', headers)
310 311
         expected_obj_count = len(expected_listing)
311 312
         self.assertEqual(expected_listing, [
312
-            x['name'].encode('utf-8') for x in actual_listing])
313
+            x['name'].encode('utf-8') if six.PY2 else x['name']
314
+            for x in actual_listing])
313 315
         self.assertEqual(str(expected_obj_count),
314 316
                          headers['x-container-object-count'])
315 317
         return headers, actual_listing
@@ -407,15 +409,16 @@ class TestContainerShardingNonUTF8(BaseTestContainerSharding):
407 409
         self.put_objects(obj_names)
408 410
         # choose some names approx in middle of each expected shard range
409 411
         markers = [
410
-            obj_names[i] for i in range(self.max_shard_size / 4,
412
+            obj_names[i] for i in range(self.max_shard_size // 4,
411 413
                                         2 * self.max_shard_size,
412
-                                        self.max_shard_size / 2)]
414
+                                        self.max_shard_size // 2)]
413 415
 
414 416
         def check_listing(objects, **params):
415 417
             qs = '&'.join(['%s=%s' % param for param in params.items()])
416 418
             headers, listing = client.get_container(
417 419
                 self.url, self.token, self.container_name, query_string=qs)
418
-            listing = [x['name'].encode('utf-8') for x in listing]
420
+            listing = [x['name'].encode('utf-8') if six.PY2 else x['name']
421
+                       for x in listing]
419 422
             if params.get('reverse'):
420 423
                 marker = params.get('marker', ShardRange.MAX)
421 424
                 end_marker = params.get('end_marker', ShardRange.MIN)
@@ -443,16 +446,17 @@ class TestContainerShardingNonUTF8(BaseTestContainerSharding):
443 446
             check_listing(objects, marker=markers[0], end_marker=markers[2])
444 447
             check_listing(objects, marker=markers[1], end_marker=markers[3])
445 448
             check_listing(objects, marker=markers[1], end_marker=markers[3],
446
-                          limit=self.max_shard_size / 4)
449
+                          limit=self.max_shard_size // 4)
447 450
             check_listing(objects, marker=markers[1], end_marker=markers[3],
448
-                          limit=self.max_shard_size / 4)
451
+                          limit=self.max_shard_size // 4)
449 452
             check_listing(objects, marker=markers[1], end_marker=markers[2],
450
-                          limit=self.max_shard_size / 2)
453
+                          limit=self.max_shard_size // 2)
451 454
             check_listing(objects, marker=markers[1], end_marker=markers[1])
452 455
             check_listing(objects, reverse=True)
453 456
             check_listing(objects, reverse=True, end_marker=markers[1])
454 457
             check_listing(objects, reverse=True, marker=markers[3],
455
-                          end_marker=markers[1], limit=self.max_shard_size / 4)
458
+                          end_marker=markers[1],
459
+                          limit=self.max_shard_size // 4)
456 460
             check_listing(objects, reverse=True, marker=markers[3],
457 461
                           end_marker=markers[1], limit=0)
458 462
             check_listing([], marker=markers[0], end_marker=markers[0])
@@ -468,9 +472,9 @@ class TestContainerShardingNonUTF8(BaseTestContainerSharding):
468 472
 
469 473
             limit = self.cluster_info['swift']['container_listing_limit']
470 474
             exc = check_listing_precondition_fails(limit=limit + 1)
471
-            self.assertIn('Maximum limit', exc.http_response_content)
475
+            self.assertIn(b'Maximum limit', exc.http_response_content)
472 476
             exc = check_listing_precondition_fails(delimiter='ab')
473
-            self.assertIn('Bad delimiter', exc.http_response_content)
477
+            self.assertIn(b'Bad delimiter', exc.http_response_content)
474 478
 
475 479
         # sanity checks
476 480
         do_listing_checks(obj_names)
@@ -544,7 +548,9 @@ class TestContainerShardingUTF8(TestContainerShardingNonUTF8):
544 548
         obj_names = []
545 549
         for x in range(number):
546 550
             name = (u'obj-\u00e4\u00ea\u00ec\u00f2\u00fb-%04d' % x)
547
-            name = name.encode('utf8').ljust(name_length, 'o')
551
+            name = name.encode('utf8').ljust(name_length, b'o')
552
+            if not six.PY2:
553
+                name = name.decode('utf8')
548 554
             obj_names.append(name)
549 555
         return obj_names
550 556
 
@@ -553,7 +559,9 @@ class TestContainerShardingUTF8(TestContainerShardingNonUTF8):
553 559
         super(TestContainerShardingUTF8, self)._setup_container_name()
554 560
         name_length = self.cluster_info['swift']['max_container_name_length']
555 561
         cont_name = self.container_name + u'-\u00e4\u00ea\u00ec\u00f2\u00fb'
556
-        self.conainer_name = cont_name.encode('utf8').ljust(name_length, 'x')
562
+        self.conainer_name = cont_name.ljust(name_length, 'x')
563
+        if six.PY2:
564
+            self.conainer_name = self.container_name.encode('utf8')
557 565
 
558 566
 
559 567
 class TestContainerSharding(BaseTestContainerSharding):
@@ -573,8 +581,9 @@ class TestContainerSharding(BaseTestContainerSharding):
573 581
 
574 582
         headers, pre_sharding_listing = client.get_container(
575 583
             self.url, self.token, self.container_name)
576
-        self.assertEqual(obj_names, [x['name'].encode('utf-8')
577
-                                     for x in pre_sharding_listing])  # sanity
584
+        self.assertEqual(obj_names, [
585
+            x['name'].encode('utf-8') if six.PY2 else x['name']
586
+            for x in pre_sharding_listing])  # sanity
578 587
 
579 588
         # Shard it
580 589
         client.post_container(self.url, self.admin_token, self.container_name,
@@ -901,7 +910,7 @@ class TestContainerSharding(BaseTestContainerSharding):
901 910
                 old_shard_range = by_name.pop(
902 911
                     orig_root_shard_ranges[0]['name'])
903 912
                 self.assertTrue(old_shard_range.deleted)
904
-                self.assert_shard_ranges_contiguous(4, by_name.values())
913
+                self.assert_shard_ranges_contiguous(4, list(by_name.values()))
905 914
             else:
906 915
                 # Everyone's on the same page. Well, except for
907 916
                 # meta_timestamps, since the shards each reported
@@ -1070,26 +1079,29 @@ class TestContainerSharding(BaseTestContainerSharding):
1070 1079
         start_listing = [
1071 1080
             o for o in obj_names if o <= expected_shard_ranges[1].upper]
1072 1081
         self.assertEqual(
1073
-            [x['name'].encode('utf-8') for x in listing[:len(start_listing)]],
1082
+            [x['name'].encode('utf-8') if six.PY2 else x['name']
1083
+             for x in listing[:len(start_listing)]],
1074 1084
             start_listing)
1075 1085
         # we can't assert much about the remaining listing, other than that
1076 1086
         # there should be something
1077 1087
         self.assertTrue(
1078
-            [x['name'].encode('utf-8') for x in listing[len(start_listing):]])
1088
+            [x['name'].encode('utf-8') if six.PY2 else x['name']
1089
+             for x in listing[len(start_listing):]])
1079 1090
         self.assertIn('x-container-object-count', headers)
1080 1091
         self.assertEqual(str(len(listing)),
1081 1092
                          headers['x-container-object-count'])
1082 1093
         headers, listing = client.get_container(self.url, self.token,
1083 1094
                                                 self.container_name,
1084 1095
                                                 query_string='reverse=on')
1085
-        self.assertEqual([x['name'].encode('utf-8')
1096
+        self.assertEqual([x['name'].encode('utf-8') if six.PY2 else x['name']
1086 1097
                           for x in listing[-len(start_listing):]],
1087 1098
                          list(reversed(start_listing)))
1088 1099
         self.assertIn('x-container-object-count', headers)
1089 1100
         self.assertEqual(str(len(listing)),
1090 1101
                          headers['x-container-object-count'])
1091 1102
         self.assertTrue(
1092
-            [x['name'].encode('utf-8') for x in listing[:-len(start_listing)]])
1103
+            [x['name'].encode('utf-8') if six.PY2 else x['name']
1104
+             for x in listing[:-len(start_listing)]])
1093 1105
 
1094 1106
         # Run the sharders again to get everything to settle
1095 1107
         self.sharders.once()
@@ -1099,7 +1111,8 @@ class TestContainerSharding(BaseTestContainerSharding):
1099 1111
         # now all shards have been cleaved we should get the complete listing
1100 1112
         headers, listing = client.get_container(self.url, self.token,
1101 1113
                                                 self.container_name)
1102
-        self.assertEqual([x['name'].encode('utf-8') for x in listing],
1114
+        self.assertEqual([x['name'].encode('utf-8') if six.PY2 else x['name']
1115
+                          for x in listing],
1103 1116
                          obj_names)
1104 1117
 
1105 1118
     def test_shrinking(self):
@@ -1409,7 +1422,7 @@ class TestContainerSharding(BaseTestContainerSharding):
1409 1422
 
1410 1423
         # put objects while all servers are up
1411 1424
         obj_names = self._make_object_names(
1412
-            num_shards * self.max_shard_size / 2)
1425
+            num_shards * self.max_shard_size // 2)
1413 1426
         self.put_objects(obj_names)
1414 1427
 
1415 1428
         client.post_container(self.url, self.admin_token, self.container_name,
@@ -2004,7 +2017,7 @@ class TestContainerSharding(BaseTestContainerSharding):
2004 2017
                             if n['id'] not in primary_ids)
2005 2018
         num_shards = 3
2006 2019
         obj_names = self._make_object_names(
2007
-            num_shards * self.max_shard_size / 2)
2020
+            num_shards * self.max_shard_size // 2)
2008 2021
         self.put_objects(obj_names)
2009 2022
         client.post_container(self.url, self.admin_token, self.container_name,
2010 2023
                               headers={'X-Container-Sharding': 'on'})

+ 7
- 7
test/probe/test_signals.py View File

@@ -48,10 +48,10 @@ class TestWSGIServerProcessHandling(unittest.TestCase):
48 48
         manager = Manager([server_name])
49 49
         manager.start()
50 50
 
51
-        starting_pids = set(pid for server in manager.servers
52
-                            for (_, pid) in server.iter_pid_files())
51
+        starting_pids = {pid for server in manager.servers
52
+                         for (_, pid) in server.iter_pid_files()}
53 53
 
54
-        body = 'test' * 10
54
+        body = b'test' * 10
55 55
         conn = httplib.HTTPConnection('%s:%s' % (ip, port))
56 56
 
57 57
         # sanity request
@@ -68,8 +68,8 @@ class TestWSGIServerProcessHandling(unittest.TestCase):
68 68
 
69 69
         manager.reload()
70 70
 
71
-        post_reload_pids = set(pid for server in manager.servers
72
-                               for (_, pid) in server.iter_pid_files())
71
+        post_reload_pids = {pid for server in manager.servers
72
+                            for (_, pid) in server.iter_pid_files()}
73 73
 
74 74
         # none of the pids we started with are being tracked after reload
75 75
         msg = 'expected all pids from %r to have died, but found %r' % (
@@ -92,8 +92,8 @@ class TestWSGIServerProcessHandling(unittest.TestCase):
92 92
         conn.close()
93 93
 
94 94
         # sanity
95
-        post_close_pids = set(pid for server in manager.servers
96
-                              for (_, pid) in server.iter_pid_files())
95
+        post_close_pids = {pid for server in manager.servers
96
+                           for (_, pid) in server.iter_pid_files()}
97 97
         self.assertEqual(post_reload_pids, post_close_pids)
98 98
 
99 99
     def test_proxy_reload(self):

Loading…
Cancel
Save