]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph-volume lvm.create rollback osd creation when prepare or activate fails 19351/head
authorAlfredo Deza <adeza@redhat.com>
Tue, 5 Dec 2017 20:31:55 +0000 (15:31 -0500)
committerAlfredo Deza <adeza@redhat.com>
Tue, 5 Dec 2017 20:32:10 +0000 (15:32 -0500)
Signed-off-by: Alfredo Deza <adeza@redhat.com>
src/ceph-volume/ceph_volume/devices/lvm/create.py

index edacecb79ecada2975293916cba867a47a0af7e0..8e6d8e021cced28b5797d5839d167bae00d565d6 100644 (file)
@@ -1,11 +1,14 @@
 from __future__ import print_function
 from textwrap import dedent
+import logging
 from ceph_volume.util import system
 from ceph_volume import decorators
-from .common import create_parser
+from .common import create_parser, rollback_osd
 from .prepare import Prepare
 from .activate import Activate
 
+logger = logging.getLogger(__name__)
+
 
 class Create(object):
 
@@ -18,8 +21,19 @@ class Create(object):
     def create(self, args):
         if not args.osd_fsid:
             args.osd_fsid = system.generate_uuid()
-        Prepare([]).prepare(args)
-        Activate([]).activate(args)
+        prepare_step = Prepare([])
+        prepare_step.safe_prepare(args)
+        osd_id = prepare_step.osd_id
+        try:
+            # we try this for activate only when 'creating' an OSD, because a rollback should not
+            # happen when doing normal activation. For example when starting an OSD, systemd will call
+            # activate, which would never need to be rolled back.
+            Activate([]).activate(args)
+        except Exception:
+            logger.error('lvm activate was unable to complete, while creating the OSD')
+            logger.info('will rollback OSD ID creation')
+            rollback_osd(args, osd_id)
+            raise
 
     def main(self):
         sub_command_help = dedent("""