示例#1
0
    def setUp(self):
        super(ContainerShareDriverTestCase, self).setUp()
        fake_utils.stub_out_utils_execute(self)
        self._context = context.get_admin_context()
        self._db = mock.Mock()
        self.fake_conf = configuration.Configuration(None)

        CONF.set_default('driver_handles_share_servers', True)

        self._driver = driver.ContainerShareDriver(
            configuration=self.fake_conf)

        self.share = cont_fakes.fake_share()
        self.access = cont_fakes.fake_access()
        self.server = {
            'public_address': self.fake_conf.lvm_share_export_ip,
            'instance_id': 'LVM',
        }

        # Used only to test compatibility with share manager
        self.share_server = "fake_share_server"
示例#2
0
    def setUp(self):
        super(CmdConnectorTest, self).setUp()

        self.configuration = conf.Configuration(None)
        self.configuration.append_config_values = mock.Mock(return_value=0)
        self.configuration.emc_nas_login = fakes.FakeData.emc_nas_login
        self.configuration.emc_nas_password = fakes.FakeData.emc_nas_password
        self.configuration.emc_nas_server = fakes.FakeData.emc_nas_server

        self.sshpool = MockSSHPool()
        with mock.patch.object(utils, "SSHPool",
                               mock.Mock(return_value=self.sshpool)):
            self.CmdHelper = connector.SSHConnector(
                configuration=self.configuration, debug=False)

            utils.SSHPool.assert_called_once_with(
                ip=fakes.FakeData.emc_nas_server,
                port=22,
                conn_timeout=None,
                login=fakes.FakeData.emc_nas_login,
                password=fakes.FakeData.emc_nas_password)
示例#3
0
    def setUp(self):
        super(GaneshaNASHelper2TestCase, self).setUp()

        CONF.set_default('ganesha_config_path', '/fakedir0/fakeconfig')
        CONF.set_default('ganesha_db_path', '/fakedir1/fake.db')
        CONF.set_default('ganesha_export_dir', '/fakedir0/export.d')
        CONF.set_default('ganesha_export_template_dir',
                         '/fakedir2/faketempl.d')
        CONF.set_default('ganesha_service_name', 'ganesha.fakeservice')
        self._context = context.get_admin_context()
        self._execute = mock.Mock(return_value=('', ''))
        self.fake_conf = config.Configuration(None)
        self.fake_conf_dir_path = '/fakedir0/exports.d'
        self._helper = ganesha.GaneshaNASHelper2(self._execute,
                                                 self.fake_conf,
                                                 tag='faketag')
        self._helper.ganesha = mock.Mock()
        self._helper.export_template = {}
        self.share = fake_share.fake_share()
        self.rule1 = fake_share.fake_access(access_level='ro')
        self.rule2 = fake_share.fake_access(access_level='rw',
                                            access_to='10.0.0.2')
示例#4
0
    def setUp(self):
        super(NativeProtocolHelperTestCase, self).setUp()
        self.fake_conf = configuration.Configuration(None)
        self._context = context.get_admin_context()
        self._share = fake_share.fake_share_instance(share_proto='CEPHFS')

        self.fake_conf.set_default('driver_handles_share_servers', False)

        self.mock_object(driver, "rados_command")

        driver.ceph_default_target = ('mon-mgr', )

        self._native_protocol_helper = driver.NativeProtocolHelper(
            None,
            self.fake_conf,
            rados_client=MockRadosModule.Rados(),
            volname="cephfs")

        self._rados_client = self._native_protocol_helper.rados_client

        self._native_protocol_helper.get_mon_addrs = mock.Mock(
            return_value=['1.2.3.4', '5.6.7.8'])
示例#5
0
 def setUp(self):
     super(NetAppCDOTDataMotionTestCase, self).setUp()
     self.backend = 'backend1'
     self.mock_cmode_client = self.mock_object(client_cmode,
                                               "NetAppCmodeClient",
                                               mock.Mock())
     self.config = configuration.Configuration(driver.share_opts,
                                               config_group=self.backend)
     self.config.append_config_values(na_opts.netapp_cluster_opts)
     self.config.append_config_values(na_opts.netapp_connection_opts)
     self.config.append_config_values(na_opts.netapp_basicauth_opts)
     self.config.append_config_values(na_opts.netapp_transport_opts)
     self.config.append_config_values(na_opts.netapp_support_opts)
     self.config.append_config_values(na_opts.netapp_provisioning_opts)
     self.config.append_config_values(na_opts.netapp_data_motion_opts)
     CONF.set_override("share_backend_name",
                       self.backend,
                       group=self.backend,
                       enforce_type=True)
     CONF.set_override("netapp_transport_type",
                       "https",
                       group=self.backend,
                       enforce_type=True)
     CONF.set_override("netapp_login",
                       "fake_user",
                       group=self.backend,
                       enforce_type=True)
     CONF.set_override("netapp_password",
                       "fake_password",
                       group=self.backend,
                       enforce_type=True)
     CONF.set_override("netapp_server_hostname",
                       "fake_hostname",
                       group=self.backend,
                       enforce_type=True)
     CONF.set_override("netapp_server_port",
                       8866,
                       group=self.backend,
                       enforce_type=True)
示例#6
0
    def setUp(self):
        super(CephFSDriverTestCase, self).setUp()
        self._execute = mock.Mock()
        self.fake_conf = configuration.Configuration(None)
        self._context = context.get_admin_context()
        self._share = fake_share.fake_share(share_proto='CEPHFS')

        self.fake_conf.set_default('driver_handles_share_servers', False)
        self.fake_conf.set_default('cephfs_auth_id', 'manila')

        self.mock_object(driver, "ceph_volume_client", MockVolumeClientModule)
        self.mock_object(driver, "ceph_module_found", True)
        self.mock_object(driver, "cephfs_share_path")
        self.mock_object(driver, 'NativeProtocolHelper')
        self.mock_object(driver, 'NFSProtocolHelper')

        self._driver = (driver.CephFSDriver(execute=self._execute,
                                            configuration=self.fake_conf))
        self._driver.protocol_helper = mock.Mock()

        self.mock_object(share_types, 'get_share_type_extra_specs',
                         mock.Mock(return_value={}))
    def _setup_mocks_copy_share_data(self):

        get_migration_info_value = {'mount': 'fake',
                                    'umount': 'fake',
                                    'access':
                                    {'access_type': 'fake',
                                     'access_to': 'fake'}}

        self.mock_object(rpcapi.ShareAPI, 'get_migration_info',
                         mock.Mock(return_value=get_migration_info_value))

        self.mock_object(driver.ShareDriver, 'get_migration_info',
                         mock.Mock(return_value=get_migration_info_value))

        self.mock_object(share_utils.Copy, 'run')
        self.mock_object(time, 'sleep')

        driver.CONF.set_default('driver_handles_share_servers', False)
        share_driver = driver.ShareDriver(
            False, configuration=configuration.Configuration(None))

        return share_driver
示例#8
0
    def test_migration_get_info(self, admin):

        expected = {
            'mount': 'mount -vt fake_proto /fake/fake_id %(path)s',
            'unmount': 'umount -v %(path)s'
        }
        fake_share = {
            'id': 'fake_id',
            'share_proto': 'fake_proto',
            'export_locations': [{
                'path': '/fake/fake_id',
                'is_admin_only': admin
            }]
        }

        driver.CONF.set_default('driver_handles_share_servers', False)
        share_driver = driver.ShareDriver(False)
        share_driver.configuration = configuration.Configuration(None)

        migration_info = share_driver.migration_get_info(
            None, fake_share, "fake_server")

        self.assertEqual(expected, migration_info)
示例#9
0
    def setUp(self):
        super(GlusterfsShareDriverTestCase, self).setUp()
        fake_utils.stub_out_utils_execute(self)
        self._execute = fake_utils.fake_execute
        self._context = context.get_admin_context()
        self.addCleanup(fake_utils.fake_execute_set_repliers, [])
        self.addCleanup(fake_utils.fake_execute_clear_log)

        CONF.set_default('glusterfs_target', '127.0.0.1:/testvol')
        CONF.set_default('glusterfs_mount_point_base', '/mnt/nfs')
        CONF.set_default('reserved_share_percentage', 50)
        CONF.set_default('glusterfs_server_password',
                         fake_remote_server_password)
        CONF.set_default('glusterfs_path_to_private_key',
                         fake_path_to_private_key)
        CONF.set_default('driver_handles_share_servers', False)

        self.fake_conf = config.Configuration(None)
        self._driver = glusterfs.GlusterfsShareDriver(
            execute=self._execute, configuration=self.fake_conf)
        self._driver.gluster_manager = mock.Mock(**fake_gluster_manager_attrs)
        self._helper_nfs = mock.Mock()
        self.share = fake_share.fake_share(share_proto='NFS')
示例#10
0
    def test_get_share_stats_refresh_true(self):
        conf = configuration.Configuration(None)
        expected_keys = [
            'QoS_support',
            'driver_version',
            'share_backend_name',
            'free_capacity_gb',
            'total_capacity_gb',
            'driver_handles_share_servers',
            'reserved_percentage',
            'vendor_name',
            'storage_protocol',
        ]
        share_driver = driver.ShareDriver(True, configuration=conf)
        fake_stats = {'fake_key': 'fake_value'}
        share_driver._stats = fake_stats

        result = share_driver.get_share_stats(True)

        self.assertNotEqual(fake_stats, result)
        for key in expected_keys:
            self.assertIn(key, result)
        self.assertEqual('Open Source', result['vendor_name'])
示例#11
0
def get_backend_configuration(backend_name):
    config_stanzas = CONF.list_all_sections()
    if backend_name not in config_stanzas:
        msg = _("Could not find backend stanza %(backend_name)s in "
                "configuration which is required for replication with "
                "the backend. Available stanzas are %(stanzas)s")
        params = {
            "stanzas": config_stanzas,
            "backend_name": backend_name,
        }
        raise exception.BadConfigurationException(reason=msg % params)

    config = configuration.Configuration(driver.share_opts,
                                         config_group=backend_name)
    config.append_config_values(na_opts.netapp_cluster_opts)
    config.append_config_values(na_opts.netapp_connection_opts)
    config.append_config_values(na_opts.netapp_basicauth_opts)
    config.append_config_values(na_opts.netapp_transport_opts)
    config.append_config_values(na_opts.netapp_support_opts)
    config.append_config_values(na_opts.netapp_provisioning_opts)
    config.append_config_values(na_opts.netapp_replication_opts)

    return config
示例#12
0
    def setUp(self):
        super(SopShareDriverTestCase, self).setUp()
        self._context = context.get_admin_context()
        self.server = {
            'instance_id': 'fake_instance_id',
            'ip': 'fake_ip',
            'username': '******',
            'password': '******',
            'pk_path': 'fake_pk_path',
            'backend_details': {
                'ip': '1.2.3.4',
                'instance_id': 'fake',
            },
        }
        CONF.set_default('hdssop_target', 'https://1.2.3.4')
        CONF.set_default('hdssop_adminuser', 'fakeuser')
        CONF.set_default('hdssop_adminpassword', 'fakepassword')
        CONF.set_default('driver_handles_share_servers', False)

        self.fake_conf = config.Configuration(None)
        self._driver = sop.SopShareDriver(configuration=self.fake_conf)
        self.share = fake_share.fake_share(share_proto='NFS')
        self._driver.share_backend_name = 'HDS_SOP'
示例#13
0
    def setUp(self):
        super(NetApp7modeDrvTestCase, self).setUp()
        self._context = context.get_admin_context()
        self._db = mock.Mock()
        self.driver = driver.NetAppShareDriver(
            self._db, configuration=configuration.Configuration(None))
        self.driver._client = mock.Mock()
        self.driver._client.send_request = mock.Mock()

        self.share = {
            'id': 'fake_uuid',
            'tenant_id': 'fake_tenant_id',
            'name': 'fake_name',
            'size': 1,
            'share_proto': 'fake'
        }
        self.snapshot = {
            'id': 'fake_snapshot_uuid',
            'tenant_id': 'fake_tenant_id',
            'share_id': 'fake_share_id'
        }
        self.helper = mock.Mock()
        self.driver._helpers = {'FAKE': self.helper}
        self.driver._licenses = ['fake']
示例#14
0
    def test_get_export_locations_with_export_ips_configured(self):
        fake_conf = configuration.Configuration(None)
        conf_args_list = [
            ('cephfs_ganesha_server_ip', '1.2.3.4'),
            ('cephfs_ganesha_export_ips', '127.0.0.1,fd3f:c057:1192:1::1,::1')]
        for args in conf_args_list:
            fake_conf.set_default(*args)

        helper = driver.NFSProtocolHelper(
            self._execute,
            fake_conf,
            ceph_vol_client=MockVolumeClientModule.CephFSVolumeClient()
        )

        cephfs_volume = {"mount_path": "/foo/bar"}

        ret = helper.get_export_locations(self._share, cephfs_volume)

        self.assertEqual(
            [
                {
                    'path': '127.0.0.1:/foo/bar',
                    'is_admin_only': False,
                    'metadata': {},
                },
                {
                    'path': '[fd3f:c057:1192:1::1]:/foo/bar',
                    'is_admin_only': False,
                    'metadata': {},
                },
                {
                    'path': '[::1]:/foo/bar',
                    'is_admin_only': False,
                    'metadata': {},
                },
            ], ret)
示例#15
0
    def test_init_identify_local_host(self, ganesha_server_ip):
        self.mock_object(driver.LOG, 'info')
        fake_conf = configuration.Configuration(None)
        conf_args_list = [('cephfs_ganesha_server_ip', ganesha_server_ip),
                          ('cephfs_ganesha_server_username', 'fake_username'),
                          ('cephfs_ganesha_server_password', 'fakepwd'),
                          ('cephfs_ganesha_path_to_private_key',
                           'fakepathtokey')]
        for args in conf_args_list:
            fake_conf.set_default(*args)

        driver.NFSProtocolHelper(
            self._execute,
            fake_conf,
            ceph_vol_client=MockVolumeClientModule.CephFSVolumeClient())

        driver.ganesha_utils.RootExecutor.assert_has_calls(
            [mock.call(self._execute)])
        if ganesha_server_ip:
            self.assertFalse(driver.socket.gethostname.called)
            self.assertFalse(driver.LOG.info.called)
        else:
            driver.socket.gethostname.assert_called_once_with()
            driver.LOG.info.assert_called_once()
    def setUp(self):
        super(GlusterfsDirectoryMappedLayoutTestCase, self).setUp()
        fake_utils.stub_out_utils_execute(self)
        self._execute = fake_utils.fake_execute
        self._context = context.get_admin_context()
        self.addCleanup(fake_utils.fake_execute_set_repliers, [])
        self.addCleanup(fake_utils.fake_execute_clear_log)

        CONF.set_default('glusterfs_target', '127.0.0.1:/testvol')
        CONF.set_default('glusterfs_mount_point_base', '/mnt/nfs')
        CONF.set_default('glusterfs_server_password',
                         fake_remote_server_password)
        CONF.set_default('glusterfs_path_to_private_key',
                         fake_path_to_private_key)

        self.fake_driver = mock.Mock()
        self.mock_object(self.fake_driver, '_execute', self._execute)
        self.fake_driver.GLUSTERFS_VERSION_MIN = (3, 6)
        self.fake_conf = config.Configuration(None)
        self.mock_object(common.GlusterManager, 'make_gluster_call')
        self._layout = layout_directory.GlusterfsDirectoryMappedLayout(
            self.fake_driver, configuration=self.fake_conf)
        self._layout.gluster_manager = mock.Mock(**fake_gluster_manager_attrs)
        self.share = fake_share.fake_share(share_proto='NFS')
示例#17
0
 def setUp(self):
     super(DockerExecHelperTestCase, self).setUp()
     self.fake_conf = configuration.Configuration(None)
     self.fake_conf.container_image_name = "fake_image"
     self.DockerExecHelper = container_helper.DockerExecHelper(
         configuration=self.fake_conf)
示例#18
0
    def setUp(self):
        super(GlusterfsVolumeMappedLayoutTestCase, self).setUp()
        fake_utils.stub_out_utils_execute(self)
        self._execute = fake_utils.fake_execute
        self._context = context.get_admin_context()

        self.glusterfs_target1 = 'root@host1:/gv1'
        self.glusterfs_target2 = 'root@host2:/gv2'
        self.glusterfs_server1 = 'root@host1'
        self.glusterfs_server2 = 'root@host2'
        self.glusterfs_server1_volumes = 'manila-share-1-1G\nshare1'
        self.glusterfs_server2_volumes = 'manila-share-2-2G\nshare2'
        self.share1 = new_share(
            export_location=self.glusterfs_target1,
            status=constants.STATUS_AVAILABLE)
        self.share2 = new_share(
            export_location=self.glusterfs_target2,
            status=constants.STATUS_AVAILABLE)
        gmgr = common.GlusterManager
        self.gmgr1 = gmgr(self.glusterfs_server1, self._execute, None, None,
                          requires={'volume': False})
        self.gmgr2 = gmgr(self.glusterfs_server2, self._execute, None, None,
                          requires={'volume': False})
        self.glusterfs_volumes_dict = (
            {'root@host1:/manila-share-1-1G': {'size': 1},
             'root@host2:/manila-share-2-2G': {'size': 2}})
        self.glusterfs_used_vols = set([
            'root@host1:/manila-share-1-1G',
            'root@host2:/manila-share-2-2G'])

        CONF.set_default('glusterfs_servers',
                         [self.glusterfs_server1, self.glusterfs_server2])
        CONF.set_default('glusterfs_server_password',
                         'fake_password')
        CONF.set_default('glusterfs_path_to_private_key',
                         '/fakepath/to/privatekey')
        CONF.set_default('glusterfs_volume_pattern',
                         'manila-share-\d+-#{size}G$')
        CONF.set_default('driver_handles_share_servers', False)

        self.fake_driver = mock.Mock()
        self.mock_object(self.fake_driver, '_execute',
                         self._execute)
        self.fake_driver.GLUSTERFS_VERSION_MIN = (3, 6)

        self.fake_conf = config.Configuration(None)
        self.mock_object(tempfile, 'mkdtemp',
                         mock.Mock(return_value='/tmp/tmpKGHKJ'))
        self.mock_object(common.GlusterManager, 'make_gluster_call')

        self.fake_private_storage = mock.Mock()

        with mock.patch.object(layout_volume.GlusterfsVolumeMappedLayout,
                               '_glustermanager',
                               side_effect=[self.gmgr1, self.gmgr2]):
            self._layout = layout_volume.GlusterfsVolumeMappedLayout(
                self.fake_driver, configuration=self.fake_conf,
                private_storage=self.fake_private_storage)
        self._layout.glusterfs_versions = {self.glusterfs_server1: ('3', '6'),
                                           self.glusterfs_server2: ('3', '7')}
        self.addCleanup(fake_utils.fake_execute_set_repliers, [])
        self.addCleanup(fake_utils.fake_execute_clear_log)
示例#19
0
    def test_init_nosupp_layout(self):
        conf = config.Configuration(None)
        conf.glusterfs_share_layout = 'nonsense_layout'

        self.assertRaises(exception.GlusterfsException,
                          GlusterfsFakeShareDriver, False, configuration=conf)
示例#20
0
 def setUp(self):
     super(LVMHelperTestCase, self).setUp()
     self.share = fake_share()
     self.fake_conf = configuration.Configuration(None)
     self.LVMHelper = storage_helper.LVMHelper(configuration=self.fake_conf)
示例#21
0
 def setUp(self):
     super(LVMHelperTestCase, self).setUp()
     self.share = fake_share()
     self.fake_conf = configuration.Configuration(None)
     self.fake_conf.container_volume_mount_path = "/tmp/shares"
     self.LVMHelper = storage_helper.LVMHelper(configuration=self.fake_conf)
示例#22
0
 def _setup(self):
     fake_conf = config.Configuration(None)
     fake_layout = mock.Mock()
     self.mock_object(importutils, "import_object",
                      mock.Mock(return_value=fake_layout))
     return fake_conf, fake_layout
示例#23
0
class WindowsSMBHelperTestCase(test.TestCase):
    _FAKE_SERVER = {'public_address': mock.sentinel.public_address}
    _FAKE_SHARE_NAME = "fake_share_name"
    _FAKE_SHARE = "\\\\%s\\%s" % (_FAKE_SERVER['public_address'],
                                  _FAKE_SHARE_NAME)
    _FAKE_SHARE_LOCATION = os.path.join(
        configuration.Configuration(None).share_mount_path, _FAKE_SHARE_NAME)
    _FAKE_ACCOUNT_NAME = 'FakeDomain\\FakeUser'
    _FAKE_RW_ACC_RULE = {
        'access_to': _FAKE_ACCOUNT_NAME,
        'access_level': constants.ACCESS_LEVEL_RW,
        'access_type': 'user',
    }

    def setUp(self):
        self._remote_exec = mock.Mock()
        fake_conf = configuration.Configuration(None)

        self._win_smb_helper = windows_smb_helper.WindowsSMBHelper(
            self._remote_exec, fake_conf)

        super(WindowsSMBHelperTestCase, self).setUp()

    def test_init_helper(self):
        self._win_smb_helper.init_helper(mock.sentinel.server)
        self._remote_exec.assert_called_once_with(mock.sentinel.server,
                                                  "Get-SmbShare")

    @ddt.data(True, False)
    @mock.patch.object(windows_smb_helper.WindowsSMBHelper, '_share_exists')
    def test_create_exports(self, share_exists, mock_share_exists):
        mock_share_exists.return_value = share_exists

        result = self._win_smb_helper.create_exports(self._FAKE_SERVER,
                                                     self._FAKE_SHARE_NAME)

        if not share_exists:
            cmd = [
                'New-SmbShare', '-Name', self._FAKE_SHARE_NAME, '-Path',
                self._win_smb_helper._windows_utils.normalize_path(
                    self._FAKE_SHARE_LOCATION), '-ReadAccess',
                "*%s" % self._win_smb_helper._NULL_SID
            ]
            self._remote_exec.assert_called_once_with(self._FAKE_SERVER, cmd)
        else:
            self.assertFalse(self._remote_exec.called)

        expected_exports = [
            {
                'is_admin_only': False,
                'metadata': {
                    'export_location_metadata_example': 'example'
                },
                'path': self._FAKE_SHARE
            },
        ]

        self.assertEqual(expected_exports, result)

    @mock.patch.object(windows_smb_helper.WindowsSMBHelper, '_share_exists')
    def test_remove_exports(self, mock_share_exists):
        mock_share_exists.return_value = True

        self._win_smb_helper.remove_exports(mock.sentinel.server,
                                            mock.sentinel.share_name)

        cmd = ['Remove-SmbShare', '-Name', mock.sentinel.share_name, "-Force"]
        self._remote_exec.assert_called_once_with(mock.sentinel.server, cmd)

    @mock.patch.object(windows_utils.WindowsUtils,
                       'get_volume_path_by_mount_path')
    @mock.patch.object(windows_smb_helper.WindowsSMBHelper,
                       '_get_share_path_by_name')
    def test_get_volume_path_by_share_name(self, mock_get_share_path,
                                           mock_get_vol_path):
        mock_get_share_path.return_value = self._FAKE_SHARE_LOCATION

        volume_path = self._win_smb_helper._get_volume_path_by_share_name(
            mock.sentinel.server, self._FAKE_SHARE_NAME)

        mock_get_share_path.assert_called_once_with(mock.sentinel.server,
                                                    self._FAKE_SHARE_NAME)
        mock_get_vol_path.assert_called_once_with(mock.sentinel.server,
                                                  self._FAKE_SHARE_LOCATION)

        self.assertEqual(mock_get_vol_path.return_value, volume_path)

    @ddt.data({
        'raw_out': '',
        'expected': []
    }, {
        'raw_out': '{"key": "val"}',
        'expected': [{
            "key": "val"
        }]
    }, {
        'raw_out': '[{"key": "val"}, {"key2": "val2"}]',
        'expected': [{
            "key": "val"
        }, {
            "key2": "val2"
        }]
    })
    @ddt.unpack
    def test_get_acls_helper(self, raw_out, expected):
        self._remote_exec.return_value = (raw_out, mock.sentinel.err)

        rules = self._win_smb_helper._get_acls(mock.sentinel.server,
                                               self._FAKE_SHARE_NAME)

        self.assertEqual(expected, rules)
        expected_cmd = ('Get-SmbShareAccess -Name %s | '
                        'Select-Object @("Name", "AccountName", '
                        '"AccessControlType", "AccessRight") | '
                        'ConvertTo-JSON -Compress') % self._FAKE_SHARE_NAME
        self._remote_exec.assert_called_once_with(mock.sentinel.server,
                                                  expected_cmd)

    @mock.patch.object(windows_smb_helper.WindowsSMBHelper, '_get_acls')
    def test_get_access_rules(self, mock_get_acls):
        helper = self._win_smb_helper
        valid_acl = {
            'AccountName': self._FAKE_ACCOUNT_NAME,
            'AccessRight': helper._WIN_ACCESS_RIGHT_FULL,
            'AccessControlType': helper._WIN_ACL_ALLOW,
        }

        valid_acls = [
            valid_acl,
            dict(valid_acl, AccessRight=helper._WIN_ACCESS_RIGHT_CHANGE),
            dict(valid_acl, AccessRight=helper._WIN_ACCESS_RIGHT_READ)
        ]
        # Those are rules that were not added by us and are expected to
        # be ignored. When encountering such a rule, a warning message
        # will be logged.
        ignored_acls = [
            dict(valid_acl, AccessRight=helper._WIN_ACCESS_RIGHT_CUSTOM),
            dict(valid_acl, AccessControlType=helper._WIN_ACL_DENY)
        ]

        mock_get_acls.return_value = valid_acls + ignored_acls
        # There won't be multiple access rules for the same account,
        # but we'll ignore this fact for the sake of this test.
        expected_rules = [
            self._FAKE_RW_ACC_RULE, self._FAKE_RW_ACC_RULE,
            dict(self._FAKE_RW_ACC_RULE,
                 access_level=constants.ACCESS_LEVEL_RO)
        ]

        rules = helper.get_access_rules(mock.sentinel.server,
                                        mock.sentinel.share_name)
        self.assertEqual(expected_rules, rules)

        mock_get_acls.assert_called_once_with(mock.sentinel.server,
                                              mock.sentinel.share_name)

    @mock.patch.object(windows_smb_helper.WindowsSMBHelper, '_refresh_acl')
    def test_grant_share_access(self, mock_refresh_acl):
        self._win_smb_helper._grant_share_access(mock.sentinel.server,
                                                 mock.sentinel.share_name,
                                                 constants.ACCESS_LEVEL_RW,
                                                 mock.sentinel.username)

        cmd = [
            "Grant-SmbShareAccess", "-Name", mock.sentinel.share_name,
            "-AccessRight", "Change", "-AccountName",
            "'%s'" % mock.sentinel.username, "-Force"
        ]
        self._remote_exec.assert_called_once_with(mock.sentinel.server, cmd)
        mock_refresh_acl.assert_called_once_with(mock.sentinel.server,
                                                 mock.sentinel.share_name)

    def test_refresh_acl(self):
        self._win_smb_helper._refresh_acl(mock.sentinel.server,
                                          mock.sentinel.share_name)

        cmd = ['Set-SmbPathAcl', '-ShareName', mock.sentinel.share_name]
        self._remote_exec.assert_called_once_with(mock.sentinel.server, cmd)

    @mock.patch.object(windows_smb_helper.WindowsSMBHelper, '_refresh_acl')
    def test_revoke_share_access(self, mock_refresh_acl):
        self._win_smb_helper._revoke_share_access(mock.sentinel.server,
                                                  mock.sentinel.share_name,
                                                  mock.sentinel.username)

        cmd = [
            "Revoke-SmbShareAccess", "-Name", mock.sentinel.share_name,
            "-AccountName",
            '"%s"' % mock.sentinel.username, "-Force"
        ]
        self._remote_exec.assert_called_once_with(mock.sentinel.server, cmd)
        mock_refresh_acl.assert_called_once_with(mock.sentinel.server,
                                                 mock.sentinel.share_name)

    def test_update_access_invalid_type(self):
        invalid_access_rule = dict(self._FAKE_RW_ACC_RULE, access_type='ip')
        self.assertRaises(exception.InvalidShareAccess,
                          self._win_smb_helper.update_access,
                          mock.sentinel.server, mock.sentinel.share_name,
                          [invalid_access_rule], [], [])

    def test_update_access_invalid_level(self):
        invalid_access_rule = dict(self._FAKE_RW_ACC_RULE,
                                   access_level='fake_level')
        self.assertRaises(exception.InvalidShareAccessLevel,
                          self._win_smb_helper.update_access,
                          mock.sentinel.server, mock.sentinel.share_name, [],
                          [invalid_access_rule], [])

    @mock.patch.object(windows_smb_helper.WindowsSMBHelper,
                       '_revoke_share_access')
    def test_update_access_deleting_invalid_rule(self, mock_revoke):
        # We want to make sure that we allow deleting invalid rules.
        invalid_access_rule = dict(self._FAKE_RW_ACC_RULE,
                                   access_level='fake_level')
        delete_rules = [invalid_access_rule, self._FAKE_RW_ACC_RULE]

        self._win_smb_helper.update_access(mock.sentinel.server,
                                           mock.sentinel.share_name, [], [],
                                           delete_rules)

        mock_revoke.assert_called_once_with(
            mock.sentinel.server, mock.sentinel.share_name,
            self._FAKE_RW_ACC_RULE['access_to'])

    @mock.patch.object(windows_smb_helper.WindowsSMBHelper,
                       'validate_access_rules')
    @mock.patch.object(windows_smb_helper.WindowsSMBHelper, 'get_access_rules')
    @mock.patch.object(windows_smb_helper.WindowsSMBHelper,
                       '_grant_share_access')
    @mock.patch.object(windows_smb_helper.WindowsSMBHelper,
                       '_revoke_share_access')
    def test_update_access(self, mock_revoke, mock_grant,
                           mock_get_access_rules, mock_validate):
        added_rules = [mock.MagicMock(), mock.MagicMock()]
        deleted_rules = [mock.MagicMock(), mock.MagicMock()]

        self._win_smb_helper.update_access(mock.sentinel.server,
                                           mock.sentinel.share_name, [],
                                           added_rules, deleted_rules)

        mock_revoke.assert_has_calls([
            mock.call(mock.sentinel.server, mock.sentinel.share_name,
                      deleted_rule['access_to'])
            for deleted_rule in deleted_rules
        ])

        mock_grant.assert_has_calls([
            mock.call(mock.sentinel.server, mock.sentinel.share_name,
                      added_rule['access_level'], added_rule['access_to'])
            for added_rule in added_rules
        ])

    @mock.patch.object(windows_smb_helper.WindowsSMBHelper,
                       '_get_rule_updates')
    @mock.patch.object(windows_smb_helper.WindowsSMBHelper,
                       'validate_access_rules')
    @mock.patch.object(windows_smb_helper.WindowsSMBHelper, 'get_access_rules')
    @mock.patch.object(windows_smb_helper.WindowsSMBHelper,
                       '_grant_share_access')
    @mock.patch.object(windows_smb_helper.WindowsSMBHelper,
                       '_revoke_share_access')
    def test_update_access_maintenance(self, mock_revoke, mock_grant,
                                       mock_get_access_rules, mock_validate,
                                       mock_get_rule_updates):
        all_rules = mock.MagicMock()
        added_rules = [mock.MagicMock(), mock.MagicMock()]
        deleted_rules = [mock.MagicMock(), mock.MagicMock()]

        mock_get_rule_updates.return_value = [added_rules, deleted_rules]

        self._win_smb_helper.update_access(mock.sentinel.server,
                                           mock.sentinel.share_name, all_rules,
                                           [], [])

        mock_get_access_rules.assert_called_once_with(mock.sentinel.server,
                                                      mock.sentinel.share_name)
        mock_get_rule_updates.assert_called_once_with(
            existing_rules=mock_get_access_rules.return_value,
            requested_rules=all_rules)
        mock_revoke.assert_has_calls([
            mock.call(mock.sentinel.server, mock.sentinel.share_name,
                      deleted_rule['access_to'])
            for deleted_rule in deleted_rules
        ])

        mock_grant.assert_has_calls([
            mock.call(mock.sentinel.server, mock.sentinel.share_name,
                      added_rule['access_level'], added_rule['access_to'])
            for added_rule in added_rules
        ])

    def test_get_rule_updates(self):
        req_rule_0 = self._FAKE_RW_ACC_RULE
        req_rule_1 = dict(self._FAKE_RW_ACC_RULE, access_to='fake_acc')

        curr_rule_0 = dict(
            self._FAKE_RW_ACC_RULE,
            access_to=self._FAKE_RW_ACC_RULE['access_to'].upper())
        curr_rule_1 = dict(self._FAKE_RW_ACC_RULE, access_to='fake_acc2')
        curr_rule_2 = dict(req_rule_1, access_level=constants.ACCESS_LEVEL_RO)

        expected_added_rules = [req_rule_1]
        expected_deleted_rules = [curr_rule_1, curr_rule_2]

        existing_rules = [curr_rule_0, curr_rule_1, curr_rule_2]
        requested_rules = [req_rule_0, req_rule_1]

        (added_rules, deleted_rules) = self._win_smb_helper._get_rule_updates(
            existing_rules, requested_rules)

        self.assertEqual(expected_added_rules, added_rules)
        self.assertEqual(expected_deleted_rules, deleted_rules)

    def test_get_share_name(self):
        result = self._win_smb_helper._get_share_name(self._FAKE_SHARE)
        self.assertEqual(self._FAKE_SHARE_NAME, result)

    def test_get_share_path_by_name(self):
        self._remote_exec.return_value = (self._FAKE_SHARE_LOCATION,
                                          mock.sentinel.std_err)

        result = self._win_smb_helper._get_share_path_by_name(
            mock.sentinel.server, mock.sentinel.share_name)

        cmd = ('Get-SmbShare -Name %s | '
               'Select-Object -ExpandProperty Path' % mock.sentinel.share_name)
        self._remote_exec.assert_called_once_with(mock.sentinel.server,
                                                  cmd,
                                                  check_exit_code=True)
        self.assertEqual(self._FAKE_SHARE_LOCATION, result)

    @mock.patch.object(windows_smb_helper.WindowsSMBHelper,
                       '_get_share_path_by_name')
    def test_get_share_path_by_export_location(self,
                                               mock_get_share_path_by_name):
        mock_get_share_path_by_name.return_value = mock.sentinel.share_path

        result = self._win_smb_helper.get_share_path_by_export_location(
            mock.sentinel.server, self._FAKE_SHARE)

        mock_get_share_path_by_name.assert_called_once_with(
            mock.sentinel.server, self._FAKE_SHARE_NAME)
        self.assertEqual(mock.sentinel.share_path, result)

    @mock.patch.object(windows_smb_helper.WindowsSMBHelper,
                       '_get_share_path_by_name')
    def test_share_exists(self, mock_get_share_path_by_name):
        result = self._win_smb_helper._share_exists(mock.sentinel.server,
                                                    mock.sentinel.share_name)

        mock_get_share_path_by_name.assert_called_once_with(
            mock.sentinel.server,
            mock.sentinel.share_name,
            ignore_missing=True)
        self.assertTrue(result)
class WindowsSMBHelperTestCase(test.TestCase):
    _FAKE_SERVER = {'public_address': mock.sentinel.public_address}
    _FAKE_SHARE_NAME = "fake_share_name"
    _FAKE_SHARE = "\\\\%s\\%s" % (_FAKE_SERVER['public_address'],
                                  _FAKE_SHARE_NAME)
    _FAKE_SHARE_LOCATION = os.path.join(
        configuration.Configuration(None).share_mount_path,
        _FAKE_SHARE_NAME)

    def setUp(self):
        self._remote_exec = mock.Mock()
        fake_conf = configuration.Configuration(None)

        self._win_smb_helper = windows_smb_helper.WindowsSMBHelper(
            self._remote_exec, fake_conf)

        super(WindowsSMBHelperTestCase, self).setUp()

    def test_init_helper(self):
        self._win_smb_helper.init_helper(mock.sentinel.server)
        self._remote_exec.assert_called_once_with(mock.sentinel.server,
                                                  "Get-SmbShare")

    @ddt.data(True, False)
    @mock.patch.object(windows_smb_helper.WindowsSMBHelper, '_share_exists')
    def test_create_export(self, share_exists, mock_share_exists):
        mock_share_exists.return_value = share_exists

        result = self._win_smb_helper.create_export(self._FAKE_SERVER,
                                                    self._FAKE_SHARE_NAME)

        if not share_exists:
            cmd = ['New-SmbShare', '-Name', self._FAKE_SHARE_NAME, '-Path',
                   self._win_smb_helper._windows_utils.normalize_path(
                       self._FAKE_SHARE_LOCATION)]
            self._remote_exec.assert_called_once_with(self._FAKE_SERVER, cmd)
        else:
            self.assertFalse(self._remote_exec.called)

        self.assertEqual(self._FAKE_SHARE, result)

    @mock.patch.object(windows_smb_helper.WindowsSMBHelper, '_share_exists')
    def test_remove_export(self, mock_share_exists):
        mock_share_exists.return_value = True

        self._win_smb_helper.remove_export(mock.sentinel.server,
                                           mock.sentinel.share_name)

        cmd = ['Remove-SmbShare', '-Name', mock.sentinel.share_name, "-Force"]
        self._remote_exec.assert_called_once_with(mock.sentinel.server, cmd)

    @mock.patch.object(windows_utils.WindowsUtils,
                       'get_volume_path_by_mount_path')
    @mock.patch.object(windows_smb_helper.WindowsSMBHelper,
                       '_get_share_path_by_name')
    def test_get_volume_path_by_share_name(self, mock_get_share_path,
                                           mock_get_vol_path):
        mock_get_share_path.return_value = self._FAKE_SHARE_LOCATION

        volume_path = self._win_smb_helper._get_volume_path_by_share_name(
            mock.sentinel.server, self._FAKE_SHARE_NAME)

        mock_get_share_path.assert_called_once_with(mock.sentinel.server,
                                                    self._FAKE_SHARE_NAME)
        mock_get_vol_path.assert_called_once_with(mock.sentinel.server,
                                                  self._FAKE_SHARE_LOCATION)

        self.assertEqual(mock_get_vol_path.return_value, volume_path)

    @ddt.data('ip', 'user')
    @mock.patch.object(windows_smb_helper.WindowsSMBHelper,
                       '_grant_share_access')
    @mock.patch.object(windows_smb_helper.WindowsSMBHelper,
                       '_grant_share_path_access')
    def test_allow_access(self, access_type, mock_grant_share_access,
                          mock_grant_share_path_access):
        mock_args = (mock.sentinel.server, mock.sentinel.share_name,
                     access_type, mock.sentinel.access_level,
                     mock.sentinel.username)

        if access_type != 'user':
            self.assertRaises(exception.InvalidShareAccess,
                              self._win_smb_helper.allow_access,
                              *mock_args)
        else:
            self._win_smb_helper.allow_access(*mock_args)

            mock_grant_share_access.assert_called_once_with(
                mock.sentinel.server,
                mock.sentinel.share_name,
                mock.sentinel.access_level,
                mock.sentinel.username)
            mock_grant_share_path_access.assert_called_once_with(
                mock.sentinel.server,
                mock.sentinel.share_name,
                mock.sentinel.access_level,
                mock.sentinel.username)

    @mock.patch.object(windows_smb_helper.WindowsSMBHelper, '_refresh_acl')
    def test_grant_share_access(self, mock_refresh_acl):
        self._win_smb_helper._grant_share_access(mock.sentinel.server,
                                                 mock.sentinel.share_name,
                                                 constants.ACCESS_LEVEL_RW,
                                                 mock.sentinel.username)

        cmd = ["Grant-SmbShareAccess", "-Name", mock.sentinel.share_name,
               "-AccessRight", "Change",
               "-AccountName", mock.sentinel.username, "-Force"]
        self._remote_exec.assert_called_once_with(mock.sentinel.server, cmd)
        mock_refresh_acl.assert_called_once_with(mock.sentinel.server,
                                                 mock.sentinel.share_name)

    @mock.patch.object(windows_smb_helper.WindowsSMBHelper,
                       '_get_volume_path_by_share_name')
    def test_grant_share_path_access(self, mock_get_vol_path):
        fake_vol_path = 'fake_vol_path'
        mock_get_vol_path.return_value = fake_vol_path

        self._win_smb_helper._grant_share_path_access(
            mock.sentinel.server,
            mock.sentinel.share_name,
            constants.ACCESS_LEVEL_RW,
            mock.sentinel.username)

        expected_ace = '"%s:(OI)(CI)M"' % mock.sentinel.username
        cmd = ["icacls", '"%s"' % fake_vol_path, "/grant",
               expected_ace, "/t", "/c"]

        self._remote_exec.assert_called_once_with(mock.sentinel.server, cmd)

    def test_refresh_acl(self):
        self._win_smb_helper._refresh_acl(mock.sentinel.server,
                                          mock.sentinel.share_name)

        cmd = ['Set-SmbPathAcl', '-ShareName', mock.sentinel.share_name]
        self._remote_exec.assert_called_once_with(mock.sentinel.server, cmd)

    @mock.patch.object(windows_smb_helper.WindowsSMBHelper,
                       '_revoke_share_path_access')
    @mock.patch.object(windows_smb_helper.WindowsSMBHelper,
                       '_revoke_share_access')
    def test_deny_access(self, mock_revoke_share_path_access,
                         mock_revoke_share_access):
        mock_access = {'access_to': mock.sentinel.username}

        self._win_smb_helper.deny_access(mock.sentinel.server,
                                         mock.sentinel.share_name,
                                         mock_access)

        mock_revoke_share_access.assert_called_once_with(
            mock.sentinel.server,
            mock.sentinel.share_name,
            mock.sentinel.username)
        mock_revoke_share_path_access.assert_called_once_with(
            mock.sentinel.server,
            mock.sentinel.share_name,
            mock.sentinel.username)

    @mock.patch.object(windows_smb_helper.WindowsSMBHelper, '_refresh_acl')
    def test_revoke_share_access(self, mock_refresh_acl):
        self._win_smb_helper._revoke_share_access(mock.sentinel.server,
                                                  mock.sentinel.share_name,
                                                  mock.sentinel.username)

        cmd = ["Revoke-SmbShareAccess", "-Name", mock.sentinel.share_name,
               "-AccountName", mock.sentinel.username, "-Force"]
        self._remote_exec.assert_called_once_with(mock.sentinel.server, cmd)
        mock_refresh_acl.assert_called_once_with(mock.sentinel.server,
                                                 mock.sentinel.share_name)

    @mock.patch.object(windows_smb_helper.WindowsSMBHelper,
                       '_get_volume_path_by_share_name')
    def test_revoke_share_path_access(self, mock_get_vol_path):
        fake_vol_path = 'fake_vol_path'
        mock_get_vol_path.return_value = fake_vol_path

        self._win_smb_helper._revoke_share_path_access(
            mock.sentinel.server,
            mock.sentinel.share_name,
            mock.sentinel.username)

        cmd = ["icacls", '"%s"' % fake_vol_path,
               "/remove", mock.sentinel.username, "/t", "/c"]
        self._remote_exec.assert_called_once_with(mock.sentinel.server, cmd)

    def test_get_share_name(self):
        result = self._win_smb_helper._get_share_name(self._FAKE_SHARE)
        self.assertEqual(self._FAKE_SHARE_NAME, result)

    def test_exports_for_share(self):
        result = self._win_smb_helper.get_exports_for_share(
            self._FAKE_SERVER, self._FAKE_SHARE_LOCATION)
        self.assertEqual([self._FAKE_SHARE], result)

    def test_get_share_path_by_name(self):
        self._remote_exec.return_value = (self._FAKE_SHARE_LOCATION,
                                          mock.sentinel.std_err)

        result = self._win_smb_helper._get_share_path_by_name(
            mock.sentinel.server,
            mock.sentinel.share_name)

        cmd = ('Get-SmbShare -Name %s | '
               'Select-Object -ExpandProperty Path' % mock.sentinel.share_name)
        self._remote_exec.assert_called_once_with(mock.sentinel.server,
                                                  cmd,
                                                  check_exit_code=True)
        self.assertEqual(self._FAKE_SHARE_LOCATION, result)

    @mock.patch.object(windows_smb_helper.WindowsSMBHelper,
                       '_get_share_path_by_name')
    def test_get_share_path_by_export_location(self,
                                               mock_get_share_path_by_name):
        mock_get_share_path_by_name.return_value = mock.sentinel.share_path

        result = self._win_smb_helper.get_share_path_by_export_location(
            mock.sentinel.server, self._FAKE_SHARE)

        mock_get_share_path_by_name.assert_called_once_with(
            mock.sentinel.server, self._FAKE_SHARE_NAME)
        self.assertEqual(mock.sentinel.share_path, result)

    @mock.patch.object(windows_smb_helper.WindowsSMBHelper,
                       '_get_share_path_by_name')
    def test_share_exists(self, mock_get_share_path_by_name):
        result = self._win_smb_helper._share_exists(mock.sentinel.server,
                                                    mock.sentinel.share_name)

        mock_get_share_path_by_name.assert_called_once_with(
            mock.sentinel.server,
            mock.sentinel.share_name,
            ignore_missing=True)
        self.assertTrue(result)
示例#25
0
 def test_init(self):
     self.assertRaises(IndexError,
                       layout.GlusterfsShareDriverBase,
                       False,
                       configuration=config.Configuration(None))
示例#26
0
    def setUp(self):
        super(NetAppClusteredDrvTestCase, self).setUp()
        self._context = context.get_admin_context()
        self._db = mock.Mock()
        self.driver = driver.NetAppClusteredShareDriver(
            self._db, configuration=configuration.Configuration(None))
        self.driver._client = mock.Mock()
        self.driver._client.send_request = mock.Mock()
        self._vserver_client = mock.Mock()
        self._vserver_client.send_request = mock.Mock()
        driver.NetAppApiClient = mock.Mock(return_value=self._vserver_client)
        self.share = {
            'id': 'fake_uuid',
            'project_id': 'fake_tenant_id',
            'name': 'fake_name',
            'size': 1,
            'share_proto': 'fake',
            'share_network_id': 'fake_net_id',
            'share_server_id': 'fake-share-srv-id',
            'network_info': {
                'network_allocations': [{
                    'ip_address': 'ip'
                }]
            }
        }
        self.snapshot = {
            'id': 'fake_snapshot_uuid',
            'project_id': 'fake_tenant_id',
            'share_id': 'fake_share_id',
            'share': self.share
        }
        self.security_service = {
            'id': 'fake_id',
            'domain': 'FAKE',
            'server': 'fake_server',
            'user': '******',
            'password': '******'
        }
        self.share_server = {
            'backend_details': {
                'vserver_name': 'fake_vserver'
            }
        }
        self.helper = mock.Mock()
        self.driver._helpers = {'FAKE': self.helper}
        self.driver._licenses = ['fake']

        self.network_info = {
            'server_id':
            'fake_server_id',
            'cidr':
            '10.0.0.0/24',
            'security_services': [
                'fake_ldap',
                'fake_kerberos',
                'fake_ad',
            ],
            'segmentation_id':
            '1000',
            'network_allocations': [
                {
                    'id': 'fake_na_id_1',
                    'ip_address': 'fake_ip_1',
                },
                {
                    'id': 'fake_na_id_2',
                    'ip_address': 'fake_ip_2',
                },
            ],
        }
示例#27
0
 def test__verify_share_server_handling_valid_cases(self, opt, allowed):
     conf = configuration.Configuration(None)
     self.mock_object(conf, 'safe_get', mock.Mock(return_value=opt))
     share_driver = driver.ShareDriver(allowed, configuration=conf)
     self.assertTrue(conf.safe_get.celled)
     self.assertEqual(opt, share_driver.driver_handles_share_servers)
示例#28
0
 def test__try_execute(self):
     execute_mixin = ShareDriverWithExecuteMixin(
         True, configuration=configuration.Configuration(None))
     self.assertRaises(exception.ProcessExecutionError,
                       execute_mixin._try_execute)
示例#29
0
import ddt
from oslo_config import cfg
import requests
import six

from manila.common import constants as const
from manila import context
from manila import exception
from manila.share import configuration
from manila.share.drivers.tegile import tegile
from manila import test

CONF = cfg.CONF

test_config = configuration.Configuration(None)
test_config.tegile_nas_server = 'some-ip'
test_config.tegile_nas_login = '******'
test_config.tegile_nas_password = '******'
test_config.reserved_share_percentage = 10
test_config.max_over_subscription_ratio = 30.0

test_share = {
    'host': 'node#fake_pool',
    'name': 'testshare',
    'id': 'a24c2ee8-525a-4406-8ccd-8d38688f8e9e',
    'share_proto': 'NFS',
    'size': 10,
}

test_share_cifs = {