예제 #1
0
 def _ensure_gluster_vol_mounted(self):
     """Ensure GlusterFS volume is native-mounted on Manila host."""
     mount_path = self._get_mount_point_for_gluster_vol()
     try:
         common._mount_gluster_vol(self.driver._execute, self.gluster_manager.export, mount_path, ensure=True)
     except exception.GlusterfsException:
         LOG.error(_LE("Could not mount the Gluster volume %s"), self.gluster_manager.volume)
         raise
예제 #2
0
 def _ensure_gluster_vol_mounted(self):
     """Ensure GlusterFS volume is native-mounted on Manila host."""
     mount_path = self._get_mount_point_for_gluster_vol()
     try:
         common._mount_gluster_vol(self.driver._execute,
                                   self.gluster_manager.export, mount_path,
                                   ensure=True)
     except exception.GlusterfsException:
         LOG.error(_LE('Could not mount the Gluster volume %s'),
                   self.gluster_manager.volume)
         raise
예제 #3
0
    def _wipe_gluster_vol(self, gluster_mgr):

        # Create a temporary mount.
        gluster_export = gluster_mgr.export
        tmpdir = tempfile.mkdtemp()
        try:
            common._mount_gluster_vol(self.driver._execute, gluster_export,
                                      tmpdir)
        except exception.GlusterfsException:
            shutil.rmtree(tmpdir, ignore_errors=True)
            raise

        # Delete the contents of a GlusterFS volume that is temporarily
        # mounted.
        # From GlusterFS version 3.7, two directories, '.trashcan' at the root
        # of the GlusterFS volume and 'internal_op' within the '.trashcan'
        # directory, are internally created when a GlusterFS volume is started.
        # GlusterFS does not allow unlink(2) of the two directories. So do not
        # delete the paths of the two directories, but delete their contents
        # along with the rest of the contents of the volume.
        srvaddr = gluster_mgr.host_access
        if common.GlusterManager.numreduct(
                self.glusterfs_versions[srvaddr]) < (3, 7):
            cmd = ['find', tmpdir, '-mindepth', '1', '-delete']
        else:
            ignored_dirs = map(lambda x: os.path.join(tmpdir, *x),
                               [('.trashcan', ), ('.trashcan', 'internal_op')])
            ignored_dirs = list(ignored_dirs)
            cmd = [
                'find', tmpdir, '-mindepth', '1', '!', '-path',
                ignored_dirs[0], '!', '-path', ignored_dirs[1], '-delete'
            ]

        try:
            self.driver._execute(*cmd, run_as_root=True)
        except exception.ProcessExecutionError as exc:
            msg = (_("Error trying to wipe gluster volume. "
                     "gluster_export: %(export)s, Error: %(error)s") % {
                         'export': gluster_export,
                         'error': exc.stderr
                     })
            LOG.error(msg)
            raise exception.GlusterfsException(msg)
        finally:
            # Unmount.
            common._umount_gluster_vol(self.driver._execute, tmpdir)
            shutil.rmtree(tmpdir, ignore_errors=True)
예제 #4
0
    def _wipe_gluster_vol(self, gluster_mgr):

        # Create a temporary mount.
        gluster_export = gluster_mgr.export
        tmpdir = tempfile.mkdtemp()
        try:
            common._mount_gluster_vol(self.driver._execute, gluster_export,
                                      tmpdir)
        except exception.GlusterfsException:
            shutil.rmtree(tmpdir, ignore_errors=True)
            raise

        # Delete the contents of a GlusterFS volume that is temporarily
        # mounted.
        # From GlusterFS version 3.7, two directories, '.trashcan' at the root
        # of the GlusterFS volume and 'internal_op' within the '.trashcan'
        # directory, are internally created when a GlusterFS volume is started.
        # GlusterFS does not allow unlink(2) of the two directories. So do not
        # delete the paths of the two directories, but delete their contents
        # along with the rest of the contents of the volume.
        srvaddr = gluster_mgr.host_access
        if common.GlusterManager.numreduct(self.glusterfs_versions[srvaddr]
                                           ) < (3, 7):
            cmd = ['find', tmpdir, '-mindepth', '1', '-delete']
        else:
            ignored_dirs = map(lambda x: os.path.join(tmpdir, *x),
                               [('.trashcan', ), ('.trashcan', 'internal_op')])
            ignored_dirs = list(ignored_dirs)
            cmd = ['find', tmpdir, '-mindepth', '1', '!', '-path',
                   ignored_dirs[0], '!', '-path', ignored_dirs[1], '-delete']

        try:
            self.driver._execute(*cmd, run_as_root=True)
        except exception.ProcessExecutionError as exc:
            msg = (_("Error trying to wipe gluster volume. "
                     "gluster_export: %(export)s, Error: %(error)s") %
                   {'export': gluster_export, 'error': exc.stderr})
            LOG.error(msg)
            raise exception.GlusterfsException(msg)
        finally:
            # Unmount.
            common._umount_gluster_vol(self.driver._execute, tmpdir)
            shutil.rmtree(tmpdir, ignore_errors=True)
예제 #5
0
 def test_mount_gluster_vol_mounted_ensure(self):
     def exec_runner(*ignore_args, **ignore_kwargs):
         raise exception.ProcessExecutionError(stderr='already mounted')
     expected_exec = self._mount_exec(fakeexport, fakemnt)
     common.LOG.warning = mock.Mock()
     fake_utils.fake_execute_set_repliers([('mount', exec_runner)])
     ret = common._mount_gluster_vol(self._execute, fakeexport, fakemnt,
                                     True)
     self.assertEqual(fake_utils.fake_execute_get_log(), expected_exec)
     self.assertIsNone(ret)
     common.LOG.warning.assert_called_with(
         "%s is already mounted.", fakeexport)
예제 #6
0
 def test_mount_gluster_vol_mounted_ensure(self):
     def exec_runner(*ignore_args, **ignore_kwargs):
         raise exception.ProcessExecutionError(stderr='already mounted')
     expected_exec = self._mount_exec(fakeexport, fakemnt)
     common.LOG.warning = mock.Mock()
     fake_utils.fake_execute_set_repliers([('mount', exec_runner)])
     ret = common._mount_gluster_vol(self._execute, fakeexport, fakemnt,
                                     True)
     self.assertEqual(fake_utils.fake_execute_get_log(), expected_exec)
     self.assertIsNone(ret)
     common.LOG.warning.assert_called_with(
         "%s is already mounted.", fakeexport)
예제 #7
0
 def test_mount_gluster_vol(self):
     expected_exec = self._mount_exec(fakeexport, fakemnt)
     ret = common._mount_gluster_vol(self._execute, fakeexport, fakemnt,
                                     False)
     self.assertEqual(fake_utils.fake_execute_get_log(), expected_exec)
     self.assertIsNone(ret)
예제 #8
0
 def test_mount_gluster_vol(self):
     expected_exec = self._mount_exec(fakeexport, fakemnt)
     ret = common._mount_gluster_vol(self._execute, fakeexport, fakemnt,
                                     False)
     self.assertEqual(fake_utils.fake_execute_get_log(), expected_exec)
     self.assertIsNone(ret)