From 5b40f69ede905bfd9413c12b6705fef6d809a929 Mon Sep 17 00:00:00 2001 From: Clay Gerrard Date: Tue, 9 Apr 2019 14:15:32 -0500 Subject: [PATCH] Add tests for unexpected names in part dir An earlier revision of the related change had a bug that this test would have discovered. Related-Change-Id: I85dcaf65b9f19ac4659fa5937f9b0b0e804fc54e Change-Id: Iedd85ec65a11de189ce73e650d674aee0dc7e402 --- test/unit/obj/test_replicator.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/test/unit/obj/test_replicator.py b/test/unit/obj/test_replicator.py index 60d18b9b66..51c54ca931 100644 --- a/test/unit/obj/test_replicator.py +++ b/test/unit/obj/test_replicator.py @@ -536,9 +536,27 @@ class TestObjectReplicator(unittest.TestCase): self._write_disk_data('sdd', with_json=True) _create_test_rings(self.testdir, devs) - self.replicator.collect_jobs() + self.replicator.collect_jobs(override_partitions=[1]) self.assertEqual(self.replicator.total_stats.failure, 0) + def test_collect_jobs_with_override_parts_and_unexpected_part_dir(self): + self.replicator.collect_jobs(override_partitions=[0, 2]) + self.assertEqual(self.replicator.total_stats.failure, 0) + os.mkdir(os.path.join(self.objects_1, 'foo')) + jobs = self.replicator.collect_jobs(override_partitions=[0, 2]) + found_jobs = set() + for j in jobs: + found_jobs.add((int(j['policy']), int(j['partition']))) + self.assertEqual(found_jobs, { + (0, 0), + (0, 2), + (1, 0), + (1, 2), + }) + num_disks = len(POLICIES[1].object_ring.devs) + # N.B. it's not clear why the UUT increments failure per device + self.assertEqual(self.replicator.total_stats.failure, num_disks) + @mock.patch('swift.obj.replicator.random.shuffle', side_effect=lambda l: l) def test_collect_jobs_multi_disk(self, mock_shuffle): devs = [