Remove copy-pasted code for fake-share

There are amounts of copy-pasted code for fake separated
in different files, they should be put in one place.

This patch moves the following into module fake_share:
    * fake_share
    * fake_snapshot
    * fake_access

Partial-Bug: #1416285

Change-Id: I78e7fc56c80ee19a8c01c5f37b428f019aa47e58
This commit is contained in:
chen-li
2015-01-29 08:37:00 +08:00
committed by li,chen
parent 26e3301f6d
commit 7623504203
8 changed files with 159 additions and 278 deletions

View File

@@ -0,0 +1,56 @@
# Copyright 2013 OpenStack Foundation
# Copyright 2015 Intel, Inc.
# All Rights Reserved
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from manila.tests.db import fakes as db_fakes
def fake_share(**kwargs):
share = {
'id': 'fakeid',
'name': 'fakename',
'size': 1,
'share_proto': 'NFS',
'share_network_id': 'fake share network id',
'share_server_id': 'fake share server id',
'export_location': 'fake_location:/fake_share',
}
share.update(kwargs)
return db_fakes.FakeModel(share)
def fake_snapshot(**kwargs):
snapshot = {
'id': 'fakesnapshotid',
'share_name': 'fakename',
'share_id': 'fakeid',
'name': 'fakesnapshotname',
'share_size': 1,
'share_proto': 'NFS',
'export_location': 'fake_location:/fake_share',
}
snapshot.update(kwargs)
return db_fakes.FakeModel(snapshot)
def fake_access(**kwargs):
access = {
'id': 'fakeaccid',
'access_type': 'ip',
'access_to': '10.0.0.1',
'state': 'active',
}
access.update(kwargs)
return db_fakes.FakeModel(access)

View File

@@ -22,7 +22,7 @@ from manila.share import configuration as conf
from manila.share.drivers.emc import driver as emc_driver
from manila.share.drivers.emc.plugins.vnx import helper
from manila import test
from manila.tests import fake_share
LOG = logging.getLogger(__name__)
@@ -196,29 +196,8 @@ disks = d7
default_cifsserver_name = 'fakeserver2'
@staticmethod
def fake_share_nfs(**kwargs):
share = {
'id': 'fakeid',
'name': 'fakename',
'size': 1,
'share_proto': 'NFS',
'export_location': '127.0.0.1:/mnt/nfs/volume-00002',
}
share.update(kwargs)
return share
@staticmethod
def fake_share_cifs(**kwargs):
share = {
'id': 'fakeid',
'name': 'fakename',
'size': 1,
'share_proto': 'CIFS',
'export_location': '127.0.0.1:/mnt/nfs/volume-00002',
'share_network_id': 'fakesharenetworkid',
}
share.update(kwargs)
return share
def fake_share(**kwargs):
return fake_share.fake_share(**kwargs)
@staticmethod
def fake_share_server(**kwargs):
@@ -237,40 +216,17 @@ disks = d7
@staticmethod
def fake_snapshot(**kwargs):
snapshot = {
'id': 'fakesnapshotid',
'share_name': 'fakename',
'share_id': 'fakeid',
'name': 'fakesnapshotname',
'share_size': 1,
'size': 1,
'share_proto': 'NFS',
'export_location': '127.0.0.1:/mnt/nfs/volume-00002',
}
snapshot.update(kwargs)
return snapshot
return fake_share.fake_snapshot(**kwargs)
@staticmethod
def fake_access(**kwargs):
access = {
'id': 'fakeaccid',
'access_type': 'ip',
'access_to': '10.0.0.2',
'state': 'active',
}
access.update(kwargs)
return access
kwargs.update(access_to='10.0.0.2')
return fake_share.fake_access(**kwargs)
@staticmethod
def fake_access_subnet(**kwargs):
access = {
'id': 'fakeaccid',
'access_type': 'ip',
'access_to': '10.0.0.2/24',
'state': 'active',
}
access.update(kwargs)
return access
kwargs.update(access_to='10.0.0.2/24')
return fake_share.fake_access(**kwargs)
@staticmethod
def fake_security_services(**kwargs):
@@ -933,7 +889,7 @@ disks = d7
@staticmethod
def resp_allow_cifs_access(access):
cifs_share = TD.fake_share_cifs()
cifs_share = TD.fake_share(share_proto='CIFS')
domain = TD.fake_security_services()[0]['domain']
user = access['access_to']
return (
@@ -946,7 +902,7 @@ disks = d7
@staticmethod
def req_allow_deny_cifs_access(access, action='grant'):
cifs_share = TD.fake_share_cifs()
cifs_share = TD.fake_share(share_proto='CIFS')
domain = TD.fake_security_services()[0]['domain']
user = access['access_to']
account = user + '@' + domain
@@ -965,7 +921,7 @@ disks = d7
@staticmethod
def req_disable_cifs_access():
share_name = TD.fake_share_cifs()['name']
share_name = TD.fake_share(share_proto='CIFS')['name']
cmd_str = 'sharesd %s set noaccess' % share_name
return [
'env', 'NAS_DB=/nas',
@@ -1282,7 +1238,7 @@ class EMCShareDriverVNXTestCase(test.TestCase):
helper.SSHConnector.run_ssh.assert_has_calls(ssh_calls)
def test_create_nfs_share_default(self):
share = TD.fake_share_nfs()
share = TD.fake_share(share_proto='NFS')
share_server = TD.fake_share_server()
vdm_name = share_server['backend_details']['share_server_name']
hook = RequestSideEffect()
@@ -1305,7 +1261,7 @@ class EMCShareDriverVNXTestCase(test.TestCase):
"NFS export path is incorrect")
def test_delete_nfs_share_default(self):
share = TD.fake_share_nfs()
share = TD.fake_share(share_proto='NFS')
share_server = TD.fake_share_server()
mover_name = share_server['backend_details']['share_server_name']
path = '/' + share['name']
@@ -1336,7 +1292,7 @@ class EMCShareDriverVNXTestCase(test.TestCase):
helper.XMLAPIConnector.request.assert_has_calls(expected_calls)
def test_delete_nfs_share_but_share_absent(self):
share = TD.fake_share_nfs()
share = TD.fake_share(share_proto='NFS')
share_server = TD.fake_share_server()
mover_name = share_server['backend_details']['share_server_name']
path = '/' + share['name']
@@ -1365,7 +1321,7 @@ class EMCShareDriverVNXTestCase(test.TestCase):
helper.XMLAPIConnector.request.assert_has_calls(expected_calls)
def test_create_cifs_share_default(self):
share = TD.fake_share_cifs()
share = TD.fake_share(share_proto='CIFS')
hook = RequestSideEffect()
ssh_hook = SSHSideEffect()
share_server = TD.fake_share_server()
@@ -1391,7 +1347,7 @@ class EMCShareDriverVNXTestCase(test.TestCase):
"CIFS export path is incorrect")
def test_delete_cifs_share_default(self):
share = TD.fake_share_cifs()
share = TD.fake_share(share_proto='CIFS')
share_server = TD.fake_share_server()
hook = RequestSideEffect()
hook.append(TD.resp_get_cifs_share_by_name(share['name']))
@@ -1400,7 +1356,8 @@ class EMCShareDriverVNXTestCase(test.TestCase):
hook.append(TD.resp_get_filesystem(share['name']))
hook.append(TD.resp_task_succeed())
helper.XMLAPIConnector.request = mock.Mock(side_effect=hook)
self.driver.delete_share(None, TD.fake_share_cifs(), share_server)
self.driver.delete_share(
None, TD.fake_share(share_proto='CIFS'), share_server)
expected_calls = [
mock.call(TD.req_get_cifs_share_by_name(share['name'])),
mock.call(TD.req_delete_cifs_share(share['name'])),
@@ -1412,7 +1369,7 @@ class EMCShareDriverVNXTestCase(test.TestCase):
helper.XMLAPIConnector.request.assert_has_calls(expected_calls)
def test_delete_cifs_share_but_share_absent(self):
share = TD.fake_share_cifs()
share = TD.fake_share(share_proto='CIFS')
share_server = TD.fake_share_server()
hook = RequestSideEffect()
hook.append(TD.resp_get_cifs_share_by_name_absence(share['name']))
@@ -1420,7 +1377,8 @@ class EMCShareDriverVNXTestCase(test.TestCase):
hook.append(TD.resp_get_filesystem(share['name']))
hook.append(TD.resp_task_succeed())
helper.XMLAPIConnector.request = mock.Mock(side_effect=hook)
self.driver.delete_share(None, TD.fake_share_cifs(), share_server)
self.driver.delete_share(
None, TD.fake_share(share_proto='CIFS'), share_server)
expected_calls = [
mock.call(TD.req_get_cifs_share_by_name(share['name'])),
mock.call(TD.req_delete_mount('/' + share['name'])),
@@ -1481,7 +1439,7 @@ class EMCShareDriverVNXTestCase(test.TestCase):
helper.XMLAPIConnector.request.assert_has_calls(expected_calls)
def test_nfs_allow_access(self):
share = TD.fake_share_nfs()
share = TD.fake_share(share_proto='NFS')
access = TD.fake_access()
share_server = TD.fake_share_server()
mover_name = share_server['backend_details']['share_server_name']
@@ -1502,7 +1460,7 @@ class EMCShareDriverVNXTestCase(test.TestCase):
helper.SSHConnector.run_ssh.assert_has_calls(expected_calls)
def test_nfs_allow_access_subnet(self):
share = TD.fake_share_nfs()
share = TD.fake_share(share_proto='NFS')
access = TD.fake_access_subnet()
share_server = TD.fake_share_server()
mover_name = share_server['backend_details']['share_server_name']
@@ -1523,7 +1481,7 @@ class EMCShareDriverVNXTestCase(test.TestCase):
helper.SSHConnector.run_ssh.assert_has_calls(expected_calls)
def test_nfs_deny_access_subnet(self):
share = TD.fake_share_nfs()
share = TD.fake_share(share_proto='NFS')
access = TD.fake_access_subnet()
share_server = TD.fake_share_server()
mover_name = share_server['backend_details']['share_server_name']
@@ -1544,7 +1502,7 @@ class EMCShareDriverVNXTestCase(test.TestCase):
helper.SSHConnector.run_ssh.assert_has_calls(expected_calls)
def test_nfs_deny_access(self):
share = TD.fake_share_nfs()
share = TD.fake_share(share_proto='NFS')
access = TD.fake_access()
share_server = TD.fake_share_server()
mover_name = share_server['backend_details']['share_server_name']
@@ -1566,7 +1524,7 @@ class EMCShareDriverVNXTestCase(test.TestCase):
mock.Mock(return_value=TD.fake_share_network()))
def test_cifs_allow_access(self):
context = 'fake_context'
share = TD.fake_share_cifs()
share = TD.fake_share(share_proto='CIFS')
access = TD.fake_access(**{'access_type': 'user',
'access_to': 'administrator'})
share_server = TD.fake_share_server()
@@ -1583,7 +1541,7 @@ class EMCShareDriverVNXTestCase(test.TestCase):
mock.Mock(return_value=TD.fake_share_network()))
def test_cifs_deny_access(self):
context = 'fake_context'
share = TD.fake_share_cifs()
share = TD.fake_share(share_proto='CIFS')
access = TD.fake_access(**{'access_type': 'user',
'access_to': 'administrator'})
share_server = TD.fake_share_server()
@@ -1599,7 +1557,7 @@ class EMCShareDriverVNXTestCase(test.TestCase):
context, share['share_network_id'])
def test_create_share_from_snapshot(self):
share = TD.fake_share_nfs()
share = TD.fake_share(share_proto='NFS')
snap = TD.fake_snapshot()
share_server = TD.fake_share_server()
fake_ckpt = "fake_ckpt"

View File

@@ -26,50 +26,13 @@ import manila.share.configuration as config
import manila.share.drivers.ibm.ganesha_utils as ganesha_utils
import manila.share.drivers.ibm.gpfs as gpfs
from manila import test
from manila.tests.db import fakes as db_fakes
from manila.tests import fake_share
from manila import utils
CONF = cfg.CONF
def fake_share(**kwargs):
share = {
'id': 'fakeid',
'name': 'fakename',
'size': 1,
'share_proto': 'NFS',
'export_location': '127.0.0.1:/mnt/nfs/share-1',
}
share.update(kwargs)
return db_fakes.FakeModel(share)
def fake_snapshot(**kwargs):
snapshot = {
'id': 'fakesnapshotid',
'share_name': 'fakename',
'share_id': 'fakeid',
'name': 'fakesnapshotname',
'share_size': 1,
'share_proto': 'NFS',
'export_location': '127.0.0.1:/mnt/nfs/volume-00002',
}
snapshot.update(kwargs)
return db_fakes.FakeModel(snapshot)
def fake_access(**kwargs):
access = {
'id': 'fakeaccid',
'access_type': 'ip',
'access_to': '10.0.0.2',
'state': 'active',
}
access.update(kwargs)
return db_fakes.FakeModel(access)
class GPFSShareDriverTestCase(test.TestCase):
"""Tests GPFSShareDriver."""
@@ -97,15 +60,15 @@ class GPFSShareDriverTestCase(test.TestCase):
self._driver._helpers = {
'KNFS': self._helper_fake
}
self.share = fake_share()
self.share = fake_share.fake_share()
self.server = {
'backend_details': {
'ip': '1.2.3.4',
'instance_id': 'fake'
}
}
self.access = fake_access()
self.snapshot = fake_snapshot()
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]

View File

@@ -26,6 +26,7 @@ from manila.share.drivers.netapp import api as naapi
from manila.share.drivers.netapp import cluster_mode as driver
from manila.share.drivers.netapp import utils as na_utils
from manila import test
from manila.tests import fake_share
from manila import utils
@@ -48,23 +49,8 @@ class NetAppClusteredDrvTestCase(test.TestCase):
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.share = fake_share.fake_share()
self.snapshot = fake_share.fake_snapshot()
self.security_service = {'id': 'fake_id',
'domain': 'FAKE',
'server': 'fake_server',
@@ -76,9 +62,11 @@ class NetAppClusteredDrvTestCase(test.TestCase):
}
}
self.helper = mock.Mock()
self.driver._helpers = {'FAKE': self.helper}
self.driver._licenses = ['fake']
self.driver._helpers = {
'NFS': self.helper,
'CIFS': self.helper,
}
self.driver._licenses = ['nfs', 'cifs']
self.network_info = {
'server_id': 'fake_server_id',
'cidr': '10.0.0.0/24',
@@ -605,8 +593,8 @@ class NetAppClusteredDrvTestCase(test.TestCase):
self._vserver_client)
args = {'containing-aggr-name': 'fake3',
'size': '1g',
'volume': 'share_fake_uuid',
'junction-path': '/share_fake_uuid'
'volume': 'share_fakeid',
'junction-path': '/share_fakeid'
}
self._vserver_client.send_request.assert_called_with(
'volume-create', args)
@@ -616,10 +604,10 @@ class NetAppClusteredDrvTestCase(test.TestCase):
self.snapshot,
'vserver',
self._vserver_client)
args = {'volume': 'share_fake_uuid',
'parent-volume': 'share_fake_share_id',
'parent-snapshot': 'share_snapshot_fake_snapshot_uuid',
'junction-path': '/share_fake_uuid'}
args = {'volume': 'share_fakeid',
'parent-volume': 'share_fakeid',
'parent-snapshot': 'share_snapshot_fakesnapshotid',
'junction-path': '/share_fakeid'}
self._vserver_client.send_request.assert_called_with(
'volume-clone-create', args)
@@ -627,11 +615,11 @@ class NetAppClusteredDrvTestCase(test.TestCase):
self.driver._deallocate_container(self.share, self._vserver_client)
self._vserver_client.send_request.assert_has_calls([
mock.call('volume-unmount',
{'volume-name': 'share_fake_uuid'}),
{'volume-name': 'share_fakeid'}),
mock.call('volume-offline',
{'name': 'share_fake_uuid'}),
{'name': 'share_fakeid'}),
mock.call('volume-destroy',
{'name': 'share_fake_uuid'})
{'name': 'share_fakeid'})
])
def test_create_export(self):
@@ -691,8 +679,8 @@ class NetAppClusteredDrvTestCase(test.TestCase):
share_server=self.share_server)
self._vserver_client.send_request.assert_called_once_with(
'snapshot-create',
{'volume': 'share_fake_share_id',
'snapshot': 'share_snapshot_fake_snapshot_uuid'})
{'volume': 'share_fakeid',
'snapshot': 'share_snapshot_fakesnapshotid'})
def test_delete_share(self):
resp = mock.Mock()
@@ -777,13 +765,9 @@ class NetAppNFSHelperTestCase(test.TestCase):
self._db = mock.Mock()
self.client = mock.Mock()
self.name = 'fake_share_name'
self.share = {'id': 'fake_uuid',
'tenant_id': 'fake_tenant_id',
'name': self.name,
'size': 1,
'export_location': 'location:/%s' % self.name,
'share_server_id': 'fake-share-srv-id',
'share_proto': 'fake'}
export_location = 'location:/%s' % self.name
self.share = fake_share.fake_share(
share_proto='NFS', name=self.name, export_location=export_location)
self.helper = driver.NetAppClusteredNFSHelper()
self.helper._client = mock.Mock()
self.helper._client.send_request = mock.Mock()
@@ -911,12 +895,11 @@ class NetAppCIFSHelperTestCase(test.TestCase):
super(NetAppCIFSHelperTestCase, self).setUp()
self._context = context.get_admin_context()
self.name = 'fake_share_name'
self.share = {'id': 'fake_uuid',
'tenant_id': 'fake_tenant_id',
'name': self.name,
'size': 1,
'export_location': '//location/%s' % self.name,
'share_proto': 'fake'}
export_location = '//location/%s' % self.name
self.share = fake_share.fake_share(
share_proto='CIFS',
name=self.name,
export_location=export_location)
self.helper = driver.NetAppClusteredCIFSHelper()
self.stubs.Set(self.helper, '_client', mock.Mock())
self.stubs.Set(self.helper._client, 'send_request', mock.Mock())

View File

@@ -24,42 +24,21 @@ from manila import exception
from manila.share import configuration as config
from manila.share.drivers import ganesha
from manila import test
from manila.tests.db import fakes as db_fakes
from manila.tests import fake_share
CONF = cfg.CONF
def fake_access(**kwargs):
access = {
'id': 'fakeaccessid',
'access_type': 'ip',
'access_to': '10.0.0.1'
}
access.update(kwargs)
return db_fakes.FakeModel(access)
def fake_share(**kwargs):
share = {
'id': 'fakeid',
'name': 'fakename',
'size': 1,
'share_proto': 'NFS',
'export_location': '127.0.0.1:/mnt/nfs/testvol',
}
share.update(kwargs)
return db_fakes.FakeModel(share)
fake_basepath = '/fakepath'
fake_export_name = 'fakename--fakeaccessid'
fake_export_name = 'fakename--fakeaccid'
fake_output_template = {
'EXPORT': {
'Export_Id': 101,
'Path': '/fakepath/fakename',
'Pseudo': '/fakepath/fakename--fakeaccessid',
'Tag': 'fakeaccessid',
'Pseudo': '/fakepath/fakename--fakeaccid',
'Tag': 'fakeaccid',
'CLIENT': {
'Clients': '10.0.0.1'
},
@@ -87,8 +66,8 @@ class GaneshaNASHelperTestCase(test.TestCase):
self._execute, self.fake_conf, tag='faketag')
self._helper.ganesha = mock.Mock()
self._helper.export_template = {'key': 'value'}
self.share = fake_share()
self.access = fake_access()
self.share = fake_share.fake_share()
self.access = fake_share.fake_access()
def test_load_conf_dir(self):
fake_template1 = {'key': 'value1'}
@@ -264,7 +243,7 @@ class GaneshaNASHelperTestCase(test.TestCase):
self.assertEqual(None, ret)
def test_allow_access_error_invalid_share(self):
access = fake_access(access_type='notip')
access = fake_share.fake_access(access_type='notip')
self.assertRaises(exception.InvalidShareAccess,
self._helper.allow_access, '/fakepath',
self.share, access)
@@ -272,5 +251,5 @@ class GaneshaNASHelperTestCase(test.TestCase):
def test_deny_access(self):
ret = self._helper.deny_access('/fakepath', self.share, self.access)
self._helper.ganesha.remove_export.assert_called_once_with(
'fakename--fakeaccessid')
'fakename--fakeaccid')
self.assertEqual(None, ret)

View File

@@ -28,9 +28,9 @@ from manila import exception
import manila.share.configuration
from manila.share.drivers import generic
from manila import test
from manila.tests.db import fakes as db_fakes
from manila.tests import fake_compute
from manila.tests import fake_service_instance
from manila.tests import fake_share
from manila.tests import fake_utils
from manila.tests import fake_volume
from manila import utils
@@ -39,45 +39,6 @@ from manila import volume
CONF = cfg.CONF
def fake_share(**kwargs):
share = {
'id': 'fakeid',
'name': 'fakename',
'size': 1,
'share_proto': 'NFS',
'share_network_id': 'fake share network id',
'share_server_id': 'fake share server id',
'export_location': '127.0.0.1:/mnt/nfs/volume-00002',
}
share.update(kwargs)
return db_fakes.FakeModel(share)
def fake_snapshot(**kwargs):
snapshot = {
'id': 'fakesnapshotid',
'share_name': 'fakename',
'share_id': 'fakeid',
'name': 'fakesnapshotname',
'share_size': 1,
'share_proto': 'NFS',
'export_location': '127.0.0.1:/mnt/nfs/volume-00002',
}
snapshot.update(kwargs)
return db_fakes.FakeModel(snapshot)
def fake_access(**kwargs):
access = {
'id': 'fakeaccid',
'access_type': 'ip',
'access_to': '10.0.0.2',
'state': 'active',
}
access.update(kwargs)
return db_fakes.FakeModel(access)
class GenericShareDriverTestCase(test.TestCase):
"""Tests GenericShareDriver."""
@@ -126,7 +87,7 @@ class GenericShareDriverTestCase(test.TestCase):
'CIFS': self._helper_cifs,
'NFS': self._helper_nfs,
}
self.share = fake_share()
self.share = fake_share.fake_share()
self.server = {
'instance_id': 'fake_instance_id',
'ip': 'fake_ip',
@@ -138,8 +99,8 @@ class GenericShareDriverTestCase(test.TestCase):
'instance_id': 'fake'
}
}
self.access = fake_access()
self.snapshot = fake_snapshot()
self.access = fake_share.fake_access()
self.snapshot = fake_share.fake_snapshot()
def test_do_setup(self):
self.stubs.Set(volume, 'API', mock.Mock())
@@ -193,7 +154,7 @@ class GenericShareDriverTestCase(test.TestCase):
self.share, self.server['backend_details'], volume2)
def test_create_share_exception(self):
share = fake_share(share_network_id=None)
share = fake_share.fake_share(share_network_id=None)
self.assertRaises(exception.ManilaException, self._driver.create_share,
self._context, share)

View File

@@ -24,7 +24,7 @@ from manila import exception
from manila.share import configuration as config
from manila.share.drivers import glusterfs
from manila import test
from manila.tests.db import fakes as db_fakes
from manila.tests import fake_share
from manila.tests import fake_utils
@@ -44,18 +44,6 @@ fake_gluster_manager_attrs = {
fake_local_share_path = '/mnt/nfs/testvol/fakename'
def fake_share(**kwargs):
share = {
'id': 'fakeid',
'name': 'fakename',
'size': 1,
'share_proto': 'NFS',
'export_location': '127.0.0.1:/mnt/nfs/testvol',
}
share.update(kwargs)
return db_fakes.FakeModel(share)
fake_access = {'access_type': 'ip', 'access_to': '10.0.0.1'}
fake_args = ('foo', 'bar')
fake_kwargs = {'key1': 'value1', 'key2': 'value2'}
fake_path_to_private_key = '/fakepath/to/privatekey'
@@ -252,7 +240,7 @@ class GlusterfsShareDriverTestCase(test.TestCase):
configuration=self.fake_conf)
self._driver.gluster_manager = mock.Mock(**fake_gluster_manager_attrs)
self._helper_nfs = mock.Mock()
self.share = fake_share()
self.share = fake_share.fake_share(share_proto='NFS')
def test_do_setup(self):
fake_gluster_manager = mock.Mock(**fake_gluster_manager_attrs)
@@ -626,44 +614,50 @@ class GlusterfsShareDriverTestCase(test.TestCase):
self.assertEqual(None, ret)
def test_get_helper_not_implemented(self):
share = fake_share(share_proto='Others')
share = fake_share.fake_share(share_proto='Others')
self.assertRaises(
exception.InvalidShare, self._driver._get_helper, share)
def test_allow_access(self):
self.stubs.Set(self._driver, '_get_helper', mock.Mock())
ret = self._driver.allow_access(self._context, self.share,
fake_access)
fake_share.fake_access)
self._driver._get_helper.assert_called_once_with(self.share)
self._driver._get_helper().\
allow_access.assert_called_once_with('/', self.share, fake_access)
allow_access.assert_called_once_with(
'/', self.share, fake_share.fake_access)
self.assertEqual(None, ret)
def test_allow_access_can_be_called_with_extra_arg_share_server(self):
self.stubs.Set(self._driver, '_get_helper', mock.Mock())
ret = self._driver.allow_access(self._context, self.share,
fake_access, share_server=None)
fake_share.fake_access,
share_server=None)
self._driver._get_helper.assert_called_once_with(self.share)
self._driver._get_helper().\
allow_access.assert_called_once_with('/', self.share, fake_access)
allow_access.assert_called_once_with(
'/', self.share, fake_share.fake_access)
self.assertEqual(None, ret)
def test_deny_access(self):
self.stubs.Set(self._driver, '_get_helper', mock.Mock())
ret = self._driver.deny_access(self._context, self.share,
fake_access)
fake_share.fake_access)
self._driver._get_helper.assert_called_once_with(self.share)
self._driver._get_helper().\
deny_access.assert_called_once_with('/', self.share, fake_access)
deny_access.assert_called_once_with(
'/', self.share, fake_share.fake_access)
self.assertEqual(None, ret)
def test_deny_access_can_be_called_with_extra_arg_share_server(self):
self.stubs.Set(self._driver, '_get_helper', mock.Mock())
ret = self._driver.deny_access(self._context, self.share,
fake_access, share_server=None)
fake_share.fake_access,
share_server=None)
self._driver._get_helper.assert_called_once_with(self.share)
self._driver._get_helper().\
deny_access.assert_called_once_with('/', self.share, fake_access)
deny_access.assert_called_once_with(
'/', self.share, fake_share.fake_access)
self.assertEqual(None, ret)
@@ -721,7 +715,7 @@ class GlusterNFSHelperTestCase(test.TestCase):
def test_manage_access_noop(self):
cbk = mock.Mock(return_value=True)
access = fake_access
access = fake_share.fake_access()
export_dir_dict = mock.Mock()
self.stubs.Set(self._helper, '_get_export_dir_dict',
mock.Mock(return_value=export_dir_dict))
@@ -738,7 +732,7 @@ class GlusterNFSHelperTestCase(test.TestCase):
def cbk(d, key, value):
d[key].append(value)
access = fake_access
access = fake_share.fake_access()
export_dir_dict = {
'example.com': ['10.0.0.1'],
'fakename': ['10.0.0.2'],
@@ -764,7 +758,7 @@ class GlusterNFSHelperTestCase(test.TestCase):
def raise_exception(*args, **kwargs):
raise exception.ProcessExecutionError()
access = fake_access
access = fake_share.fake_access()
export_dir_dict = {
'example.com': ['10.0.0.1'],
'fakename': ['10.0.0.2'],
@@ -791,7 +785,7 @@ class GlusterNFSHelperTestCase(test.TestCase):
def cbk(d, key, value):
d.pop(key)
access = fake_access
access = fake_share.fake_access()
args = ('volume', 'reset', self._helper.gluster_manager.volume,
NFS_EXPORT_DIR)
export_dir_dict = {'fakename': ['10.0.0.1']}
@@ -806,8 +800,8 @@ class GlusterNFSHelperTestCase(test.TestCase):
*args)
def test_allow_access_with_share_having_noaccess(self):
access = fake_access
share = fake_share()
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,
@@ -820,8 +814,8 @@ class GlusterNFSHelperTestCase(test.TestCase):
*args)
def test_allow_access_with_share_having_access(self):
access = fake_access
share = fake_share()
access = fake_share.fake_access()
share = fake_share.fake_share()
export_dir_dict = {'fakename': ['10.0.0.1']}
self.stubs.Set(self._helper, '_get_export_dir_dict',
mock.Mock(return_value=export_dir_dict))
@@ -830,8 +824,8 @@ class GlusterNFSHelperTestCase(test.TestCase):
self.assertFalse(self._helper.gluster_manager.gluster_call.called)
def test_deny_access_with_share_having_noaccess(self):
access = fake_access
share = fake_share()
access = fake_share.fake_access()
share = fake_share.fake_share()
export_dir_dict = {}
self.stubs.Set(self._helper, '_get_export_dir_dict',
mock.Mock(return_value=export_dir_dict))
@@ -840,8 +834,8 @@ class GlusterNFSHelperTestCase(test.TestCase):
self.assertFalse(self._helper.gluster_manager.gluster_call.called)
def test_deny_access_with_share_having_access(self):
access = fake_access
share = fake_share()
access = fake_share.fake_access()
share = fake_share.fake_share()
export_dir_dict = {
'example.com': ['10.0.0.1'],
'fakename': ['10.0.0.1'],

View File

@@ -26,27 +26,14 @@ from manila import context
from manila import exception
from manila.share.drivers import service_instance
from manila import test
from manila.tests.db import fakes as db_fakes
from manila.tests import fake_compute
from manila.tests import fake_network
from manila.tests import fake_share
from manila import utils
CONF = cfg.CONF
def fake_share(**kwargs):
share = {
'id': 'fakeid',
'name': 'fakename',
'size': 1,
'share_proto': 'NFS',
'share_network_id': 'fake share network id',
'export_location': '127.0.0.1:/mnt/nfs/volume-00002',
}
share.update(kwargs)
return db_fakes.FakeModel(share)
class ServiceInstanceManagerTestCase(test.TestCase):
"""Tests InstanceManager."""
@@ -77,7 +64,7 @@ class ServiceInstanceManagerTestCase(test.TestCase):
'CIFS': self._helper_cifs,
'NFS': self._helper_nfs,
}
self.share = fake_share()
self.share = fake_share.fake_share()
self.instance_id = 'fake_instance_id'
def test_get_service_network_net_exists(self):