OSDN Git Service

Recreate Storagepool (#5)
[karesansui/karesansui.git] / bin / ready_mount.py
index a034d42..3af9f8f 100755 (executable)
@@ -68,42 +68,17 @@ class ReadyMount(KssCommand):
             print >>sys.stderr, _('Failed to make tmpdir. path=%s' % (tmp_dir_path))
             raise
 
-        self.up_progress(10)
-        mount_command_args = (MOUNT_CMD,
-                              opts.dev,
-                              tmp_dir_path,
-                              )
-        umount_command_args = (UMOUNT_CMD,
-                               tmp_dir_path,
-                               )
-
-        is_mountable = False
         try:
-            (mount_cmd_rc, mount_cmd_res) = execute_command(mount_command_args)
-            if mount_cmd_rc == 0:
-                is_mountable = True
-            else:
-                self.logger.debug('Failed to mount. dev=%s' % (opts.dev))
-        finally:
-            (umount_cmd_rc, umount_cmd_res) = execute_command(umount_command_args)
-
-        self.up_progress(30)
-        if is_mountable is False and opts.format is True:
-            first_command_args = YES_CMD
-            second_command_args = (FORMAT_CMD,
-                                   "-t",
-                                   opts.type,
-                                   opts.dev,
-                                   )
-            format_command_args = (first_command_args,
-                                   second_command_args,
+            self.up_progress(10)
+            mount_command_args = (MOUNT_CMD,
+                                  opts.dev,
+                                  tmp_dir_path,
+                                  )
+            umount_command_args = (UMOUNT_CMD,
+                                   tmp_dir_path,
                                    )
 
-            (format_cmd_rc, format_cmd_res) = pipe_execute_command(format_command_args)
-            if format_cmd_rc != 0:
-                self.logger.error('Failed to format. dev=%s type=%s res=%s' % (opts.dev, opts.type, format_cmd_res))
-                print >>sys.stderr, _('Failed to format. dev=%s type=%s res=%s' % (opts.dev, opts.type, format_cmd_res))
-
+            is_mountable = False
             try:
                 (mount_cmd_rc, mount_cmd_res) = execute_command(mount_command_args)
                 if mount_cmd_rc == 0:
@@ -113,13 +88,41 @@ class ReadyMount(KssCommand):
             finally:
                 (umount_cmd_rc, umount_cmd_res) = execute_command(umount_command_args)
 
-        self.up_progress(40)
-        try:
-            os.rmdir(tmp_dir_path)
-        except Exception, e:
-            self.logger.error('Failed to delete tmpdir. path=%s' % (tmp_dir_path))
-            print >>sys.stderr, _('Failed to delete tmpdir. path=%s' % (tmp_dir_path))
-            raise
+            self.up_progress(30)
+            if is_mountable is False and opts.format is True:
+                first_command_args = YES_CMD
+                second_command_args = (FORMAT_CMD,
+                                       "-t",
+                                       opts.type,
+                                       opts.dev,
+                                       )
+                format_command_args = (first_command_args,
+                                       second_command_args,
+                                       )
+
+                (format_cmd_rc, format_cmd_res) = pipe_execute_command(format_command_args)
+                if format_cmd_rc != 0:
+                    self.logger.error('Failed to format. dev=%s type=%s res=%s' % (opts.dev, opts.type, format_cmd_res))
+                    print >>sys.stderr, _('Failed to format. dev=%s type=%s res=%s' % (opts.dev, opts.type, format_cmd_res))
+
+                try:
+                    (mount_cmd_rc, mount_cmd_res) = execute_command(mount_command_args)
+                    if mount_cmd_rc == 0:
+                        is_mountable = True
+                    else:
+                        self.logger.debug('Failed to mount. dev=%s' % (opts.dev))
+                finally:
+                    (umount_cmd_rc, umount_cmd_res) = execute_command(umount_command_args)
+
+            self.up_progress(40)
+
+        finally:
+            try:
+                os.rmdir(tmp_dir_path)
+            except Exception, e:
+                self.logger.error('Failed to delete tmpdir. path=%s' % (tmp_dir_path))
+                print >>sys.stderr, _('Failed to delete tmpdir. path=%s' % (tmp_dir_path))
+                raise
 
         return is_mountable