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') CONF.set_default('ganesha_rados_store_enable', True) CONF.set_default('ganesha_rados_store_pool_name', 'ceph_pool') CONF.set_default('ganesha_rados_export_index', 'fake_index') CONF.set_default('ganesha_rados_export_counter', 'fake_counter') self._context = context.get_admin_context() self._execute = mock.Mock(return_value=('', '')) self.ceph_vol_client = mock.Mock() 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', ceph_vol_client=self.ceph_vol_client) 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')
def test_share_allow_deny_access(self): """Test share access allow any deny rules.""" share = fake_share.fake_share(id='fakeid', share_proto='NFS', share_id='fakeshareid') self.driver.create_share(self._context, share) access = fake_share.fake_access() # Attach server for accessing share with the fake access rules allow_access = self.driver._allow_access(self._context, share, access) self.assertEqual(allow_access['driver_volume_type'], share['share_proto']) self.assertEqual('1.1.1.1:3260', allow_access['data']['target_portal']) (srv_name, srv_params) = RUNTIME_VARS['servers'][0] self.assertEqual(srv_params['iscsi'], allow_access['data']['target_ip']) self.assertEqual(share['id'], allow_access['data']['id']) self.assertEqual('CHAP', allow_access['data']['auth_method']) self.assertEqual('test_chap_user', allow_access['data']['auth_username']) self.assertEqual('test_chap_secret', allow_access['data']['auth_password']) # Detach will not throw any error with missing access rules dup_access = fake_share.fake_access() self.driver._deny_access(self._context, share, dup_access) # Detach server from the share with deny access rules self.driver._deny_access(self._context, share, access) self.driver.delete_share(self._context, share)
def test_manage_access_adding_entry_cmd_fail(self): def cbk(d, key, value): d[key].append(value) def raise_exception(*args, **kwargs): raise exception.ProcessExecutionError() access = fake_share.fake_access() export_dir_dict = { 'example.com': ['10.0.0.1'], 'fakename': ['10.0.0.2'], } export_str = '/example.com(10.0.0.1),/fakename(10.0.0.2|10.0.0.1)' args = ('volume', 'set', self._helper.gluster_manager.volume, NFS_EXPORT_DIR, export_str) self.mock_object(self._helper, '_get_export_dir_dict', mock.Mock(return_value=export_dir_dict)) self.mock_object(self._helper.gluster_manager, 'gluster_call', mock.Mock(side_effect=raise_exception)) self.mock_object(glusterfs.LOG, 'error') self.assertRaises(exception.ProcessExecutionError, self._helper._manage_access, fake_share_name, access['access_type'], access['access_to'], cbk) self._helper._get_export_dir_dict.assert_called_once_with() self._helper.gluster_manager.gluster_call.assert_called_once_with( *args) glusterfs.LOG.error.assert_called_once_with(mock.ANY, mock.ANY)
def setUp(self): super(HDFSNativeShareDriverTestCase, self).setUp() self._context = context.get_admin_context() self._hdfs_execute = mock.Mock(return_value=('', '')) self.local_ip = '192.168.1.1' CONF.set_default('driver_handles_share_servers', False) CONF.set_default('hdfs_namenode_ip', self.local_ip) CONF.set_default('hdfs_ssh_name', 'fake_sshname') CONF.set_default('hdfs_ssh_pw', 'fake_sshpw') CONF.set_default('hdfs_ssh_private_key', 'fake_sshkey') self.fake_conf = config.Configuration(None) self._driver = hdfs_native.HDFSNativeShareDriver( execute=self._hdfs_execute, configuration=self.fake_conf) self.hdfs_bin = 'hdfs' self._driver._hdfs_bin = 'fake_hdfs_bin' self.share = fake_share.fake_share(share_proto='HDFS') self.snapshot = fake_share.fake_snapshot(share_proto='HDFS') self.access = fake_share.fake_access(access_type='user') self.fakesharepath = 'hdfs://1.2.3.4:5/share-0' self.fakesnapshotpath = '/share-0/.snapshot/snapshot-0' socket.gethostname = mock.Mock(return_value='testserver') socket.gethostbyname_ex = mock.Mock( return_value=('localhost', ['localhost.localdomain', 'testserver'], ['127.0.0.1', self.local_ip]))
def test_allow_access_with_incorrect_access_type(self): share = fake_share.fake_share(id='fakeid1', share_proto='NFS') access = fake_share.fake_access(access_type='fake_type') self.assertRaises(manila_exception.ZadaraInvalidShareAccessType, self.driver._allow_access, self._context, share, access)
def setUp(self): super(HDFSNativeShareDriverTestCase, self).setUp() self._context = context.get_admin_context() self._hdfs_execute = mock.Mock(return_value=('', '')) self.local_ip = '192.168.1.1' CONF.set_default('driver_handles_share_servers', False) CONF.set_default('hdfs_namenode_ip', self.local_ip) CONF.set_default('hdfs_ssh_name', 'fake_sshname') CONF.set_default('hdfs_ssh_pw', 'fake_sshpw') CONF.set_default('hdfs_ssh_private_key', 'fake_sshkey') self.fake_conf = config.Configuration(None) self._driver = hdfs_native.HDFSNativeShareDriver( execute=self._hdfs_execute, configuration=self.fake_conf) self.hdfs_bin = 'hdfs' self._driver._hdfs_bin = 'fake_hdfs_bin' self.share = fake_share.fake_share(share_proto='HDFS') self.snapshot = fake_share.fake_snapshot(share_proto='HDFS') self.access = fake_share.fake_access(access_type='user') self.fakesharepath = 'hdfs://1.2.3.4:5/share-0' self.fakesnapshotpath = '/share-0/.snapshot/snapshot-0' socket.gethostname = mock.Mock(return_value='testserver') socket.gethostbyname_ex = mock.Mock(return_value=( 'localhost', ['localhost.localdomain', 'testserver'], ['127.0.0.1', self.local_ip]))
def test_manage_access_adding_entry_cmd_fail(self): def cbk(li, v): li.append(v) def raise_exception(*args, **kwargs): raise exception.ProcessExecutionError() access = fake_share.fake_access() export_list = ['10.0.0.2'] self.mock_object(self._helper, '_get_vol_exports', mock.Mock(return_value=export_list)) self.mock_object(self._helper.gluster_manager, 'gluster_call', mock.Mock(side_effect=raise_exception)) self.assertRaises(exception.ProcessExecutionError, self._helper._manage_access, access['access_type'], access['access_to'], cbk) self._helper._get_vol_exports.assert_called_once_with() export_str = '10.0.0.2,10.0.0.1' args = ('volume', 'set', self._helper.gluster_manager.volume, NFS_RPC_AUTH_ALLOW, export_str) self._helper.gluster_manager.gluster_call.assert_called_once_with( *args)
def test_update_access_invalid_access(self): access = fake_share.fake_access(access_type='ip', access_to='fake', access_level='rw') self.assertRaises(exception.InvalidShareAccess, self._driver.update_access, self._context, self.share, [access], [], [])
def setUp(self): super(HDFSNativeShareDriverTestCase, self).setUp() self._context = context.get_admin_context() self._hdfs_execute = mock.Mock(return_value=("", "")) self.local_ip = "192.168.1.1" CONF.set_default("driver_handles_share_servers", False) CONF.set_default("hdfs_namenode_ip", self.local_ip) CONF.set_default("hdfs_ssh_name", "fake_sshname") CONF.set_default("hdfs_ssh_pw", "fake_sshpw") CONF.set_default("hdfs_ssh_private_key", "fake_sshkey") self.fake_conf = config.Configuration(None) self._driver = hdfs_native.HDFSNativeShareDriver(execute=self._hdfs_execute, configuration=self.fake_conf) self.hdfs_bin = "hdfs" self._driver._hdfs_bin = "fake_hdfs_bin" self.share = fake_share.fake_share(share_proto="HDFS") self.snapshot = fake_share.fake_snapshot(share_proto="HDFS") self.access = fake_share.fake_access(access_type="user") self.fakesharepath = "hdfs://1.2.3.4:5/share-0" self.fakesnapshotpath = "/share-0/.snapshot/snapshot-0" socket.gethostname = mock.Mock(return_value="testserver") socket.gethostbyname_ex = mock.Mock( return_value=("localhost", ["localhost.localdomain", "testserver"], ["127.0.0.1", self.local_ip]) )
def test_allow_access_invalid_access_level(self): self.assertRaises(exception.InvalidShareAccess, self._driver.allow_access, self._context, self.share, fake_share.fake_access( access_level='invalid_access_level'), share_server=None)
def test_allow_access_with_incorrect_proto(self): share_server = fakes.SHARE_SERVER share = fake_share.fake_share(share_proto='FAKE_PROTO') access = fake_share.fake_access() self.assertRaises(exception.InvalidShare, self.connection.allow_access, None, share, access, share_server)
def test_allow_nfs_access_with_incorrect_access_type(self): share_server = fakes.SHARE_SERVER share = fakes.NFS_SHARE access = fake_share.fake_access(access_type='fake_type') self.assertRaises(exception.InvalidShareAccess, self.connection.allow_access, None, share, access, share_server)
def test_allow_access_with_invalid_access_level(self): share_server = fakes.SHARE_SERVER share = fakes.CIFS_SHARE access = fake_share.fake_access(access_level='fake_level') self.assertRaises(exception.InvalidShareAccessLevel, self.connection.allow_access, None, share, access, share_server)
def test_allow_access_nonip(self): self._driver.rpc.call = mock.Mock(wraps=fake_rpc_handler) self.access = fake_share.fake_access(**{"access_type": "non_existant_access_type"}) self.assertRaises( exception.InvalidShareAccess, self._driver._allow_access, self._context, self.share, self.access )
def test_allow_access_invalid_access_level(self): self.assertRaises( exception.InvalidShareAccess, self._driver.allow_access, self._context, self.share, fake_share.fake_access(access_level='invalid_access_level'), share_server=None)
def test_update_access_invalid_share_access_level(self): bad_rule = fake_share.fake_access(access_level='RO', id='fakeid') expected = {'fakeid': {'state': 'error'}} result = self._helper.update_access(self._context, self.share, access_rules=[bad_rule], add_rules=[], delete_rules=[]) self.assertEqual(expected, result)
def test_deny_access_with_share_having_noaccess(self): access = fake_share.fake_access() share = fake_share.fake_share() export_dir_dict = {} self.mock_object(self._helper, '_get_export_dir_dict', mock.Mock(return_value=export_dir_dict)) self._helper.deny_access(None, share, access) self._helper._get_export_dir_dict.assert_called_once_with() self.assertFalse(self._helper.gluster_manager.gluster_call.called)
def test_allow_access_nonip(self): self._driver.rpc.call = mock.Mock(wraps=fake_rpc_handler) self.access = fake_share.fake_access( **{"access_type": "non_existant_access_type"}) self.assertRaises(exception.InvalidShareAccess, self._driver._allow_access, self._context, self.share, self.access)
def test_deny_access_nonip(self, mock_debug): self._driver.rpc.call = mock.Mock(wraps=fake_rpc_handler) self.access = fake_share.fake_access( access_type="non_existant_access_type") self._driver.deny_access(self._context, self.share, self.access) mock_debug.assert_called_with( 'Quobyte driver only supports ip access control. ' 'Ignoring deny access call for %s , %s', 'fakename', 'fake_project_uuid')
def test_allow_access_with_share_having_access(self): access = fake_share.fake_access() share = fake_share.fake_share() export_list = ['10.0.0.1'] self.mock_object(self._helper, '_get_vol_exports', mock.Mock(return_value=export_list)) self._helper.allow_access(None, share, access) self._helper._get_vol_exports.assert_called_once_with() self.assertFalse(self._helper.gluster_manager.gluster_call.called)
def test_deny_access_nonip(self, mock_debug): self._driver.rpc.call = mock.Mock(wraps=fake_rpc_handler) self.access = fake_share.fake_access( access_type="non_existant_access_type") self._driver._deny_access(self._context, self.share, self.access) mock_debug.assert_called_with( 'Quobyte driver only supports ip access control. ' 'Ignoring deny access call for %s , %s', 'fakename', 'fake_project_uuid')
def test_no_active_ctrl(self): share = fake_share.fake_share(id='fakeid', share_proto='NFS', share_id='fakeshareid') self.driver.create_share(self._context, share) access = fake_share.fake_access() RUNTIME_VARS['controllers'] = [] self.assertRaises(manila_exception.ZadaraVPSANoActiveController, self.driver._allow_access, self._context, share, access)
def setUp(self): super(QuobyteShareDriverTestCase, self).setUp() self._context = context.get_admin_context() CONF.set_default('driver_handles_share_servers', False) self.fake_conf = config.Configuration(None) self._driver = quobyte.QuobyteShareDriver(configuration=self.fake_conf) self._driver.rpc = mock.Mock() self.share = fake_share.fake_share(share_proto='NFS') self.access = fake_share.fake_access()
def test_update_access_invalid_share_access_type(self): mock_gh = self._helper.ganesha self.mock_object(mock_gh, 'check_export_exists', mock.Mock(return_value=False)) bad_rule = fake_share.fake_access(access_type='notip', id='fakeid') expected = {'fakeid': {'state': 'error'}} result = self._helper.update_access(self._context, self.share, access_rules=[bad_rule], add_rules=[], delete_rules=[]) self.assertEqual(expected, result)
def setUp(self): super(GPFSShareDriverTestCase, self).setUp() self._context = context.get_admin_context() self._gpfs_execute = mock.Mock(return_value=('', '')) self._helper_fake = mock.Mock() CONF.set_default('driver_handles_share_servers', False) self.fake_conf = config.Configuration(None) self._driver = gpfs.GPFSShareDriver(execute=self._gpfs_execute, configuration=self.fake_conf) self._knfs_helper = gpfs.KNFSHelper(self._gpfs_execute, self.fake_conf) self._gnfs_helper = gpfs.GNFSHelper(self._gpfs_execute, self.fake_conf) self.fakedev = "/dev/gpfs0" self.fakefspath = "/gpfs0" self.fakesharepath = "/gpfs0/share-fakeid" self.fakesnapshotpath = "/gpfs0/.snapshots/snapshot-fakesnapshotid" self.mock_object(gpfs.os.path, 'exists', mock.Mock(return_value=True)) self._driver._helpers = { 'KNFS': self._helper_fake } self.share = fake_share.fake_share(share_proto='NFS') self.server = { 'backend_details': { 'ip': '1.2.3.4', 'instance_id': 'fake' } } self.access = fake_share.fake_access() self.snapshot = fake_share.fake_snapshot() self.local_ip = "192.11.22.1" self.remote_ip = "192.11.22.2" gpfs_nfs_server_list = [self.local_ip, self.remote_ip] self._knfs_helper.configuration.gpfs_nfs_server_list = \ gpfs_nfs_server_list self._gnfs_helper.configuration.gpfs_nfs_server_list = \ gpfs_nfs_server_list self._gnfs_helper.configuration.ganesha_config_path = \ "fake_ganesha_config_path" self.sshlogin = "******" self.sshkey = "fake_sshkey" self.gservice = "fake_ganesha_service" self._gnfs_helper.configuration.gpfs_ssh_login = self.sshlogin self._gnfs_helper.configuration.gpfs_ssh_private_key = self.sshkey self._gnfs_helper.configuration.ganesha_service_name = self.gservice self.mock_object(socket, 'gethostname', mock.Mock(return_value="testserver")) self.mock_object(socket, 'gethostbyname_ex', mock.Mock( return_value=('localhost', ['localhost.localdomain', 'testserver'], ['127.0.0.1', self.local_ip]) ))
def test_allow_access_with_share_having_access(self): access = fake_share.fake_access() share = fake_share.fake_share() export_dir_dict = {'fakename': ['10.0.0.1']} self.mock_object(self._helper, '_get_export_dir_dict', mock.Mock(return_value=export_dir_dict)) self._helper.gluster_manager.path = '/fakename' self._helper.allow_access(None, share, access) self._helper._get_export_dir_dict.assert_called_once_with() self.assertFalse(self._helper.gluster_manager.set_vol_option.called)
def test_allow_access_with_share_having_access(self): access = fake_share.fake_access() share = fake_share.fake_share() export_dir_dict = {'fakename': ['10.0.0.1']} self.mock_object(self._helper, '_get_export_dir_dict', mock.Mock(return_value=export_dir_dict)) self._helper.gluster_manager.path = '/fakename' self._helper.allow_access(None, share, access) self._helper._get_export_dir_dict.assert_called_once_with() self.assertFalse(self._helper.gluster_manager.gluster_call.called)
def setUp(self): super(MapRFSNativeShareDriverTestCase, self).setUp() self._context = context.get_admin_context() self._hdfs_execute = mock.Mock(return_value=('', '')) self.local_ip = '192.168.1.1' CONF.set_default('driver_handles_share_servers', False) CONF.set_default('maprfs_clinode_ip', [self.local_ip]) CONF.set_default('maprfs_ssh_name', 'fake_sshname') CONF.set_default('maprfs_ssh_pw', 'fake_sshpw') CONF.set_default('maprfs_ssh_private_key', 'fake_sshkey') CONF.set_default('maprfs_rename_managed_volume', True) self.fake_conf = config.Configuration(None) self.cluster_name = 'fake' export_locations = {0: {'path': '/share-0'}} export_locations[0]['el_metadata'] = { 'volume-name': 'share-0'} self.share = fake_share.fake_share(share_proto='MAPRFS', name='share-0', size=2, share_id=1, export_locations=export_locations, export_location='/share-0') self.snapshot = fake_share.fake_snapshot(share_proto='MAPRFS', name='fake', share_name=self.share['name'], share_id=self.share['id'], share=self.share, share_instance=self.share, provider_location='fake') self.access = fake_share.fake_access(access_type='user', access_to='fake', access_level='rw') self.snapshot = self.snapshot.values self.snapshot.update(share_instance=self.share) self.export_path = 'maprfs:///share-0 -C -Z -N fake' self.fakesnapshot_path = '/share-0/.snapshot/snapshot-0' self.hadoop_bin = '/usr/bin/hadoop' self.maprcli_bin = '/usr/bin/maprcli' self.mock_object(utils, 'execute') self.mock_object( mapru.socket, 'gethostname', mock.Mock(return_value='testserver')) self.mock_object( mapru.socket, 'gethostbyname_ex', mock.Mock(return_value=( 'localhost', ['localhost.localdomain', mapru.socket.gethostname.return_value], ['127.0.0.1', self.local_ip]))) self._driver = maprfs.MapRFSNativeShareDriver( configuration=self.fake_conf) self._driver.do_setup(self._context) self._driver.api.get_share_metadata = mock.Mock(return_value={}) self._driver.api.update_share_metadata = mock.Mock()
def test_allow_access_with_share_having_access(self, share_key, gmgr_path): access = fake_share.fake_access() share = fake_share.fake_share() export_dir_dict = {share_key: ['10.0.0.1']} self.mock_object(self._helper, '_get_export_dir_dict', mock.Mock(return_value=export_dir_dict)) self._helper.gluster_manager.path = gmgr_path self._helper.allow_access(None, share, access) self._helper._get_export_dir_dict.assert_called_once_with() self.assertFalse(self._helper.gluster_manager.gluster_call.called)
def setUp(self): super(MapRFSNativeShareDriverTestCase, self).setUp() self._context = context.get_admin_context() self._hdfs_execute = mock.Mock(return_value=('', '')) self.local_ip = '192.168.1.1' CONF.set_default('driver_handles_share_servers', False) CONF.set_default('maprfs_clinode_ip', [self.local_ip]) CONF.set_default('maprfs_ssh_name', 'fake_sshname') CONF.set_default('maprfs_ssh_pw', 'fake_sshpw') CONF.set_default('maprfs_ssh_private_key', 'fake_sshkey') CONF.set_default('maprfs_rename_managed_volume', True) self.fake_conf = config.Configuration(None) self.cluster_name = 'fake' export_locations = {0: {'path': '/share-0'}} export_locations[0]['el_metadata'] = {'volume-name': 'share-0'} self.share = fake_share.fake_share(share_proto='MAPRFS', name='share-0', size=2, share_id=1, export_locations=export_locations, export_location='/share-0') self.snapshot = fake_share.fake_snapshot(share_proto='MAPRFS', name='fake', share_name=self.share['name'], share_id=self.share['id'], share=self.share, share_instance=self.share, provider_location='fake') self.access = fake_share.fake_access(access_type='user', access_to='fake', access_level='rw') self.snapshot = self.snapshot.values self.snapshot.update(share_instance=self.share) self.export_path = 'maprfs:///share-0 -C -Z -N fake' self.fakesnapshot_path = '/share-0/.snapshot/snapshot-0' self.hadoop_bin = '/usr/bin/hadoop' self.maprcli_bin = '/usr/bin/maprcli' self.mock_object(utils, 'execute') self.mock_object(mapru.socket, 'gethostname', mock.Mock(return_value='testserver')) self.mock_object( mapru.socket, 'gethostbyname_ex', mock.Mock(return_value=('localhost', [ 'localhost.localdomain', mapru.socket.gethostname.return_value ], ['127.0.0.1', self.local_ip]))) self._driver = maprfs.MapRFSNativeShareDriver( configuration=self.fake_conf) self._driver.do_setup(self._context) self._driver.api.get_share_metadata = mock.Mock(return_value={}) self._driver.api.update_share_metadata = mock.Mock()
def test_manage_access_noop(self): cbk = mock.Mock(return_value=True) access = fake_share.fake_access() export_dir_dict = mock.Mock() self.mock_object(self._helper, '_get_export_dir_dict', mock.Mock(return_value=export_dir_dict)) ret = self._helper._manage_access(fake_share_name, access['access_type'], access['access_to'], cbk) self._helper._get_export_dir_dict.assert_called_once_with() cbk.assert_called_once_with(export_dir_dict, fake_share_name, access['access_to']) self.assertEqual(None, ret)
def test_manage_access_noop(self): cbk = mock.Mock(return_value=True) access = fake_share.fake_access() export_list = mock.Mock() self.mock_object(self._helper, '_get_vol_exports', mock.Mock(return_value=export_list)) ret = self._helper._manage_access(access['access_type'], access['access_to'], cbk) self._helper._get_vol_exports.assert_called_once_with() cbk.assert_called_once_with(export_list, access['access_to']) self.assertIsNone(ret)
def test_allow_access_with_share_having_noaccess(self): access = fake_share.fake_access() share = fake_share.fake_share() export_dir_dict = {'example.com': ['10.0.0.1']} export_str = '/example.com(10.0.0.1),/fakename(10.0.0.1)' args = ('volume', 'set', self._helper.gluster_manager.volume, NFS_EXPORT_DIR, export_str) self.mock_object(self._helper, '_get_export_dir_dict', mock.Mock(return_value=export_dir_dict)) self._helper.allow_access(None, share, access) self._helper._get_export_dir_dict.assert_called_once_with() self._helper.gluster_manager.gluster_call.assert_called_once_with( *args)
def test_allow_ro_access(self): def rpc_handler(name, *args): if name == "resolveVolumeName": return {"volume_uuid": "voluuid"} elif name == "exportVolume": return {"nfs_server_ip": "10.10.1.1", "nfs_export_path": "/voluuid"} self._driver.rpc.call = mock.Mock(wraps=rpc_handler) ro_access = fake_share.fake_access(access_level="ro") self._driver._allow_access(self._context, self.share, ro_access) self._driver.rpc.call.assert_called_with( "exportVolume", {"volume_uuid": "voluuid", "read_only": True, "add_allow_ip": "10.0.0.1"} )
def test_deny_access_with_share_having_access(self): access = fake_share.fake_access() share = fake_share.fake_share() export_list = ['10.0.0.1', '10.0.0.2'] self.mock_object(self._helper, '_get_vol_exports', mock.Mock(return_value=export_list)) self._helper.deny_access(None, share, access) self._helper._get_vol_exports.assert_called_once_with() export_str = '10.0.0.2' argseq = ((NFS_RPC_AUTH_ALLOW, export_str), (NFS_RPC_AUTH_REJECT, None)) self.assertEqual( [mock.call(*a) for a in argseq], self._helper.gluster_manager.set_vol_option.call_args_list)
def setUp(self): super(GaneshaNFSHelperTestCase, self).setUp() self.gluster_manager = mock.Mock(**fake_gluster_manager_attrs) self._execute = mock.Mock(return_value=('', '')) self._root_execute = mock.Mock(return_value=('', '')) self.access = fake_share.fake_access() self.fake_conf = config.Configuration(None) self.fake_template = {'key': 'value'} self.share = fake_share.fake_share() self.mock_object(glusterfs.ganesha_utils, 'RootExecutor', mock.Mock(return_value=self._root_execute)) self.mock_object(glusterfs.ganesha.GaneshaNASHelper, '__init__', mock.Mock()) self._helper = glusterfs.GaneshaNFSHelper( self._execute, self.fake_conf, gluster_manager=self.gluster_manager)
def test_allow_ro_access(self): def rpc_handler(name, *args): if name == 'resolveVolumeName': return {'volume_uuid': 'voluuid'} elif name == 'exportVolume': return {'nfs_server_ip': '10.10.1.1', 'nfs_export_path': '/voluuid'} self._driver.rpc.call = mock.Mock(wraps=rpc_handler) ro_access = fake_share.fake_access(access_level='ro') self._driver.allow_access(self._context, self.share, ro_access) self._driver.rpc.call.assert_called_with( 'exportVolume', {'volume_uuid': 'voluuid', 'read_only': True, 'add_allow_ip': '10.0.0.1'})
def test_manage_access_removing_last_entry(self): def cbk(d, key, value): d.pop(key) access = fake_share.fake_access() args = ('volume', 'reset', self._helper.gluster_manager.volume, NFS_EXPORT_DIR) export_dir_dict = {'fakename': ['10.0.0.1']} self.mock_object(self._helper, '_get_export_dir_dict', mock.Mock(return_value=export_dir_dict)) ret = self._helper._manage_access(fake_share_name, access['access_type'], access['access_to'], cbk) self.assertEqual(None, ret) self._helper._get_export_dir_dict.assert_called_once_with() self._helper.gluster_manager.gluster_call.assert_called_once_with( *args)
def test_deny_access_with_share_having_access(self): access = fake_share.fake_access() share = fake_share.fake_share() export_dir_dict = { 'example.com': ['10.0.0.1'], 'fakename': ['10.0.0.1'], } export_str = '/example.com(10.0.0.1)' args = (NFS_EXPORT_DIR, export_str) self.mock_object(self._helper, '_get_export_dir_dict', mock.Mock(return_value=export_dir_dict)) self._helper.gluster_manager.path = '/fakename' self._helper.deny_access(None, share, access) self._helper._get_export_dir_dict.assert_called_once_with() self._helper.gluster_manager.set_vol_option.assert_called_once_with( *args)
def setUp(self): super(GaneshaNASHelperTestCase, 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._execute = mock.Mock(return_value=('', '')) self.fake_conf = config.Configuration(None) self.fake_conf_dir_path = '/fakedir0/exports.d' self._helper = ganesha.GaneshaNASHelper( self._execute, self.fake_conf, tag='faketag') self._helper.ganesha = mock.Mock() self._helper.export_template = {'key': 'value'} self.share = fake_share.fake_share() self.access = fake_share.fake_access()
def test_manage_access_removing_last_entry(self): def cbk(li, v): li.remove(v) access = fake_share.fake_access() export_list = ['10.0.0.1'] self.mock_object(self._helper, '_get_vol_exports', mock.Mock(return_value=export_list)) ret = self._helper._manage_access(access['access_type'], access['access_to'], cbk) self.assertIsNone(ret) self._helper._get_vol_exports.assert_called_once_with() argseq = ((NFS_RPC_AUTH_ALLOW, None), (NFS_RPC_AUTH_REJECT, '*')) self.assertEqual( [mock.call(*a) for a in argseq], self._helper.gluster_manager.set_vol_option.call_args_list)
def test_allow_access_with_share_having_noaccess(self): access = fake_share.fake_access() share = fake_share.fake_share() export_list = ['10.0.0.2'] self.mock_object(self._helper, '_get_vol_exports', mock.Mock(return_value=export_list)) self._helper.allow_access(None, share, access) self._helper._get_vol_exports.assert_called_once_with() export_str = '10.0.0.2,10.0.0.1' argseq = (('volume', 'set', self._helper.gluster_manager.volume, NFS_RPC_AUTH_ALLOW, export_str), ('volume', 'reset', self._helper.gluster_manager.volume, NFS_RPC_AUTH_REJECT)) self.assertEqual( [mock.call(*a, log=mock.ANY) for a in argseq], self._helper.gluster_manager.gluster_call.call_args_list)
def test_manage_access_adding_entry(self): def cbk(d, key, value): d[key].append(value) access = fake_share.fake_access() export_dir_dict = { 'example.com': ['10.0.0.1'], 'fakename': ['10.0.0.2'], } export_str = '/example.com(10.0.0.1),/fakename(10.0.0.2|10.0.0.1)' args = ('volume', 'set', self._helper.gluster_manager.volume, NFS_EXPORT_DIR, export_str) self.mock_object(self._helper, '_get_export_dir_dict', mock.Mock(return_value=export_dir_dict)) ret = self._helper._manage_access(fake_share_name, access['access_type'], access['access_to'], cbk) self.assertEqual(None, ret) self._helper._get_export_dir_dict.assert_called_once_with() self._helper.gluster_manager.gluster_call.assert_called_once_with( *args)