From: Loic Dachary Date: Wed, 2 Mar 2016 12:17:44 +0000 (+0700) Subject: ceph-disk: protect destroy with the activate lock X-Git-Tag: v10.1.0~200^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=e51ac3eec800800e47bf3c744a0bb27eb29d1224;p=ceph.git ceph-disk: protect destroy with the activate lock So that it does not race against an activation. Signed-off-by: Loic Dachary --- diff --git a/src/ceph-disk/ceph_disk/main.py b/src/ceph-disk/ceph_disk/main.py index 77d530186d2..d0ec596c2aa 100755 --- a/src/ceph-disk/ceph_disk/main.py +++ b/src/ceph-disk/ceph_disk/main.py @@ -3560,6 +3560,14 @@ def destroy_lookup_device(args, predicate, description): def main_destroy(args): + activate_lock.acquire() # noqa + try: + main_destroy_locked(args) + finally: + activate_lock.release() # noqa + + +def main_destroy_locked(args): osd_id = args.destroy_by_id path = args.path target_dev = None diff --git a/src/ceph-disk/tests/test_main.py b/src/ceph-disk/tests/test_main.py index 1cbf1747956..f59824c0187 100644 --- a/src/ceph-disk/tests/test_main.py +++ b/src/ceph-disk/tests/test_main.py @@ -1158,6 +1158,8 @@ class TestCephDiskDeactivateAndDestroy(unittest.TestCase): main.unmount(path) def test_main_destroy(self): + data = tempfile.mkdtemp() + main.setup_statedir(data) OSD_UUID = '4fbd7e29-9d25-41b8-afd0-062c0ceff05d' MPATH_OSD_UUID = '4fbd7e29-8ae0-4982-bf9d-5a8d867af560' part_uuid = '0ce28a16-6d5d-11e5-aec3-fa163e5c167b' @@ -1253,6 +1255,7 @@ class TestCephDiskDeactivateAndDestroy(unittest.TestCase): _check_osd_status=lambda cluster, osd_id: 1, ): self.assertRaises(Exception, main.main_destroy, args) + shutil.rmtree(data) def test_remove_from_crush_map_fail(self): cluster = 'ceph'