]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph-disk: protect destroy with the activate lock 7552/head
authorLoic Dachary <ldachary@redhat.com>
Wed, 2 Mar 2016 12:17:44 +0000 (19:17 +0700)
committerLoic Dachary <ldachary@redhat.com>
Fri, 4 Mar 2016 02:13:35 +0000 (09:13 +0700)
So that it does not race against an activation.

Signed-off-by: Loic Dachary <loic@dachary.org>
src/ceph-disk/ceph_disk/main.py
src/ceph-disk/tests/test_main.py

index 77d530186d23a768e85ffeb641a970a321f3912c..d0ec596c2aa43aec2dcb27f7c4d8a24cc02197be 100755 (executable)
@@ -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
index 1cbf1747956c1c8e44528b61d3f4617c24eca900..f59824c018738bfa4be55057b17ef3e17bfa7b24 100644 (file)
@@ -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'