コード例 #1
0
ファイル: test_remotefs.py プロジェクト: e0ne/os-brick
 def test_init_sets_mount_base(self):
     client = remotefs.RemoteFsClient("cifs", root_helper='true',
                                      smbfs_mount_point_base='/fake',
                                      cifs_mount_point_base='/fake2')
     # Tests that although the FS type is "cifs", the config option
     # starts with "smbfs_"
     self.assertEqual('/fake', client._mount_base)
コード例 #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
コード例 #3
0
 def test_mount_race(self, mock_execute):
     err_msg = 'mount.nfs: /var/asdf is already mounted'
     mock_execute.side_effect = putils.ProcessExecutionError(stderr=err_msg)
     client = remotefs.RemoteFsClient("nfs",
                                      root_helper='true',
                                      nfs_mount_point_base='/var/asdf')
     client._do_mount('nfs', '192.0.2.20:/share', '/var/asdf')
コード例 #4
0
 def test_vzstorage_with_auth(self, mock_read_mounts):
     client = remotefs.RemoteFsClient("vzstorage",
                                      root_helper='true',
                                      execute=putils.execute,
                                      vzstorage_mount_point_base='/mnt')
     cluster_name = 'qwe'
     password = '******'
     share = '%s:%s' % (cluster_name, password)
     mount_point = client.get_mount_point(share)
     client.mount(share)
     calls = [
         mock.call('mkdir', '-p', mount_point, check_exit_code=0),
         mock.call('pstorage',
                   '-c',
                   cluster_name,
                   'auth-node',
                   '-P',
                   process_input=password,
                   root_helper='true',
                   run_as_root=True),
         mock.call('pstorage-mount',
                   '-c',
                   cluster_name,
                   mount_point,
                   root_helper='true',
                   check_exit_code=0,
                   run_as_root=True)
     ]
     self.mock_execute.assert_has_calls(calls)
コード例 #5
0
ファイル: nfs.py プロジェクト: yachika-ralhan/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', 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
コード例 #6
0
    def __init__(self, execute=putils.execute, *args, **kwargs):
        self._remotefsclient = None
        super(NfsDriver, self).__init__(*args, **kwargs)
        self.configuration.append_config_values(nfs_opts)
        root_helper = utils.get_root_helper()
        # base bound to instance is used in RemoteFsConnector.
        self.base = getattr(self.configuration,
                            'nfs_mount_point_base',
                            CONF.nfs_mount_point_base)
        self.base = os.path.realpath(self.base)
        opts = getattr(self.configuration,
                       'nfs_mount_options',
                       CONF.nfs_mount_options)

        nas_mount_options = getattr(self.configuration,
                                    'nas_mount_options',
                                    None)
        if nas_mount_options is not None:
            LOG.debug('overriding nfs_mount_options with nas_mount_options')
            opts = nas_mount_options

        self._remotefsclient = remotefs_brick.RemoteFsClient(
            'nfs', root_helper, execute=execute,
            nfs_mount_point_base=self.base,
            nfs_mount_options=opts)
コード例 #7
0
    def __init__(self, execute=putils.execute, *args, **kwargs):
        self._remotefsclient = None
        super(NfsDriver, self).__init__(*args, **kwargs)
        self.configuration.append_config_values(nfs_opts)
        root_helper = utils.get_root_helper()
        # base bound to instance is used in RemoteFsConnector.
        self.base = getattr(self.configuration, 'nfs_mount_point_base')
        self.base = os.path.realpath(self.base)
        opts = getattr(self.configuration, 'nfs_mount_options')

        nas_mount_options = getattr(self.configuration, 'nas_mount_options',
                                    None)
        if nas_mount_options is not None:
            LOG.debug('overriding nfs_mount_options with nas_mount_options')
            opts = nas_mount_options

        self._remotefsclient = remotefs_brick.RemoteFsClient(
            'nfs',
            root_helper,
            execute=execute,
            nfs_mount_point_base=self.base,
            nfs_mount_options=opts)

        self._sparse_copy_volume_data = True
        self.reserved_percentage = self.configuration.reserved_percentage
        self.max_over_subscription_ratio = (
            self.configuration.max_over_subscription_ratio)
コード例 #8
0
ファイル: test_remotefs.py プロジェクト: e0ne/os-brick
    def test_vzstorage_with_mds_list(self, mock_read_mounts, mock_exists):
        client = remotefs.RemoteFsClient("vzstorage", root_helper='true',
                                         vzstorage_mount_point_base='/mnt')
        cluster_name = 'qwe'
        mds_list = ['10.0.0.1', '10.0.0.2']
        share = '%s:/%s' % (','.join(mds_list), cluster_name)
        mount_point = client.get_mount_point(share)
        vz_conf_dir = os.path.join('/etc/pstorage/clusters/', cluster_name)

        tmp_dir = '/tmp/fake_dir/'

        with mock.patch.object(tempfile, 'mkdtemp',
                               return_value=tmp_dir):
            mock_open = mock.mock_open()
            with mock.patch.object(six.moves.builtins, "open",
                                   mock_open, create=True):
                client.mount(share)

                write_calls = [mock.call(tmp_dir + 'bs_list', 'w'),
                               mock.call().__enter__(),
                               mock.call().write('10.0.0.1\n'),
                               mock.call().write('10.0.0.2\n'),
                               mock.call().__exit__(None, None, None)]

                mock_open.assert_has_calls(write_calls)
        calls = [mock.call('mkdir', '-p', mount_point, check_exit_code=0),
                 mock.call('cp', '-rf', tmp_dir, vz_conf_dir,
                           run_as_root=True, root_helper='true'),
                 mock.call('chown', '-R', 'root:root', vz_conf_dir,
                           run_as_root=True, root_helper='true'),
                 mock.call('pstorage-mount', '-c', cluster_name, mount_point,
                           root_helper='true', check_exit_code=0,
                           run_as_root=True)]
        self.mock_execute.assert_has_calls(calls)
コード例 #9
0
    def test_init_nfs_calls_check_nfs_options(self):
        to_patch = remotefs.RemoteFsClient._check_nfs_options
        with mock.patch.object(to_patch) as mock_check_nfs_options:
            remotefs.RemoteFsClient("nfs",
                                    root_helper='true',
                                    nfs_mount_point_base='/fake')

        mock_check_nfs_options.assert_called_once_with()
コード例 #10
0
ファイル: nfs.py プロジェクト: homolkad/deb-cinder
 def _init_backup_repo_path(self):
     remotefsclient = remotefs_brick.RemoteFsClient(
         'nfs',
         utils.get_root_helper(),
         nfs_mount_point_base=self.backup_mount_point_base,
         nfs_mount_options=self.mount_options)
     remotefsclient.mount(self.backup_share)
     return remotefsclient.get_mount_point(self.backup_share)
コード例 #11
0
 def test_mount_failure(self, mock_execute):
     err_msg = 'mount.nfs: nfs broke'
     mock_execute.side_effect = putils.ProcessExecutionError(stderr=err_msg)
     client = remotefs.RemoteFsClient("nfs",
                                      root_helper='true',
                                      nfs_mount_point_base='/var/asdf')
     self.assertRaises(putils.ProcessExecutionError, client._do_mount,
                       'nfs', '192.0.2.20:/share', '/var/asdf')
コード例 #12
0
ファイル: test_remotefs.py プロジェクト: e0ne/os-brick
 def test_read_mounts(self):
     mounts = """device1 on mnt_point1
                 device2 on mnt_point2 type ext4 opts"""
     with mock.patch.object(priv_rootwrap, 'execute',
                            return_value=[mounts, '']):
         client = remotefs.RemoteFsClient("cifs", root_helper='true',
                                          smbfs_mount_point_base='/mnt')
         ret = client._read_mounts()
         self.assertEqual(ret, {'mnt_point1': 'device1',
                                'mnt_point2': 'device2'})
コード例 #13
0
ファイル: test_remotefs.py プロジェクト: e0ne/os-brick
 def test_mount_already_mounted(self, mock_do_mount, mock_execute):
     share = "10.0.0.1:/share"
     client = remotefs.RemoteFsClient("cifs", root_helper='true',
                                      smbfs_mount_point_base='/mnt')
     mounts = {client.get_mount_point(share): 'some_dev'}
     with mock.patch.object(client, '_read_mounts',
                            return_value=mounts):
         client.mount(share)
         self.assertEqual(mock_do_mount.call_count, 0)
         self.assertEqual(mock_execute.call_count, 0)
コード例 #14
0
    def test_mount_race(self, mock_execute):
        err_msg = 'mount.nfs: /var/asdf is already mounted'
        mock_execute.side_effect = putils.ProcessExecutionError(stderr=err_msg)
        mounts = {'192.0.2.20:/share': '/var/asdf/'}
        client = remotefs.RemoteFsClient("nfs",
                                         root_helper='true',
                                         nfs_mount_point_base='/var/asdf')

        with mock.patch.object(client, '_read_mounts', return_value=mounts):
            client._do_mount('nfs', '192.0.2.20:/share', '/var/asdf')
コード例 #15
0
ファイル: test_remotefs.py プロジェクト: e0ne/os-brick
 def test_cifs(self, mock_read_mounts):
     client = remotefs.RemoteFsClient("cifs", root_helper='true',
                                      smbfs_mount_point_base='/mnt')
     share = '10.0.0.1:/qwe'
     mount_point = client.get_mount_point(share)
     client.mount(share)
     calls = [mock.call('mkdir', '-p', mount_point, check_exit_code=0),
              mock.call('mount', '-t', 'cifs', share, mount_point,
                        run_as_root=True, root_helper='true',
                        check_exit_code=0)]
     self.mock_execute.assert_has_calls(calls)
コード例 #16
0
ファイル: glusterfs.py プロジェクト: simplivity/cinder
 def __init__(self, execute=processutils.execute, *args, **kwargs):
     self._remotefsclient = None
     super(GlusterfsDriver, self).__init__(*args, **kwargs)
     self.configuration.append_config_values(volume_opts)
     root_helper = utils.get_root_helper()
     self.base = getattr(self.configuration,
                         'glusterfs_mount_point_base',
                         CONF.glusterfs_mount_point_base)
     self._remotefsclient = remotefs_brick.RemoteFsClient(
         'glusterfs', root_helper, execute,
         glusterfs_mount_point_base=self.base)
コード例 #17
0
ファイル: test_remotefs.py プロジェクト: e0ne/os-brick
 def test_vzstorage_by_cluster_name(self, mock_read_mounts):
     client = remotefs.RemoteFsClient("vzstorage", root_helper='true',
                                      vzstorage_mount_point_base='/mnt')
     share = 'qwe'
     cluster_name = share
     mount_point = client.get_mount_point(share)
     client.mount(share)
     calls = [mock.call('mkdir', '-p', mount_point, check_exit_code=0),
              mock.call('pstorage-mount', '-c', cluster_name, mount_point,
                        root_helper='true', check_exit_code=0,
                        run_as_root=True)]
     self.mock_execute.assert_has_calls(calls)
コード例 #18
0
    def __init__(self, execute=putils.execute, *args, **kwargs):
        self._remotefsclient = None
        super(VZStorageDriver, self).__init__(*args, **kwargs)
        self.configuration.append_config_values(vzstorage_opts)
        self._execute_as_root = False
        root_helper = utils.get_root_helper()
        # base bound to instance is used in RemoteFsConnector.
        self.base = self.configuration.vzstorage_mount_point_base
        opts = self.configuration.vzstorage_mount_options

        self._remotefsclient = remotefs.RemoteFsClient(
            'vzstorage', root_helper, execute=execute,
            vzstorage_mount_point_base=self.base,
            vzstorage_mount_options=opts)
コード例 #19
0
 def __init__(self, execute=putils.execute, *args, **kwargs):
     self._remotefsclient = None
     super(SmbfsDriver, self).__init__(*args, **kwargs)
     self.configuration.append_config_values(volume_opts)
     root_helper = utils.get_root_helper()
     self.base = getattr(self.configuration, 'smbfs_mount_point_base')
     opts = getattr(self.configuration, 'smbfs_mount_options')
     self._remotefsclient = remotefs.RemoteFsClient(
         'cifs',
         root_helper,
         execute=execute,
         smbfs_mount_point_base=self.base,
         smbfs_mount_options=opts)
     self.img_suffix = None
コード例 #20
0
 def test_read_mounts(self):
     mounts = """device1 mnt_point1 ext4 rw,seclabel,relatime 0 0
                 device2 mnt_point2 ext4 rw,seclabel,relatime 0 0"""
     with mock.patch('os_brick.remotefs.remotefs.open',
                     mock.mock_open(read_data=mounts)) as mock_open:
         client = remotefs.RemoteFsClient("cifs",
                                          root_helper='true',
                                          smbfs_mount_point_base='/mnt')
         ret = client._read_mounts()
         mock_open.assert_called_once_with('/proc/mounts', 'r')
     self.assertEqual(ret, {
         'mnt_point1': 'device1',
         'mnt_point2': 'device2'
     })
コード例 #21
0
 def test_read_mounts(self):
     mounts = """device1 mnt_point1 ext4 rw,seclabel,relatime 0 0
                 device2 mnt_point2 ext4 rw,seclabel,relatime 0 0"""
     mockopen = mock.mock_open(read_data=mounts)
     mockopen.return_value.__iter__ = lambda self: iter(self.readline, '')
     with mock.patch.object(six.moves.builtins,
                            "open",
                            mockopen,
                            create=True):
         client = remotefs.RemoteFsClient("cifs",
                                          root_helper='true',
                                          smbfs_mount_point_base='/mnt')
         ret = client._read_mounts()
     self.assertEqual(ret, {
         'mnt_point1': 'device1',
         'mnt_point2': 'device2'
     })
コード例 #22
0
    def test_vzstorage_with_mds_list(self, mock_read_mounts):
        client = remotefs.RemoteFsClient("vzstorage",
                                         root_helper='true',
                                         execute=putils.execute,
                                         vzstorage_mount_point_base='/mnt')
        cluster_name = 'qwe'
        mds_list = ['10.0.0.1', '10.0.0.2']
        share = '%s:/%s' % (','.join(mds_list), cluster_name)
        mount_point = client.get_mount_point(share)
        vz_conf_dir = os.path.join('/etc/pstorage/clusters/', cluster_name)

        tmp_dir = tempfile.mkdtemp()
        with mock.patch.object(tempfile, 'mkdtemp', return_value=tmp_dir):
            client.mount(share)

        saved_mds_list = open(os.path.join(tmp_dir, 'bs_list')).read().split()
        self.assertEqual(set(mds_list), set(saved_mds_list))
        calls = [
            mock.call('mkdir', '-p', mount_point, check_exit_code=0),
            mock.call('cp',
                      '-rf',
                      tmp_dir,
                      vz_conf_dir,
                      run_as_root=True,
                      root_helper='true'),
            mock.call('chown',
                      '-R',
                      'root:root',
                      vz_conf_dir,
                      run_as_root=True,
                      root_helper='true'),
            mock.call('pstorage-mount',
                      '-c',
                      cluster_name,
                      mount_point,
                      root_helper='true',
                      check_exit_code=0,
                      run_as_root=True)
        ]
        self.mock_execute.assert_has_calls(calls)
コード例 #23
0
 def test_nfs(self, mock_read_mounts):
     client = remotefs.RemoteFsClient("nfs",
                                      root_helper='true',
                                      execute=putils.execute,
                                      nfs_mount_point_base='/mnt')
     share = '10.0.0.1:/qwe'
     mount_point = client.get_mount_point(share)
     client.mount(share)
     calls = [
         mock.call('mkdir', '-p', mount_point, check_exit_code=0),
         mock.call('mount',
                   '-t',
                   'nfs',
                   '-o',
                   'vers=4,minorversion=1',
                   share,
                   mount_point,
                   check_exit_code=0,
                   run_as_root=True,
                   root_helper='true')
     ]
     self.mock_execute.assert_has_calls(calls)
コード例 #24
0
ファイル: test_remotefs.py プロジェクト: e0ne/os-brick
 def test_init_nfs_calls_check_nfs_options(self, mock_check_nfs_options):
     remotefs.RemoteFsClient("nfs", root_helper='true',
                             nfs_mount_point_base='/fake')
     mock_check_nfs_options.assert_called_once_with()
コード例 #25
0
ファイル: test_remotefs.py プロジェクト: e0ne/os-brick
 def test_vzstorage_invalid_share(self, mock_read_mounts):
     client = remotefs.RemoteFsClient("vzstorage", root_helper='true',
                                      vzstorage_mount_point_base='/mnt')
     self.assertRaises(exception.BrickException, client.mount, ':')