Esempio n. 1
0
    def _init_backup_repo_path(self):
        remotefsclient = remotefs_brick.RemoteFsClient(
            'glusterfs',
            self._root_helper,
            glusterfs_mount_point_base=self.backup_mount_point_base)
        remotefsclient.mount(self.backup_share)

        # Ensure we can write to this share
        mount_path = remotefsclient.get_mount_point(self.backup_share)

        group_id = os.getegid()
        current_group_id = utils.get_file_gid(mount_path)
        current_mode = utils.get_file_mode(mount_path)

        if group_id != current_group_id:
            cmd = ['chgrp', group_id, mount_path]
            self._execute(*cmd, root_helper=self._root_helper,
                          run_as_root=True)

        if not (current_mode & stat.S_IWGRP):
            cmd = ['chmod', 'g+w', mount_path]
            self._execute(*cmd, root_helper=self._root_helper,
                          run_as_root=True)

        return mount_path
Esempio n. 2
0
    def _init_backup_repo_path(self):
        remotefsclient = remotefs_brick.RemoteFsClient(
            'glusterfs',
            self._root_helper,
            glusterfs_mount_point_base=self.backup_mount_point_base)
        remotefsclient.mount(self.backup_share)

        # Ensure we can write to this share
        mount_path = remotefsclient.get_mount_point(self.backup_share)

        group_id = os.getegid()
        current_group_id = utils.get_file_gid(mount_path)
        current_mode = utils.get_file_mode(mount_path)

        if group_id != current_group_id:
            cmd = ['chgrp', group_id, mount_path]
            self._execute(*cmd,
                          root_helper=self._root_helper,
                          run_as_root=True)

        if not (current_mode & stat.S_IWGRP):
            cmd = ['chmod', 'g+w', mount_path]
            self._execute(*cmd,
                          root_helper=self._root_helper,
                          run_as_root=True)

        return mount_path
Esempio n. 3
0
    def _init_backup_repo_path(self):
        if self.backup_share is None:
            LOG.info("_init_backup_repo_path: "
                     "backup_share is not set in configuration")
            return

        remotefsclient = remotefs_brick.RemoteFsClient(
            'nfs',
            self._root_helper,
            nfs_mount_point_base=self.backup_mount_point_base,
            nfs_mount_options=self.mount_options)
        remotefsclient.mount(self.backup_share)

        # Ensure we can write to this share
        mount_path = remotefsclient.get_mount_point(self.backup_share)

        group_id = os.getegid()
        current_group_id = utils.get_file_gid(mount_path)
        current_mode = utils.get_file_mode(mount_path)

        if group_id != current_group_id:
            cmd = ['chgrp', '-R', group_id, mount_path]
            self._execute(*cmd,
                          root_helper=self._root_helper,
                          run_as_root=True)

        if not (current_mode & stat.S_IWGRP):
            cmd = ['chmod', '-R', 'g+w', mount_path]
            self._execute(*cmd,
                          root_helper=self._root_helper,
                          run_as_root=True)

        return mount_path
Esempio n. 4
0
File: nfs.py Progetto: mahak/cinder
    def _init_backup_repo_path(self):
        if self.backup_share is None:
            LOG.info("_init_backup_repo_path: "
                     "backup_share is not set in configuration")
            return

        remotefsclient = remotefs_brick.RemoteFsClient(
            'nfs',
            self._root_helper,
            nfs_mount_point_base=self.backup_mount_point_base,
            nfs_mount_options=self.mount_options)
        remotefsclient.mount(self.backup_share)

        # Ensure we can write to this share
        mount_path = remotefsclient.get_mount_point(self.backup_share)

        group_id = os.getegid()
        current_group_id = utils.get_file_gid(mount_path)
        current_mode = utils.get_file_mode(mount_path)

        if group_id != current_group_id:
            cmd = ['chgrp', '-R', group_id, mount_path]
            self._execute(*cmd, root_helper=self._root_helper,
                          run_as_root=True)

        if not (current_mode & stat.S_IWGRP):
            cmd = ['chmod', '-R', 'g+w', mount_path]
            self._execute(*cmd, root_helper=self._root_helper,
                          run_as_root=True)

        return mount_path
Esempio n. 5
0
    def test_get_file_gid(self, mock_stat):
        class stat_result:
            st_mode = 0o777
            st_gid = 33333

        test_file = '/var/tmp/made_up_file'
        mock_stat.return_value = stat_result
        gid = utils.get_file_gid(test_file)
        self.assertEqual(gid, 33333)
        mock_stat.assert_called_once_with(test_file)
Esempio n. 6
0
    def test_get_file_gid(self, mock_stat):

        class stat_result:
            st_mode = 0o777
            st_gid = 33333

        test_file = '/var/tmp/made_up_file'
        mock_stat.return_value = stat_result
        gid = utils.get_file_gid(test_file)
        self.assertEqual(gid, 33333)
        mock_stat.assert_called_once_with(test_file)
Esempio n. 7
0
    def test_get_file_gid(self):
        test_file = '/var/tmp/made_up_file'

        orig_os_stat = os.stat
        os.stat = self._make_fake_stat(test_file, orig_os_stat)

        self.mox.ReplayAll()

        gid = utils.get_file_gid(test_file)
        self.assertEqual(gid, 33333)

        self.mox.VerifyAll()

        os.stat = orig_os_stat
Esempio n. 8
0
    def test_get_file_gid(self):
        test_file = '/var/tmp/made_up_file'

        orig_os_stat = os.stat
        os.stat = self._make_fake_stat(test_file, orig_os_stat)

        self.mox.ReplayAll()

        gid = utils.get_file_gid(test_file)
        self.assertEqual(gid, 33333)

        self.mox.VerifyAll()

        os.stat = orig_os_stat
Esempio n. 9
0
    def _ensure_share_mounted(self, glusterfs_share):
        """Mount GlusterFS share.
        :param glusterfs_share: string
        """
        mount_path = self._get_mount_point_for_share(glusterfs_share)
        self._mount_glusterfs(glusterfs_share, mount_path, ensure=True)

        # Ensure we can write to this share
        group_id = os.getegid()
        current_group_id = utils.get_file_gid(mount_path)
        current_mode = utils.get_file_mode(mount_path)

        if group_id != current_group_id:
            cmd = ['chgrp', group_id, mount_path]
            self._execute(*cmd, run_as_root=True)

        if not (current_mode & stat.S_IWGRP):
            cmd = ['chmod', 'g+w', mount_path]
            self._execute(*cmd, run_as_root=True)

        self._ensure_share_writable(mount_path)
Esempio n. 10
0
    def _ensure_share_mounted(self, glusterfs_share):
        """Mount GlusterFS share.
        :param glusterfs_share: string
        """
        mount_path = self._get_mount_point_for_share(glusterfs_share)
        self._mount_glusterfs(glusterfs_share, mount_path, ensure=True)

        # Ensure we can write to this share
        group_id = os.getegid()
        current_group_id = utils.get_file_gid(mount_path)
        current_mode = utils.get_file_mode(mount_path)

        if group_id != current_group_id:
            cmd = ['chgrp', group_id, mount_path]
            self._execute(*cmd, run_as_root=True)

        if not (current_mode & stat.S_IWGRP):
            cmd = ['chmod', 'g+w', mount_path]
            self._execute(*cmd, run_as_root=True)

        self._ensure_share_writable(mount_path)