Replace legacy StubOutForTesting class

The Manila test module uses a class called StubOutForTesting, which
is an awkward holdover from when the unit tests were using Mox.
Alex wrote a more elegant and capable mocker method,
manila.test.TestCase.mock_object, in the Cinder project which we
have now added to Manila. So to remove the duplicate functionality
and legacy code, all references to self.stubs.Set() in the Manila
tests should be replaced with self.mock_object() and any related
dead code should be removed.

Resolves-bug: #1415602
Change-Id: Ie5f203c0b2cb57ad00d9ec8db0529075b6fef261
This commit is contained in:
Clinton Knight 2015-01-28 14:35:02 -05:00
parent 77e3087ad0
commit 65d1158526
46 changed files with 1311 additions and 1364 deletions

View File

@ -101,16 +101,6 @@ class Database(fixtures.Fixture):
db_migrate.stamp('head') db_migrate.stamp('head')
class StubOutForTesting(object):
def __init__(self, parent):
self.parent = parent
def Set(self, obj, attr_name, new_attr):
stub = mock.patch.object(obj, attr_name, new_attr)
stub.start()
self.parent.addCleanup(stub.stop)
class TestCase(base_test.BaseTestCase): class TestCase(base_test.BaseTestCase):
"""Test case base class for all unit tests.""" """Test case base class for all unit tests."""
@ -132,7 +122,6 @@ class TestCase(base_test.BaseTestCase):
) )
self.useFixture(_DB_CACHE) self.useFixture(_DB_CACHE)
self.stubs = StubOutForTesting(self)
self.injected = [] self.injected = []
self._services = [] self._services = []
self.flags(fatal_exception_format_errors=True) self.flags(fatal_exception_format_errors=True)
@ -153,7 +142,7 @@ class TestCase(base_test.BaseTestCase):
self.useFixture(self.messaging_conf) self.useFixture(self.messaging_conf)
rpc.init(CONF) rpc.init(CONF)
fake_notifier.stub_notifier(self.stubs) fake_notifier.stub_notifier(self)
def tearDown(self): def tearDown(self):
"""Runs after each test method to tear down test environment.""" """Runs after each test method to tear down test environment."""
@ -195,12 +184,12 @@ class TestCase(base_test.BaseTestCase):
self._services.append(svc) self._services.append(svc)
return svc return svc
# TODO(cknight): StubOutForTesting should be removed in favor of this.
def mock_object(self, obj, attr_name, new_attr=None, **kwargs): def mock_object(self, obj, attr_name, new_attr=None, **kwargs):
"""Use python mock to mock an object attribute """Use python mock to mock an object attribute
Mocks the specified objects attribute with the given value. Mocks the specified objects attribute with the given value.
Automatically performs 'addCleanup' for the mock. Automatically performs 'addCleanup' for the mock.
""" """
if not new_attr: if not new_attr:
new_attr = mock.Mock() new_attr = mock.Mock()

View File

@ -207,9 +207,10 @@ class AdminActionsTest(test.TestCase):
def test_admin_force_delete_snapshot(self): def test_admin_force_delete_snapshot(self):
snapshot = stubs.stub_snapshot(1, host='foo') snapshot = stubs.stub_snapshot(1, host='foo')
self.stubs.Set(db, 'share_get', lambda x, y: snapshot) self.mock_object(db, 'share_get', lambda x, y: snapshot)
self.stubs.Set(db, 'share_snapshot_get', lambda x, y: snapshot) self.mock_object(db, 'share_snapshot_get', lambda x, y: snapshot)
self.stubs.Set(share_api.API, 'delete_snapshot', lambda *x, **y: True) self.mock_object(share_api.API, 'delete_snapshot',
lambda *x, **y: True)
path = '/v1/fake/snapshots/%s/action' % snapshot['id'] path = '/v1/fake/snapshots/%s/action' % snapshot['id']
req = webob.Request.blank(path) req = webob.Request.blank(path)
req.method = 'POST' req.method = 'POST'
@ -221,9 +222,10 @@ class AdminActionsTest(test.TestCase):
def test_member_force_delete_snapshot(self): def test_member_force_delete_snapshot(self):
snapshot = stubs.stub_snapshot(1, host='foo') snapshot = stubs.stub_snapshot(1, host='foo')
self.stubs.Set(db, 'share_get', lambda x, y: snapshot) self.mock_object(db, 'share_get', lambda x, y: snapshot)
self.stubs.Set(db, 'share_snapshot_get', lambda x, y: snapshot) self.mock_object(db, 'share_snapshot_get', lambda x, y: snapshot)
self.stubs.Set(share_api.API, 'delete_snapshot', lambda *x, **y: True) self.mock_object(share_api.API, 'delete_snapshot',
lambda *x, **y: True)
path = '/v1/fake/snapshots/%s/action' % snapshot['id'] path = '/v1/fake/snapshots/%s/action' % snapshot['id']
req = webob.Request.blank(path) req = webob.Request.blank(path)
req.method = 'POST' req.method = 'POST'

View File

@ -180,12 +180,12 @@ class ServicesTest(test.TestCase):
def setUp(self): def setUp(self):
super(ServicesTest, self).setUp() super(ServicesTest, self).setUp()
self.stubs.Set(db, "service_get_all", fake_service_get_all) self.mock_object(db, "service_get_all", fake_service_get_all)
self.stubs.Set(timeutils, "utcnow", fake_utcnow) self.mock_object(timeutils, "utcnow", fake_utcnow)
self.stubs.Set(db, "service_get_by_args", self.mock_object(db, "service_get_by_args",
fake_service_get_by_host_binary) fake_service_get_by_host_binary)
self.stubs.Set(db, "service_update", fake_service_update) self.mock_object(db, "service_update", fake_service_update)
self.stubs.Set(policy, "enforce", fake_policy_enforce) self.mock_object(policy, "enforce", fake_policy_enforce)
self.context = context.get_admin_context() self.context = context.get_admin_context()
self.controller = services.ServiceController() self.controller = services.ServiceController()

View File

@ -48,12 +48,12 @@ class ShareActionsTest(test.TestCase):
super(ShareActionsTest, self).setUp() super(ShareActionsTest, self).setUp()
self.controller = share_actions.ShareActionsController() self.controller = share_actions.ShareActionsController()
self.stubs.Set(share_api.API, 'get', stubs.stub_share_get) self.mock_object(share_api.API, 'get', stubs.stub_share_get)
def test_allow_access(self): def test_allow_access(self):
def _stub_allow_access(*args, **kwargs): def _stub_allow_access(*args, **kwargs):
return {'fake': 'fake'} return {'fake': 'fake'}
self.stubs.Set(share_api.API, "allow_access", _stub_allow_access) self.mock_object(share_api.API, "allow_access", _stub_allow_access)
id = 'fake_share_id' id = 'fake_share_id'
body = { body = {
@ -70,7 +70,7 @@ class ShareActionsTest(test.TestCase):
def test_allow_access_cert_min_accessto(self): def test_allow_access_cert_min_accessto(self):
def _stub_allow_access(*args, **kwargs): def _stub_allow_access(*args, **kwargs):
return {'fake': 'fake'} return {'fake': 'fake'}
self.stubs.Set(share_api.API, "allow_access", _stub_allow_access) self.mock_object(share_api.API, "allow_access", _stub_allow_access)
body = { body = {
"os-allow_access": { "os-allow_access": {
@ -86,7 +86,7 @@ class ShareActionsTest(test.TestCase):
def test_allow_access_cert_typical_accessto(self): def test_allow_access_cert_typical_accessto(self):
def _stub_allow_access(*args, **kwargs): def _stub_allow_access(*args, **kwargs):
return {'fake': 'fake'} return {'fake': 'fake'}
self.stubs.Set(share_api.API, "allow_access", _stub_allow_access) self.mock_object(share_api.API, "allow_access", _stub_allow_access)
body = { body = {
"os-allow_access": { "os-allow_access": {
@ -102,7 +102,7 @@ class ShareActionsTest(test.TestCase):
def test_allow_access_cert_max_accessto(self): def test_allow_access_cert_max_accessto(self):
def _stub_allow_access(*args, **kwargs): def _stub_allow_access(*args, **kwargs):
return {'fake': 'fake'} return {'fake': 'fake'}
self.stubs.Set(share_api.API, "allow_access", _stub_allow_access) self.mock_object(share_api.API, "allow_access", _stub_allow_access)
access_to = 'x' * 64 access_to = 'x' * 64
body = { body = {
@ -204,8 +204,8 @@ class ShareActionsTest(test.TestCase):
def _stub_deny_access(*args, **kwargs): def _stub_deny_access(*args, **kwargs):
pass pass
self.stubs.Set(share_api.API, "deny_access", _stub_deny_access) self.mock_object(share_api.API, "deny_access", _stub_deny_access)
self.stubs.Set(share_api.API, "access_get", _fake_access_get) self.mock_object(share_api.API, "access_get", _fake_access_get)
id = 'fake_share_id' id = 'fake_share_id'
body = {"os-deny_access": {"access_id": 'fake_acces_id'}} body = {"os-deny_access": {"access_id": 'fake_acces_id'}}
@ -217,8 +217,8 @@ class ShareActionsTest(test.TestCase):
def _stub_deny_access(*args, **kwargs): def _stub_deny_access(*args, **kwargs):
pass pass
self.stubs.Set(share_api.API, "deny_access", _stub_deny_access) self.mock_object(share_api.API, "deny_access", _stub_deny_access)
self.stubs.Set(share_api.API, "access_get", _fake_access_get) self.mock_object(share_api.API, "access_get", _fake_access_get)
id = 'super_fake_share_id' id = 'super_fake_share_id'
body = {"os-deny_access": {"access_id": 'fake_acces_id'}} body = {"os-deny_access": {"access_id": 'fake_acces_id'}}
@ -236,7 +236,8 @@ class ShareActionsTest(test.TestCase):
"access_type": "fakeip", "access_type": "fakeip",
"access_to": "127.0.0.1"}] "access_to": "127.0.0.1"}]
self.stubs.Set(share_api.API, "access_get_all", _fake_access_get_all) self.mock_object(share_api.API, "access_get_all",
_fake_access_get_all)
id = 'fake_share_id' id = 'fake_share_id'
body = {"os-access_list": None} body = {"os-access_list": None}
req = fakes.HTTPRequest.blank('/v1/tenant1/shares/%s/action' % id) req = fakes.HTTPRequest.blank('/v1/tenant1/shares/%s/action' % id)

View File

@ -65,7 +65,7 @@ class VolumeTypesExtraSpecsTest(test.TestCase):
def setUp(self): def setUp(self):
super(VolumeTypesExtraSpecsTest, self).setUp() super(VolumeTypesExtraSpecsTest, self).setUp()
self.flags(host='fake') self.flags(host='fake')
self.stubs.Set(manila.db, 'volume_type_get', volume_type_get) self.mock_object(manila.db, 'volume_type_get', volume_type_get)
self.api_path = '/v2/fake/os-volume-types/1/extra_specs' self.api_path = '/v2/fake/os-volume-types/1/extra_specs'
self.controller = types_extra_specs.VolumeTypeExtraSpecsController() self.controller = types_extra_specs.VolumeTypeExtraSpecsController()
@ -74,8 +74,8 @@ class VolumeTypesExtraSpecsTest(test.TestCase):
self.addCleanup(fake_notifier.reset) self.addCleanup(fake_notifier.reset)
def test_index(self): def test_index(self):
self.stubs.Set(manila.db, 'volume_type_extra_specs_get', self.mock_object(manila.db, 'volume_type_extra_specs_get',
return_volume_type_extra_specs) return_volume_type_extra_specs)
req = fakes.HTTPRequest.blank(self.api_path) req = fakes.HTTPRequest.blank(self.api_path)
res_dict = self.controller.index(req, 1) res_dict = self.controller.index(req, 1)
@ -83,8 +83,8 @@ class VolumeTypesExtraSpecsTest(test.TestCase):
self.assertEqual('value1', res_dict['extra_specs']['key1']) self.assertEqual('value1', res_dict['extra_specs']['key1'])
def test_index_no_data(self): def test_index_no_data(self):
self.stubs.Set(manila.db, 'volume_type_extra_specs_get', self.mock_object(manila.db, 'volume_type_extra_specs_get',
return_empty_volume_type_extra_specs) return_empty_volume_type_extra_specs)
req = fakes.HTTPRequest.blank(self.api_path) req = fakes.HTTPRequest.blank(self.api_path)
res_dict = self.controller.index(req, 1) res_dict = self.controller.index(req, 1)
@ -92,8 +92,8 @@ class VolumeTypesExtraSpecsTest(test.TestCase):
self.assertEqual(0, len(res_dict['extra_specs'])) self.assertEqual(0, len(res_dict['extra_specs']))
def test_show(self): def test_show(self):
self.stubs.Set(manila.db, 'volume_type_extra_specs_get', self.mock_object(manila.db, 'volume_type_extra_specs_get',
return_volume_type_extra_specs) return_volume_type_extra_specs)
req = fakes.HTTPRequest.blank(self.api_path + '/key5') req = fakes.HTTPRequest.blank(self.api_path + '/key5')
res_dict = self.controller.show(req, 1, 'key5') res_dict = self.controller.show(req, 1, 'key5')
@ -101,16 +101,16 @@ class VolumeTypesExtraSpecsTest(test.TestCase):
self.assertEqual('value5', res_dict['key5']) self.assertEqual('value5', res_dict['key5'])
def test_show_spec_not_found(self): def test_show_spec_not_found(self):
self.stubs.Set(manila.db, 'volume_type_extra_specs_get', self.mock_object(manila.db, 'volume_type_extra_specs_get',
return_empty_volume_type_extra_specs) return_empty_volume_type_extra_specs)
req = fakes.HTTPRequest.blank(self.api_path + '/key6') req = fakes.HTTPRequest.blank(self.api_path + '/key6')
self.assertRaises(webob.exc.HTTPNotFound, self.controller.show, self.assertRaises(webob.exc.HTTPNotFound, self.controller.show,
req, 1, 'key6') req, 1, 'key6')
def test_delete(self): def test_delete(self):
self.stubs.Set(manila.db, 'volume_type_extra_specs_delete', self.mock_object(manila.db, 'volume_type_extra_specs_delete',
delete_volume_type_extra_specs) delete_volume_type_extra_specs)
self.assertEqual(len(fake_notifier.NOTIFICATIONS), 0) self.assertEqual(len(fake_notifier.NOTIFICATIONS), 0)
req = fakes.HTTPRequest.blank(self.api_path + '/key5') req = fakes.HTTPRequest.blank(self.api_path + '/key5')
@ -118,17 +118,17 @@ class VolumeTypesExtraSpecsTest(test.TestCase):
self.assertEqual(len(fake_notifier.NOTIFICATIONS), 1) self.assertEqual(len(fake_notifier.NOTIFICATIONS), 1)
def test_delete_not_found(self): def test_delete_not_found(self):
self.stubs.Set(manila.db, 'volume_type_extra_specs_delete', self.mock_object(manila.db, 'volume_type_extra_specs_delete',
delete_volume_type_extra_specs_not_found) delete_volume_type_extra_specs_not_found)
req = fakes.HTTPRequest.blank(self.api_path + '/key6') req = fakes.HTTPRequest.blank(self.api_path + '/key6')
self.assertRaises(webob.exc.HTTPNotFound, self.controller.delete, self.assertRaises(webob.exc.HTTPNotFound, self.controller.delete,
req, 1, 'key6') req, 1, 'key6')
def test_create(self): def test_create(self):
self.stubs.Set(manila.db, self.mock_object(manila.db,
'volume_type_extra_specs_update_or_create', 'volume_type_extra_specs_update_or_create',
return_create_volume_type_extra_specs) return_create_volume_type_extra_specs)
body = {"extra_specs": {"key1": "value1"}} body = {"extra_specs": {"key1": "value1"}}
self.assertEqual(len(fake_notifier.NOTIFICATIONS), 0) self.assertEqual(len(fake_notifier.NOTIFICATIONS), 0)
@ -139,9 +139,9 @@ class VolumeTypesExtraSpecsTest(test.TestCase):
self.assertEqual('value1', res_dict['extra_specs']['key1']) self.assertEqual('value1', res_dict['extra_specs']['key1'])
def test_create_with_too_small_key(self): def test_create_with_too_small_key(self):
self.stubs.Set(manila.db, self.mock_object(manila.db,
'volume_type_extra_specs_update_or_create', 'volume_type_extra_specs_update_or_create',
return_create_volume_type_extra_specs) return_create_volume_type_extra_specs)
too_small_key = "" too_small_key = ""
body = {"extra_specs": {too_small_key: "value"}} body = {"extra_specs": {too_small_key: "value"}}
self.assertEqual(len(fake_notifier.NOTIFICATIONS), 0) self.assertEqual(len(fake_notifier.NOTIFICATIONS), 0)
@ -150,9 +150,9 @@ class VolumeTypesExtraSpecsTest(test.TestCase):
self.controller.create, req, 1, body) self.controller.create, req, 1, body)
def test_create_with_too_big_key(self): def test_create_with_too_big_key(self):
self.stubs.Set(manila.db, self.mock_object(manila.db,
'volume_type_extra_specs_update_or_create', 'volume_type_extra_specs_update_or_create',
return_create_volume_type_extra_specs) return_create_volume_type_extra_specs)
too_big_key = "k" * 256 too_big_key = "k" * 256
body = {"extra_specs": {too_big_key: "value"}} body = {"extra_specs": {too_big_key: "value"}}
self.assertEqual(len(fake_notifier.NOTIFICATIONS), 0) self.assertEqual(len(fake_notifier.NOTIFICATIONS), 0)
@ -161,9 +161,9 @@ class VolumeTypesExtraSpecsTest(test.TestCase):
self.controller.create, req, 1, body) self.controller.create, req, 1, body)
def test_create_with_too_small_value(self): def test_create_with_too_small_value(self):
self.stubs.Set(manila.db, self.mock_object(manila.db,
'volume_type_extra_specs_update_or_create', 'volume_type_extra_specs_update_or_create',
return_create_volume_type_extra_specs) return_create_volume_type_extra_specs)
too_small_value = "" too_small_value = ""
body = {"extra_specs": {"key": too_small_value}} body = {"extra_specs": {"key": too_small_value}}
self.assertEqual(len(fake_notifier.NOTIFICATIONS), 0) self.assertEqual(len(fake_notifier.NOTIFICATIONS), 0)
@ -172,9 +172,9 @@ class VolumeTypesExtraSpecsTest(test.TestCase):
self.controller.create, req, 1, body) self.controller.create, req, 1, body)
def test_create_with_too_big_value(self): def test_create_with_too_big_value(self):
self.stubs.Set(manila.db, self.mock_object(manila.db,
'volume_type_extra_specs_update_or_create', 'volume_type_extra_specs_update_or_create',
return_create_volume_type_extra_specs) return_create_volume_type_extra_specs)
too_big_value = "v" * 256 too_big_value = "v" * 256
body = {"extra_specs": {"key": too_big_value}} body = {"extra_specs": {"key": too_big_value}}
self.assertEqual(len(fake_notifier.NOTIFICATIONS), 0) self.assertEqual(len(fake_notifier.NOTIFICATIONS), 0)
@ -231,9 +231,9 @@ class VolumeTypesExtraSpecsTest(test.TestCase):
res_dict['extra_specs']['other3_alphanum.-_:']) res_dict['extra_specs']['other3_alphanum.-_:'])
def test_update_item(self): def test_update_item(self):
self.stubs.Set(manila.db, self.mock_object(manila.db,
'volume_type_extra_specs_update_or_create', 'volume_type_extra_specs_update_or_create',
return_create_volume_type_extra_specs) return_create_volume_type_extra_specs)
body = {"key1": "value1"} body = {"key1": "value1"}
self.assertEqual(len(fake_notifier.NOTIFICATIONS), 0) self.assertEqual(len(fake_notifier.NOTIFICATIONS), 0)
@ -244,9 +244,9 @@ class VolumeTypesExtraSpecsTest(test.TestCase):
self.assertEqual('value1', res_dict['key1']) self.assertEqual('value1', res_dict['key1'])
def test_update_item_too_many_keys(self): def test_update_item_too_many_keys(self):
self.stubs.Set(manila.db, self.mock_object(manila.db,
'volume_type_extra_specs_update_or_create', 'volume_type_extra_specs_update_or_create',
return_create_volume_type_extra_specs) return_create_volume_type_extra_specs)
body = {"key1": "value1", "key2": "value2"} body = {"key1": "value1", "key2": "value2"}
req = fakes.HTTPRequest.blank(self.api_path + '/key1') req = fakes.HTTPRequest.blank(self.api_path + '/key1')
@ -254,9 +254,9 @@ class VolumeTypesExtraSpecsTest(test.TestCase):
req, 1, 'key1', body) req, 1, 'key1', body)
def test_update_item_body_uri_mismatch(self): def test_update_item_body_uri_mismatch(self):
self.stubs.Set(manila.db, self.mock_object(manila.db,
'volume_type_extra_specs_update_or_create', 'volume_type_extra_specs_update_or_create',
return_create_volume_type_extra_specs) return_create_volume_type_extra_specs)
body = {"key1": "value1"} body = {"key1": "value1"}
req = fakes.HTTPRequest.blank(self.api_path + '/bad') req = fakes.HTTPRequest.blank(self.api_path + '/bad')

View File

@ -80,14 +80,14 @@ class VolumeTypesManageApiTest(test.TestCase):
"""to reset notifier drivers left over from other api/contrib tests""" """to reset notifier drivers left over from other api/contrib tests"""
fake_notifier.reset() fake_notifier.reset()
self.addCleanup(fake_notifier.reset) self.addCleanup(fake_notifier.reset)
self.stubs.Set(volume_types, 'create', self.mock_object(volume_types, 'create',
return_volume_types_create) return_volume_types_create)
self.stubs.Set(volume_types, 'get_volume_type_by_name', self.mock_object(volume_types, 'get_volume_type_by_name',
return_volume_types_get_by_name) return_volume_types_get_by_name)
self.stubs.Set(volume_types, 'get_volume_type', self.mock_object(volume_types, 'get_volume_type',
return_volume_types_get_volume_type) return_volume_types_get_volume_type)
self.stubs.Set(volume_types, 'destroy', self.mock_object(volume_types, 'destroy',
return_volume_types_destroy) return_volume_types_destroy)
def test_volume_types_delete(self): def test_volume_types_delete(self):
req = fakes.HTTPRequest.blank('/v2/fake/types/1') req = fakes.HTTPRequest.blank('/v2/fake/types/1')

View File

@ -30,7 +30,6 @@ from manila.api.v1 import limits
from manila.api.v1 import router from manila.api.v1 import router
from manila.api import versions from manila.api import versions
from manila import context from manila import context
from manila import exception as exc
from manila import wsgi from manila import wsgi
@ -84,33 +83,6 @@ def wsgi_app(inner_app_v2=None, fake_auth=True, fake_auth_context=None,
return mapper return mapper
def stub_out_rate_limiting(stubs):
def fake_rate_init(self, app):
# super(limits.RateLimitingMiddleware, self).__init__(app)
self.application = app
# FIXME(ja): unsure about limits in volumes
# stubs.Set(manila.api.openstack.compute.limits.RateLimitingMiddleware,
# '__init__', fake_rate_init)
# stubs.Set(manila.api.openstack.compute.limits.RateLimitingMiddleware,
# '__call__', fake_wsgi)
def stub_out_key_pair_funcs(stubs, have_key_pair=True):
def key_pair(context, user_id):
return [dict(name='key', public_key='public_key')]
def one_key_pair(context, user_id, name):
if name == 'key':
return dict(name='key', public_key='public_key')
else:
raise exc.KeypairNotFound(user_id=user_id, name=name)
def no_key_pair(context, user_id):
return []
class FakeToken(object): class FakeToken(object):
id_count = 0 id_count = 0

View File

@ -52,15 +52,15 @@ class BaseLimitTestSuite(test.TestCase):
def setUp(self): def setUp(self):
super(BaseLimitTestSuite, self).setUp() super(BaseLimitTestSuite, self).setUp()
self.time = 0.0 self.time = 0.0
self.stubs.Set(limits.Limit, "_get_time", self._get_time) self.mock_object(limits.Limit, "_get_time", self._get_time)
self.absolute_limits = {} self.absolute_limits = {}
def stub_get_project_quotas(context, project_id, usages=True): def stub_get_project_quotas(context, project_id, usages=True):
return dict((k, dict(limit=v)) return dict((k, dict(limit=v))
for k, v in self.absolute_limits.items()) for k, v in self.absolute_limits.items())
self.stubs.Set(manila.quota.QUOTAS, "get_project_quotas", self.mock_object(manila.quota.QUOTAS, "get_project_quotas",
stub_get_project_quotas) stub_get_project_quotas)
def _get_time(self): def _get_time(self):
"""Return the "time" according to this test suite.""" """Return the "time" according to this test suite."""

View File

@ -107,7 +107,7 @@ class ShareApiTest(test.TestCase):
sec_service = self.ss_active_directory.copy() sec_service = self.ss_active_directory.copy()
create_stub = mock.Mock( create_stub = mock.Mock(
return_value=sec_service) return_value=sec_service)
self.stubs.Set(db, 'security_service_create', create_stub) self.mock_object(db, 'security_service_create', create_stub)
req = fakes.HTTPRequest.blank('/security-services') req = fakes.HTTPRequest.blank('/security-services')
res_dict = self.controller.create( res_dict = self.controller.create(

View File

@ -90,13 +90,12 @@ class ShareMetaDataTest(test.TestCase):
def setUp(self): def setUp(self):
super(ShareMetaDataTest, self).setUp() super(ShareMetaDataTest, self).setUp()
self.share_api = manila.share.api.API() self.share_api = manila.share.api.API()
fakes.stub_out_key_pair_funcs(self.stubs) self.mock_object(manila.db, 'share_get', return_share)
self.stubs.Set(manila.db, 'share_get', return_share) self.mock_object(manila.db, 'share_metadata_get',
self.stubs.Set(manila.db, 'share_metadata_get', return_share_metadata)
return_share_metadata)
self.stubs.Set(self.share_api, 'update_share_metadata', self.mock_object(self.share_api, 'update_share_metadata',
fake_update_share_metadata) fake_update_share_metadata)
self.share_controller = shares.ShareController() self.share_controller = shares.ShareController()
self.controller = share_metadata.ShareMetadataController() self.controller = share_metadata.ShareMetadataController()
@ -127,15 +126,15 @@ class ShareMetaDataTest(test.TestCase):
self.assertEqual(expected, res_dict) self.assertEqual(expected, res_dict)
def test_index_nonexistent_share(self): def test_index_nonexistent_share(self):
self.stubs.Set(manila.db, 'share_metadata_get', self.mock_object(manila.db, 'share_metadata_get',
return_share_nonexistent) return_share_nonexistent)
req = fakes.HTTPRequest.blank(self.url) req = fakes.HTTPRequest.blank(self.url)
self.assertRaises(webob.exc.HTTPNotFound, self.assertRaises(webob.exc.HTTPNotFound,
self.controller.index, req, self.url) self.controller.index, req, self.url)
def test_index_no_data(self): def test_index_no_data(self):
self.stubs.Set(manila.db, 'share_metadata_get', self.mock_object(manila.db, 'share_metadata_get',
return_empty_share_metadata) return_empty_share_metadata)
req = fakes.HTTPRequest.blank(self.url) req = fakes.HTTPRequest.blank(self.url)
res_dict = self.controller.index(req, self.req_id) res_dict = self.controller.index(req, self.req_id)
expected = {'metadata': {}} expected = {'metadata': {}}
@ -148,24 +147,24 @@ class ShareMetaDataTest(test.TestCase):
self.assertEqual(expected, res_dict) self.assertEqual(expected, res_dict)
def test_show_nonexistent_share(self): def test_show_nonexistent_share(self):
self.stubs.Set(manila.db, 'share_metadata_get', self.mock_object(manila.db, 'share_metadata_get',
return_share_nonexistent) return_share_nonexistent)
req = fakes.HTTPRequest.blank(self.url + '/key2') req = fakes.HTTPRequest.blank(self.url + '/key2')
self.assertRaises(webob.exc.HTTPNotFound, self.assertRaises(webob.exc.HTTPNotFound,
self.controller.show, req, self.req_id, 'key2') self.controller.show, req, self.req_id, 'key2')
def test_show_meta_not_found(self): def test_show_meta_not_found(self):
self.stubs.Set(manila.db, 'share_metadata_get', self.mock_object(manila.db, 'share_metadata_get',
return_empty_share_metadata) return_empty_share_metadata)
req = fakes.HTTPRequest.blank(self.url + '/key6') req = fakes.HTTPRequest.blank(self.url + '/key6')
self.assertRaises(webob.exc.HTTPNotFound, self.assertRaises(webob.exc.HTTPNotFound,
self.controller.show, req, self.req_id, 'key6') self.controller.show, req, self.req_id, 'key6')
def test_delete(self): def test_delete(self):
self.stubs.Set(manila.db, 'share_metadata_get', self.mock_object(manila.db, 'share_metadata_get',
return_share_metadata) return_share_metadata)
self.stubs.Set(manila.db, 'share_metadata_delete', self.mock_object(manila.db, 'share_metadata_delete',
delete_share_metadata) delete_share_metadata)
req = fakes.HTTPRequest.blank(self.url + '/key2') req = fakes.HTTPRequest.blank(self.url + '/key2')
req.method = 'DELETE' req.method = 'DELETE'
res = self.controller.delete(req, self.req_id, 'key2') res = self.controller.delete(req, self.req_id, 'key2')
@ -173,26 +172,26 @@ class ShareMetaDataTest(test.TestCase):
self.assertEqual(200, res.status_int) self.assertEqual(200, res.status_int)
def test_delete_nonexistent_share(self): def test_delete_nonexistent_share(self):
self.stubs.Set(manila.db, 'share_get', self.mock_object(manila.db, 'share_get',
return_share_nonexistent) return_share_nonexistent)
req = fakes.HTTPRequest.blank(self.url + '/key1') req = fakes.HTTPRequest.blank(self.url + '/key1')
req.method = 'DELETE' req.method = 'DELETE'
self.assertRaises(webob.exc.HTTPNotFound, self.assertRaises(webob.exc.HTTPNotFound,
self.controller.delete, req, self.req_id, 'key1') self.controller.delete, req, self.req_id, 'key1')
def test_delete_meta_not_found(self): def test_delete_meta_not_found(self):
self.stubs.Set(manila.db, 'share_metadata_get', self.mock_object(manila.db, 'share_metadata_get',
return_empty_share_metadata) return_empty_share_metadata)
req = fakes.HTTPRequest.blank(self.url + '/key6') req = fakes.HTTPRequest.blank(self.url + '/key6')
req.method = 'DELETE' req.method = 'DELETE'
self.assertRaises(webob.exc.HTTPNotFound, self.assertRaises(webob.exc.HTTPNotFound,
self.controller.delete, req, self.req_id, 'key6') self.controller.delete, req, self.req_id, 'key6')
def test_create(self): def test_create(self):
self.stubs.Set(manila.db, 'share_metadata_get', self.mock_object(manila.db, 'share_metadata_get',
return_empty_share_metadata) return_empty_share_metadata)
self.stubs.Set(manila.db, 'share_metadata_update', self.mock_object(manila.db, 'share_metadata_update',
return_create_share_metadata) return_create_share_metadata)
req = fakes.HTTPRequest.blank('/v1/share_metadata') req = fakes.HTTPRequest.blank('/v1/share_metadata')
req.method = 'POST' req.method = 'POST'
@ -203,8 +202,8 @@ class ShareMetaDataTest(test.TestCase):
self.assertEqual(body, res_dict) self.assertEqual(body, res_dict)
def test_create_empty_body(self): def test_create_empty_body(self):
self.stubs.Set(manila.db, 'share_metadata_update', self.mock_object(manila.db, 'share_metadata_update',
return_create_share_metadata) return_create_share_metadata)
req = fakes.HTTPRequest.blank(self.url) req = fakes.HTTPRequest.blank(self.url)
req.method = 'POST' req.method = 'POST'
req.headers["content-type"] = "application/json" req.headers["content-type"] = "application/json"
@ -213,8 +212,8 @@ class ShareMetaDataTest(test.TestCase):
self.controller.create, req, self.req_id, None) self.controller.create, req, self.req_id, None)
def test_create_item_empty_key(self): def test_create_item_empty_key(self):
self.stubs.Set(manila.db, 'share_metadata_update', self.mock_object(manila.db, 'share_metadata_update',
return_create_share_metadata) return_create_share_metadata)
req = fakes.HTTPRequest.blank(self.url + '/key1') req = fakes.HTTPRequest.blank(self.url + '/key1')
req.method = 'PUT' req.method = 'PUT'
body = {"meta": {"": "value1"}} body = {"meta": {"": "value1"}}
@ -225,8 +224,8 @@ class ShareMetaDataTest(test.TestCase):
self.controller.create, req, self.req_id, body) self.controller.create, req, self.req_id, body)
def test_create_item_key_too_long(self): def test_create_item_key_too_long(self):
self.stubs.Set(manila.db, 'share_metadata_update', self.mock_object(manila.db, 'share_metadata_update',
return_create_share_metadata) return_create_share_metadata)
req = fakes.HTTPRequest.blank(self.url + '/key1') req = fakes.HTTPRequest.blank(self.url + '/key1')
req.method = 'PUT' req.method = 'PUT'
body = {"meta": {("a" * 260): "value1"}} body = {"meta": {("a" * 260): "value1"}}
@ -238,12 +237,12 @@ class ShareMetaDataTest(test.TestCase):
req, self.req_id, body) req, self.req_id, body)
def test_create_nonexistent_share(self): def test_create_nonexistent_share(self):
self.stubs.Set(manila.db, 'share_get', self.mock_object(manila.db, 'share_get',
return_share_nonexistent) return_share_nonexistent)
self.stubs.Set(manila.db, 'share_metadata_get', self.mock_object(manila.db, 'share_metadata_get',
return_share_metadata) return_share_metadata)
self.stubs.Set(manila.db, 'share_metadata_update', self.mock_object(manila.db, 'share_metadata_update',
return_create_share_metadata) return_create_share_metadata)
req = fakes.HTTPRequest.blank('/v1/share_metadata') req = fakes.HTTPRequest.blank('/v1/share_metadata')
req.method = 'POST' req.method = 'POST'
@ -254,8 +253,8 @@ class ShareMetaDataTest(test.TestCase):
self.controller.create, req, self.req_id, body) self.controller.create, req, self.req_id, body)
def test_update_all(self): def test_update_all(self):
self.stubs.Set(manila.db, 'share_metadata_update', self.mock_object(manila.db, 'share_metadata_update',
return_create_share_metadata) return_create_share_metadata)
req = fakes.HTTPRequest.blank(self.url) req = fakes.HTTPRequest.blank(self.url)
req.method = 'PUT' req.method = 'PUT'
req.content_type = "application/json" req.content_type = "application/json"
@ -271,8 +270,8 @@ class ShareMetaDataTest(test.TestCase):
self.assertEqual(expected, res_dict) self.assertEqual(expected, res_dict)
def test_update_all_empty_container(self): def test_update_all_empty_container(self):
self.stubs.Set(manila.db, 'share_metadata_update', self.mock_object(manila.db, 'share_metadata_update',
return_create_share_metadata) return_create_share_metadata)
req = fakes.HTTPRequest.blank(self.url) req = fakes.HTTPRequest.blank(self.url)
req.method = 'PUT' req.method = 'PUT'
req.content_type = "application/json" req.content_type = "application/json"
@ -283,8 +282,8 @@ class ShareMetaDataTest(test.TestCase):
self.assertEqual(expected, res_dict) self.assertEqual(expected, res_dict)
def test_update_all_malformed_container(self): def test_update_all_malformed_container(self):
self.stubs.Set(manila.db, 'share_metadata_update', self.mock_object(manila.db, 'share_metadata_update',
return_create_share_metadata) return_create_share_metadata)
req = fakes.HTTPRequest.blank(self.url) req = fakes.HTTPRequest.blank(self.url)
req.method = 'PUT' req.method = 'PUT'
req.content_type = "application/json" req.content_type = "application/json"
@ -300,8 +299,8 @@ class ShareMetaDataTest(test.TestCase):
{None: 'value'}, {None: 'value'},
{None: None}) {None: None})
def test_update_all_malformed_data(self, metadata): def test_update_all_malformed_data(self, metadata):
self.stubs.Set(manila.db, 'share_metadata_update', self.mock_object(manila.db, 'share_metadata_update',
return_create_share_metadata) return_create_share_metadata)
req = fakes.HTTPRequest.blank(self.url) req = fakes.HTTPRequest.blank(self.url)
req.method = 'PUT' req.method = 'PUT'
req.content_type = "application/json" req.content_type = "application/json"
@ -313,7 +312,7 @@ class ShareMetaDataTest(test.TestCase):
expected) expected)
def test_update_all_nonexistent_share(self): def test_update_all_nonexistent_share(self):
self.stubs.Set(manila.db, 'share_get', return_share_nonexistent) self.mock_object(manila.db, 'share_get', return_share_nonexistent)
req = fakes.HTTPRequest.blank(self.url) req = fakes.HTTPRequest.blank(self.url)
req.method = 'PUT' req.method = 'PUT'
req.content_type = "application/json" req.content_type = "application/json"
@ -324,8 +323,8 @@ class ShareMetaDataTest(test.TestCase):
self.controller.update_all, req, '100', body) self.controller.update_all, req, '100', body)
def test_update_item(self): def test_update_item(self):
self.stubs.Set(manila.db, 'share_metadata_update', self.mock_object(manila.db, 'share_metadata_update',
return_create_share_metadata) return_create_share_metadata)
req = fakes.HTTPRequest.blank(self.url + '/key1') req = fakes.HTTPRequest.blank(self.url + '/key1')
req.method = 'PUT' req.method = 'PUT'
body = {"meta": {"key1": "value1"}} body = {"meta": {"key1": "value1"}}
@ -336,8 +335,8 @@ class ShareMetaDataTest(test.TestCase):
self.assertEqual(expected, res_dict) self.assertEqual(expected, res_dict)
def test_update_item_nonexistent_share(self): def test_update_item_nonexistent_share(self):
self.stubs.Set(manila.db, 'share_get', self.mock_object(manila.db, 'share_get',
return_share_nonexistent) return_share_nonexistent)
req = fakes.HTTPRequest.blank('/v1.1/fake/shares/asdf/metadata/key1') req = fakes.HTTPRequest.blank('/v1.1/fake/shares/asdf/metadata/key1')
req.method = 'PUT' req.method = 'PUT'
body = {"meta": {"key1": "value1"}} body = {"meta": {"key1": "value1"}}
@ -349,8 +348,8 @@ class ShareMetaDataTest(test.TestCase):
body) body)
def test_update_item_empty_body(self): def test_update_item_empty_body(self):
self.stubs.Set(manila.db, 'share_metadata_update', self.mock_object(manila.db, 'share_metadata_update',
return_create_share_metadata) return_create_share_metadata)
req = fakes.HTTPRequest.blank(self.url + '/key1') req = fakes.HTTPRequest.blank(self.url + '/key1')
req.method = 'PUT' req.method = 'PUT'
req.headers["content-type"] = "application/json" req.headers["content-type"] = "application/json"
@ -360,8 +359,8 @@ class ShareMetaDataTest(test.TestCase):
None) None)
def test_update_item_empty_key(self): def test_update_item_empty_key(self):
self.stubs.Set(manila.db, 'share_metadata_update', self.mock_object(manila.db, 'share_metadata_update',
return_create_share_metadata) return_create_share_metadata)
req = fakes.HTTPRequest.blank(self.url + '/key1') req = fakes.HTTPRequest.blank(self.url + '/key1')
req.method = 'PUT' req.method = 'PUT'
body = {"meta": {"": "value1"}} body = {"meta": {"": "value1"}}
@ -372,8 +371,8 @@ class ShareMetaDataTest(test.TestCase):
self.controller.update, req, self.req_id, '', body) self.controller.update, req, self.req_id, '', body)
def test_update_item_key_too_long(self): def test_update_item_key_too_long(self):
self.stubs.Set(manila.db, 'share_metadata_update', self.mock_object(manila.db, 'share_metadata_update',
return_create_share_metadata) return_create_share_metadata)
req = fakes.HTTPRequest.blank(self.url + '/key1') req = fakes.HTTPRequest.blank(self.url + '/key1')
req.method = 'PUT' req.method = 'PUT'
body = {"meta": {("a" * 260): "value1"}} body = {"meta": {("a" * 260): "value1"}}
@ -385,8 +384,8 @@ class ShareMetaDataTest(test.TestCase):
req, self.req_id, ("a" * 260), body) req, self.req_id, ("a" * 260), body)
def test_update_item_value_too_long(self): def test_update_item_value_too_long(self):
self.stubs.Set(manila.db, 'share_metadata_update', self.mock_object(manila.db, 'share_metadata_update',
return_create_share_metadata) return_create_share_metadata)
req = fakes.HTTPRequest.blank(self.url + '/key1') req = fakes.HTTPRequest.blank(self.url + '/key1')
req.method = 'PUT' req.method = 'PUT'
body = {"meta": {"key1": ("a" * 1025)}} body = {"meta": {"key1": ("a" * 1025)}}
@ -398,8 +397,8 @@ class ShareMetaDataTest(test.TestCase):
req, self.req_id, "key1", body) req, self.req_id, "key1", body)
def test_update_item_too_many_keys(self): def test_update_item_too_many_keys(self):
self.stubs.Set(manila.db, 'share_metadata_update', self.mock_object(manila.db, 'share_metadata_update',
return_create_share_metadata) return_create_share_metadata)
req = fakes.HTTPRequest.blank(self.url + '/key1') req = fakes.HTTPRequest.blank(self.url + '/key1')
req.method = 'PUT' req.method = 'PUT'
body = {"meta": {"key1": "value1", "key2": "value2"}} body = {"meta": {"key1": "value1", "key2": "value2"}}
@ -411,8 +410,8 @@ class ShareMetaDataTest(test.TestCase):
body) body)
def test_update_item_body_uri_mismatch(self): def test_update_item_body_uri_mismatch(self):
self.stubs.Set(manila.db, 'share_metadata_update', self.mock_object(manila.db, 'share_metadata_update',
return_create_share_metadata) return_create_share_metadata)
req = fakes.HTTPRequest.blank(self.url + '/bad') req = fakes.HTTPRequest.blank(self.url + '/bad')
req.method = 'PUT' req.method = 'PUT'
body = {"meta": {"key1": "value1"}} body = {"meta": {"key1": "value1"}}
@ -424,8 +423,8 @@ class ShareMetaDataTest(test.TestCase):
body) body)
def test_invalid_metadata_items_on_create(self): def test_invalid_metadata_items_on_create(self):
self.stubs.Set(manila.db, 'share_metadata_update', self.mock_object(manila.db, 'share_metadata_update',
return_create_share_metadata) return_create_share_metadata)
req = fakes.HTTPRequest.blank(self.url) req = fakes.HTTPRequest.blank(self.url)
req.method = 'POST' req.method = 'POST'
req.headers["content-type"] = "application/json" req.headers["content-type"] = "application/json"

View File

@ -161,10 +161,10 @@ class ShareServerAPITest(test.TestCase):
def setUp(self): def setUp(self):
super(ShareServerAPITest, self).setUp() super(ShareServerAPITest, self).setUp()
self.controller = share_servers.ShareServerController() self.controller = share_servers.ShareServerController()
self.stubs.Set(policy, 'check_policy', self.mock_object(policy, 'check_policy',
mock.Mock(return_value=True)) mock.Mock(return_value=True))
self.stubs.Set(db_api, 'share_server_get_all', self.mock_object(db_api, 'share_server_get_all',
mock.Mock(return_value=fake_share_server_get_all())) mock.Mock(return_value=fake_share_server_get_all()))
def test_index_no_filters(self): def test_index_no_filters(self):
result = self.controller.index(FakeRequestAdmin) result = self.controller.index(FakeRequestAdmin)
@ -221,8 +221,8 @@ class ShareServerAPITest(test.TestCase):
self.assertEqual(len(result['share_servers']), 0) self.assertEqual(len(result['share_servers']), 0)
def test_show(self): def test_show(self):
self.stubs.Set(db_api, 'share_server_get', self.mock_object(db_api, 'share_server_get',
mock.Mock(return_value=fake_share_server_get())) mock.Mock(return_value=fake_share_server_get()))
result = self.controller.show( result = self.controller.show(
FakeRequestAdmin, FakeRequestAdmin,
fake_share_server_get_result['share_server']['id']) fake_share_server_get_result['share_server']['id'])
@ -234,9 +234,9 @@ class ShareServerAPITest(test.TestCase):
fake_share_server_get_result['share_server']) fake_share_server_get_result['share_server'])
def test_details(self): def test_details(self):
self.stubs.Set(db_api, 'share_server_get', self.mock_object(db_api, 'share_server_get',
mock.Mock(return_value=fake_share_server_get())) mock.Mock(return_value=fake_share_server_get()))
self.stubs.Set( self.mock_object(
db_api, 'share_server_backend_details_get', db_api, 'share_server_backend_details_get',
mock.Mock(return_value=fake_share_server_backend_details_get())) mock.Mock(return_value=fake_share_server_backend_details_get()))
result = self.controller.details( result = self.controller.details(
@ -253,10 +253,9 @@ class ShareServerAPITest(test.TestCase):
def test_delete_active_server(self): def test_delete_active_server(self):
share_server = FakeShareServer(status=constants.STATUS_ACTIVE) share_server = FakeShareServer(status=constants.STATUS_ACTIVE)
self.stubs.Set(db_api, 'share_server_get', self.mock_object(db_api, 'share_server_get',
mock.Mock(return_value=share_server)) mock.Mock(return_value=share_server))
self.stubs.Set(self.controller.share_api, 'delete_share_server', self.mock_object(self.controller.share_api, 'delete_share_server')
mock.Mock())
self.controller.delete( self.controller.delete(
FakeRequestAdmin, FakeRequestAdmin,
fake_share_server_get_result['share_server']['id']) fake_share_server_get_result['share_server']['id'])
@ -269,10 +268,9 @@ class ShareServerAPITest(test.TestCase):
def test_delete_error_server(self): def test_delete_error_server(self):
share_server = FakeShareServer(status=constants.STATUS_ERROR) share_server = FakeShareServer(status=constants.STATUS_ERROR)
self.stubs.Set(db_api, 'share_server_get', self.mock_object(db_api, 'share_server_get',
mock.Mock(return_value=share_server)) mock.Mock(return_value=share_server))
self.stubs.Set(self.controller.share_api, 'delete_share_server', self.mock_object(self.controller.share_api, 'delete_share_server')
mock.Mock())
self.controller.delete( self.controller.delete(
FakeRequestAdmin, FakeRequestAdmin,
fake_share_server_get_result['share_server']['id']) fake_share_server_get_result['share_server']['id'])
@ -290,10 +288,10 @@ class ShareServerAPITest(test.TestCase):
raise exception.ShareServerInUse(share_server_id=share_server_id) raise exception.ShareServerInUse(share_server_id=share_server_id)
share_server = fake_share_server_get() share_server = fake_share_server_get()
self.stubs.Set(db_api, 'share_server_get', self.mock_object(db_api, 'share_server_get',
mock.Mock(return_value=share_server)) mock.Mock(return_value=share_server))
self.stubs.Set(self.controller.share_api, 'delete_share_server', self.mock_object(self.controller.share_api, 'delete_share_server',
mock.Mock(side_effect=raise_not_share_server_in_use)) mock.Mock(side_effect=raise_not_share_server_in_use))
self.assertRaises(exc.HTTPConflict, self.assertRaises(exc.HTTPConflict,
self.controller.delete, self.controller.delete,
FakeRequestAdmin, FakeRequestAdmin,
@ -310,8 +308,8 @@ class ShareServerAPITest(test.TestCase):
raise exception.ShareServerNotFound( raise exception.ShareServerNotFound(
share_server_id=share_server_id) share_server_id=share_server_id)
self.stubs.Set(db_api, 'share_server_get', self.mock_object(db_api, 'share_server_get',
mock.Mock(side_effect=raise_not_found)) mock.Mock(side_effect=raise_not_found))
self.assertRaises(exc.HTTPNotFound, self.assertRaises(exc.HTTPNotFound,
self.controller.delete, self.controller.delete,
FakeRequestAdmin, FakeRequestAdmin,
@ -323,8 +321,8 @@ class ShareServerAPITest(test.TestCase):
def test_delete_creating_server(self): def test_delete_creating_server(self):
share_server = FakeShareServer(status=constants.STATUS_CREATING) share_server = FakeShareServer(status=constants.STATUS_CREATING)
self.stubs.Set(db_api, 'share_server_get', self.mock_object(db_api, 'share_server_get',
mock.Mock(return_value=share_server)) mock.Mock(return_value=share_server))
self.assertRaises(exc.HTTPForbidden, self.assertRaises(exc.HTTPForbidden,
self.controller.delete, self.controller.delete,
FakeRequestAdmin, FakeRequestAdmin,
@ -335,8 +333,8 @@ class ShareServerAPITest(test.TestCase):
def test_delete_deleting_server(self): def test_delete_deleting_server(self):
share_server = FakeShareServer(status=constants.STATUS_DELETING) share_server = FakeShareServer(status=constants.STATUS_DELETING)
self.stubs.Set(db_api, 'share_server_get', self.mock_object(db_api, 'share_server_get',
mock.Mock(return_value=share_server)) mock.Mock(return_value=share_server))
self.assertRaises(exc.HTTPForbidden, self.assertRaises(exc.HTTPForbidden,
self.controller.delete, self.controller.delete,
FakeRequestAdmin, FakeRequestAdmin,

View File

@ -32,13 +32,13 @@ class ShareSnapshotApiTest(test.TestCase):
super(ShareSnapshotApiTest, self).setUp() super(ShareSnapshotApiTest, self).setUp()
self.controller = share_snapshots.ShareSnapshotsController() self.controller = share_snapshots.ShareSnapshotsController()
self.stubs.Set(share_api.API, 'get', stubs.stub_share_get) self.mock_object(share_api.API, 'get', stubs.stub_share_get)
self.stubs.Set(share_api.API, 'get_all_snapshots', self.mock_object(share_api.API, 'get_all_snapshots',
stubs.stub_snapshot_get_all_by_project) stubs.stub_snapshot_get_all_by_project)
self.stubs.Set(share_api.API, 'get_snapshot', self.mock_object(share_api.API, 'get_snapshot',
stubs.stub_snapshot_get) stubs.stub_snapshot_get)
self.stubs.Set(share_api.API, 'snapshot_update', self.mock_object(share_api.API, 'snapshot_update',
stubs.stub_snapshot_update) stubs.stub_snapshot_update)
self.snp_example = { self.snp_example = {
'share_id': 100, 'share_id': 100,
'size': 12, 'size': 12,
@ -49,8 +49,8 @@ class ShareSnapshotApiTest(test.TestCase):
self.maxDiff = None self.maxDiff = None
def test_snapshot_create(self): def test_snapshot_create(self):
self.stubs.Set(share_api.API, 'create_snapshot', self.mock_object(share_api.API, 'create_snapshot',
stubs.stub_snapshot_create) stubs.stub_snapshot_create)
body = { body = {
'snapshot': { 'snapshot': {
'share_id': 100, 'share_id': 100,
@ -96,15 +96,15 @@ class ShareSnapshotApiTest(test.TestCase):
body) body)
def test_snapshot_delete(self): def test_snapshot_delete(self):
self.stubs.Set(share_api.API, 'delete_snapshot', self.mock_object(share_api.API, 'delete_snapshot',
stubs.stub_snapshot_delete) stubs.stub_snapshot_delete)
req = fakes.HTTPRequest.blank('/snapshots/200') req = fakes.HTTPRequest.blank('/snapshots/200')
resp = self.controller.delete(req, 200) resp = self.controller.delete(req, 200)
self.assertEqual(resp.status_int, 202) self.assertEqual(resp.status_int, 202)
def test_snapshot_delete_nofound(self): def test_snapshot_delete_nofound(self):
self.stubs.Set(share_api.API, 'get_snapshot', self.mock_object(share_api.API, 'get_snapshot',
stubs.stub_snapshot_get_notfound) stubs.stub_snapshot_get_notfound)
req = fakes.HTTPRequest.blank('/snapshots/200') req = fakes.HTTPRequest.blank('/snapshots/200')
self.assertRaises(webob.exc.HTTPNotFound, self.assertRaises(webob.exc.HTTPNotFound,
self.controller.delete, self.controller.delete,
@ -141,16 +141,16 @@ class ShareSnapshotApiTest(test.TestCase):
self.assertEqual(res_dict, expected) self.assertEqual(res_dict, expected)
def test_snapshot_show_nofound(self): def test_snapshot_show_nofound(self):
self.stubs.Set(share_api.API, 'get_snapshot', self.mock_object(share_api.API, 'get_snapshot',
stubs.stub_snapshot_get_notfound) stubs.stub_snapshot_get_notfound)
req = fakes.HTTPRequest.blank('/snapshots/200') req = fakes.HTTPRequest.blank('/snapshots/200')
self.assertRaises(webob.exc.HTTPNotFound, self.assertRaises(webob.exc.HTTPNotFound,
self.controller.show, self.controller.show,
req, '200') req, '200')
def test_snapshot_list_summary(self): def test_snapshot_list_summary(self):
self.stubs.Set(share_api.API, 'get_all_snapshots', self.mock_object(share_api.API, 'get_all_snapshots',
stubs.stub_snapshot_get_all_by_project) stubs.stub_snapshot_get_all_by_project)
req = fakes.HTTPRequest.blank('/snapshots') req = fakes.HTTPRequest.blank('/snapshots')
res_dict = self.controller.index(req) res_dict = self.controller.index(req)
expected = { expected = {
@ -195,8 +195,8 @@ class ShareSnapshotApiTest(test.TestCase):
{'id': 'id2', 'display_name': 'n2'}, {'id': 'id2', 'display_name': 'n2'},
{'id': 'id3', 'display_name': 'n3'}, {'id': 'id3', 'display_name': 'n3'},
] ]
self.stubs.Set(share_api.API, 'get_all_snapshots', self.mock_object(share_api.API, 'get_all_snapshots',
mock.Mock(return_value=snapshots)) mock.Mock(return_value=snapshots))
result = self.controller.index(req) result = self.controller.index(req)
@ -251,8 +251,8 @@ class ShareSnapshotApiTest(test.TestCase):
{'id': 'id3', 'display_name': 'n3'}, {'id': 'id3', 'display_name': 'n3'},
] ]
self.stubs.Set(share_api.API, 'get_all_snapshots', self.mock_object(share_api.API, 'get_all_snapshots',
mock.Mock(return_value=snapshots)) mock.Mock(return_value=snapshots))
result = self.controller.detail(req) result = self.controller.detail(req)

View File

@ -34,13 +34,14 @@ class ShareApiTest(test.TestCase):
def setUp(self): def setUp(self):
super(ShareApiTest, self).setUp() super(ShareApiTest, self).setUp()
self.controller = shares.ShareController() self.controller = shares.ShareController()
self.stubs.Set(share_api.API, 'get_all', self.mock_object(share_api.API, 'get_all',
stubs.stub_get_all_shares) stubs.stub_get_all_shares)
self.stubs.Set(share_api.API, 'get', self.mock_object(share_api.API, 'get',
stubs.stub_share_get) stubs.stub_share_get)
self.stubs.Set(share_api.API, 'update', stubs.stub_share_update) self.mock_object(share_api.API, 'update', stubs.stub_share_update)
self.stubs.Set(share_api.API, 'delete', stubs.stub_share_delete) self.mock_object(share_api.API, 'delete', stubs.stub_share_delete)
self.stubs.Set(share_api.API, 'get_snapshot', stubs.stub_snapshot_get) self.mock_object(share_api.API, 'get_snapshot',
stubs.stub_snapshot_get)
self.maxDiff = None self.maxDiff = None
self.shr_example = { self.shr_example = {
"size": 100, "size": 100,
@ -99,7 +100,7 @@ class ShareApiTest(test.TestCase):
size=100, size=100,
share_proto=shr['share_proto'].upper(), share_proto=shr['share_proto'].upper(),
availability_zone=shr['availability_zone'])) availability_zone=shr['availability_zone']))
self.stubs.Set(share_api.API, 'create', create_mock) self.mock_object(share_api.API, 'create', create_mock)
body = {"share": copy.deepcopy(shr)} body = {"share": copy.deepcopy(shr)}
req = fakes.HTTPRequest.blank('/shares') req = fakes.HTTPRequest.blank('/shares')
@ -124,8 +125,8 @@ class ShareApiTest(test.TestCase):
share_proto=shr['share_proto'].upper(), share_proto=shr['share_proto'].upper(),
availability_zone=shr['availability_zone'], availability_zone=shr['availability_zone'],
share_network_id=shr['share_network_id'])) share_network_id=shr['share_network_id']))
self.stubs.Set(share_api.API, 'create', create_mock) self.mock_object(share_api.API, 'create', create_mock)
self.stubs.Set(share_api.API, 'get_share_network', mock.Mock( self.mock_object(share_api.API, 'get_share_network', mock.Mock(
return_value={'id': 'fakenetid'})) return_value={'id': 'fakenetid'}))
body = {"share": copy.deepcopy(shr)} body = {"share": copy.deepcopy(shr)}
@ -155,7 +156,7 @@ class ShareApiTest(test.TestCase):
availability_zone=shr['availability_zone'], availability_zone=shr['availability_zone'],
snapshot_id=shr['snapshot_id'], snapshot_id=shr['snapshot_id'],
share_network_id=shr['share_network_id'])) share_network_id=shr['share_network_id']))
self.stubs.Set(share_api.API, 'create', create_mock) self.mock_object(share_api.API, 'create', create_mock)
body = {"share": copy.deepcopy(shr)} body = {"share": copy.deepcopy(shr)}
req = fakes.HTTPRequest.blank('/shares') req = fakes.HTTPRequest.blank('/shares')
res_dict = self.controller.create(req, body) res_dict = self.controller.create(req, body)
@ -181,11 +182,12 @@ class ShareApiTest(test.TestCase):
availability_zone=shr['availability_zone'], availability_zone=shr['availability_zone'],
snapshot_id=shr['snapshot_id'], snapshot_id=shr['snapshot_id'],
share_network_id=shr['share_network_id'])) share_network_id=shr['share_network_id']))
self.stubs.Set(share_api.API, 'create', create_mock) self.mock_object(share_api.API, 'create', create_mock)
self.stubs.Set(share_api.API, 'get_snapshot', stubs.stub_snapshot_get) self.mock_object(share_api.API, 'get_snapshot',
self.stubs.Set(share_api.API, 'get', mock.Mock( stubs.stub_snapshot_get)
self.mock_object(share_api.API, 'get', mock.Mock(
return_value={'share_network_id': parent_share_net})) return_value={'share_network_id': parent_share_net}))
self.stubs.Set(share_api.API, 'get_share_network', mock.Mock( self.mock_object(share_api.API, 'get_share_network', mock.Mock(
return_value={'id': parent_share_net})) return_value={'id': parent_share_net}))
body = {"share": copy.deepcopy(shr)} body = {"share": copy.deepcopy(shr)}
@ -215,11 +217,12 @@ class ShareApiTest(test.TestCase):
availability_zone=shr['availability_zone'], availability_zone=shr['availability_zone'],
snapshot_id=shr['snapshot_id'], snapshot_id=shr['snapshot_id'],
share_network_id=shr['share_network_id'])) share_network_id=shr['share_network_id']))
self.stubs.Set(share_api.API, 'create', create_mock) self.mock_object(share_api.API, 'create', create_mock)
self.stubs.Set(share_api.API, 'get_snapshot', stubs.stub_snapshot_get) self.mock_object(share_api.API, 'get_snapshot',
self.stubs.Set(share_api.API, 'get', mock.Mock( stubs.stub_snapshot_get)
self.mock_object(share_api.API, 'get', mock.Mock(
return_value={'share_network_id': parent_share_net})) return_value={'share_network_id': parent_share_net}))
self.stubs.Set(share_api.API, 'get_share_network', mock.Mock( self.mock_object(share_api.API, 'get_share_network', mock.Mock(
return_value={'id': parent_share_net})) return_value={'id': parent_share_net}))
body = {"share": copy.deepcopy(shr)} body = {"share": copy.deepcopy(shr)}
@ -231,7 +234,7 @@ class ShareApiTest(test.TestCase):
parent_share_net) parent_share_net)
def test_share_create_from_snapshot_invalid_share_net(self): def test_share_create_from_snapshot_invalid_share_net(self):
self.stubs.Set(share_api.API, 'create', mock.Mock()) self.mock_object(share_api.API, 'create')
shr = { shr = {
"size": 100, "size": 100,
"name": "Share Test Name", "name": "Share Test Name",
@ -282,8 +285,8 @@ class ShareApiTest(test.TestCase):
self.assertEqual(expected, res_dict) self.assertEqual(expected, res_dict)
def test_share_show_no_share(self): def test_share_show_no_share(self):
self.stubs.Set(share_api.API, 'get', self.mock_object(share_api.API, 'get',
stubs.stub_share_get_notfound) stubs.stub_share_get_notfound)
req = fakes.HTTPRequest.blank('/shares/1') req = fakes.HTTPRequest.blank('/shares/1')
self.assertRaises(webob.exc.HTTPNotFound, self.assertRaises(webob.exc.HTTPNotFound,
self.controller.show, self.controller.show,
@ -322,8 +325,8 @@ class ShareApiTest(test.TestCase):
self.assertNotEqual(res_dict['share']["size"], shr["size"]) self.assertNotEqual(res_dict['share']["size"], shr["size"])
def test_share_delete_no_share(self): def test_share_delete_no_share(self):
self.stubs.Set(share_api.API, 'get', self.mock_object(share_api.API, 'get',
stubs.stub_share_get_notfound) stubs.stub_share_get_notfound)
req = fakes.HTTPRequest.blank('/shares/1') req = fakes.HTTPRequest.blank('/shares/1')
self.assertRaises(webob.exc.HTTPNotFound, self.assertRaises(webob.exc.HTTPNotFound,
self.controller.delete, self.controller.delete,
@ -357,8 +360,8 @@ class ShareApiTest(test.TestCase):
{'id': 'id2', 'display_name': 'n2'}, {'id': 'id2', 'display_name': 'n2'},
{'id': 'id3', 'display_name': 'n3'}, {'id': 'id3', 'display_name': 'n3'},
] ]
self.stubs.Set(share_api.API, 'get_all', self.mock_object(share_api.API, 'get_all',
mock.Mock(return_value=shares)) mock.Mock(return_value=shares))
result = self.controller.index(req) result = self.controller.index(req)
@ -393,8 +396,8 @@ class ShareApiTest(test.TestCase):
self._share_list_summary_with_search_opts(use_admin_context=True) self._share_list_summary_with_search_opts(use_admin_context=True)
def test_share_list_summary(self): def test_share_list_summary(self):
self.stubs.Set(share_api.API, 'get_all', self.mock_object(share_api.API, 'get_all',
stubs.stub_share_get_all_by_project) stubs.stub_share_get_all_by_project)
req = fakes.HTTPRequest.blank('/shares') req = fakes.HTTPRequest.blank('/shares')
res_dict = self.controller.index(req) res_dict = self.controller.index(req)
expected = { expected = {
@ -453,8 +456,8 @@ class ShareApiTest(test.TestCase):
}, },
{'id': 'id3', 'display_name': 'n3'}, {'id': 'id3', 'display_name': 'n3'},
] ]
self.stubs.Set(share_api.API, 'get_all', self.mock_object(share_api.API, 'get_all',
mock.Mock(return_value=shares)) mock.Mock(return_value=shares))
result = self.controller.detail(req) result = self.controller.detail(req)
@ -502,8 +505,8 @@ class ShareApiTest(test.TestCase):
self._share_list_detail_with_search_opts(use_admin_context=True) self._share_list_detail_with_search_opts(use_admin_context=True)
def test_share_list_detail(self): def test_share_list_detail(self):
self.stubs.Set(share_api.API, 'get_all', self.mock_object(share_api.API, 'get_all',
stubs.stub_share_get_all_by_project) stubs.stub_share_get_all_by_project)
env = {'QUERY_STRING': 'name=Share+Test+Name'} env = {'QUERY_STRING': 'name=Share+Test+Name'}
req = fakes.HTTPRequest.blank('/shares/detail', environ=env) req = fakes.HTTPRequest.blank('/shares/detail', environ=env)
res_dict = self.controller.detail(req) res_dict = self.controller.detail(req)

View File

@ -69,8 +69,8 @@ class VolumeTypesApiTest(test.TestCase):
self.controller = types.VolumeTypesController() self.controller = types.VolumeTypesController()
def test_volume_types_index(self): def test_volume_types_index(self):
self.stubs.Set(volume_types, 'get_all_types', self.mock_object(volume_types, 'get_all_types',
return_volume_types_get_all_types) return_volume_types_get_all_types)
req = fakes.HTTPRequest.blank('/v2/fake/types') req = fakes.HTTPRequest.blank('/v2/fake/types')
res_dict = self.controller.index(req) res_dict = self.controller.index(req)
@ -84,8 +84,8 @@ class VolumeTypesApiTest(test.TestCase):
self.assertEqual('value1', entry['extra_specs']['key1']) self.assertEqual('value1', entry['extra_specs']['key1'])
def test_volume_types_index_no_data(self): def test_volume_types_index_no_data(self):
self.stubs.Set(volume_types, 'get_all_types', self.mock_object(volume_types, 'get_all_types',
return_empty_volume_types_get_all_types) return_empty_volume_types_get_all_types)
req = fakes.HTTPRequest.blank('/v2/fake/types') req = fakes.HTTPRequest.blank('/v2/fake/types')
res_dict = self.controller.index(req) res_dict = self.controller.index(req)
@ -93,8 +93,8 @@ class VolumeTypesApiTest(test.TestCase):
self.assertEqual(0, len(res_dict['volume_types'])) self.assertEqual(0, len(res_dict['volume_types']))
def test_volume_types_show(self): def test_volume_types_show(self):
self.stubs.Set(volume_types, 'get_volume_type', self.mock_object(volume_types, 'get_volume_type',
return_volume_types_get_volume_type) return_volume_types_get_volume_type)
req = fakes.HTTPRequest.blank('/v2/fake/types/1') req = fakes.HTTPRequest.blank('/v2/fake/types/1')
res_dict = self.controller.show(req, 1) res_dict = self.controller.show(req, 1)
@ -104,8 +104,8 @@ class VolumeTypesApiTest(test.TestCase):
self.assertEqual('vol_type_1', res_dict['volume_type']['name']) self.assertEqual('vol_type_1', res_dict['volume_type']['name'])
def test_volume_types_show_not_found(self): def test_volume_types_show_not_found(self):
self.stubs.Set(volume_types, 'get_volume_type', self.mock_object(volume_types, 'get_volume_type',
return_volume_types_get_volume_type) return_volume_types_get_volume_type)
req = fakes.HTTPRequest.blank('/v2/fake/types/777') req = fakes.HTTPRequest.blank('/v2/fake/types/777')
self.assertRaises(webob.exc.HTTPNotFound, self.controller.show, self.assertRaises(webob.exc.HTTPNotFound, self.controller.show,

View File

@ -70,10 +70,10 @@ class NovaApiTestCase(test.TestCase):
self.api = nova.API() self.api = nova.API()
self.novaclient = FakeNovaClient() self.novaclient = FakeNovaClient()
self.ctx = context.get_admin_context() self.ctx = context.get_admin_context()
self.stubs.Set(nova, 'novaclient', self.mock_object(nova, 'novaclient',
mock.Mock(return_value=self.novaclient)) mock.Mock(return_value=self.novaclient))
self.stubs.Set(nova, '_untranslate_server_summary_view', self.mock_object(nova, '_untranslate_server_summary_view',
lambda server: server) lambda server: server)
def test_server_create(self): def test_server_create(self):
result = self.api.server_create(self.ctx, 'server_name', 'fake_image', result = self.api.server_create(self.ctx, 'server_name', 'fake_image',
@ -81,7 +81,7 @@ class NovaApiTestCase(test.TestCase):
self.assertEqual(result['id'], 'created_id') self.assertEqual(result['id'], 'created_id')
def test_server_delete(self): def test_server_delete(self):
self.stubs.Set(self.novaclient.servers, 'delete', mock.Mock()) self.mock_object(self.novaclient.servers, 'delete')
self.api.server_delete(self.ctx, 'id1') self.api.server_delete(self.ctx, 'id1')
self.novaclient.servers.delete.assert_called_once_with('id1') self.novaclient.servers.delete.assert_called_once_with('id1')
@ -93,7 +93,8 @@ class NovaApiTestCase(test.TestCase):
def test_server_get_by_name_or_id(self): def test_server_get_by_name_or_id(self):
instance_id = 'instance_id1' instance_id = 'instance_id1'
server = {'id': instance_id, 'fake_key': 'fake_value'} server = {'id': instance_id, 'fake_key': 'fake_value'}
self.stubs.Set(utils, 'find_resource', mock.Mock(return_value=server)) self.mock_object(utils, 'find_resource',
mock.Mock(return_value=server))
result = self.api.server_get_by_name_or_id(self.ctx, instance_id) result = self.api.server_get_by_name_or_id(self.ctx, instance_id)
@ -111,98 +112,96 @@ class NovaApiTestCase(test.TestCase):
self.api.server_list(self.ctx)) self.api.server_list(self.ctx))
def test_server_pause(self): def test_server_pause(self):
self.stubs.Set(self.novaclient.servers, 'pause', mock.Mock()) self.mock_object(self.novaclient.servers, 'pause')
self.api.server_pause(self.ctx, 'id1') self.api.server_pause(self.ctx, 'id1')
self.novaclient.servers.pause.assert_called_once_with('id1') self.novaclient.servers.pause.assert_called_once_with('id1')
def test_server_unpause(self): def test_server_unpause(self):
self.stubs.Set(self.novaclient.servers, 'unpause', mock.Mock()) self.mock_object(self.novaclient.servers, 'unpause')
self.api.server_unpause(self.ctx, 'id1') self.api.server_unpause(self.ctx, 'id1')
self.novaclient.servers.unpause.assert_called_once_with('id1') self.novaclient.servers.unpause.assert_called_once_with('id1')
def test_server_suspend(self): def test_server_suspend(self):
self.stubs.Set(self.novaclient.servers, 'suspend', mock.Mock()) self.mock_object(self.novaclient.servers, 'suspend')
self.api.server_suspend(self.ctx, 'id1') self.api.server_suspend(self.ctx, 'id1')
self.novaclient.servers.suspend.assert_called_once_with('id1') self.novaclient.servers.suspend.assert_called_once_with('id1')
def test_server_resume(self): def test_server_resume(self):
self.stubs.Set(self.novaclient.servers, 'resume', mock.Mock()) self.mock_object(self.novaclient.servers, 'resume')
self.api.server_resume(self.ctx, 'id1') self.api.server_resume(self.ctx, 'id1')
self.novaclient.servers.resume.assert_called_once_with('id1') self.novaclient.servers.resume.assert_called_once_with('id1')
def test_server_reboot_hard(self): def test_server_reboot_hard(self):
self.stubs.Set(self.novaclient.servers, 'reboot', mock.Mock()) self.mock_object(self.novaclient.servers, 'reboot')
self.api.server_reboot(self.ctx, 'id1') self.api.server_reboot(self.ctx, 'id1')
self.novaclient.servers.reboot.assert_called_once_with( self.novaclient.servers.reboot.assert_called_once_with(
'id1', nova_servers.REBOOT_HARD) 'id1', nova_servers.REBOOT_HARD)
def test_server_reboot_soft(self): def test_server_reboot_soft(self):
self.stubs.Set(self.novaclient.servers, 'reboot', mock.Mock()) self.mock_object(self.novaclient.servers, 'reboot')
self.api.server_reboot(self.ctx, 'id1', True) self.api.server_reboot(self.ctx, 'id1', True)
self.novaclient.servers.reboot.assert_called_once_with( self.novaclient.servers.reboot.assert_called_once_with(
'id1', nova_servers.REBOOT_SOFT) 'id1', nova_servers.REBOOT_SOFT)
def test_server_rebuild(self): def test_server_rebuild(self):
self.stubs.Set(self.novaclient.servers, 'rebuild', mock.Mock()) self.mock_object(self.novaclient.servers, 'rebuild')
self.api.server_rebuild(self.ctx, 'id1', 'fake_image') self.api.server_rebuild(self.ctx, 'id1', 'fake_image')
self.novaclient.servers.rebuild.assert_called_once_with('id1', self.novaclient.servers.rebuild.assert_called_once_with('id1',
'fake_image', 'fake_image',
None) None)
def test_instance_volume_attach(self): def test_instance_volume_attach(self):
self.stubs.Set(self.novaclient.volumes, 'create_server_volume', self.mock_object(self.novaclient.volumes, 'create_server_volume')
mock.Mock())
self.api.instance_volume_attach(self.ctx, 'instance_id', self.api.instance_volume_attach(self.ctx, 'instance_id',
'vol_id', 'device') 'vol_id', 'device')
self.novaclient.volumes.create_server_volume.\ self.novaclient.volumes.create_server_volume.\
assert_called_once_with('instance_id', 'vol_id', 'device') assert_called_once_with('instance_id', 'vol_id', 'device')
def test_instance_volume_detach(self): def test_instance_volume_detach(self):
self.stubs.Set(self.novaclient.volumes, 'delete_server_volume', self.mock_object(self.novaclient.volumes, 'delete_server_volume')
mock.Mock())
self.api.instance_volume_detach(self.ctx, 'instance_id', self.api.instance_volume_detach(self.ctx, 'instance_id',
'att_id') 'att_id')
self.novaclient.volumes.delete_server_volume.\ self.novaclient.volumes.delete_server_volume.\
assert_called_once_with('instance_id', 'att_id') assert_called_once_with('instance_id', 'att_id')
def test_instance_volumes_list(self): def test_instance_volumes_list(self):
self.stubs.Set(self.novaclient.volumes, 'get_server_volumes', self.mock_object(
mock.Mock(return_value=[Volume('id1'), Volume('id2')])) self.novaclient.volumes, 'get_server_volumes',
mock.Mock(return_value=[Volume('id1'), Volume('id2')]))
self.cinderclient = self.novaclient self.cinderclient = self.novaclient
self.stubs.Set(cinder, 'cinderclient', self.mock_object(cinder, 'cinderclient',
mock.Mock(return_value=self.novaclient)) mock.Mock(return_value=self.novaclient))
result = self.api.instance_volumes_list(self.ctx, 'instance_id') result = self.api.instance_volumes_list(self.ctx, 'instance_id')
self.assertEqual(len(result), 2) self.assertEqual(len(result), 2)
self.assertEqual(result[0].id, 'id1') self.assertEqual(result[0].id, 'id1')
self.assertEqual(result[1].id, 'id2') self.assertEqual(result[1].id, 'id2')
def test_server_update(self): def test_server_update(self):
self.stubs.Set(self.novaclient.servers, 'update', mock.Mock()) self.mock_object(self.novaclient.servers, 'update')
self.api.server_update(self.ctx, 'id1', 'new_name') self.api.server_update(self.ctx, 'id1', 'new_name')
self.novaclient.servers.update.assert_called_once_with('id1', self.novaclient.servers.update.assert_called_once_with('id1',
name='new_name') name='new_name')
def test_update_server_volume(self): def test_update_server_volume(self):
self.stubs.Set(self.novaclient.volumes, 'update_server_volume', self.mock_object(self.novaclient.volumes, 'update_server_volume')
mock.Mock())
self.api.update_server_volume(self.ctx, 'instance_id', 'att_id', self.api.update_server_volume(self.ctx, 'instance_id', 'att_id',
'new_vol_id') 'new_vol_id')
self.novaclient.volumes.update_server_volume.\ self.novaclient.volumes.update_server_volume.\
assert_called_once_with('instance_id', 'att_id', 'new_vol_id') assert_called_once_with('instance_id', 'att_id', 'new_vol_id')
def test_keypair_create(self): def test_keypair_create(self):
self.stubs.Set(self.novaclient.keypairs, 'create', mock.Mock()) self.mock_object(self.novaclient.keypairs, 'create')
self.api.keypair_create(self.ctx, 'keypair_name') self.api.keypair_create(self.ctx, 'keypair_name')
self.novaclient.keypairs.create.assert_called_once_with('keypair_name') self.novaclient.keypairs.create.assert_called_once_with('keypair_name')
def test_keypair_import(self): def test_keypair_import(self):
self.stubs.Set(self.novaclient.keypairs, 'create', mock.Mock()) self.mock_object(self.novaclient.keypairs, 'create')
self.api.keypair_import(self.ctx, 'keypair_name', 'fake_pub_key') self.api.keypair_import(self.ctx, 'keypair_name', 'fake_pub_key')
self.novaclient.keypairs.create.\ self.novaclient.keypairs.create.\
assert_called_once_with('keypair_name', 'fake_pub_key') assert_called_once_with('keypair_name', 'fake_pub_key')
def test_keypair_delete(self): def test_keypair_delete(self):
self.stubs.Set(self.novaclient.keypairs, 'delete', mock.Mock()) self.mock_object(self.novaclient.keypairs, 'delete')
self.api.keypair_delete(self.ctx, 'fake_keypair_id') self.api.keypair_delete(self.ctx, 'fake_keypair_id')
self.novaclient.keypairs.delete.\ self.novaclient.keypairs.delete.\
assert_called_once_with('fake_keypair_id') assert_called_once_with('fake_keypair_id')

View File

@ -61,10 +61,11 @@ class FakeNotifier(object):
NOTIFICATIONS.append(msg) NOTIFICATIONS.append(msg)
def stub_notifier(stubs): def stub_notifier(testcase):
stubs.Set(messaging, 'Notifier', FakeNotifier) testcase.mock_object(messaging, 'Notifier', FakeNotifier)
if rpc.NOTIFIER: if rpc.NOTIFIER:
serializer = getattr(rpc.NOTIFIER, '_serializer', None) serializer = getattr(rpc.NOTIFIER, '_serializer', None)
stubs.Set(rpc, 'NOTIFIER', FakeNotifier(rpc.NOTIFIER.transport, testcase.mock_object(rpc, 'NOTIFIER',
rpc.NOTIFIER.publisher_id, FakeNotifier(rpc.NOTIFIER.transport,
serializer=serializer)) rpc.NOTIFIER.publisher_id,
serializer=serializer))

View File

@ -105,7 +105,7 @@ def fake_execute(*cmd_parts, **kwargs):
return reply return reply
def stub_out_utils_execute(stubs): def stub_out_utils_execute(testcase):
fake_execute_set_repliers([]) fake_execute_set_repliers([])
fake_execute_clear_log() fake_execute_clear_log()
stubs.Set(utils, 'execute', fake_execute) testcase.mock_object(utils, 'execute', fake_execute)

View File

@ -86,8 +86,8 @@ class NeutronApiTest(test.TestCase):
def setUp(self): def setUp(self):
super(NeutronApiTest, self).setUp() super(NeutronApiTest, self).setUp()
self.context = context.get_admin_context() self.context = context.get_admin_context()
self.stubs.Set(base, 'Base', fakes.FakeModel) self.mock_object(base, 'Base', fakes.FakeModel)
self.stubs.Set( self.mock_object(
clientv20, 'Client', mock.Mock(return_value=FakeNeutronClient())) clientv20, 'Client', mock.Mock(return_value=FakeNeutronClient()))
self.neutron_api = neutron_api.API() self.neutron_api = neutron_api.API()
@ -116,8 +116,8 @@ class NeutronApiTest(test.TestCase):
def test_create_port_with_all_args(self): def test_create_port_with_all_args(self):
# Set up test data # Set up test data
self.stubs.Set(self.neutron_api, '_has_port_binding_extension', self.mock_object(self.neutron_api, '_has_port_binding_extension',
mock.Mock(return_value=True)) mock.Mock(return_value=True))
port_args = { port_args = {
'tenant_id': 'test tenant', 'network_id': 'test net', 'tenant_id': 'test tenant', 'network_id': 'test net',
'host_id': 'test host', 'subnet_id': 'test subnet', 'host_id': 'test host', 'subnet_id': 'test subnet',
@ -149,8 +149,8 @@ class NeutronApiTest(test.TestCase):
def test_create_port_with_required_args(self): def test_create_port_with_required_args(self):
# Set up test data # Set up test data
self.stubs.Set(self.neutron_api, '_has_port_binding_extension', self.mock_object(self.neutron_api, '_has_port_binding_extension',
mock.Mock(return_value=True)) mock.Mock(return_value=True))
port_args = {'tenant_id': 'test tenant', 'network_id': 'test net'} port_args = {'tenant_id': 'test tenant', 'network_id': 'test net'}
# Execute method 'create_port' # Execute method 'create_port'
@ -166,10 +166,10 @@ class NeutronApiTest(test.TestCase):
@mock.patch.object(neutron_api.LOG, 'exception', mock.Mock()) @mock.patch.object(neutron_api.LOG, 'exception', mock.Mock())
def test_create_port_exception(self): def test_create_port_exception(self):
# Set up test data # Set up test data
self.stubs.Set( self.mock_object(
self.neutron_api, '_has_port_binding_extension', self.neutron_api, '_has_port_binding_extension',
mock.Mock(return_value=True)) mock.Mock(return_value=True))
self.stubs.Set( self.mock_object(
self.neutron_api.client, 'create_port', self.neutron_api.client, 'create_port',
mock.Mock(side_effect=neutron_client_exc.NeutronClientException)) mock.Mock(side_effect=neutron_client_exc.NeutronClientException))
port_args = {'tenant_id': 'test tenant', 'network_id': 'test net'} port_args = {'tenant_id': 'test tenant', 'network_id': 'test net'}
@ -188,10 +188,10 @@ class NeutronApiTest(test.TestCase):
@mock.patch.object(neutron_api.LOG, 'exception', mock.Mock()) @mock.patch.object(neutron_api.LOG, 'exception', mock.Mock())
def test_create_port_exception_status_409(self): def test_create_port_exception_status_409(self):
# Set up test data # Set up test data
self.stubs.Set( self.mock_object(
self.neutron_api, '_has_port_binding_extension', self.neutron_api, '_has_port_binding_extension',
mock.Mock(return_value=True)) mock.Mock(return_value=True))
self.stubs.Set( self.mock_object(
self.neutron_api.client, 'create_port', self.neutron_api.client, 'create_port',
mock.Mock(side_effect=neutron_client_exc.NeutronClientException( mock.Mock(side_effect=neutron_client_exc.NeutronClientException(
status_code=409))) status_code=409)))
@ -210,7 +210,7 @@ class NeutronApiTest(test.TestCase):
def test_delete_port(self): def test_delete_port(self):
# Set up test data # Set up test data
self.stubs.Set(self.neutron_api.client, 'delete_port', mock.Mock()) self.mock_object(self.neutron_api.client, 'delete_port')
port_id = 'test port id' port_id = 'test port id'
# Execute method 'delete_port' # Execute method 'delete_port'
@ -224,7 +224,7 @@ class NeutronApiTest(test.TestCase):
# Set up test data # Set up test data
search_opts = {'test_option': 'test_value'} search_opts = {'test_option': 'test_value'}
fake_ports = [{'fake port': 'fake port info'}] fake_ports = [{'fake port': 'fake port info'}]
self.stubs.Set( self.mock_object(
self.neutron_api.client, 'list_ports', self.neutron_api.client, 'list_ports',
mock.Mock(return_value={'ports': fake_ports})) mock.Mock(return_value={'ports': fake_ports}))
@ -241,7 +241,7 @@ class NeutronApiTest(test.TestCase):
# Set up test data # Set up test data
port_id = 'test port id' port_id = 'test port id'
fake_port = {'fake port': 'fake port info'} fake_port = {'fake port': 'fake port info'}
self.stubs.Set( self.mock_object(
self.neutron_api.client, 'show_port', self.neutron_api.client, 'show_port',
mock.Mock(return_value={'port': fake_port})) mock.Mock(return_value={'port': fake_port}))
@ -257,7 +257,7 @@ class NeutronApiTest(test.TestCase):
# Set up test data # Set up test data
network_id = 'test network id' network_id = 'test network id'
fake_network = {'fake network': 'fake network info'} fake_network = {'fake network': 'fake network info'}
self.stubs.Set( self.mock_object(
self.neutron_api.client, 'show_network', self.neutron_api.client, 'show_network',
mock.Mock(return_value={'network': fake_network})) mock.Mock(return_value={'network': fake_network}))
@ -273,7 +273,7 @@ class NeutronApiTest(test.TestCase):
def test_get_subnet(self): def test_get_subnet(self):
# Set up test data # Set up test data
subnet_id = 'fake subnet id' subnet_id = 'fake subnet id'
self.stubs.Set( self.mock_object(
self.neutron_api.client, 'show_subnet', self.neutron_api.client, 'show_subnet',
mock.Mock(return_value={'subnet': {}})) mock.Mock(return_value={'subnet': {}}))
@ -289,7 +289,7 @@ class NeutronApiTest(test.TestCase):
def test_get_all_network(self): def test_get_all_network(self):
# Set up test data # Set up test data
fake_networks = [{'fake network': 'fake network info'}] fake_networks = [{'fake network': 'fake network info'}]
self.stubs.Set( self.mock_object(
self.neutron_api.client, 'list_networks', self.neutron_api.client, 'list_networks',
mock.Mock(return_value={'networks': fake_networks})) mock.Mock(return_value={'networks': fake_networks}))
@ -307,7 +307,7 @@ class NeutronApiTest(test.TestCase):
{'name': neutron_constants.PORTBINDING_EXT}, {'name': neutron_constants.PORTBINDING_EXT},
{'name': neutron_constants.PROVIDER_NW_EXT}, {'name': neutron_constants.PROVIDER_NW_EXT},
] ]
self.stubs.Set( self.mock_object(
self.neutron_api.client, 'list_extensions', self.neutron_api.client, 'list_extensions',
mock.Mock(return_value={'extensions': extensions})) mock.Mock(return_value={'extensions': extensions}))
@ -368,7 +368,7 @@ class NeutronApiTest(test.TestCase):
def test_list_routers(self): def test_list_routers(self):
# Set up test data # Set up test data
fake_routers = [{'fake router': 'fake router info'}] fake_routers = [{'fake router': 'fake router info'}]
self.stubs.Set( self.mock_object(
self.neutron_api.client, 'list_routers', self.neutron_api.client, 'list_routers',
mock.Mock(return_value={'routers': fake_routers})) mock.Mock(return_value={'routers': fake_routers}))
@ -383,7 +383,7 @@ class NeutronApiTest(test.TestCase):
def test_create_network_exception(self): def test_create_network_exception(self):
# Set up test data # Set up test data
net_args = {'tenant_id': 'test tenant', 'name': 'test name'} net_args = {'tenant_id': 'test tenant', 'name': 'test name'}
self.stubs.Set( self.mock_object(
self.neutron_api.client, 'create_network', self.neutron_api.client, 'create_network',
mock.Mock(side_effect=neutron_client_exc.NeutronClientException)) mock.Mock(side_effect=neutron_client_exc.NeutronClientException))
@ -406,7 +406,7 @@ class NeutronApiTest(test.TestCase):
'net_id': 'test net id', 'net_id': 'test net id',
'cidr': '10.0.0.0/24', 'cidr': '10.0.0.0/24',
} }
self.stubs.Set( self.mock_object(
self.neutron_api.client, 'create_subnet', self.neutron_api.client, 'create_subnet',
mock.Mock(side_effect=neutron_client_exc.NeutronClientException)) mock.Mock(side_effect=neutron_client_exc.NeutronClientException))
@ -431,7 +431,7 @@ class NeutronApiTest(test.TestCase):
def test_create_router_exception(self): def test_create_router_exception(self):
# Set up test data # Set up test data
router_args = {'tenant_id': 'test tenant', 'name': 'test name'} router_args = {'tenant_id': 'test tenant', 'name': 'test name'}
self.stubs.Set( self.mock_object(
self.neutron_api.client, 'create_router', self.neutron_api.client, 'create_router',
mock.Mock(side_effect=neutron_client_exc.NeutronClientException)) mock.Mock(side_effect=neutron_client_exc.NeutronClientException))
@ -462,7 +462,7 @@ class NeutronApiTest(test.TestCase):
# Set up test data # Set up test data
port_id = 'test_port' port_id = 'test_port'
fixed_ips = {'fixed_ips': [{'subnet_id': 'test subnet'}]} fixed_ips = {'fixed_ips': [{'subnet_id': 'test subnet'}]}
self.stubs.Set( self.mock_object(
self.neutron_api.client, 'update_port', self.neutron_api.client, 'update_port',
mock.Mock(side_effect=neutron_client_exc.NeutronClientException)) mock.Mock(side_effect=neutron_client_exc.NeutronClientException))
@ -501,7 +501,7 @@ class NeutronApiTest(test.TestCase):
{'destination': '0.0.0.0/0', 'nexthop': '8.8.8.8', }, {'destination': '0.0.0.0/0', 'nexthop': '8.8.8.8', },
], ],
} }
self.stubs.Set( self.mock_object(
self.neutron_api.client, 'update_router', self.neutron_api.client, 'update_router',
mock.Mock(side_effect=neutron_client_exc.NeutronClientException)) mock.Mock(side_effect=neutron_client_exc.NeutronClientException))
@ -520,7 +520,7 @@ class NeutronApiTest(test.TestCase):
# Set up test data # Set up test data
router_id = 'test router id' router_id = 'test router id'
fake_router = {'fake router': 'fake router info'} fake_router = {'fake router': 'fake router info'}
self.stubs.Set( self.mock_object(
self.neutron_api.client, 'show_router', self.neutron_api.client, 'show_router',
mock.Mock(return_value={'router': fake_router})) mock.Mock(return_value={'router': fake_router}))
@ -537,8 +537,7 @@ class NeutronApiTest(test.TestCase):
router_id = 'test port id' router_id = 'test port id'
subnet_id = 'test subnet id' subnet_id = 'test subnet id'
port_id = 'test port id' port_id = 'test port id'
self.stubs.Set( self.mock_object(self.neutron_api.client, 'add_interface_router')
self.neutron_api.client, 'add_interface_router', mock.Mock())
# Execute method 'router_add_interface' # Execute method 'router_add_interface'
self.neutron_api.router_add_interface(router_id, subnet_id, port_id) self.neutron_api.router_add_interface(router_id, subnet_id, port_id)
@ -553,7 +552,7 @@ class NeutronApiTest(test.TestCase):
router_id = 'test port id' router_id = 'test port id'
subnet_id = 'test subnet id' subnet_id = 'test subnet id'
port_id = 'test port id' port_id = 'test port id'
self.stubs.Set( self.mock_object(
self.neutron_api.client, 'add_interface_router', self.neutron_api.client, 'add_interface_router',
mock.Mock(side_effect=neutron_client_exc.NeutronClientException)) mock.Mock(side_effect=neutron_client_exc.NeutronClientException))

View File

@ -314,7 +314,7 @@ class NeutronSingleNetworkPluginTest(test.TestCase):
} }
} }
fake_net = {'subnets': ['fake1', 'fake2', fake_subnet_id]} fake_net = {'subnets': ['fake1', 'fake2', fake_subnet_id]}
self.stubs.Set( self.mock_object(
neutron_api.API, 'get_network', mock.Mock(return_value=fake_net)) neutron_api.API, 'get_network', mock.Mock(return_value=fake_net))
with test_utils.create_temp_config_with_opts(config_data): with test_utils.create_temp_config_with_opts(config_data):
@ -352,7 +352,7 @@ class NeutronSingleNetworkPluginTest(test.TestCase):
'neutron_subnet_id': 'fake_subnet_id', 'neutron_subnet_id': 'fake_subnet_id',
} }
} }
self.stubs.Set( self.mock_object(
neutron_api.API, 'get_network', mock.Mock(return_value=fake_net)) neutron_api.API, 'get_network', mock.Mock(return_value=fake_net))
with test_utils.create_temp_config_with_opts(config_data): with test_utils.create_temp_config_with_opts(config_data):
@ -370,7 +370,7 @@ class NeutronSingleNetworkPluginTest(test.TestCase):
} }
} }
fake_net = {'subnets': [fake_subnet_id]} fake_net = {'subnets': [fake_subnet_id]}
self.stubs.Set( self.mock_object(
neutron_api.API, 'get_network', mock.Mock(return_value=fake_net)) neutron_api.API, 'get_network', mock.Mock(return_value=fake_net))
with test_utils.create_temp_config_with_opts(config_data): with test_utils.create_temp_config_with_opts(config_data):
instance = plugin.NeutronSingleNetworkPlugin() instance = plugin.NeutronSingleNetworkPlugin()
@ -400,7 +400,7 @@ class NeutronSingleNetworkPluginTest(test.TestCase):
'neutron_net_id': n, 'neutron_net_id': n,
'neutron_subnet_id': s, 'neutron_subnet_id': s,
} }
self.stubs.Set( self.mock_object(
instance.db, 'share_network_update', instance.db, 'share_network_update',
mock.Mock(return_value=share_network)) mock.Mock(return_value=share_network))
@ -420,7 +420,7 @@ class NeutronSingleNetworkPluginTest(test.TestCase):
share_network_upd = 'updated_fake_share_network' share_network_upd = 'updated_fake_share_network'
count = 2 count = 2
device_owner = 'fake_device_owner' device_owner = 'fake_device_owner'
self.stubs.Set( self.mock_object(
instance, '_update_share_network_net_data', instance, '_update_share_network_net_data',
mock.Mock(return_value=share_network_upd)) mock.Mock(return_value=share_network_upd))

View File

@ -44,7 +44,7 @@ class HostFiltersTestCase(test.TestCase):
def _stub_service_is_up(self, ret_value): def _stub_service_is_up(self, ret_value):
def fake_service_is_up(service): def fake_service_is_up(service):
return ret_value return ret_value
self.stubs.Set(utils, 'service_is_up', fake_service_is_up) self.mock_object(utils, 'service_is_up', fake_service_is_up)
def test_capacity_filter_passes(self): def test_capacity_filter_passes(self):
self._stub_service_is_up(True) self._stub_service_is_up(True)

View File

@ -90,7 +90,7 @@ class HostManagerTestCase(test.TestCase):
info['got_fprops'].append(filter_props) info['got_fprops'].append(filter_props)
return True return True
self.stubs.Set(FakeFilterClass1, '_filter_one', fake_filter_one) self.mock_object(FakeFilterClass1, '_filter_one', fake_filter_one)
result = self.host_manager.get_filtered_hosts(self.fake_hosts, result = self.host_manager.get_filtered_hosts(self.fake_hosts,
fake_properties) fake_properties)
self._verify_result(info, result) self._verify_result(info, result)

View File

@ -178,7 +178,7 @@ class SimpleSchedulerSharesTestCase(test.TestCase):
def setUp(self): def setUp(self):
super(SimpleSchedulerSharesTestCase, self).setUp() super(SimpleSchedulerSharesTestCase, self).setUp()
self.stubs.Set(share_rpcapi, 'ShareAPI', mock.Mock()) self.mock_object(share_rpcapi, 'ShareAPI')
self.driver = simple.SimpleScheduler() self.driver = simple.SimpleScheduler()
self.context = context.RequestContext('fake_user', 'fake_project') self.context = context.RequestContext('fake_user', 'fake_project')

View File

@ -111,7 +111,7 @@ class EMCShareFrameworkTestCase(test.TestCase):
self.configuration = conf.Configuration(None) self.configuration = conf.Configuration(None)
self.configuration.append_config_values = mock.Mock(return_value=0) self.configuration.append_config_values = mock.Mock(return_value=0)
self.configuration.share_backend_name = FAKE_BACKEND self.configuration.share_backend_name = FAKE_BACKEND
self.stubs.Set(self.configuration, 'safe_get', self._fake_safe_get) self.mock_object(self.configuration, 'safe_get', self._fake_safe_get)
self.driver = emcdriver.EMCShareDriver( self.driver = emcdriver.EMCShareDriver(
configuration=self.configuration) configuration=self.configuration)

View File

@ -1141,7 +1141,7 @@ class EMCShareDriverVNXTestCase(test.TestCase):
self.configuration.emc_nas_password = 'fakepwd' self.configuration.emc_nas_password = 'fakepwd'
self.configuration.emc_nas_server = TD.emc_nas_server_default self.configuration.emc_nas_server = TD.emc_nas_server_default
self.configuration.share_backend_name = 'fake_backend' self.configuration.share_backend_name = 'fake_backend'
self.stubs.Set(self.configuration, 'safe_get', self._fake_safe_get) self.mock_object(self.configuration, 'safe_get', self._fake_safe_get)
self.driver = emc_driver.EMCShareDriver( self.driver = emc_driver.EMCShareDriver(
configuration=self.configuration) configuration=self.configuration)
self.driver_setup() self.driver_setup()

View File

@ -141,12 +141,12 @@ class GaneshaManagerTestCase(test.TestCase):
self.mock_restart_service): self.mock_restart_service):
self._manager = manager.GaneshaManager( self._manager = manager.GaneshaManager(
self._execute, 'faketag', **manager_fake_kwargs) self._execute, 'faketag', **manager_fake_kwargs)
self.stubs.Set(utils, 'synchronized', self.mock_object(utils, 'synchronized',
mock.Mock(return_value=lambda f: f)) mock.Mock(return_value=lambda f: f))
def test_init(self): def test_init(self):
self.stubs.Set(self._manager, 'reset_exports', mock.Mock()) self.mock_object(self._manager, 'reset_exports')
self.stubs.Set(self._manager, 'restart_service', mock.Mock()) self.mock_object(self._manager, 'restart_service')
self.assertEqual('/fakedir0/fakeconfig', self.assertEqual('/fakedir0/fakeconfig',
self._manager.ganesha_config_path) self._manager.ganesha_config_path)
self.assertEqual('faketag', self._manager.tag) self.assertEqual('faketag', self._manager.tag)
@ -174,7 +174,7 @@ class GaneshaManagerTestCase(test.TestCase):
raise exception.GaneshaCommandFailure() raise exception.GaneshaCommandFailure()
test_execute = mock.Mock(side_effect=raise_exception) test_execute = mock.Mock(side_effect=raise_exception)
self.stubs.Set(manager.LOG, 'error', mock.Mock()) self.mock_object(manager.LOG, 'error')
with contextlib.nested( with contextlib.nested(
mock.patch.object(manager.GaneshaManager, 'get_export_id', mock.patch.object(manager.GaneshaManager, 'get_export_id',
return_value=100), return_value=100),
@ -199,7 +199,7 @@ class GaneshaManagerTestCase(test.TestCase):
raise exception.GaneshaCommandFailure() raise exception.GaneshaCommandFailure()
test_execute = mock.Mock(side_effect=raise_exception) test_execute = mock.Mock(side_effect=raise_exception)
self.stubs.Set(manager.LOG, 'error', mock.Mock()) self.mock_object(manager.LOG, 'error')
with contextlib.nested( with contextlib.nested(
mock.patch.object(manager.GaneshaManager, 'get_export_id', mock.patch.object(manager.GaneshaManager, 'get_export_id',
return_value=100), return_value=100),
@ -226,8 +226,8 @@ class GaneshaManagerTestCase(test.TestCase):
def test_write_file(self): def test_write_file(self):
test_data = 'fakedata' test_data = 'fakedata'
self.stubs.Set(manager.pipes, 'quote', self.mock_object(manager.pipes, 'quote',
mock.Mock(return_value='fakefile.conf.RANDOM')) mock.Mock(return_value='fakefile.conf.RANDOM'))
test_args = [ test_args = [
('mktemp', '-p', '/fakedir0/export.d', '-t', ('mktemp', '-p', '/fakedir0/export.d', '-t',
'fakefile.conf.XXXXXX'), 'fakefile.conf.XXXXXX'),
@ -242,8 +242,8 @@ class GaneshaManagerTestCase(test.TestCase):
if args == test_args[0]: if args == test_args[0]:
return ('fakefile.conf.RANDOM\n', '') return ('fakefile.conf.RANDOM\n', '')
self.stubs.Set(self._manager, 'execute', self.mock_object(self._manager, 'execute',
mock.Mock(side_effect=return_tmpfile)) mock.Mock(side_effect=return_tmpfile))
self._manager._write_file(test_path, test_data) self._manager._write_file(test_path, test_data)
self._manager.execute.assert_has_calls([ self._manager.execute.assert_has_calls([
mock.call(*test_args[0]), mock.call(*test_args[0]),
@ -253,9 +253,9 @@ class GaneshaManagerTestCase(test.TestCase):
def test_write_conf_file(self): def test_write_conf_file(self):
test_data = 'fakedata' test_data = 'fakedata'
self.stubs.Set(self._manager, '_getpath', self.mock_object(self._manager, '_getpath',
mock.Mock(return_value=test_path)) mock.Mock(return_value=test_path))
self.stubs.Set(self._manager, '_write_file', mock.Mock()) self.mock_object(self._manager, '_write_file')
ret = self._manager._write_conf_file(test_name, test_data) ret = self._manager._write_conf_file(test_name, test_data)
self.assertEqual(test_path, ret) self.assertEqual(test_path, ret)
self._manager._getpath.assert_called_once_with(test_name) self._manager._getpath.assert_called_once_with(test_name)
@ -265,9 +265,9 @@ class GaneshaManagerTestCase(test.TestCase):
def test_mkindex(self): def test_mkindex(self):
test_ls_output = 'INDEX.conf\nfakefile.conf\nfakefile.txt' test_ls_output = 'INDEX.conf\nfakefile.conf\nfakefile.txt'
test_index = '%include /fakedir0/export.d/fakefile.conf\n' test_index = '%include /fakedir0/export.d/fakefile.conf\n'
self.stubs.Set(self._manager, 'execute', self.mock_object(self._manager, 'execute',
mock.Mock(return_value=(test_ls_output, ''))) mock.Mock(return_value=(test_ls_output, '')))
self.stubs.Set(self._manager, '_write_conf_file', mock.Mock()) self.mock_object(self._manager, '_write_conf_file')
ret = self._manager._mkindex() ret = self._manager._mkindex()
self._manager.execute.assert_called_once_with( self._manager.execute.assert_called_once_with(
'ls', '/fakedir0/export.d', run_as_root=False) 'ls', '/fakedir0/export.d', run_as_root=False)
@ -278,12 +278,12 @@ class GaneshaManagerTestCase(test.TestCase):
def test_read_export_file(self): def test_read_export_file(self):
test_args = ('cat', test_path) test_args = ('cat', test_path)
test_kwargs = {'message': 'reading export fakefile'} test_kwargs = {'message': 'reading export fakefile'}
self.stubs.Set(self._manager, '_getpath', self.mock_object(self._manager, '_getpath',
mock.Mock(return_value=test_path)) mock.Mock(return_value=test_path))
self.stubs.Set(self._manager, 'execute', self.mock_object(self._manager, 'execute',
mock.Mock(return_value=(test_ganesha_cnf,))) mock.Mock(return_value=(test_ganesha_cnf,)))
self.stubs.Set(manager, 'parseconf', self.mock_object(manager, 'parseconf',
mock.Mock(return_value=test_dict_unicode)) mock.Mock(return_value=test_dict_unicode))
ret = self._manager._read_export_file(test_name) ret = self._manager._read_export_file(test_name)
self._manager._getpath.assert_called_once_with(test_name) self._manager._getpath.assert_called_once_with(test_name)
self._manager.execute.assert_called_once_with( self._manager.execute.assert_called_once_with(
@ -292,10 +292,10 @@ class GaneshaManagerTestCase(test.TestCase):
self.assertEqual(test_dict_unicode, ret) self.assertEqual(test_dict_unicode, ret)
def test_write_export_file(self): def test_write_export_file(self):
self.stubs.Set(manager, 'mkconf', self.mock_object(manager, 'mkconf',
mock.Mock(return_value=test_ganesha_cnf)) mock.Mock(return_value=test_ganesha_cnf))
self.stubs.Set(self._manager, '_write_conf_file', self.mock_object(self._manager, '_write_conf_file',
mock.Mock(return_value=test_path)) mock.Mock(return_value=test_path))
ret = self._manager._write_export_file(test_name, test_dict_str) ret = self._manager._write_export_file(test_name, test_dict_str)
manager.mkconf.assert_called_once_with(test_dict_str) manager.mkconf.assert_called_once_with(test_dict_str)
self._manager._write_conf_file.assert_called_once_with( self._manager._write_conf_file.assert_called_once_with(
@ -310,10 +310,10 @@ class GaneshaManagerTestCase(test.TestCase):
u'CLIENT': {u'Clients': u"'ip1','ip2'"} u'CLIENT': {u'Clients': u"'ip1','ip2'"}
} }
} }
self.stubs.Set(manager, 'mkconf', self.mock_object(manager, 'mkconf',
mock.Mock(return_value=test_ganesha_cnf)) mock.Mock(return_value=test_ganesha_cnf))
self.stubs.Set(self._manager, '_write_conf_file', self.mock_object(self._manager, '_write_conf_file',
mock.Mock(return_value=test_path)) mock.Mock(return_value=test_path))
self.assertRaises(exception.InvalidParameterValue, self.assertRaises(exception.InvalidParameterValue,
self._manager._write_export_file, self._manager._write_export_file,
test_name, test_errordict) test_name, test_errordict)
@ -321,10 +321,10 @@ class GaneshaManagerTestCase(test.TestCase):
self.assertFalse(self._manager._write_conf_file.called) self.assertFalse(self._manager._write_conf_file.called)
def test_rm_export_file(self): def test_rm_export_file(self):
self.stubs.Set(self._manager, 'execute', self.mock_object(self._manager, 'execute',
mock.Mock(return_value=('', ''))) mock.Mock(return_value=('', '')))
self.stubs.Set(self._manager, '_getpath', self.mock_object(self._manager, '_getpath',
mock.Mock(return_value=test_path)) mock.Mock(return_value=test_path))
ret = self._manager._rm_export_file(test_name) ret = self._manager._rm_export_file(test_name)
self._manager._getpath.assert_called_once_with(test_name) self._manager._getpath.assert_called_once_with(test_name)
self._manager.execute.assert_called_once_with('rm', test_path) self._manager.execute.assert_called_once_with('rm', test_path)
@ -333,8 +333,8 @@ class GaneshaManagerTestCase(test.TestCase):
def test_dbus_send_ganesha(self): def test_dbus_send_ganesha(self):
test_args = ('arg1', 'arg2') test_args = ('arg1', 'arg2')
test_kwargs = {'key': 'value'} test_kwargs = {'key': 'value'}
self.stubs.Set(self._manager, 'execute', self.mock_object(self._manager, 'execute',
mock.Mock(return_value=('', ''))) mock.Mock(return_value=('', '')))
ret = self._manager._dbus_send_ganesha('fakemethod', *test_args, ret = self._manager._dbus_send_ganesha('fakemethod', *test_args,
**test_kwargs) **test_kwargs)
self._manager.execute.assert_called_once_with( self._manager.execute.assert_called_once_with(
@ -346,18 +346,17 @@ class GaneshaManagerTestCase(test.TestCase):
self.assertEqual(None, ret) self.assertEqual(None, ret)
def test_remove_export_dbus(self): def test_remove_export_dbus(self):
self.stubs.Set(self._manager, '_dbus_send_ganesha', self.mock_object(self._manager, '_dbus_send_ganesha')
mock.Mock())
ret = self._manager._remove_export_dbus(test_export_id) ret = self._manager._remove_export_dbus(test_export_id)
self._manager._dbus_send_ganesha.assert_called_once_with( self._manager._dbus_send_ganesha.assert_called_once_with(
'RemoveExport', 'uint16:101') 'RemoveExport', 'uint16:101')
self.assertEqual(None, ret) self.assertEqual(None, ret)
def test_add_export(self): def test_add_export(self):
self.stubs.Set(self._manager, '_write_export_file', self.mock_object(self._manager, '_write_export_file',
mock.Mock(return_value=test_path)) mock.Mock(return_value=test_path))
self.stubs.Set(self._manager, '_dbus_send_ganesha', mock.Mock()) self.mock_object(self._manager, '_dbus_send_ganesha')
self.stubs.Set(self._manager, '_mkindex', mock.Mock()) self.mock_object(self._manager, '_mkindex')
ret = self._manager.add_export(test_name, test_dict_str) ret = self._manager.add_export(test_name, test_dict_str)
self._manager._write_export_file.assert_called_once_with( self._manager._write_export_file.assert_called_once_with(
test_name, test_dict_str) test_name, test_dict_str)
@ -368,13 +367,14 @@ class GaneshaManagerTestCase(test.TestCase):
self.assertEqual(None, ret) self.assertEqual(None, ret)
def test_add_export_error_during_mkindex(self): def test_add_export_error_during_mkindex(self):
self.stubs.Set(self._manager, '_write_export_file', self.mock_object(self._manager, '_write_export_file',
mock.Mock(return_value=test_path)) mock.Mock(return_value=test_path))
self.stubs.Set(self._manager, '_dbus_send_ganesha', mock.Mock()) self.mock_object(self._manager, '_dbus_send_ganesha')
self.stubs.Set(self._manager, '_mkindex', self.mock_object(
mock.Mock(side_effect=exception.GaneshaCommandFailure)) self._manager, '_mkindex',
self.stubs.Set(self._manager, '_rm_export_file', mock.Mock()) mock.Mock(side_effect=exception.GaneshaCommandFailure))
self.stubs.Set(self._manager, '_remove_export_dbus', mock.Mock()) self.mock_object(self._manager, '_rm_export_file')
self.mock_object(self._manager, '_remove_export_dbus')
self.assertRaises(exception.GaneshaCommandFailure, self.assertRaises(exception.GaneshaCommandFailure,
self._manager.add_export, test_name, test_dict_str) self._manager.add_export, test_name, test_dict_str)
self._manager._write_export_file.assert_called_once_with( self._manager._write_export_file.assert_called_once_with(
@ -388,12 +388,13 @@ class GaneshaManagerTestCase(test.TestCase):
test_export_id) test_export_id)
def test_add_export_error_during_write_export_file(self): def test_add_export_error_during_write_export_file(self):
self.stubs.Set(self._manager, '_write_export_file', self.mock_object(
mock.Mock(side_effect=exception.GaneshaCommandFailure)) self._manager, '_write_export_file',
self.stubs.Set(self._manager, '_dbus_send_ganesha', mock.Mock()) mock.Mock(side_effect=exception.GaneshaCommandFailure))
self.stubs.Set(self._manager, '_mkindex', mock.Mock()) self.mock_object(self._manager, '_dbus_send_ganesha')
self.stubs.Set(self._manager, '_rm_export_file', mock.Mock()) self.mock_object(self._manager, '_mkindex')
self.stubs.Set(self._manager, '_remove_export_dbus', mock.Mock()) self.mock_object(self._manager, '_rm_export_file')
self.mock_object(self._manager, '_remove_export_dbus')
self.assertRaises(exception.GaneshaCommandFailure, self.assertRaises(exception.GaneshaCommandFailure,
self._manager.add_export, test_name, test_dict_str) self._manager.add_export, test_name, test_dict_str)
self._manager._write_export_file.assert_called_once_with( self._manager._write_export_file.assert_called_once_with(
@ -404,14 +405,14 @@ class GaneshaManagerTestCase(test.TestCase):
self.assertFalse(self._manager._remove_export_dbus.called) self.assertFalse(self._manager._remove_export_dbus.called)
def test_add_export_error_during_dbus_send_ganesha(self): def test_add_export_error_during_dbus_send_ganesha(self):
self.stubs.Set(self._manager, '_write_export_file', self.mock_object(self._manager, '_write_export_file',
mock.Mock(return_value=test_path)) mock.Mock(return_value=test_path))
self.stubs.Set(self._manager, '_dbus_send_ganesha', self.mock_object(
mock.Mock(side_effect=exception.GaneshaCommandFailure)) self._manager, '_dbus_send_ganesha',
self.stubs.Set(self._manager, '_mkindex', mock.Mock(side_effect=exception.GaneshaCommandFailure))
mock.Mock()) self.mock_object(self._manager, '_mkindex')
self.stubs.Set(self._manager, '_rm_export_file', mock.Mock()) self.mock_object(self._manager, '_rm_export_file')
self.stubs.Set(self._manager, '_remove_export_dbus', mock.Mock()) self.mock_object(self._manager, '_remove_export_dbus')
self.assertRaises(exception.GaneshaCommandFailure, self.assertRaises(exception.GaneshaCommandFailure,
self._manager.add_export, test_name, test_dict_str) self._manager.add_export, test_name, test_dict_str)
self._manager._write_export_file.assert_called_once_with( self._manager._write_export_file.assert_called_once_with(
@ -424,11 +425,11 @@ class GaneshaManagerTestCase(test.TestCase):
self.assertFalse(self._manager._remove_export_dbus.called) self.assertFalse(self._manager._remove_export_dbus.called)
def test_remove_export(self): def test_remove_export(self):
self.stubs.Set(self._manager, '_read_export_file', self.mock_object(self._manager, '_read_export_file',
mock.Mock(return_value=test_dict_unicode)) mock.Mock(return_value=test_dict_unicode))
methods = ('_remove_export_dbus', '_rm_export_file', '_mkindex') methods = ('_remove_export_dbus', '_rm_export_file', '_mkindex')
for method in methods: for method in methods:
self.stubs.Set(self._manager, method, mock.Mock()) self.mock_object(self._manager, method)
ret = self._manager.remove_export(test_name) ret = self._manager.remove_export(test_name)
self._manager._read_export_file.assert_called_once_with(test_name) self._manager._read_export_file.assert_called_once_with(test_name)
self._manager._remove_export_dbus.assert_called_once_with( self._manager._remove_export_dbus.assert_called_once_with(
@ -438,11 +439,12 @@ class GaneshaManagerTestCase(test.TestCase):
self.assertEqual(None, ret) self.assertEqual(None, ret)
def test_remove_export_error_during_read_export_file(self): def test_remove_export_error_during_read_export_file(self):
self.stubs.Set(self._manager, '_read_export_file', self.mock_object(
mock.Mock(side_effect=exception.GaneshaCommandFailure)) self._manager, '_read_export_file',
mock.Mock(side_effect=exception.GaneshaCommandFailure))
methods = ('_remove_export_dbus', '_rm_export_file', '_mkindex') methods = ('_remove_export_dbus', '_rm_export_file', '_mkindex')
for method in methods: for method in methods:
self.stubs.Set(self._manager, method, mock.Mock()) self.mock_object(self._manager, method)
self.assertRaises(exception.GaneshaCommandFailure, self.assertRaises(exception.GaneshaCommandFailure,
self._manager.remove_export, test_name) self._manager.remove_export, test_name)
self._manager._read_export_file.assert_called_once_with(test_name) self._manager._read_export_file.assert_called_once_with(test_name)
@ -451,13 +453,14 @@ class GaneshaManagerTestCase(test.TestCase):
self._manager._mkindex.assert_called_once_with() self._manager._mkindex.assert_called_once_with()
def test_remove_export_error_during_remove_export_dbus(self): def test_remove_export_error_during_remove_export_dbus(self):
self.stubs.Set(self._manager, '_read_export_file', self.mock_object(self._manager, '_read_export_file',
mock.Mock(return_value=test_dict_unicode)) mock.Mock(return_value=test_dict_unicode))
self.stubs.Set(self._manager, '_remove_export_dbus', self.mock_object(
mock.Mock(side_effect=exception.GaneshaCommandFailure)) self._manager, '_remove_export_dbus',
mock.Mock(side_effect=exception.GaneshaCommandFailure))
methods = ('_rm_export_file', '_mkindex') methods = ('_rm_export_file', '_mkindex')
for method in methods: for method in methods:
self.stubs.Set(self._manager, method, mock.Mock()) self.mock_object(self._manager, method)
self.assertRaises(exception.GaneshaCommandFailure, self.assertRaises(exception.GaneshaCommandFailure,
self._manager.remove_export, test_name) self._manager.remove_export, test_name)
self._manager._read_export_file.assert_called_once_with(test_name) self._manager._read_export_file.assert_called_once_with(test_name)
@ -467,8 +470,8 @@ class GaneshaManagerTestCase(test.TestCase):
self._manager._mkindex.assert_called_once_with() self._manager._mkindex.assert_called_once_with()
def test_get_export_id(self): def test_get_export_id(self):
self.stubs.Set(self._manager, 'execute', self.mock_object(self._manager, 'execute',
mock.Mock(return_value=('exportid|101', ''))) mock.Mock(return_value=('exportid|101', '')))
ret = self._manager.get_export_id() ret = self._manager.get_export_id()
self._manager.execute.assert_called_once_with( self._manager.execute.assert_called_once_with(
'sqlite3', self._manager.ganesha_db_path, 'sqlite3', self._manager.ganesha_db_path,
@ -478,8 +481,8 @@ class GaneshaManagerTestCase(test.TestCase):
self.assertEqual(101, ret) self.assertEqual(101, ret)
def test_get_export_id_nobump(self): def test_get_export_id_nobump(self):
self.stubs.Set(self._manager, 'execute', self.mock_object(self._manager, 'execute',
mock.Mock(return_value=('exportid|101', ''))) mock.Mock(return_value=('exportid|101', '')))
ret = self._manager.get_export_id(bump=False) ret = self._manager.get_export_id(bump=False)
self._manager.execute.assert_called_once_with( self._manager.execute.assert_called_once_with(
'sqlite3', self._manager.ganesha_db_path, 'sqlite3', self._manager.ganesha_db_path,
@ -488,9 +491,9 @@ class GaneshaManagerTestCase(test.TestCase):
self.assertEqual(101, ret) self.assertEqual(101, ret)
def test_get_export_id_error_invalid_export_db(self): def test_get_export_id_error_invalid_export_db(self):
self.stubs.Set(self._manager, 'execute', self.mock_object(self._manager, 'execute',
mock.Mock(return_value=('invalid', ''))) mock.Mock(return_value=('invalid', '')))
self.stubs.Set(manager.LOG, 'error', mock.Mock()) self.mock_object(manager.LOG, 'error')
self.assertRaises(exception.InvalidSqliteDB, self.assertRaises(exception.InvalidSqliteDB,
self._manager.get_export_id) self._manager.get_export_id)
manager.LOG.error.assert_called_once_with( manager.LOG.error.assert_called_once_with(
@ -502,15 +505,15 @@ class GaneshaManagerTestCase(test.TestCase):
run_as_root=False) run_as_root=False)
def test_restart_service(self): def test_restart_service(self):
self.stubs.Set(self._manager, 'execute', mock.Mock()) self.mock_object(self._manager, 'execute')
ret = self._manager.restart_service() ret = self._manager.restart_service()
self._manager.execute.assert_called_once_with( self._manager.execute.assert_called_once_with(
'service', 'ganesha.fakeservice', 'restart') 'service', 'ganesha.fakeservice', 'restart')
self.assertEqual(None, ret) self.assertEqual(None, ret)
def test_reset_exports(self): def test_reset_exports(self):
self.stubs.Set(self._manager, 'execute', mock.Mock()) self.mock_object(self._manager, 'execute')
self.stubs.Set(self._manager, '_mkindex', mock.Mock()) self.mock_object(self._manager, '_mkindex')
ret = self._manager.reset_exports() ret = self._manager.reset_exports()
self._manager.execute.assert_called_once_with( self._manager.execute.assert_called_once_with(
'sh', '-c', 'rm /fakedir0/export.d/*.conf') 'sh', '-c', 'rm /fakedir0/export.d/*.conf')

View File

@ -45,7 +45,7 @@ class GaneshaUtilsTests(test.TestCase):
self.assertEqual(walk_test_list, ret) self.assertEqual(walk_test_list, ret)
def test_path_from(self): def test_path_from(self):
self.stubs.Set(os.path, 'abspath', self.mock_object(os.path, 'abspath',
lambda path: os.path.join('/foo/bar', path)) lambda path: os.path.join('/foo/bar', path))
ret = utils.path_from('baz.py', '../quux', 'tic/tac/toe') ret = utils.path_from('baz.py', '../quux', 'tic/tac/toe')
self.assertEqual('/foo/quux/tic/tac/toe', os.path.normpath(ret)) self.assertEqual('/foo/quux/tic/tac/toe', os.path.normpath(ret))

View File

@ -266,7 +266,7 @@ class HuaweiShareDriverTestCase(test.TestCase):
self.configuration.share_backend_name = 'fake_share_backend_name' self.configuration.share_backend_name = 'fake_share_backend_name'
self.configuration.driver_handles_share_servers = False self.configuration.driver_handles_share_servers = False
self.configuration.manila_huawei_conf_file = self.fake_conf_file self.configuration.manila_huawei_conf_file = self.fake_conf_file
self.stubs.Set(time, 'sleep', fake_sleep) self.mock_object(time, 'sleep', fake_sleep)
driver = FakeHuaweiNasDriver(configuration=self.configuration) driver = FakeHuaweiNasDriver(configuration=self.configuration)
self.driver = driver self.driver = driver
self.driver.helper.test_normal = True self.driver.helper.test_normal = True

View File

@ -98,9 +98,9 @@ class GaneshaUtilsTestCase(test.TestCase):
self.sshlogin = "fake_login" self.sshlogin = "fake_login"
self.sshkey = "fake_sshkey" self.sshkey = "fake_sshkey"
self.STARTING_EXPORT_ID = 100 self.STARTING_EXPORT_ID = 100
self.stubs.Set(socket, 'gethostname', self.mock_object(socket, 'gethostname',
mock.Mock(return_value="testserver")) mock.Mock(return_value="testserver"))
self.stubs.Set(socket, 'gethostbyname_ex', mock.Mock( self.mock_object(socket, 'gethostbyname_ex', mock.Mock(
return_value=('localhost', return_value=('localhost',
['localhost.localdomain', 'testserver'], ['localhost.localdomain', 'testserver'],
['127.0.0.1'] + self.local_ip) ['127.0.0.1'] + self.local_ip)
@ -108,8 +108,8 @@ class GaneshaUtilsTestCase(test.TestCase):
def test_get_export_by_path(self): def test_get_export_by_path(self):
fake_export = {'export_id': '100'} fake_export = {'export_id': '100'}
self.stubs.Set(ganesha_utils, '_get_export_by_path', self.mock_object(ganesha_utils, '_get_export_by_path',
mock.Mock(return_value=fake_export)) mock.Mock(return_value=fake_export))
export = ganesha_utils.get_export_by_path(self.fake_exports, export = ganesha_utils.get_export_by_path(self.fake_exports,
self.fake_path) self.fake_path)
self.assertEqual(export, fake_export) self.assertEqual(export, fake_export)
@ -119,8 +119,8 @@ class GaneshaUtilsTestCase(test.TestCase):
def test_export_exists(self): def test_export_exists(self):
fake_export = {'export_id': '100'} fake_export = {'export_id': '100'}
self.stubs.Set(ganesha_utils, '_get_export_by_path', self.mock_object(ganesha_utils, '_get_export_by_path',
mock.Mock(return_value=fake_export)) mock.Mock(return_value=fake_export))
result = ganesha_utils.export_exists(self.fake_exports, self.fake_path) result = ganesha_utils.export_exists(self.fake_exports, self.fake_path)
self.assertTrue(result) self.assertTrue(result)
ganesha_utils._get_export_by_path.assert_called_once_with( ganesha_utils._get_export_by_path.assert_called_once_with(
@ -184,7 +184,7 @@ class GaneshaUtilsTestCase(test.TestCase):
configpath = self.fake_configpath configpath = self.fake_configpath
methods = ('_publish_local_config', '_publish_remote_config') methods = ('_publish_local_config', '_publish_remote_config')
for method in methods: for method in methods:
self.stubs.Set(ganesha_utils, method, mock.Mock()) self.mock_object(ganesha_utils, method)
ganesha_utils.publish_ganesha_config(self.servers, self.sshlogin, ganesha_utils.publish_ganesha_config(self.servers, self.sshlogin,
self.sshkey, configpath, self.sshkey, configpath,
self.fake_pre_lines, self.fake_pre_lines,
@ -198,7 +198,7 @@ class GaneshaUtilsTestCase(test.TestCase):
) )
def test_reload_ganesha_config(self): def test_reload_ganesha_config(self):
self.stubs.Set(utils, 'execute', mock.Mock(return_value=True)) self.mock_object(utils, 'execute', mock.Mock(return_value=True))
service = 'ganesha.nfsd' service = 'ganesha.nfsd'
ganesha_utils.reload_ganesha_config(self.servers, self.sshlogin) ganesha_utils.reload_ganesha_config(self.servers, self.sshlogin)
reload_cmd = ['service', service, 'restart'] reload_cmd = ['service', service, 'restart']
@ -213,9 +213,9 @@ class GaneshaUtilsTestCase(test.TestCase):
@mock.patch('six.moves.builtins.open') @mock.patch('six.moves.builtins.open')
def test__publish_local_config(self, mock_open): def test__publish_local_config(self, mock_open):
self.stubs.Set(utils, 'execute', mock.Mock(return_value=True)) self.mock_object(utils, 'execute', mock.Mock(return_value=True))
fake_timestamp = 1415506949.75 fake_timestamp = 1415506949.75
self.stubs.Set(time, 'time', mock.Mock(return_value=fake_timestamp)) self.mock_object(time, 'time', mock.Mock(return_value=fake_timestamp))
configpath = self.fake_configpath configpath = self.fake_configpath
tmp_path = '%s.tmp.%s' % (configpath, fake_timestamp) tmp_path = '%s.tmp.%s' % (configpath, fake_timestamp)
ganesha_utils._publish_local_config(configpath, ganesha_utils._publish_local_config(configpath,
@ -231,10 +231,11 @@ class GaneshaUtilsTestCase(test.TestCase):
@mock.patch('six.moves.builtins.open') @mock.patch('six.moves.builtins.open')
def test__publish_local_config_exception(self, mock_open): def test__publish_local_config_exception(self, mock_open):
self.stubs.Set(utils, 'execute', self.mock_object(
mock.Mock(side_effect=exception.ProcessExecutionError)) utils, 'execute',
mock.Mock(side_effect=exception.ProcessExecutionError))
fake_timestamp = 1415506949.75 fake_timestamp = 1415506949.75
self.stubs.Set(time, 'time', mock.Mock(return_value=fake_timestamp)) self.mock_object(time, 'time', mock.Mock(return_value=fake_timestamp))
configpath = self.fake_configpath configpath = self.fake_configpath
tmp_path = '%s.tmp.%s' % (configpath, fake_timestamp) tmp_path = '%s.tmp.%s' % (configpath, fake_timestamp)
self.assertRaises(exception.GPFSGaneshaException, self.assertRaises(exception.GPFSGaneshaException,
@ -255,8 +256,9 @@ class GaneshaUtilsTestCase(test.TestCase):
utils.execute.assert_called_once_with(*scpcmd, run_as_root=False) utils.execute.assert_called_once_with(*scpcmd, run_as_root=False)
def test__publish_remote_config_exception(self): def test__publish_remote_config_exception(self):
self.stubs.Set(utils, 'execute', self.mock_object(
mock.Mock(side_effect=exception.ProcessExecutionError)) utils, 'execute',
mock.Mock(side_effect=exception.ProcessExecutionError))
server = self.remote_ips[1] server = self.remote_ips[1]
dest = '%s@%s:%s' % (self.sshlogin, server, self.fake_configpath) dest = '%s@%s:%s' % (self.sshlogin, server, self.fake_configpath)
scpcmd = ['scp', '-i', self.sshkey, self.fake_configpath, dest] scpcmd = ['scp', '-i', self.sshkey, self.fake_configpath, dest]

View File

@ -58,7 +58,7 @@ class GPFSShareDriverTestCase(test.TestCase):
self.fakefspath = "/gpfs0" self.fakefspath = "/gpfs0"
self.fakesharepath = "/gpfs0/share-fakeid" self.fakesharepath = "/gpfs0/share-fakeid"
self.fakesnapshotpath = "/gpfs0/.snapshots/snapshot-fakesnapshotid" self.fakesnapshotpath = "/gpfs0/.snapshots/snapshot-fakesnapshotid"
self.stubs.Set(gpfs.os.path, 'exists', mock.Mock(return_value=True)) self.mock_object(gpfs.os.path, 'exists', mock.Mock(return_value=True))
self._driver._helpers = { self._driver._helpers = {
'KNFS': self._helper_fake 'KNFS': self._helper_fake
} }
@ -86,9 +86,9 @@ class GPFSShareDriverTestCase(test.TestCase):
self._gnfs_helper.configuration.gpfs_ssh_login = self.sshlogin self._gnfs_helper.configuration.gpfs_ssh_login = self.sshlogin
self._gnfs_helper.configuration.gpfs_ssh_private_key = self.sshkey self._gnfs_helper.configuration.gpfs_ssh_private_key = self.sshkey
self._gnfs_helper.configuration.ganesha_service_name = self.gservice self._gnfs_helper.configuration.ganesha_service_name = self.gservice
self.stubs.Set(socket, 'gethostname', self.mock_object(socket, 'gethostname',
mock.Mock(return_value="testserver")) mock.Mock(return_value="testserver"))
self.stubs.Set(socket, 'gethostbyname_ex', mock.Mock( self.mock_object(socket, 'gethostbyname_ex', mock.Mock(
return_value=('localhost', return_value=('localhost',
['localhost.localdomain', 'testserver'], ['localhost.localdomain', 'testserver'],
['127.0.0.1', self.local_ip]) ['127.0.0.1', self.local_ip])
@ -100,7 +100,7 @@ class GPFSShareDriverTestCase(test.TestCase):
self.assertEqual(self._driver._stats, result) self.assertEqual(self._driver._stats, result)
def test_get_share_stats_refresh_true(self): def test_get_share_stats_refresh_true(self):
self.stubs.Set( self.mock_object(
self._driver, '_get_available_capacity', self._driver, '_get_available_capacity',
mock.Mock(return_value=(11111.0, 12345.0))) mock.Mock(return_value=(11111.0, 12345.0)))
result = self._driver.get_share_stats(True) result = self._driver.get_share_stats(True)
@ -118,15 +118,15 @@ class GPFSShareDriverTestCase(test.TestCase):
self._driver.configuration.gpfs_mount_point_base) self._driver.configuration.gpfs_mount_point_base)
def test_do_setup(self): def test_do_setup(self):
self.stubs.Set(self._driver, '_setup_helpers', mock.Mock()) self.mock_object(self._driver, '_setup_helpers')
self._driver.do_setup(self._context) self._driver.do_setup(self._context)
self._driver._setup_helpers.assert_called_any() self._driver._setup_helpers.assert_called_any()
def test_setup_helpers(self): def test_setup_helpers(self):
self._driver._helpers = {} self._driver._helpers = {}
CONF.set_default('gpfs_share_helpers', ['KNFS=fakenfs']) CONF.set_default('gpfs_share_helpers', ['KNFS=fakenfs'])
self.stubs.Set(gpfs.importutils, 'import_class', self.mock_object(gpfs.importutils, 'import_class',
mock.Mock(return_value=self._helper_fake)) mock.Mock(return_value=self._helper_fake))
self._driver._setup_helpers() self._driver._setup_helpers()
gpfs.importutils.import_class.assert_has_calls( gpfs.importutils.import_class.assert_has_calls(
[mock.call('fakenfs')] [mock.call('fakenfs')]
@ -143,7 +143,7 @@ class GPFSShareDriverTestCase(test.TestCase):
self._helper_fake.create_export.return_value = 'fakelocation' self._helper_fake.create_export.return_value = 'fakelocation'
methods = ('_create_share', '_get_share_path') methods = ('_create_share', '_get_share_path')
for method in methods: for method in methods:
self.stubs.Set(self._driver, method, mock.Mock()) self.mock_object(self._driver, method)
result = self._driver.create_share(self._context, self.share, result = self._driver.create_share(self._context, self.share,
share_server=self.server) share_server=self.server)
self._driver._create_share.assert_called_once_with(self.share) self._driver._create_share.assert_called_once_with(self.share)
@ -447,7 +447,7 @@ class GPFSShareDriverTestCase(test.TestCase):
) )
def test__gpfs_local_execute(self): def test__gpfs_local_execute(self):
self.stubs.Set(utils, 'execute', mock.Mock(return_value=True)) self.mock_object(utils, 'execute', mock.Mock(return_value=True))
cmd = "testcmd" cmd = "testcmd"
self._driver._gpfs_local_execute(cmd) self._driver._gpfs_local_execute(cmd)
utils.execute.assert_called_once_with(cmd, run_as_root=True) utils.execute.assert_called_once_with(cmd, run_as_root=True)
@ -467,7 +467,7 @@ class GPFSShareDriverTestCase(test.TestCase):
self._knfs_helper._execute = mock.Mock( self._knfs_helper._execute = mock.Mock(
return_value=['/fs0 <world>', 0] return_value=['/fs0 <world>', 0]
) )
self.stubs.Set(re, 'search', mock.Mock(return_value=None)) self.mock_object(re, 'search', mock.Mock(return_value=None))
export_opts = None export_opts = None
self._knfs_helper._get_export_options = mock.Mock( self._knfs_helper._get_export_options = mock.Mock(
return_value=export_opts return_value=export_opts
@ -488,7 +488,7 @@ class GPFSShareDriverTestCase(test.TestCase):
def test_knfs_allow_access_access_exists(self): def test_knfs_allow_access_access_exists(self):
out = ['/fs0 <world>', 0] out = ['/fs0 <world>', 0]
self._knfs_helper._execute = mock.Mock(return_value=out) self._knfs_helper._execute = mock.Mock(return_value=out)
self.stubs.Set(re, 'search', mock.Mock(return_value="fake")) self.mock_object(re, 'search', mock.Mock(return_value="fake"))
self._knfs_helper._get_export_options = mock.Mock() self._knfs_helper._get_export_options = mock.Mock()
access_type = self.access['access_type'] access_type = self.access['access_type']
access = self.access['access_to'] access = self.access['access_to']
@ -548,7 +548,7 @@ class GPFSShareDriverTestCase(test.TestCase):
self._knfs_helper._publish_access.assert_called_once_with(*cmd) self._knfs_helper._publish_access.assert_called_once_with(*cmd)
def test_knfs__publish_access(self): def test_knfs__publish_access(self):
self.stubs.Set(utils, 'execute', mock.Mock()) self.mock_object(utils, 'execute')
cmd = ['fakecmd'] cmd = ['fakecmd']
self._knfs_helper._publish_access(*cmd) self._knfs_helper._publish_access(*cmd)
utils.execute.assert_any_call(*cmd, run_as_root=True, utils.execute.assert_any_call(*cmd, run_as_root=True,
@ -561,8 +561,9 @@ class GPFSShareDriverTestCase(test.TestCase):
self.assertTrue(socket.gethostname.called) self.assertTrue(socket.gethostname.called)
def test_knfs__publish_access_exception(self): def test_knfs__publish_access_exception(self):
self.stubs.Set(utils, 'execute', self.mock_object(
mock.Mock(side_effect=exception.ProcessExecutionError)) utils, 'execute',
mock.Mock(side_effect=exception.ProcessExecutionError))
cmd = ['fakecmd'] cmd = ['fakecmd']
self.assertRaises(exception.ProcessExecutionError, self.assertRaises(exception.ProcessExecutionError,
self._knfs_helper._publish_access, *cmd) self._knfs_helper._publish_access, *cmd)
@ -621,20 +622,20 @@ class GPFSShareDriverTestCase(test.TestCase):
self._gnfs_helper._get_export_options = mock.Mock( self._gnfs_helper._get_export_options = mock.Mock(
return_value=export_opts return_value=export_opts
) )
self.stubs.Set(ganesha_utils, 'parse_ganesha_config', mock.Mock( self.mock_object(ganesha_utils, 'parse_ganesha_config', mock.Mock(
return_value=(pre_lines, exports) return_value=(pre_lines, exports)
)) ))
self.stubs.Set(ganesha_utils, 'export_exists', mock.Mock( self.mock_object(ganesha_utils, 'export_exists', mock.Mock(
return_value=False return_value=False
)) ))
self.stubs.Set(ganesha_utils, 'get_next_id', mock.Mock( self.mock_object(ganesha_utils, 'get_next_id', mock.Mock(
return_value=101 return_value=101
)) ))
self.stubs.Set(ganesha_utils, 'get_export_template', mock.Mock( self.mock_object(ganesha_utils, 'get_export_template', mock.Mock(
return_value={} return_value={}
)) ))
self.stubs.Set(ganesha_utils, 'publish_ganesha_config', mock.Mock()) self.mock_object(ganesha_utils, 'publish_ganesha_config')
self.stubs.Set(ganesha_utils, 'reload_ganesha_config', mock.Mock()) self.mock_object(ganesha_utils, 'reload_ganesha_config')
self._gnfs_helper._ganesha_process_request( self._gnfs_helper._ganesha_process_request(
"allow_access", local_path, self.share, access_type, access "allow_access", local_path, self.share, access_type, access
) )
@ -661,17 +662,17 @@ class GPFSShareDriverTestCase(test.TestCase):
initial_access = "10.0.0.1,10.0.0.2" initial_access = "10.0.0.1,10.0.0.2"
export = {"rw_access": initial_access} export = {"rw_access": initial_access}
exports = {} exports = {}
self.stubs.Set(ganesha_utils, 'parse_ganesha_config', mock.Mock( self.mock_object(ganesha_utils, 'parse_ganesha_config', mock.Mock(
return_value=(pre_lines, exports) return_value=(pre_lines, exports)
)) ))
self.stubs.Set(ganesha_utils, 'get_export_by_path', mock.Mock( self.mock_object(ganesha_utils, 'get_export_by_path', mock.Mock(
return_value=export return_value=export
)) ))
self.stubs.Set(ganesha_utils, 'format_access_list', mock.Mock( self.mock_object(ganesha_utils, 'format_access_list', mock.Mock(
return_value="10.0.0.1" return_value="10.0.0.1"
)) ))
self.stubs.Set(ganesha_utils, 'publish_ganesha_config', mock.Mock()) self.mock_object(ganesha_utils, 'publish_ganesha_config')
self.stubs.Set(ganesha_utils, 'reload_ganesha_config', mock.Mock()) self.mock_object(ganesha_utils, 'reload_ganesha_config')
self._gnfs_helper._ganesha_process_request( self._gnfs_helper._ganesha_process_request(
"deny_access", local_path, self.share, access_type, access "deny_access", local_path, self.share, access_type, access
) )
@ -694,14 +695,14 @@ class GPFSShareDriverTestCase(test.TestCase):
pre_lines = [] pre_lines = []
exports = {} exports = {}
export = {} export = {}
self.stubs.Set(ganesha_utils, 'parse_ganesha_config', mock.Mock( self.mock_object(ganesha_utils, 'parse_ganesha_config', mock.Mock(
return_value=(pre_lines, exports) return_value=(pre_lines, exports)
)) ))
self.stubs.Set(ganesha_utils, 'get_export_by_path', mock.Mock( self.mock_object(ganesha_utils, 'get_export_by_path', mock.Mock(
return_value=export return_value=export
)) ))
self.stubs.Set(ganesha_utils, 'publish_ganesha_config', mock.Mock()) self.mock_object(ganesha_utils, 'publish_ganesha_config')
self.stubs.Set(ganesha_utils, 'reload_ganesha_config', mock.Mock()) self.mock_object(ganesha_utils, 'reload_ganesha_config')
self._gnfs_helper._ganesha_process_request( self._gnfs_helper._ganesha_process_request(
"remove_export", local_path, self.share "remove_export", local_path, self.share
) )

View File

@ -163,17 +163,16 @@ class NetAppClusteredDrvTestCase(test.TestCase):
vserver_name = \ vserver_name = \
self.driver.configuration.netapp_vserver_name_template % \ self.driver.configuration.netapp_vserver_name_template % \
self.network_info['server_id'] self.network_info['server_id']
self.stubs.Set(self.driver.db, 'share_server_backend_details_set', self.mock_object(self.driver.db, 'share_server_backend_details_set')
mock.Mock()) self.mock_object(self.driver, '_vserver_exists',
self.stubs.Set(self.driver, '_vserver_exists', mock.Mock(return_value=True))
mock.Mock(return_value=True)) self.mock_object(self.driver, '_get_cluster_nodes',
self.stubs.Set(self.driver, '_get_cluster_nodes', mock.Mock(return_value=nodes))
mock.Mock(return_value=nodes)) self.mock_object(self.driver, '_get_node_data_port',
self.stubs.Set(self.driver, '_get_node_data_port', mock.Mock(return_value=port))
mock.Mock(return_value=port)) self.mock_object(self.driver, '_create_lif_if_not_exists')
self.stubs.Set(self.driver, '_create_lif_if_not_exists', mock.Mock()) self.mock_object(self.driver, '_enable_nfs')
self.stubs.Set(self.driver, '_enable_nfs', mock.Mock()) self.mock_object(self.driver, '_setup_security_services')
self.stubs.Set(self.driver, '_setup_security_services', mock.Mock())
returned_data = self.driver._vserver_create_if_not_exists( returned_data = self.driver._vserver_create_if_not_exists(
self.network_info) self.network_info)
@ -217,17 +216,16 @@ class NetAppClusteredDrvTestCase(test.TestCase):
vserver_name = \ vserver_name = \
self.driver.configuration.netapp_vserver_name_template % \ self.driver.configuration.netapp_vserver_name_template % \
network_info['server_id'] network_info['server_id']
self.stubs.Set(self.driver.db, 'share_server_backend_details_set', self.mock_object(self.driver.db, 'share_server_backend_details_set')
mock.Mock()) self.mock_object(self.driver, '_vserver_exists',
self.stubs.Set(self.driver, '_vserver_exists', mock.Mock(return_value=False))
mock.Mock(return_value=False)) self.mock_object(self.driver, '_create_vserver')
self.stubs.Set(self.driver, '_create_vserver', mock.Mock()) self.mock_object(self.driver, '_get_cluster_nodes',
self.stubs.Set(self.driver, '_get_cluster_nodes', mock.Mock(return_value=nodes))
mock.Mock(return_value=nodes)) self.mock_object(self.driver, '_get_node_data_port',
self.stubs.Set(self.driver, '_get_node_data_port', mock.Mock(return_value=port))
mock.Mock(return_value=port)) self.mock_object(self.driver, '_create_lif_if_not_exists')
self.stubs.Set(self.driver, '_create_lif_if_not_exists', mock.Mock()) self.mock_object(self.driver, '_enable_nfs')
self.stubs.Set(self.driver, '_enable_nfs', mock.Mock())
returned_data = self.driver._vserver_create_if_not_exists(network_info) returned_data = self.driver._vserver_create_if_not_exists(network_info)
@ -268,18 +266,17 @@ class NetAppClusteredDrvTestCase(test.TestCase):
vserver_name = \ vserver_name = \
self.driver.configuration.netapp_vserver_name_template % \ self.driver.configuration.netapp_vserver_name_template % \
network_info['server_id'] network_info['server_id']
self.stubs.Set(self.driver.db, 'share_server_backend_details_set', self.mock_object(self.driver.db, 'share_server_backend_details_set')
mock.Mock()) self.mock_object(self.driver, '_vserver_exists',
self.stubs.Set(self.driver, '_vserver_exists', mock.Mock(return_value=False))
mock.Mock(return_value=False)) self.mock_object(self.driver, '_create_vserver')
self.stubs.Set(self.driver, '_create_vserver', mock.Mock()) self.mock_object(self.driver, '_get_cluster_nodes',
self.stubs.Set(self.driver, '_get_cluster_nodes', mock.Mock(return_value=nodes))
mock.Mock(return_value=nodes)) self.mock_object(self.driver, '_get_node_data_port',
self.stubs.Set(self.driver, '_get_node_data_port', mock.Mock(return_value=port))
mock.Mock(return_value=port)) self.mock_object(self.driver, '_create_lif_if_not_exists')
self.stubs.Set(self.driver, '_create_lif_if_not_exists', mock.Mock()) self.mock_object(self.driver, '_enable_nfs')
self.stubs.Set(self.driver, '_enable_nfs', mock.Mock()) self.mock_object(self.driver, '_setup_security_services')
self.stubs.Set(self.driver, '_setup_security_services', mock.Mock())
returned_data = self.driver._vserver_create_if_not_exists(network_info) returned_data = self.driver._vserver_create_if_not_exists(network_info)
@ -467,8 +464,9 @@ class NetAppClusteredDrvTestCase(test.TestCase):
fake_share.fake_share(share_proto='NFSBOGUS'), fake_share.fake_share(share_proto='NFSBOGUS'),
fake_share.fake_share(share_proto='CIFSBOGUS')) fake_share.fake_share(share_proto='CIFSBOGUS'))
def test_get_helper_with_wrong_proto(self, share): def test_get_helper_with_wrong_proto(self, share):
self.stubs.Set(self.driver, '_check_licenses', self.mock_object(self.driver,
mock.Mock(return_value=share['share_proto'])) '_check_licenses',
mock.Mock(return_value=share['share_proto']))
self.assertRaises(exception.NetAppException, self.assertRaises(exception.NetAppException,
self.driver._get_helper, share) self.driver._get_helper, share)
@ -570,8 +568,8 @@ class NetAppClusteredDrvTestCase(test.TestCase):
'domain': 'FAKE', 'domain': 'FAKE',
} }
self.driver._configure_dns = mock.Mock() self.driver._configure_dns = mock.Mock()
self.stubs.Set(self._vserver_client, 'send_request', self.mock_object(self._vserver_client, 'send_request',
mock.Mock(side_effect=naapi.NaApiError())) mock.Mock(side_effect=naapi.NaApiError()))
self.assertRaises( self.assertRaises(
exception.NetAppException, exception.NetAppException,
@ -744,9 +742,9 @@ class NetAppClusteredDrvTestCase(test.TestCase):
licenses = naapi.NaElement('fake_licenses_as_response') licenses = naapi.NaElement('fake_licenses_as_response')
licenses.translate_struct(licenses_dict) licenses.translate_struct(licenses_dict)
self.stubs.Set(self.driver._client, 'send_request', self.mock_object(self.driver._client, 'send_request',
mock.Mock(return_value=licenses)) mock.Mock(return_value=licenses))
self.stubs.Set(driver.LOG, 'info', mock.Mock()) self.mock_object(driver.LOG, 'info')
response = self.driver._check_licenses() response = self.driver._check_licenses()
@ -756,9 +754,9 @@ class NetAppClusteredDrvTestCase(test.TestCase):
self.assertEqual(response, ['fake_license_1', 'fake_license_2']) self.assertEqual(response, ['fake_license_1', 'fake_license_2'])
def test_licenses_exception_raise(self): def test_licenses_exception_raise(self):
self.stubs.Set(self.driver._client, 'send_request', self.mock_object(self.driver._client, 'send_request',
mock.Mock(side_effect=naapi.NaApiError())) mock.Mock(side_effect=naapi.NaApiError()))
self.stubs.Set(driver.LOG, 'error', mock.Mock()) self.mock_object(driver.LOG, 'error')
self.driver._check_licenses() self.driver._check_licenses()
@ -786,11 +784,11 @@ class NetAppNFSHelperTestCase(test.TestCase):
def test_create_share(self): def test_create_share(self):
export_ip = 'fake_export_ip' export_ip = 'fake_export_ip'
junction = 'fake-vserver-location' junction = 'fake-vserver-location'
self.stubs.Set(self.helper._client, 'send_request', mock.Mock()) self.mock_object(self.helper._client, 'send_request')
self.helper._client.send_request().get_child_by_name = mock.Mock() self.helper._client.send_request().get_child_by_name = mock.Mock()
self.helper._client.send_request().get_child_by_name().get_content = ( self.helper._client.send_request().get_child_by_name().get_content = (
mock.Mock(side_effect=lambda: junction)) mock.Mock(side_effect=lambda: junction))
self.stubs.Set(self.helper, 'add_rules', mock.Mock()) self.mock_object(self.helper, 'add_rules')
location = self.helper.create_share(self.share['name'], export_ip) location = self.helper.create_share(self.share['name'], export_ip)
@ -825,8 +823,8 @@ class NetAppNFSHelperTestCase(test.TestCase):
if pathname.startswith(volume_path): if pathname.startswith(volume_path):
raise naapi.NaApiError('13114') raise naapi.NaApiError('13114')
self.stubs.Set(self.helper._client, 'send_request', self.mock_object(self.helper._client, 'send_request',
mock.Mock(side_effect=raise_exception_13114)) mock.Mock(side_effect=raise_exception_13114))
self.helper.add_rules(volume_path, rules) self.helper.add_rules(volume_path, rules)
@ -847,8 +845,8 @@ class NetAppNFSHelperTestCase(test.TestCase):
not self.helper.nfs_exports_with_prefix): not self.helper.nfs_exports_with_prefix):
raise naapi.NaApiError('13114') raise naapi.NaApiError('13114')
self.stubs.Set(self.helper._client, 'send_request', self.mock_object(self.helper._client, 'send_request',
mock.Mock(side_effect=raise_exception_13114)) mock.Mock(side_effect=raise_exception_13114))
self.helper.add_rules(volume_path, rules) self.helper.add_rules(volume_path, rules)
@ -912,8 +910,8 @@ class NetAppCIFSHelperTestCase(test.TestCase):
name=self.name, name=self.name,
export_location=export_location) export_location=export_location)
self.helper = driver.NetAppClusteredCIFSHelper() self.helper = driver.NetAppClusteredCIFSHelper()
self.stubs.Set(self.helper, '_client', mock.Mock()) self.mock_object(self.helper, '_client')
self.stubs.Set(self.helper._client, 'send_request', mock.Mock()) self.mock_object(self.helper._client, 'send_request')
def test_create_share(self): def test_create_share(self):
self.helper.create_share(self.name, '1.1.1.1') self.helper.create_share(self.name, '1.1.1.1')
@ -946,8 +944,8 @@ class NetAppCIFSHelperTestCase(test.TestCase):
) )
def test_allow_access_user_type_rule_already_present(self): def test_allow_access_user_type_rule_already_present(self):
self.stubs.Set(self.helper._client, 'send_request', self.mock_object(self.helper._client, 'send_request',
mock.Mock(side_effect=naapi.NaApiError('13130'))) mock.Mock(side_effect=naapi.NaApiError('13130')))
access = {'access_to': 'fake_access', 'access_type': 'user'} access = {'access_to': 'fake_access', 'access_type': 'user'}
self.assertRaises( self.assertRaises(
exception.ShareAccessExists, exception.ShareAccessExists,
@ -993,8 +991,8 @@ class NetAppCIFSHelperTestCase(test.TestCase):
) )
def test_deny_access_exception_raised(self): def test_deny_access_exception_raised(self):
self.stubs.Set(self.helper, '_restrict_access', self.mock_object(self.helper, '_restrict_access',
mock.Mock(side_effect=naapi.NaApiError())) mock.Mock(side_effect=naapi.NaApiError()))
self.assertRaises( self.assertRaises(
naapi.NaApiError, naapi.NaApiError,
self.helper.deny_access, self.helper.deny_access,

View File

@ -80,14 +80,14 @@ class GaneshaNASHelperTestCase(test.TestCase):
copy.deepcopy(tmpl1), copy.deepcopy(tmpl2)) copy.deepcopy(tmpl1), copy.deepcopy(tmpl2))
tmpl1.update(tmpl2) tmpl1.update(tmpl2)
self.stubs.Set(ganesha.os, 'listdir', self.mock_object(ganesha.os, 'listdir',
mock.Mock(return_value=fake_ls_dir)) mock.Mock(return_value=fake_ls_dir))
self.stubs.Set(ganesha.LOG, 'info', mock.Mock()) self.mock_object(ganesha.LOG, 'info')
self.stubs.Set(ganesha.ganesha_manager, 'parseconf', self.mock_object(ganesha.ganesha_manager, 'parseconf',
mock.Mock(side_effect=[fake_template1, mock.Mock(side_effect=[fake_template1,
fake_template2])) fake_template2]))
self.stubs.Set(ganesha.ganesha_utils, 'patch', self.mock_object(ganesha.ganesha_utils, 'patch',
mock.Mock(side_effect=fake_patch_run)) mock.Mock(side_effect=fake_patch_run))
with mock.patch('six.moves.builtins.open', with mock.patch('six.moves.builtins.open',
mock.mock_open()) as mockopen: mock.mock_open()) as mockopen:
mockopen().read.side_effect = ['fakeconf0', 'fakeconf1'] mockopen().read.side_effect = ['fakeconf0', 'fakeconf1']
@ -108,13 +108,13 @@ class GaneshaNASHelperTestCase(test.TestCase):
self.assertEqual(fake_template2, ret) self.assertEqual(fake_template2, ret)
def test_load_conf_dir_no_conf_dir_must_exist_false(self): def test_load_conf_dir_no_conf_dir_must_exist_false(self):
self.stubs.Set( self.mock_object(
ganesha.os, 'listdir', ganesha.os, 'listdir',
mock.Mock(side_effect=OSError(errno.ENOENT, mock.Mock(side_effect=OSError(errno.ENOENT,
os.strerror(errno.ENOENT)))) os.strerror(errno.ENOENT))))
self.stubs.Set(ganesha.LOG, 'info', mock.Mock()) self.mock_object(ganesha.LOG, 'info')
self.stubs.Set(ganesha.ganesha_manager, 'parseconf', mock.Mock()) self.mock_object(ganesha.ganesha_manager, 'parseconf')
self.stubs.Set(ganesha.ganesha_utils, 'patch', mock.Mock()) self.mock_object(ganesha.ganesha_utils, 'patch')
with mock.patch('six.moves.builtins.open', with mock.patch('six.moves.builtins.open',
mock.mock_open(read_data='fakeconf')) as mockopen: mock.mock_open(read_data='fakeconf')) as mockopen:
ret = self._helper._load_conf_dir(self.fake_conf_dir_path, ret = self._helper._load_conf_dir(self.fake_conf_dir_path,
@ -129,7 +129,7 @@ class GaneshaNASHelperTestCase(test.TestCase):
self.assertEqual({}, ret) self.assertEqual({}, ret)
def test_load_conf_dir_error_no_conf_dir_must_exist_true(self): def test_load_conf_dir_error_no_conf_dir_must_exist_true(self):
self.stubs.Set( self.mock_object(
ganesha.os, 'listdir', ganesha.os, 'listdir',
mock.Mock(side_effect=OSError(errno.ENOENT, mock.Mock(side_effect=OSError(errno.ENOENT,
os.strerror(errno.ENOENT)))) os.strerror(errno.ENOENT))))
@ -138,7 +138,7 @@ class GaneshaNASHelperTestCase(test.TestCase):
ganesha.os.listdir.assert_called_once_with(self.fake_conf_dir_path) ganesha.os.listdir.assert_called_once_with(self.fake_conf_dir_path)
def test_load_conf_dir_error_conf_dir_present_must_exist_false(self): def test_load_conf_dir_error_conf_dir_present_must_exist_false(self):
self.stubs.Set( self.mock_object(
ganesha.os, 'listdir', ganesha.os, 'listdir',
mock.Mock(side_effect=OSError(errno.EACCES, mock.Mock(side_effect=OSError(errno.EACCES,
os.strerror(errno.EACCES)))) os.strerror(errno.EACCES))))
@ -147,7 +147,7 @@ class GaneshaNASHelperTestCase(test.TestCase):
ganesha.os.listdir.assert_called_once_with(self.fake_conf_dir_path) ganesha.os.listdir.assert_called_once_with(self.fake_conf_dir_path)
def test_load_conf_dir_error(self): def test_load_conf_dir_error(self):
self.stubs.Set( self.mock_object(
ganesha.os, 'listdir', ganesha.os, 'listdir',
mock.Mock(side_effect=RuntimeError('fake error'))) mock.Mock(side_effect=RuntimeError('fake error')))
self.assertRaises(RuntimeError, self._helper._load_conf_dir, self.assertRaises(RuntimeError, self._helper._load_conf_dir,
@ -157,11 +157,11 @@ class GaneshaNASHelperTestCase(test.TestCase):
def test_init_helper(self): def test_init_helper(self):
mock_template = mock.Mock() mock_template = mock.Mock()
mock_ganesha_manager = mock.Mock() mock_ganesha_manager = mock.Mock()
self.stubs.Set(ganesha.ganesha_manager, 'GaneshaManager', self.mock_object(ganesha.ganesha_manager, 'GaneshaManager',
mock.Mock(return_value=mock_ganesha_manager)) mock.Mock(return_value=mock_ganesha_manager))
self.stubs.Set(self._helper, '_load_conf_dir', self.mock_object(self._helper, '_load_conf_dir',
mock.Mock(return_value=mock_template)) mock.Mock(return_value=mock_template))
self.stubs.Set(self._helper, '_default_config_hook', mock.Mock()) self.mock_object(self._helper, '_default_config_hook')
ret = self._helper.init_helper() ret = self._helper.init_helper()
ganesha.ganesha_manager.GaneshaManager.assert_called_once_with( ganesha.ganesha_manager.GaneshaManager.assert_called_once_with(
self._execute, 'faketag', self._execute, 'faketag',
@ -179,12 +179,12 @@ class GaneshaNASHelperTestCase(test.TestCase):
def test_init_helper_conf_dir_empty(self): def test_init_helper_conf_dir_empty(self):
mock_template = mock.Mock() mock_template = mock.Mock()
mock_ganesha_manager = mock.Mock() mock_ganesha_manager = mock.Mock()
self.stubs.Set(ganesha.ganesha_manager, 'GaneshaManager', self.mock_object(ganesha.ganesha_manager, 'GaneshaManager',
mock.Mock(return_value=mock_ganesha_manager)) mock.Mock(return_value=mock_ganesha_manager))
self.stubs.Set(self._helper, '_load_conf_dir', self.mock_object(self._helper, '_load_conf_dir',
mock.Mock(return_value={})) mock.Mock(return_value={}))
self.stubs.Set(self._helper, '_default_config_hook', self.mock_object(self._helper, '_default_config_hook',
mock.Mock(return_value=mock_template)) mock.Mock(return_value=mock_template))
ret = self._helper.init_helper() ret = self._helper.init_helper()
ganesha.ganesha_manager.GaneshaManager.assert_called_once_with( ganesha.ganesha_manager.GaneshaManager.assert_called_once_with(
self._execute, 'faketag', self._execute, 'faketag',
@ -201,10 +201,10 @@ class GaneshaNASHelperTestCase(test.TestCase):
def test_default_config_hook(self): def test_default_config_hook(self):
fake_template = {'key': 'value'} fake_template = {'key': 'value'}
self.stubs.Set(ganesha.ganesha_utils, 'path_from', self.mock_object(ganesha.ganesha_utils, 'path_from',
mock.Mock(return_value='/fakedir3/fakeconfdir')) mock.Mock(return_value='/fakedir3/fakeconfdir'))
self.stubs.Set(self._helper, '_load_conf_dir', self.mock_object(self._helper, '_load_conf_dir',
mock.Mock(return_value=fake_template)) mock.Mock(return_value=fake_template))
ret = self._helper._default_config_hook() ret = self._helper._default_config_hook()
ganesha.ganesha_utils.path_from.assert_called_once_with( ganesha.ganesha_utils.path_from.assert_called_once_with(
ganesha.__file__, 'conf') ganesha.__file__, 'conf')
@ -223,12 +223,12 @@ class GaneshaNASHelperTestCase(test.TestCase):
mock_ganesha_utils_patch(copy.deepcopy(tmpl1), tmpl2, tmpl3) mock_ganesha_utils_patch(copy.deepcopy(tmpl1), tmpl2, tmpl3)
tmpl1.update(tmpl3) tmpl1.update(tmpl3)
self.stubs.Set(self._helper.ganesha, 'get_export_id', self.mock_object(self._helper.ganesha, 'get_export_id',
mock.Mock(return_value=101)) mock.Mock(return_value=101))
self.stubs.Set(self._helper, '_fsal_hook', self.mock_object(self._helper, '_fsal_hook',
mock.Mock(return_value='fakefsal')) mock.Mock(return_value='fakefsal'))
self.stubs.Set(ganesha.ganesha_utils, 'patch', self.mock_object(ganesha.ganesha_utils, 'patch',
mock.Mock(side_effect=fake_patch_run)) mock.Mock(side_effect=fake_patch_run))
ret = self._helper.allow_access(fake_basepath, self.share, ret = self._helper.allow_access(fake_basepath, self.share,
self.access) self.access)
self._helper.ganesha.get_export_id.assert_called_once_with() self._helper.ganesha.get_export_id.assert_called_once_with()

View File

@ -83,9 +83,10 @@ class GenericShareDriverTestCase(test.TestCase):
context="fake", instance_name="fake", context="fake", instance_name="fake",
share_network_id=self.fake_sn["id"], old_server_ip="fake") share_network_id=self.fake_sn["id"], old_server_ip="fake")
self.stubs.Set(utils, 'synchronized', self.mock_object(utils, 'synchronized',
mock.Mock(return_value=lambda f: f)) mock.Mock(return_value=lambda f: f))
self.stubs.Set(generic.os.path, 'exists', mock.Mock(return_value=True)) self.mock_object(generic.os.path, 'exists',
mock.Mock(return_value=True))
self._driver._helpers = { self._driver._helpers = {
'CIFS': self._helper_cifs, 'CIFS': self._helper_cifs,
'NFS': self._helper_nfs, 'NFS': self._helper_nfs,
@ -106,9 +107,9 @@ class GenericShareDriverTestCase(test.TestCase):
self.snapshot = fake_share.fake_snapshot() self.snapshot = fake_share.fake_snapshot()
def test_do_setup(self): def test_do_setup(self):
self.stubs.Set(volume, 'API', mock.Mock()) self.mock_object(volume, 'API')
self.stubs.Set(compute, 'API', mock.Mock()) self.mock_object(compute, 'API')
self.stubs.Set(self._driver, '_setup_helpers', mock.Mock()) self.mock_object(self._driver, '_setup_helpers')
self._driver.do_setup(self._context) self._driver.do_setup(self._context)
volume.API.assert_called_once_with() volume.API.assert_called_once_with()
compute.API.assert_called_once_with() compute.API.assert_called_once_with()
@ -117,8 +118,8 @@ class GenericShareDriverTestCase(test.TestCase):
def test_setup_helpers(self): def test_setup_helpers(self):
self._driver._helpers = {} self._driver._helpers = {}
CONF.set_default('share_helpers', ['NFS=fakenfs']) CONF.set_default('share_helpers', ['NFS=fakenfs'])
self.stubs.Set(generic.importutils, 'import_class', self.mock_object(generic.importutils, 'import_class',
mock.Mock(return_value=self._helper_nfs)) mock.Mock(return_value=self._helper_nfs))
self._driver._setup_helpers() self._driver._setup_helpers()
generic.importutils.import_class.assert_has_calls([ generic.importutils.import_class.assert_has_calls([
mock.call('fakenfs') mock.call('fakenfs')
@ -134,12 +135,12 @@ class GenericShareDriverTestCase(test.TestCase):
volume = 'fake_volume' volume = 'fake_volume'
volume2 = 'fake_volume2' volume2 = 'fake_volume2'
self._helper_nfs.create_export.return_value = 'fakelocation' self._helper_nfs.create_export.return_value = 'fakelocation'
self.stubs.Set(self._driver, '_allocate_container', self.mock_object(self._driver, '_allocate_container',
mock.Mock(return_value=volume)) mock.Mock(return_value=volume))
self.stubs.Set(self._driver, '_attach_volume', self.mock_object(self._driver, '_attach_volume',
mock.Mock(return_value=volume2)) mock.Mock(return_value=volume2))
self.stubs.Set(self._driver, '_format_device', mock.Mock()) self.mock_object(self._driver, '_format_device')
self.stubs.Set(self._driver, '_mount_device', mock.Mock()) self.mock_object(self._driver, '_mount_device')
result = self._driver.create_share( result = self._driver.create_share(
self._context, self.share, share_server=self.server) self._context, self.share, share_server=self.server)
@ -163,8 +164,8 @@ class GenericShareDriverTestCase(test.TestCase):
def test_format_device(self): def test_format_device(self):
volume = {'mountpoint': 'fake_mount_point'} volume = {'mountpoint': 'fake_mount_point'}
self.stubs.Set(self._driver, '_ssh_exec', self.mock_object(self._driver, '_ssh_exec',
mock.Mock(return_value=('', ''))) mock.Mock(return_value=('', '')))
self._driver._format_device(self.server, volume) self._driver._format_device(self.server, volume)
self._driver._ssh_exec.assert_called_once_with( self._driver._ssh_exec.assert_called_once_with(
self.server, self.server,
@ -175,14 +176,13 @@ class GenericShareDriverTestCase(test.TestCase):
server = {'instance_id': 'fake_server_id'} server = {'instance_id': 'fake_server_id'}
mount_path = '/fake/mount/path' mount_path = '/fake/mount/path'
volume = {'mountpoint': 'fake_mount_point'} volume = {'mountpoint': 'fake_mount_point'}
self.stubs.Set(self._driver, '_is_device_mounted', self.mock_object(self._driver, '_is_device_mounted',
mock.Mock(return_value=False)) mock.Mock(return_value=False))
self.stubs.Set(self._driver, '_sync_mount_temp_and_perm_files', self.mock_object(self._driver, '_sync_mount_temp_and_perm_files')
mock.Mock()) self.mock_object(self._driver, '_get_mount_path',
self.stubs.Set(self._driver, '_get_mount_path', mock.Mock(return_value=mount_path))
mock.Mock(return_value=mount_path)) self.mock_object(self._driver, '_ssh_exec',
self.stubs.Set(self._driver, '_ssh_exec', mock.Mock(return_value=('', '')))
mock.Mock(return_value=('', '')))
self._driver._mount_device(self.share, server, volume) self._driver._mount_device(self.share, server, volume)
@ -201,11 +201,11 @@ class GenericShareDriverTestCase(test.TestCase):
def test_mount_device_present(self): def test_mount_device_present(self):
mount_path = '/fake/mount/path' mount_path = '/fake/mount/path'
volume = {'mountpoint': 'fake_mount_point'} volume = {'mountpoint': 'fake_mount_point'}
self.stubs.Set(self._driver, '_is_device_mounted', self.mock_object(self._driver, '_is_device_mounted',
mock.Mock(return_value=True)) mock.Mock(return_value=True))
self.stubs.Set(self._driver, '_get_mount_path', self.mock_object(self._driver, '_get_mount_path',
mock.Mock(return_value=mount_path)) mock.Mock(return_value=mount_path))
self.stubs.Set(generic.LOG, 'warning', mock.Mock()) self.mock_object(generic.LOG, 'warning')
self._driver._mount_device(self.share, self.server, volume) self._driver._mount_device(self.share, self.server, volume)
@ -216,10 +216,11 @@ class GenericShareDriverTestCase(test.TestCase):
def test_mount_device_exception_raised(self): def test_mount_device_exception_raised(self):
volume = {'mountpoint': 'fake_mount_point'} volume = {'mountpoint': 'fake_mount_point'}
self.stubs.Set(self._driver, '_get_mount_path', self.mock_object(self._driver, '_get_mount_path',
mock.Mock(return_value='fake')) mock.Mock(return_value='fake'))
self.stubs.Set(self._driver, '_is_device_mounted', self.mock_object(
mock.Mock(side_effect=exception.ProcessExecutionError)) self._driver, '_is_device_mounted',
mock.Mock(side_effect=exception.ProcessExecutionError))
self.assertRaises( self.assertRaises(
exception.ShareBackendException, exception.ShareBackendException,
@ -234,14 +235,13 @@ class GenericShareDriverTestCase(test.TestCase):
def test_unmount_device_present(self): def test_unmount_device_present(self):
mount_path = '/fake/mount/path' mount_path = '/fake/mount/path'
self.stubs.Set(self._driver, '_is_device_mounted', self.mock_object(self._driver, '_is_device_mounted',
mock.Mock(return_value=True)) mock.Mock(return_value=True))
self.stubs.Set(self._driver, '_sync_mount_temp_and_perm_files', self.mock_object(self._driver, '_sync_mount_temp_and_perm_files')
mock.Mock()) self.mock_object(self._driver, '_get_mount_path',
self.stubs.Set(self._driver, '_get_mount_path', mock.Mock(return_value=mount_path))
mock.Mock(return_value=mount_path)) self.mock_object(self._driver, '_ssh_exec',
self.stubs.Set(self._driver, '_ssh_exec', mock.Mock(return_value=('', '')))
mock.Mock(return_value=('', '')))
self._driver._unmount_device(self.share, self.server) self._driver._unmount_device(self.share, self.server)
@ -257,11 +257,11 @@ class GenericShareDriverTestCase(test.TestCase):
def test_unmount_device_not_present(self): def test_unmount_device_not_present(self):
mount_path = '/fake/mount/path' mount_path = '/fake/mount/path'
self.stubs.Set(self._driver, '_is_device_mounted', self.mock_object(self._driver, '_is_device_mounted',
mock.Mock(return_value=False)) mock.Mock(return_value=False))
self.stubs.Set(self._driver, '_get_mount_path', self.mock_object(self._driver, '_get_mount_path',
mock.Mock(return_value=mount_path)) mock.Mock(return_value=mount_path))
self.stubs.Set(generic.LOG, 'warning', mock.Mock()) self.mock_object(generic.LOG, 'warning')
self._driver._unmount_device(self.share, self.server) self._driver._unmount_device(self.share, self.server)
@ -275,10 +275,10 @@ class GenericShareDriverTestCase(test.TestCase):
mount_path = '/fake/mount/path' mount_path = '/fake/mount/path'
mounts = "%(dev)s on %(path)s" % {'dev': volume['mountpoint'], mounts = "%(dev)s on %(path)s" % {'dev': volume['mountpoint'],
'path': mount_path} 'path': mount_path}
self.stubs.Set(self._driver, '_ssh_exec', self.mock_object(self._driver, '_ssh_exec',
mock.Mock(return_value=(mounts, ''))) mock.Mock(return_value=(mounts, '')))
self.stubs.Set(self._driver, '_get_mount_path', self.mock_object(self._driver, '_get_mount_path',
mock.Mock(return_value=mount_path)) mock.Mock(return_value=mount_path))
result = self._driver._is_device_mounted( result = self._driver._is_device_mounted(
self.share, self.server, volume) self.share, self.server, volume)
@ -291,10 +291,10 @@ class GenericShareDriverTestCase(test.TestCase):
def test_is_device_mounted_true_no_volume_provided(self): def test_is_device_mounted_true_no_volume_provided(self):
mount_path = '/fake/mount/path' mount_path = '/fake/mount/path'
mounts = "/fake/dev/path on %(path)s type fake" % {'path': mount_path} mounts = "/fake/dev/path on %(path)s type fake" % {'path': mount_path}
self.stubs.Set(self._driver, '_ssh_exec', self.mock_object(self._driver, '_ssh_exec',
mock.Mock(return_value=(mounts, ''))) mock.Mock(return_value=(mounts, '')))
self.stubs.Set(self._driver, '_get_mount_path', self.mock_object(self._driver, '_get_mount_path',
mock.Mock(return_value=mount_path)) mock.Mock(return_value=mount_path))
result = self._driver._is_device_mounted(self.share, self.server) result = self._driver._is_device_mounted(self.share, self.server)
@ -308,10 +308,10 @@ class GenericShareDriverTestCase(test.TestCase):
volume = {'mountpoint': 'fake_mount_point', 'id': 'fake_id'} volume = {'mountpoint': 'fake_mount_point', 'id': 'fake_id'}
mounts = "%(dev)s on %(path)s" % {'dev': '/fake', mounts = "%(dev)s on %(path)s" % {'dev': '/fake',
'path': mount_path} 'path': mount_path}
self.stubs.Set(self._driver, '_ssh_exec', self.mock_object(self._driver, '_ssh_exec',
mock.Mock(return_value=(mounts, ''))) mock.Mock(return_value=(mounts, '')))
self.stubs.Set(self._driver, '_get_mount_path', self.mock_object(self._driver, '_get_mount_path',
mock.Mock(return_value=mount_path)) mock.Mock(return_value=mount_path))
result = self._driver._is_device_mounted( result = self._driver._is_device_mounted(
self.share, self.server, volume) self.share, self.server, volume)
@ -324,10 +324,10 @@ class GenericShareDriverTestCase(test.TestCase):
def test_is_device_mounted_false_no_volume_provided(self): def test_is_device_mounted_false_no_volume_provided(self):
mount_path = '/fake/mount/path' mount_path = '/fake/mount/path'
mounts = "%(path)s" % {'path': 'fake'} mounts = "%(path)s" % {'path': 'fake'}
self.stubs.Set(self._driver, '_ssh_exec', self.mock_object(self._driver, '_ssh_exec',
mock.Mock(return_value=(mounts, ''))) mock.Mock(return_value=(mounts, '')))
self.stubs.Set(self._driver, '_get_mount_path', self.mock_object(self._driver, '_get_mount_path',
mock.Mock(return_value=mount_path)) mock.Mock(return_value=mount_path))
result = self._driver._is_device_mounted(self.share, self.server) result = self._driver._is_device_mounted(self.share, self.server)
@ -337,7 +337,7 @@ class GenericShareDriverTestCase(test.TestCase):
self.assertEqual(result, False) self.assertEqual(result, False)
def test_sync_mount_temp_and_perm_files(self): def test_sync_mount_temp_and_perm_files(self):
self.stubs.Set(self._driver, '_ssh_exec', mock.Mock()) self.mock_object(self._driver, '_ssh_exec')
self._driver._sync_mount_temp_and_perm_files(self.server) self._driver._sync_mount_temp_and_perm_files(self.server)
self._driver._ssh_exec.has_calls( self._driver._ssh_exec.has_calls(
mock.call( mock.call(
@ -346,8 +346,9 @@ class GenericShareDriverTestCase(test.TestCase):
mock.call(self.server, ['sudo', 'mount', '-a'])) mock.call(self.server, ['sudo', 'mount', '-a']))
def test_sync_mount_temp_and_perm_files_raise_error_on_copy(self): def test_sync_mount_temp_and_perm_files_raise_error_on_copy(self):
self.stubs.Set(self._driver, '_ssh_exec', self.mock_object(
mock.Mock(side_effect=exception.ProcessExecutionError)) self._driver, '_ssh_exec',
mock.Mock(side_effect=exception.ProcessExecutionError))
self.assertRaises( self.assertRaises(
exception.ShareBackendException, exception.ShareBackendException,
self._driver._sync_mount_temp_and_perm_files, self._driver._sync_mount_temp_and_perm_files,
@ -362,8 +363,8 @@ class GenericShareDriverTestCase(test.TestCase):
if args[1][1] == 'cp': if args[1][1] == 'cp':
raise exception.ProcessExecutionError() raise exception.ProcessExecutionError()
self.stubs.Set(self._driver, '_ssh_exec', self.mock_object(self._driver, '_ssh_exec',
mock.Mock(side_effect=raise_error_on_mount)) mock.Mock(side_effect=raise_error_on_mount))
self.assertRaises( self.assertRaises(
exception.ShareBackendException, exception.ShareBackendException,
self._driver._sync_mount_temp_and_perm_files, self._driver._sync_mount_temp_and_perm_files,
@ -383,10 +384,9 @@ class GenericShareDriverTestCase(test.TestCase):
def test_attach_volume_not_attached(self): def test_attach_volume_not_attached(self):
availiable_volume = fake_volume.FakeVolume() availiable_volume = fake_volume.FakeVolume()
attached_volume = fake_volume.FakeVolume(status='in-use') attached_volume = fake_volume.FakeVolume(status='in-use')
self.stubs.Set(self._driver.compute_api, 'instance_volume_attach', self.mock_object(self._driver.compute_api, 'instance_volume_attach')
mock.Mock()) self.mock_object(self._driver.volume_api, 'get',
self.stubs.Set(self._driver.volume_api, 'get', mock.Mock(return_value=attached_volume))
mock.Mock(return_value=attached_volume))
result = self._driver._attach_volume(self._context, self.share, result = self._driver._attach_volume(self._context, self.share,
'fake_inst_id', availiable_volume) 'fake_inst_id', availiable_volume)
@ -401,8 +401,8 @@ class GenericShareDriverTestCase(test.TestCase):
def test_attach_volume_attached_correct(self): def test_attach_volume_attached_correct(self):
fake_server = fake_compute.FakeServer() fake_server = fake_compute.FakeServer()
attached_volume = fake_volume.FakeVolume(status='in-use') attached_volume = fake_volume.FakeVolume(status='in-use')
self.stubs.Set(self._driver.compute_api, 'instance_volumes_list', self.mock_object(self._driver.compute_api, 'instance_volumes_list',
mock.Mock(return_value=[attached_volume])) mock.Mock(return_value=[attached_volume]))
result = self._driver._attach_volume(self._context, self.share, result = self._driver._attach_volume(self._context, self.share,
fake_server, attached_volume) fake_server, attached_volume)
@ -413,8 +413,8 @@ class GenericShareDriverTestCase(test.TestCase):
fake_server = fake_compute.FakeServer() fake_server = fake_compute.FakeServer()
attached_volume = fake_volume.FakeVolume(status='in-use') attached_volume = fake_volume.FakeVolume(status='in-use')
anoter_volume = fake_volume.FakeVolume(id='fake_id2', status='in-use') anoter_volume = fake_volume.FakeVolume(id='fake_id2', status='in-use')
self.stubs.Set(self._driver.compute_api, 'instance_volumes_list', self.mock_object(self._driver.compute_api, 'instance_volumes_list',
mock.Mock(return_value=[anoter_volume])) mock.Mock(return_value=[anoter_volume]))
self.assertRaises(exception.ManilaException, self.assertRaises(exception.ManilaException,
self._driver._attach_volume, self._context, self._driver._attach_volume, self._context,
self.share, fake_server, attached_volume) self.share, fake_server, attached_volume)
@ -422,8 +422,8 @@ class GenericShareDriverTestCase(test.TestCase):
def test_attach_volume_failed_attach(self): def test_attach_volume_failed_attach(self):
fake_server = fake_compute.FakeServer() fake_server = fake_compute.FakeServer()
availiable_volume = fake_volume.FakeVolume() availiable_volume = fake_volume.FakeVolume()
self.stubs.Set(self._driver.compute_api, 'instance_volume_attach', self.mock_object(self._driver.compute_api, 'instance_volume_attach',
mock.Mock(side_effect=exception.ManilaException)) mock.Mock(side_effect=exception.ManilaException))
self.assertRaises(exception.ManilaException, self.assertRaises(exception.ManilaException,
self._driver._attach_volume, self._driver._attach_volume,
self._context, self.share, fake_server, self._context, self.share, fake_server,
@ -433,10 +433,9 @@ class GenericShareDriverTestCase(test.TestCase):
fake_server = fake_compute.FakeServer() fake_server = fake_compute.FakeServer()
availiable_volume = fake_volume.FakeVolume() availiable_volume = fake_volume.FakeVolume()
error_volume = fake_volume.FakeVolume(status='error') error_volume = fake_volume.FakeVolume(status='error')
self.stubs.Set(self._driver.compute_api, 'instance_volume_attach', self.mock_object(self._driver.compute_api, 'instance_volume_attach')
mock.Mock()) self.mock_object(self._driver.volume_api, 'get',
self.stubs.Set(self._driver.volume_api, 'get', mock.Mock(return_value=error_volume))
mock.Mock(return_value=error_volume))
self.assertRaises(exception.ManilaException, self.assertRaises(exception.ManilaException,
self._driver._attach_volume, self._driver._attach_volume,
self._context, self.share, self._context, self.share,
@ -445,22 +444,22 @@ class GenericShareDriverTestCase(test.TestCase):
def test_get_volume(self): def test_get_volume(self):
volume = fake_volume.FakeVolume( volume = fake_volume.FakeVolume(
display_name=CONF.volume_name_template % self.share['id']) display_name=CONF.volume_name_template % self.share['id'])
self.stubs.Set(self._driver.volume_api, 'get_all', self.mock_object(self._driver.volume_api, 'get_all',
mock.Mock(return_value=[volume])) mock.Mock(return_value=[volume]))
result = self._driver._get_volume(self._context, self.share['id']) result = self._driver._get_volume(self._context, self.share['id'])
self.assertEqual(result, volume) self.assertEqual(result, volume)
def test_get_volume_none(self): def test_get_volume_none(self):
self.stubs.Set(self._driver.volume_api, 'get_all', self.mock_object(self._driver.volume_api, 'get_all',
mock.Mock(return_value=[])) mock.Mock(return_value=[]))
result = self._driver._get_volume(self._context, self.share['id']) result = self._driver._get_volume(self._context, self.share['id'])
self.assertEqual(result, None) self.assertEqual(result, None)
def test_get_volume_error(self): def test_get_volume_error(self):
volume = fake_volume.FakeVolume( volume = fake_volume.FakeVolume(
display_name=CONF.volume_name_template % self.share['id']) display_name=CONF.volume_name_template % self.share['id'])
self.stubs.Set(self._driver.volume_api, 'get_all', self.mock_object(self._driver.volume_api, 'get_all',
mock.Mock(return_value=[volume, volume])) mock.Mock(return_value=[volume, volume]))
self.assertRaises(exception.ManilaException, self.assertRaises(exception.ManilaException,
self._driver._get_volume, self._driver._get_volume,
self._context, self.share['id']) self._context, self.share['id'])
@ -469,15 +468,15 @@ class GenericShareDriverTestCase(test.TestCase):
volume_snapshot = fake_volume.FakeVolumeSnapshot( volume_snapshot = fake_volume.FakeVolumeSnapshot(
display_name=CONF.volume_snapshot_name_template % display_name=CONF.volume_snapshot_name_template %
self.snapshot['id']) self.snapshot['id'])
self.stubs.Set(self._driver.volume_api, 'get_all_snapshots', self.mock_object(self._driver.volume_api, 'get_all_snapshots',
mock.Mock(return_value=[volume_snapshot])) mock.Mock(return_value=[volume_snapshot]))
result = self._driver._get_volume_snapshot(self._context, result = self._driver._get_volume_snapshot(self._context,
self.snapshot['id']) self.snapshot['id'])
self.assertEqual(result, volume_snapshot) self.assertEqual(result, volume_snapshot)
def test_get_volume_snapshot_none(self): def test_get_volume_snapshot_none(self):
self.stubs.Set(self._driver.volume_api, 'get_all_snapshots', self.mock_object(self._driver.volume_api, 'get_all_snapshots',
mock.Mock(return_value=[])) mock.Mock(return_value=[]))
result = self._driver._get_volume_snapshot(self._context, result = self._driver._get_volume_snapshot(self._context,
self.share['id']) self.share['id'])
self.assertEqual(result, None) self.assertEqual(result, None)
@ -486,9 +485,9 @@ class GenericShareDriverTestCase(test.TestCase):
volume_snapshot = fake_volume.FakeVolumeSnapshot( volume_snapshot = fake_volume.FakeVolumeSnapshot(
display_name=CONF.volume_snapshot_name_template % display_name=CONF.volume_snapshot_name_template %
self.snapshot['id']) self.snapshot['id'])
self.stubs.Set(self._driver.volume_api, 'get_all_snapshots', self.mock_object(self._driver.volume_api, 'get_all_snapshots',
mock.Mock(return_value=[volume_snapshot, mock.Mock(return_value=[volume_snapshot,
volume_snapshot])) volume_snapshot]))
self.assertRaises(exception.ManilaException, self.assertRaises(exception.ManilaException,
self._driver._get_volume_snapshot, self._context, self._driver._get_volume_snapshot, self._context,
self.share['id']) self.share['id'])
@ -496,14 +495,13 @@ class GenericShareDriverTestCase(test.TestCase):
def test_detach_volume(self): def test_detach_volume(self):
availiable_volume = fake_volume.FakeVolume() availiable_volume = fake_volume.FakeVolume()
attached_volume = fake_volume.FakeVolume(status='in-use') attached_volume = fake_volume.FakeVolume(status='in-use')
self.stubs.Set(self._driver, '_get_volume', self.mock_object(self._driver, '_get_volume',
mock.Mock(return_value=attached_volume)) mock.Mock(return_value=attached_volume))
self.stubs.Set(self._driver.compute_api, 'instance_volumes_list', self.mock_object(self._driver.compute_api, 'instance_volumes_list',
mock.Mock(return_value=[attached_volume])) mock.Mock(return_value=[attached_volume]))
self.stubs.Set(self._driver.compute_api, 'instance_volume_detach', self.mock_object(self._driver.compute_api, 'instance_volume_detach')
mock.Mock()) self.mock_object(self._driver.volume_api, 'get',
self.stubs.Set(self._driver.volume_api, 'get', mock.Mock(return_value=availiable_volume))
mock.Mock(return_value=availiable_volume))
self._driver._detach_volume(self._context, self.share, self._driver._detach_volume(self._context, self.share,
self.server['backend_details']) self.server['backend_details'])
@ -519,14 +517,13 @@ class GenericShareDriverTestCase(test.TestCase):
def test_detach_volume_detached(self): def test_detach_volume_detached(self):
availiable_volume = fake_volume.FakeVolume() availiable_volume = fake_volume.FakeVolume()
attached_volume = fake_volume.FakeVolume(status='in-use') attached_volume = fake_volume.FakeVolume(status='in-use')
self.stubs.Set(self._driver, '_get_volume', self.mock_object(self._driver, '_get_volume',
mock.Mock(return_value=attached_volume)) mock.Mock(return_value=attached_volume))
self.stubs.Set(self._driver.compute_api, 'instance_volumes_list', self.mock_object(self._driver.compute_api, 'instance_volumes_list',
mock.Mock(return_value=[])) mock.Mock(return_value=[]))
self.stubs.Set(self._driver.volume_api, 'get', self.mock_object(self._driver.volume_api, 'get',
mock.Mock(return_value=availiable_volume)) mock.Mock(return_value=availiable_volume))
self.stubs.Set(self._driver.compute_api, 'instance_volume_detach', self.mock_object(self._driver.compute_api, 'instance_volume_detach')
mock.Mock())
self._driver._detach_volume(self._context, self.share, self._driver._detach_volume(self._context, self.share,
self.server['backend_details']) self.server['backend_details'])
@ -538,8 +535,8 @@ class GenericShareDriverTestCase(test.TestCase):
def test_allocate_container(self): def test_allocate_container(self):
fake_vol = fake_volume.FakeVolume() fake_vol = fake_volume.FakeVolume()
self.fake_conf.cinder_volume_type = 'fake_volume_type' self.fake_conf.cinder_volume_type = 'fake_volume_type'
self.stubs.Set(self._driver.volume_api, 'create', self.mock_object(self._driver.volume_api, 'create',
mock.Mock(return_value=fake_vol)) mock.Mock(return_value=fake_vol))
result = self._driver._allocate_container(self._context, self.share) result = self._driver._allocate_container(self._context, self.share)
self.assertEqual(result, fake_vol) self.assertEqual(result, fake_vol)
@ -554,10 +551,10 @@ class GenericShareDriverTestCase(test.TestCase):
def test_allocate_container_with_snaphot(self): def test_allocate_container_with_snaphot(self):
fake_vol = fake_volume.FakeVolume() fake_vol = fake_volume.FakeVolume()
fake_vol_snap = fake_volume.FakeVolumeSnapshot() fake_vol_snap = fake_volume.FakeVolumeSnapshot()
self.stubs.Set(self._driver, '_get_volume_snapshot', self.mock_object(self._driver, '_get_volume_snapshot',
mock.Mock(return_value=fake_vol_snap)) mock.Mock(return_value=fake_vol_snap))
self.stubs.Set(self._driver.volume_api, 'create', self.mock_object(self._driver.volume_api, 'create',
mock.Mock(return_value=fake_vol)) mock.Mock(return_value=fake_vol))
result = self._driver._allocate_container(self._context, result = self._driver._allocate_container(self._context,
self.share, self.share,
@ -573,8 +570,8 @@ class GenericShareDriverTestCase(test.TestCase):
def test_allocate_container_error(self): def test_allocate_container_error(self):
fake_vol = fake_volume.FakeVolume(status='error') fake_vol = fake_volume.FakeVolume(status='error')
self.stubs.Set(self._driver.volume_api, 'create', self.mock_object(self._driver.volume_api, 'create',
mock.Mock(return_value=fake_vol)) mock.Mock(return_value=fake_vol))
self.assertRaises(exception.ManilaException, self.assertRaises(exception.ManilaException,
self._driver._allocate_container, self._driver._allocate_container,
@ -583,10 +580,10 @@ class GenericShareDriverTestCase(test.TestCase):
def test_deallocate_container(self): def test_deallocate_container(self):
fake_vol = fake_volume.FakeVolume() fake_vol = fake_volume.FakeVolume()
self.stubs.Set(self._driver, '_get_volume', self.mock_object(self._driver, '_get_volume',
mock.Mock(return_value=fake_vol)) mock.Mock(return_value=fake_vol))
self.stubs.Set(self._driver.volume_api, 'delete', mock.Mock()) self.mock_object(self._driver.volume_api, 'delete')
self.stubs.Set(self._driver.volume_api, 'get', mock.Mock( self.mock_object(self._driver.volume_api, 'get', mock.Mock(
side_effect=exception.VolumeNotFound(volume_id=fake_vol['id']))) side_effect=exception.VolumeNotFound(volume_id=fake_vol['id'])))
self._driver._deallocate_container(self._context, self.share) self._driver._deallocate_container(self._context, self.share)
@ -602,11 +599,11 @@ class GenericShareDriverTestCase(test.TestCase):
vol1 = 'fake_vol1' vol1 = 'fake_vol1'
vol2 = 'fake_vol2' vol2 = 'fake_vol2'
self._helper_nfs.create_export.return_value = 'fakelocation' self._helper_nfs.create_export.return_value = 'fakelocation'
self.stubs.Set(self._driver, '_allocate_container', self.mock_object(self._driver, '_allocate_container',
mock.Mock(return_value=vol1)) mock.Mock(return_value=vol1))
self.stubs.Set(self._driver, '_attach_volume', self.mock_object(self._driver, '_attach_volume',
mock.Mock(return_value=vol2)) mock.Mock(return_value=vol2))
self.stubs.Set(self._driver, '_mount_device', mock.Mock()) self.mock_object(self._driver, '_mount_device')
result = self._driver.create_share_from_snapshot( result = self._driver.create_share_from_snapshot(
self._context, self._context,
@ -626,11 +623,11 @@ class GenericShareDriverTestCase(test.TestCase):
self.server['backend_details'], self.share['name']) self.server['backend_details'], self.share['name'])
def test_delete_share_no_share_servers_handling(self): def test_delete_share_no_share_servers_handling(self):
self.stubs.Set(self._driver, '_deallocate_container', mock.Mock()) self.mock_object(self._driver, '_deallocate_container')
self.stubs.Set( self.mock_object(
self._driver.service_instance_manager, self._driver.service_instance_manager,
'get_common_server', mock.Mock(return_value=self.server)) 'get_common_server', mock.Mock(return_value=self.server))
self.stubs.Set( self.mock_object(
self._driver.service_instance_manager, self._driver.service_instance_manager,
'ensure_service_instance', mock.Mock(return_value=False)) 'ensure_service_instance', mock.Mock(return_value=False))
@ -647,9 +644,9 @@ class GenericShareDriverTestCase(test.TestCase):
self._context, self.server['backend_details']) self._context, self.server['backend_details'])
def test_delete_share(self): def test_delete_share(self):
self.stubs.Set(self._driver, '_unmount_device', mock.Mock()) self.mock_object(self._driver, '_unmount_device')
self.stubs.Set(self._driver, '_detach_volume', mock.Mock()) self.mock_object(self._driver, '_detach_volume')
self.stubs.Set(self._driver, '_deallocate_container', mock.Mock()) self.mock_object(self._driver, '_deallocate_container')
self._driver.delete_share( self._driver.delete_share(
self._context, self.share, share_server=self.server) self._context, self.share, share_server=self.server)
@ -668,9 +665,9 @@ class GenericShareDriverTestCase(test.TestCase):
self._context, self.server['backend_details']) self._context, self.server['backend_details'])
def test_delete_share_without_share_server(self): def test_delete_share_without_share_server(self):
self.stubs.Set(self._driver, '_unmount_device', mock.Mock()) self.mock_object(self._driver, '_unmount_device')
self.stubs.Set(self._driver, '_detach_volume', mock.Mock()) self.mock_object(self._driver, '_detach_volume')
self.stubs.Set(self._driver, '_deallocate_container', mock.Mock()) self.mock_object(self._driver, '_deallocate_container')
self._driver.delete_share( self._driver.delete_share(
self._context, self.share, share_server=None) self._context, self.share, share_server=None)
@ -682,9 +679,9 @@ class GenericShareDriverTestCase(test.TestCase):
self._driver.admin_context, self.share) self._driver.admin_context, self.share)
def test_delete_share_without_server_backend_details(self): def test_delete_share_without_server_backend_details(self):
self.stubs.Set(self._driver, '_unmount_device', mock.Mock()) self.mock_object(self._driver, '_unmount_device')
self.stubs.Set(self._driver, '_detach_volume', mock.Mock()) self.mock_object(self._driver, '_detach_volume')
self.stubs.Set(self._driver, '_deallocate_container', mock.Mock()) self.mock_object(self._driver, '_deallocate_container')
fake_share_server = { fake_share_server = {
'instance_id': 'fake_instance_id', 'instance_id': 'fake_instance_id',
@ -705,11 +702,11 @@ class GenericShareDriverTestCase(test.TestCase):
self._driver.admin_context, self.share) self._driver.admin_context, self.share)
def test_delete_share_without_server_availability(self): def test_delete_share_without_server_availability(self):
self.stubs.Set(self._driver, '_unmount_device', mock.Mock()) self.mock_object(self._driver, '_unmount_device')
self.stubs.Set(self._driver, '_detach_volume', mock.Mock()) self.mock_object(self._driver, '_detach_volume')
self.stubs.Set(self._driver, '_deallocate_container', mock.Mock()) self.mock_object(self._driver, '_deallocate_container')
self.stubs.Set( self.mock_object(
self._driver.service_instance_manager, self._driver.service_instance_manager,
'ensure_service_instance', mock.Mock(return_value=False)) 'ensure_service_instance', mock.Mock(return_value=False))
self._driver.delete_share( self._driver.delete_share(
@ -727,10 +724,10 @@ class GenericShareDriverTestCase(test.TestCase):
def test_create_snapshot(self): def test_create_snapshot(self):
fake_vol = fake_volume.FakeVolume() fake_vol = fake_volume.FakeVolume()
fake_vol_snap = fake_volume.FakeVolumeSnapshot(share_id=fake_vol['id']) fake_vol_snap = fake_volume.FakeVolumeSnapshot(share_id=fake_vol['id'])
self.stubs.Set(self._driver, '_get_volume', self.mock_object(self._driver, '_get_volume',
mock.Mock(return_value=fake_vol)) mock.Mock(return_value=fake_vol))
self.stubs.Set(self._driver.volume_api, 'create_snapshot_force', self.mock_object(self._driver.volume_api, 'create_snapshot_force',
mock.Mock(return_value=fake_vol_snap)) mock.Mock(return_value=fake_vol_snap))
self._driver.create_snapshot(self._context, fake_vol_snap, self._driver.create_snapshot(self._context, fake_vol_snap,
share_server=self.server) share_server=self.server)
@ -747,12 +744,13 @@ class GenericShareDriverTestCase(test.TestCase):
def test_delete_snapshot(self): def test_delete_snapshot(self):
fake_vol_snap = fake_volume.FakeVolumeSnapshot() fake_vol_snap = fake_volume.FakeVolumeSnapshot()
fake_vol_snap2 = {'id': 'fake_vol_snap2'} fake_vol_snap2 = {'id': 'fake_vol_snap2'}
self.stubs.Set(self._driver, '_get_volume_snapshot', self.mock_object(self._driver, '_get_volume_snapshot',
mock.Mock(return_value=fake_vol_snap2)) mock.Mock(return_value=fake_vol_snap2))
self.stubs.Set(self._driver.volume_api, 'delete_snapshot', mock.Mock()) self.mock_object(self._driver.volume_api, 'delete_snapshot')
self.stubs.Set(self._driver.volume_api, 'get_snapshot', self.mock_object(
mock.Mock(side_effect=exception.VolumeSnapshotNotFound( self._driver.volume_api, 'get_snapshot',
snapshot_id=fake_vol_snap['id']))) mock.Mock(side_effect=exception.VolumeSnapshotNotFound(
snapshot_id=fake_vol_snap['id'])))
self._driver.delete_snapshot(self._context, fake_vol_snap, self._driver.delete_snapshot(self._context, fake_vol_snap,
share_server=self.server) share_server=self.server)
@ -768,11 +766,11 @@ class GenericShareDriverTestCase(test.TestCase):
vol1 = 'fake_vol1' vol1 = 'fake_vol1'
vol2 = 'fake_vol2' vol2 = 'fake_vol2'
self._helper_nfs.create_export.return_value = 'fakelocation' self._helper_nfs.create_export.return_value = 'fakelocation'
self.stubs.Set(self._driver, '_get_volume', self.mock_object(self._driver, '_get_volume',
mock.Mock(return_value=vol1)) mock.Mock(return_value=vol1))
self.stubs.Set(self._driver, '_attach_volume', self.mock_object(self._driver, '_attach_volume',
mock.Mock(return_value=vol2)) mock.Mock(return_value=vol2))
self.stubs.Set(self._driver, '_mount_device', mock.Mock()) self.mock_object(self._driver, '_mount_device')
self._driver.ensure_share( self._driver.ensure_share(
self._context, self.share, share_server=self.server) self._context, self.share, share_server=self.server)
@ -835,9 +833,9 @@ class GenericShareDriverTestCase(test.TestCase):
net_info = {'server_id': 'fake', net_info = {'server_id': 'fake',
'neutron_net_id': 'fake-net-id', 'neutron_net_id': 'fake-net-id',
'neutron_subnet_id': 'fake-subnet-id'} 'neutron_subnet_id': 'fake-subnet-id'}
self.stubs.Set(self._driver.service_instance_manager, self.mock_object(self._driver.service_instance_manager,
'set_up_service_instance', 'set_up_service_instance',
mock.Mock(side_effect=raise_exception)) mock.Mock(side_effect=raise_exception))
self.assertRaises(exception.ServiceInstanceException, self.assertRaises(exception.ServiceInstanceException,
self._driver.setup_server, self._driver.setup_server,
net_info) net_info)
@ -862,9 +860,9 @@ class GenericShareDriverTestCase(test.TestCase):
ssh.get_transport().is_active = mock.Mock(return_value=True) ssh.get_transport().is_active = mock.Mock(return_value=True)
ssh_pool = mock.Mock() ssh_pool = mock.Mock()
ssh_pool.create = mock.Mock(return_value=ssh) ssh_pool.create = mock.Mock(return_value=ssh)
self.stubs.Set(utils, 'SSHPool', mock.Mock(return_value=ssh_pool)) self.mock_object(utils, 'SSHPool', mock.Mock(return_value=ssh_pool))
self.stubs.Set(processutils, 'ssh_execute', self.mock_object(processutils, 'ssh_execute',
mock.Mock(return_value=ssh_output)) mock.Mock(return_value=ssh_output))
self._driver.ssh_connections = {} self._driver.ssh_connections = {}
result = self._driver._ssh_exec(self.server, cmd) result = self._driver._ssh_exec(self.server, cmd)
@ -888,8 +886,8 @@ class GenericShareDriverTestCase(test.TestCase):
ssh.get_transport = mock.Mock() ssh.get_transport = mock.Mock()
ssh.get_transport().is_active = mock.Mock(side_effect=lambda: True) ssh.get_transport().is_active = mock.Mock(side_effect=lambda: True)
ssh_pool = mock.Mock() ssh_pool = mock.Mock()
self.stubs.Set(processutils, 'ssh_execute', self.mock_object(processutils, 'ssh_execute',
mock.Mock(return_value=ssh_output)) mock.Mock(return_value=ssh_output))
self._driver.ssh_connections = { self._driver.ssh_connections = {
self.server['instance_id']: (ssh_pool, ssh) self.server['instance_id']: (ssh_pool, ssh)
} }
@ -913,8 +911,8 @@ class GenericShareDriverTestCase(test.TestCase):
ssh_pool = mock.Mock() ssh_pool = mock.Mock()
ssh_pool.create = mock.Mock(side_effect=lambda: ssh) ssh_pool.create = mock.Mock(side_effect=lambda: ssh)
ssh_pool.remove = mock.Mock() ssh_pool.remove = mock.Mock()
self.stubs.Set(processutils, 'ssh_execute', self.mock_object(processutils, 'ssh_execute',
mock.Mock(return_value=ssh_output)) mock.Mock(return_value=ssh_output))
self._driver.ssh_connections = { self._driver.ssh_connections = {
self.server['instance_id']: (ssh_pool, ssh) self.server['instance_id']: (ssh_pool, ssh)
} }
@ -1026,7 +1024,7 @@ class NFSHelperTestCase(test.TestCase):
def setUp(self): def setUp(self):
super(NFSHelperTestCase, self).setUp() super(NFSHelperTestCase, self).setUp()
fake_utils.stub_out_utils_execute(self.stubs) fake_utils.stub_out_utils_execute(self)
self.fake_conf = manila.share.configuration.Configuration(None) self.fake_conf = manila.share.configuration.Configuration(None)
self._ssh_exec = mock.Mock(return_value=('', '')) self._ssh_exec = mock.Mock(return_value=('', ''))
self._execute = mock.Mock(return_value=('', '')) self._execute = mock.Mock(return_value=('', ''))
@ -1044,8 +1042,7 @@ class NFSHelperTestCase(test.TestCase):
self.assertEqual(ret, expected_location) self.assertEqual(ret, expected_location)
def test_allow_access(self): def test_allow_access(self):
self.stubs.Set(self._helper, '_sync_nfs_temp_and_perm_files', self.mock_object(self._helper, '_sync_nfs_temp_and_perm_files')
mock.Mock())
self._helper.allow_access(self.server, 'fake_share', self._helper.allow_access(self.server, 'fake_share',
'ip', '10.0.0.2') 'ip', '10.0.0.2')
local_path = os.path.join(CONF.share_mount_path, 'fake_share') local_path = os.path.join(CONF.share_mount_path, 'fake_share')
@ -1066,8 +1063,7 @@ class NFSHelperTestCase(test.TestCase):
) )
def test_deny_access(self): def test_deny_access(self):
self.stubs.Set(self._helper, '_sync_nfs_temp_and_perm_files', self.mock_object(self._helper, '_sync_nfs_temp_and_perm_files')
mock.Mock())
local_path = os.path.join(CONF.share_mount_path, 'fake_share') local_path = os.path.join(CONF.share_mount_path, 'fake_share')
self._helper.deny_access(self.server, 'fake_share', 'ip', '10.0.0.2') self._helper.deny_access(self.server, 'fake_share', 'ip', '10.0.0.2')
export_string = ':'.join(['10.0.0.2', local_path]) export_string = ':'.join(['10.0.0.2', local_path])
@ -1109,8 +1105,8 @@ class CIFSHelperTestCase(test.TestCase):
else: else:
return ('', '') return ('', '')
self.stubs.Set(self._helper, '_ssh_exec', self.mock_object(self._helper, '_ssh_exec',
mock.Mock(side_effect=fake_ssh_exec)) mock.Mock(side_effect=fake_ssh_exec))
ret = self._helper.create_export(self.server_details, self.share_name) ret = self._helper.create_export(self.server_details, self.share_name)
expected_location = '//%s/%s' % ( expected_location = '//%s/%s' % (
@ -1193,8 +1189,8 @@ class CIFSHelperTestCase(test.TestCase):
else: else:
return ('', '') return ('', '')
self.stubs.Set(self._helper, '_ssh_exec', self.mock_object(self._helper, '_ssh_exec',
mock.Mock(side_effect=fake_ssh_exec)) mock.Mock(side_effect=fake_ssh_exec))
self._helper.remove_export(self.server_details, self.share_name) self._helper.remove_export(self.server_details, self.share_name)
@ -1212,9 +1208,9 @@ class CIFSHelperTestCase(test.TestCase):
def test_allow_access_ip_exist(self): def test_allow_access_ip_exist(self):
ip = '1.1.1.1' ip = '1.1.1.1'
hosts = [ip, ] hosts = [ip, ]
self.stubs.Set(self._helper, '_get_allow_hosts', self.mock_object(self._helper, '_get_allow_hosts',
mock.Mock(return_value=hosts)) mock.Mock(return_value=hosts))
self.stubs.Set(self._helper, '_set_allow_hosts', mock.Mock()) self.mock_object(self._helper, '_set_allow_hosts')
self.assertRaises( self.assertRaises(
exception.ShareAccessExists, exception.ShareAccessExists,
@ -1232,9 +1228,9 @@ class CIFSHelperTestCase(test.TestCase):
def test_allow_access_ip_does_not_exist(self): def test_allow_access_ip_does_not_exist(self):
ip = '1.1.1.1' ip = '1.1.1.1'
hosts = [] hosts = []
self.stubs.Set(self._helper, '_get_allow_hosts', self.mock_object(self._helper, '_get_allow_hosts',
mock.Mock(return_value=hosts)) mock.Mock(return_value=hosts))
self.stubs.Set(self._helper, '_set_allow_hosts', mock.Mock()) self.mock_object(self._helper, '_set_allow_hosts')
self._helper.allow_access( self._helper.allow_access(
self.server_details, self.share_name, 'ip', ip) self.server_details, self.share_name, 'ip', ip)
@ -1257,9 +1253,9 @@ class CIFSHelperTestCase(test.TestCase):
def test_deny_access_list_has_value(self): def test_deny_access_list_has_value(self):
ip = '1.1.1.1' ip = '1.1.1.1'
hosts = [ip, ] hosts = [ip, ]
self.stubs.Set(self._helper, '_get_allow_hosts', self.mock_object(self._helper, '_get_allow_hosts',
mock.Mock(return_value=hosts)) mock.Mock(return_value=hosts))
self.stubs.Set(self._helper, '_set_allow_hosts', mock.Mock()) self.mock_object(self._helper, '_set_allow_hosts')
self._helper.deny_access( self._helper.deny_access(
self.server_details, self.share_name, 'ip', ip) self.server_details, self.share_name, 'ip', ip)
@ -1272,9 +1268,9 @@ class CIFSHelperTestCase(test.TestCase):
def test_deny_access_list_does_not_have_value(self): def test_deny_access_list_does_not_have_value(self):
ip = '1.1.1.1' ip = '1.1.1.1'
hosts = [] hosts = []
self.stubs.Set(self._helper, '_get_allow_hosts', self.mock_object(self._helper, '_get_allow_hosts',
mock.Mock(return_value=hosts)) mock.Mock(return_value=hosts))
self.stubs.Set(self._helper, '_set_allow_hosts', mock.Mock()) self.mock_object(self._helper, '_set_allow_hosts')
self._helper.deny_access( self._helper.deny_access(
self.server_details, self.share_name, 'ip', ip) self.server_details, self.share_name, 'ip', ip)
@ -1284,12 +1280,12 @@ class CIFSHelperTestCase(test.TestCase):
self._helper._set_allow_hosts.assert_has_calls([]) self._helper._set_allow_hosts.assert_has_calls([])
def test_deny_access_force(self): def test_deny_access_force(self):
self.stubs.Set( self.mock_object(
self._helper, self._helper,
'_get_allow_hosts', '_get_allow_hosts',
mock.Mock(side_effect=exception.ProcessExecutionError()), mock.Mock(side_effect=exception.ProcessExecutionError()),
) )
self.stubs.Set(self._helper, '_set_allow_hosts', mock.Mock()) self.mock_object(self._helper, '_set_allow_hosts')
self._helper.deny_access( self._helper.deny_access(
self.server_details, self.share_name, 'ip', '1.1.1.1', force=True) self.server_details, self.share_name, 'ip', '1.1.1.1', force=True)
@ -1302,9 +1298,9 @@ class CIFSHelperTestCase(test.TestCase):
def raise_process_execution_error(*args, **kwargs): def raise_process_execution_error(*args, **kwargs):
raise exception.ProcessExecutionError() raise exception.ProcessExecutionError()
self.stubs.Set(self._helper, '_get_allow_hosts', self.mock_object(self._helper, '_get_allow_hosts',
mock.Mock(side_effect=raise_process_execution_error)) mock.Mock(side_effect=raise_process_execution_error))
self.stubs.Set(self._helper, '_set_allow_hosts', mock.Mock()) self.mock_object(self._helper, '_set_allow_hosts')
self.assertRaises( self.assertRaises(
exception.ProcessExecutionError, exception.ProcessExecutionError,
self._helper.deny_access, self._helper.deny_access,

View File

@ -122,8 +122,8 @@ class GlusterManagerTestCase(test.TestCase):
def test_get_gluster_vol_option_empty_volinfo(self): def test_get_gluster_vol_option_empty_volinfo(self):
args = ('--xml', 'volume', 'info', self._gluster_manager.volume) args = ('--xml', 'volume', 'info', self._gluster_manager.volume)
self.stubs.Set(self._gluster_manager, 'gluster_call', self.mock_object(self._gluster_manager, 'gluster_call',
mock.Mock(return_value=('', {}))) mock.Mock(return_value=('', {})))
self.assertRaises(exception.GlusterfsException, self.assertRaises(exception.GlusterfsException,
self._gluster_manager.get_gluster_vol_option, self._gluster_manager.get_gluster_vol_option,
NFS_EXPORT_DIR) NFS_EXPORT_DIR)
@ -136,8 +136,8 @@ class GlusterManagerTestCase(test.TestCase):
raise RuntimeError('fake error') raise RuntimeError('fake error')
args = ('--xml', 'volume', 'info', self._gluster_manager.volume) args = ('--xml', 'volume', 'info', self._gluster_manager.volume)
self.stubs.Set(self._gluster_manager, 'gluster_call', self.mock_object(self._gluster_manager, 'gluster_call',
mock.Mock(side_effect=raise_exception)) mock.Mock(side_effect=raise_exception))
self.assertRaises(RuntimeError, self.assertRaises(RuntimeError,
self._gluster_manager.get_gluster_vol_option, self._gluster_manager.get_gluster_vol_option,
NFS_EXPORT_DIR) NFS_EXPORT_DIR)
@ -157,8 +157,8 @@ class GlusterManagerTestCase(test.TestCase):
</cliOutput>""", '' </cliOutput>""", ''
args = ('--xml', 'volume', 'info', self._gluster_manager.volume) args = ('--xml', 'volume', 'info', self._gluster_manager.volume)
self.stubs.Set(self._gluster_manager, 'gluster_call', self.mock_object(self._gluster_manager, 'gluster_call',
mock.Mock(side_effect=xml_output)) mock.Mock(side_effect=xml_output))
self.assertRaises(exception.InvalidShare, self.assertRaises(exception.InvalidShare,
self._gluster_manager.get_gluster_vol_option, self._gluster_manager.get_gluster_vol_option,
NFS_EXPORT_DIR) NFS_EXPORT_DIR)
@ -179,8 +179,8 @@ class GlusterManagerTestCase(test.TestCase):
</cliOutput>""", '' </cliOutput>""", ''
args = ('--xml', 'volume', 'info', self._gluster_manager.volume) args = ('--xml', 'volume', 'info', self._gluster_manager.volume)
self.stubs.Set(self._gluster_manager, 'gluster_call', self.mock_object(self._gluster_manager, 'gluster_call',
mock.Mock(side_effect=xml_output)) mock.Mock(side_effect=xml_output))
ret = self._gluster_manager.get_gluster_vol_option(NFS_EXPORT_DIR) ret = self._gluster_manager.get_gluster_vol_option(NFS_EXPORT_DIR)
self.assertEqual(None, ret) self.assertEqual(None, ret)
self._gluster_manager.gluster_call.assert_called_once_with(*args) self._gluster_manager.gluster_call.assert_called_once_with(*args)
@ -206,8 +206,8 @@ class GlusterManagerTestCase(test.TestCase):
</cliOutput>""", '' </cliOutput>""", ''
args = ('--xml', 'volume', 'info', self._gluster_manager.volume) args = ('--xml', 'volume', 'info', self._gluster_manager.volume)
self.stubs.Set(self._gluster_manager, 'gluster_call', self.mock_object(self._gluster_manager, 'gluster_call',
mock.Mock(side_effect=xml_output)) mock.Mock(side_effect=xml_output))
ret = self._gluster_manager.get_gluster_vol_option(NFS_EXPORT_DIR) ret = self._gluster_manager.get_gluster_vol_option(NFS_EXPORT_DIR)
self.assertEqual('/foo(10.0.0.1|10.0.0.2),/bar(10.0.0.1)', ret) self.assertEqual('/foo(10.0.0.1|10.0.0.2),/bar(10.0.0.1)', ret)
self._gluster_manager.gluster_call.assert_called_once_with(*args) self._gluster_manager.gluster_call.assert_called_once_with(*args)
@ -218,7 +218,7 @@ class GlusterfsShareDriverTestCase(test.TestCase):
def setUp(self): def setUp(self):
super(GlusterfsShareDriverTestCase, self).setUp() super(GlusterfsShareDriverTestCase, self).setUp()
fake_utils.stub_out_utils_execute(self.stubs) fake_utils.stub_out_utils_execute(self)
self._execute = fake_utils.fake_execute self._execute = fake_utils.fake_execute
self._context = context.get_admin_context() self._context = context.get_admin_context()
self.addCleanup(fake_utils.fake_execute_set_repliers, []) self.addCleanup(fake_utils.fake_execute_set_repliers, [])
@ -246,9 +246,9 @@ class GlusterfsShareDriverTestCase(test.TestCase):
fake_gluster_manager = mock.Mock(**fake_gluster_manager_attrs) fake_gluster_manager = mock.Mock(**fake_gluster_manager_attrs)
methods = ('_ensure_gluster_vol_mounted', '_setup_helpers') methods = ('_ensure_gluster_vol_mounted', '_setup_helpers')
for method in methods: for method in methods:
self.stubs.Set(self._driver, method, mock.Mock()) self.mock_object(self._driver, method)
self.stubs.Set(glusterfs, 'GlusterManager', self.mock_object(glusterfs, 'GlusterManager',
mock.Mock(return_value=fake_gluster_manager)) mock.Mock(return_value=fake_gluster_manager))
expected_exec = ['mount.glusterfs'] expected_exec = ['mount.glusterfs']
exec_cmd1 = 'mount.glusterfs' exec_cmd1 = 'mount.glusterfs'
expected_exec = [exec_cmd1] expected_exec = [exec_cmd1]
@ -286,12 +286,12 @@ class GlusterfsShareDriverTestCase(test.TestCase):
'gluster_call.side_effect': exception.ProcessExecutionError, 'gluster_call.side_effect': exception.ProcessExecutionError,
'get_gluster_vol_option.return_value': 'off'} 'get_gluster_vol_option.return_value': 'off'}
fake_gluster_manager = mock.Mock(**attrs) fake_gluster_manager = mock.Mock(**attrs)
self.stubs.Set(glusterfs.LOG, 'error', mock.Mock()) self.mock_object(glusterfs.LOG, 'error')
methods = ('_ensure_gluster_vol_mounted', '_setup_helpers') methods = ('_ensure_gluster_vol_mounted', '_setup_helpers')
for method in methods: for method in methods:
self.stubs.Set(self._driver, method, mock.Mock()) self.mock_object(self._driver, method)
self.stubs.Set(glusterfs, 'GlusterManager', self.mock_object(glusterfs, 'GlusterManager',
mock.Mock(return_value=fake_gluster_manager)) mock.Mock(return_value=fake_gluster_manager))
expected_exec = ['mount.glusterfs'] expected_exec = ['mount.glusterfs']
exec_cmd1 = 'mount.glusterfs' exec_cmd1 = 'mount.glusterfs'
expected_exec = [exec_cmd1] expected_exec = [exec_cmd1]
@ -317,12 +317,12 @@ class GlusterfsShareDriverTestCase(test.TestCase):
'gluster_call.side_effect': exception.ProcessExecutionError, 'gluster_call.side_effect': exception.ProcessExecutionError,
'get_gluster_vol_option.return_value': 'on'} 'get_gluster_vol_option.return_value': 'on'}
fake_gluster_manager = mock.Mock(**attrs) fake_gluster_manager = mock.Mock(**attrs)
self.stubs.Set(glusterfs.LOG, 'error', mock.Mock()) self.mock_object(glusterfs.LOG, 'error')
methods = ('_ensure_gluster_vol_mounted', '_setup_helpers') methods = ('_ensure_gluster_vol_mounted', '_setup_helpers')
for method in methods: for method in methods:
self.stubs.Set(self._driver, method, mock.Mock()) self.mock_object(self._driver, method)
self.stubs.Set(glusterfs, 'GlusterManager', self.mock_object(glusterfs, 'GlusterManager',
mock.Mock(return_value=fake_gluster_manager)) mock.Mock(return_value=fake_gluster_manager))
expected_exec = ['mount.glusterfs'] expected_exec = ['mount.glusterfs']
exec_cmd1 = 'mount.glusterfs' exec_cmd1 = 'mount.glusterfs'
expected_exec = [exec_cmd1] expected_exec = [exec_cmd1]
@ -343,8 +343,8 @@ class GlusterfsShareDriverTestCase(test.TestCase):
self._driver._ensure_gluster_vol_mounted.assert_called_once_with() self._driver._ensure_gluster_vol_mounted.assert_called_once_with()
def test_setup_helpers(self): def test_setup_helpers(self):
self.stubs.Set(glusterfs, 'GlusterNFSHelper', self.mock_object(glusterfs, 'GlusterNFSHelper',
mock.Mock(return_value=self._helper_nfs)) mock.Mock(return_value=self._helper_nfs))
self._driver._setup_helpers() self._driver._setup_helpers()
glusterfs.GlusterNFSHelper.assert_called_once_with( glusterfs.GlusterNFSHelper.assert_called_once_with(
self._execute, self.fake_conf, self._execute, self.fake_conf,
@ -479,13 +479,13 @@ class GlusterfsShareDriverTestCase(test.TestCase):
self._driver._update_share_stats) self._driver._update_share_stats)
def test_create_share(self): def test_create_share(self):
self.stubs.Set(self._driver, '_get_helper', mock.Mock()) self.mock_object(self._driver, '_get_helper')
args = ('volume', 'quota', 'testvol', 'limit-usage', '/fakename', args = ('volume', 'quota', 'testvol', 'limit-usage', '/fakename',
'1GB') '1GB')
exec_cmd1 = 'mkdir %s' % fake_local_share_path exec_cmd1 = 'mkdir %s' % fake_local_share_path
expected_exec = [exec_cmd1, ] expected_exec = [exec_cmd1, ]
expected_ret = 'testuser@127.0.0.1:/testvol/fakename' expected_ret = 'testuser@127.0.0.1:/testvol/fakename'
self.stubs.Set( self.mock_object(
self._driver, '_get_local_share_path', self._driver, '_get_local_share_path',
mock.Mock(return_value=fake_local_share_path)) mock.Mock(return_value=fake_local_share_path))
ret = self._driver.create_share(self._context, self.share) ret = self._driver.create_share(self._context, self.share)
@ -500,14 +500,12 @@ class GlusterfsShareDriverTestCase(test.TestCase):
def exec_runner(*ignore_args, **ignore_kw): def exec_runner(*ignore_args, **ignore_kw):
raise exception.ProcessExecutionError raise exception.ProcessExecutionError
self.stubs.Set(self._driver, '_get_helper', mock.Mock()) self.mock_object(self._driver, '_get_helper')
self.stubs.Set( self.mock_object(
self._driver, '_get_local_share_path', self._driver, '_get_local_share_path',
mock.Mock(return_value=fake_local_share_path)) mock.Mock(return_value=fake_local_share_path))
self.stubs.Set( self.mock_object(self._driver, '_cleanup_create_share')
self._driver, '_cleanup_create_share', mock.Mock()) self.mock_object(glusterfs.LOG, 'error')
self.stubs.Set(
glusterfs.LOG, 'error', mock.Mock())
expected_exec = ['mkdir %s' % fake_local_share_path] expected_exec = ['mkdir %s' % fake_local_share_path]
fake_utils.fake_execute_set_repliers([(expected_exec[0], fake_utils.fake_execute_set_repliers([(expected_exec[0],
exec_runner)]) exec_runner)])
@ -522,7 +520,7 @@ class GlusterfsShareDriverTestCase(test.TestCase):
mock.ANY, mock.ANY) mock.ANY, mock.ANY)
def test_create_share_error_unsupported_share_type(self): def test_create_share_error_unsupported_share_type(self):
self.stubs.Set( self.mock_object(
self._driver, '_get_helper', self._driver, '_get_helper',
mock.Mock(side_effect=exception. mock.Mock(side_effect=exception.
InvalidShare(reason="Unsupported Share type"))) InvalidShare(reason="Unsupported Share type")))
@ -533,7 +531,7 @@ class GlusterfsShareDriverTestCase(test.TestCase):
def test_create_share_can_be_called_with_extra_arg_share_server(self): def test_create_share_can_be_called_with_extra_arg_share_server(self):
share_server = None share_server = None
self._driver._get_local_share_path = mock.Mock() self._driver._get_local_share_path = mock.Mock()
self.stubs.Set(self._driver, '_get_helper', mock.Mock()) self.mock_object(self._driver, '_get_helper')
with mock.patch.object(os.path, 'join', return_value=None): with mock.patch.object(os.path, 'join', return_value=None):
ret = self._driver.create_share(self._context, self.share, ret = self._driver.create_share(self._context, self.share,
share_server) share_server)
@ -546,8 +544,7 @@ class GlusterfsShareDriverTestCase(test.TestCase):
def test_cleanup_create_share_local_share_path_exists(self): def test_cleanup_create_share_local_share_path_exists(self):
expected_exec = ['rm -rf %s' % fake_local_share_path] expected_exec = ['rm -rf %s' % fake_local_share_path]
self.stubs.Set( self.mock_object(os.path, 'exists', mock.Mock(return_value=True))
os.path, 'exists', mock.Mock(return_value=True))
ret = self._driver._cleanup_create_share(fake_local_share_path, ret = self._driver._cleanup_create_share(fake_local_share_path,
self.share['name']) self.share['name'])
os.path.exists.assert_called_once_with(fake_local_share_path) os.path.exists.assert_called_once_with(fake_local_share_path)
@ -561,10 +558,8 @@ class GlusterfsShareDriverTestCase(test.TestCase):
expected_exec = ['rm -rf %s' % fake_local_share_path] expected_exec = ['rm -rf %s' % fake_local_share_path]
fake_utils.fake_execute_set_repliers([(expected_exec[0], fake_utils.fake_execute_set_repliers([(expected_exec[0],
exec_runner)]) exec_runner)])
self.stubs.Set( self.mock_object(glusterfs.LOG, 'error')
glusterfs.LOG, 'error', mock.Mock()) self.mock_object(os.path, 'exists', mock.Mock(return_value=True))
self.stubs.Set(
os.path, 'exists', mock.Mock(return_value=True))
self.assertRaises(exception.GlusterfsException, self.assertRaises(exception.GlusterfsException,
self._driver._cleanup_create_share, self._driver._cleanup_create_share,
fake_local_share_path, self.share['name']) fake_local_share_path, self.share['name'])
@ -572,8 +567,7 @@ class GlusterfsShareDriverTestCase(test.TestCase):
glusterfs.LOG.error.assert_called_once_with(mock.ANY, mock.ANY) glusterfs.LOG.error.assert_called_once_with(mock.ANY, mock.ANY)
def test_cleanup_create_share_local_share_path_does_not_exist(self): def test_cleanup_create_share_local_share_path_does_not_exist(self):
self.stubs.Set( self.mock_object(os.path, 'exists', mock.Mock(return_value=False))
os.path, 'exists', mock.Mock(return_value=False))
ret = self._driver._cleanup_create_share(fake_local_share_path, ret = self._driver._cleanup_create_share(fake_local_share_path,
self.share['name']) self.share['name'])
os.path.exists.assert_called_once_with(fake_local_share_path) os.path.exists.assert_called_once_with(fake_local_share_path)
@ -619,7 +613,7 @@ class GlusterfsShareDriverTestCase(test.TestCase):
exception.InvalidShare, self._driver._get_helper, share) exception.InvalidShare, self._driver._get_helper, share)
def test_allow_access(self): def test_allow_access(self):
self.stubs.Set(self._driver, '_get_helper', mock.Mock()) self.mock_object(self._driver, '_get_helper')
ret = self._driver.allow_access(self._context, self.share, ret = self._driver.allow_access(self._context, self.share,
fake_share.fake_access) fake_share.fake_access)
self._driver._get_helper.assert_called_once_with(self.share) self._driver._get_helper.assert_called_once_with(self.share)
@ -629,7 +623,7 @@ class GlusterfsShareDriverTestCase(test.TestCase):
self.assertEqual(None, ret) self.assertEqual(None, ret)
def test_allow_access_can_be_called_with_extra_arg_share_server(self): def test_allow_access_can_be_called_with_extra_arg_share_server(self):
self.stubs.Set(self._driver, '_get_helper', mock.Mock()) self.mock_object(self._driver, '_get_helper')
ret = self._driver.allow_access(self._context, self.share, ret = self._driver.allow_access(self._context, self.share,
fake_share.fake_access, fake_share.fake_access,
share_server=None) share_server=None)
@ -640,7 +634,7 @@ class GlusterfsShareDriverTestCase(test.TestCase):
self.assertEqual(None, ret) self.assertEqual(None, ret)
def test_deny_access(self): def test_deny_access(self):
self.stubs.Set(self._driver, '_get_helper', mock.Mock()) self.mock_object(self._driver, '_get_helper')
ret = self._driver.deny_access(self._context, self.share, ret = self._driver.deny_access(self._context, self.share,
fake_share.fake_access) fake_share.fake_access)
self._driver._get_helper.assert_called_once_with(self.share) self._driver._get_helper.assert_called_once_with(self.share)
@ -650,7 +644,7 @@ class GlusterfsShareDriverTestCase(test.TestCase):
self.assertEqual(None, ret) self.assertEqual(None, ret)
def test_deny_access_can_be_called_with_extra_arg_share_server(self): def test_deny_access_can_be_called_with_extra_arg_share_server(self):
self.stubs.Set(self._driver, '_get_helper', mock.Mock()) self.mock_object(self._driver, '_get_helper')
ret = self._driver.deny_access(self._context, self.share, ret = self._driver.deny_access(self._context, self.share,
fake_share.fake_access, fake_share.fake_access,
share_server=None) share_server=None)
@ -666,7 +660,7 @@ class GlusterNFSHelperTestCase(test.TestCase):
def setUp(self): def setUp(self):
super(GlusterNFSHelperTestCase, self).setUp() super(GlusterNFSHelperTestCase, self).setUp()
fake_utils.stub_out_utils_execute(self.stubs) fake_utils.stub_out_utils_execute(self)
gluster_manager = mock.Mock(**fake_gluster_manager_attrs) gluster_manager = mock.Mock(**fake_gluster_manager_attrs)
self._execute = mock.Mock(return_value=('', '')) self._execute = mock.Mock(return_value=('', ''))
self.fake_conf = config.Configuration(None) self.fake_conf = config.Configuration(None)
@ -687,9 +681,9 @@ class GlusterNFSHelperTestCase(test.TestCase):
def raise_exception(*args, **kwargs): def raise_exception(*args, **kwargs):
raise exception.ProcessExecutionError() raise exception.ProcessExecutionError()
self.stubs.Set(glusterfs.LOG, 'error', mock.Mock()) self.mock_object(glusterfs.LOG, 'error')
self.stubs.Set(self._helper.gluster_manager, 'gluster_call', self.mock_object(self._helper.gluster_manager, 'gluster_call',
mock.Mock(side_effect=raise_exception)) mock.Mock(side_effect=raise_exception))
self.assertRaises(exception.GlusterfsException, self.assertRaises(exception.GlusterfsException,
self._helper.init_helper) self._helper.init_helper)
self._helper.gluster_manager.gluster_call.assert_called_once_with( self._helper.gluster_manager.gluster_call.assert_called_once_with(
@ -698,8 +692,9 @@ class GlusterNFSHelperTestCase(test.TestCase):
def test_get_export_dir_dict(self): def test_get_export_dir_dict(self):
output_str = '/foo(10.0.0.1|10.0.0.2),/bar(10.0.0.1)' output_str = '/foo(10.0.0.1|10.0.0.2),/bar(10.0.0.1)'
self.stubs.Set(self._helper.gluster_manager, 'get_gluster_vol_option', self.mock_object(self._helper.gluster_manager,
mock.Mock(return_value=output_str)) 'get_gluster_vol_option',
mock.Mock(return_value=output_str))
ret = self._helper._get_export_dir_dict() ret = self._helper._get_export_dir_dict()
self.assertEqual( self.assertEqual(
{'foo': ['10.0.0.1', '10.0.0.2'], 'bar': ['10.0.0.1']}, ret) {'foo': ['10.0.0.1', '10.0.0.2'], 'bar': ['10.0.0.1']}, ret)
@ -717,8 +712,8 @@ class GlusterNFSHelperTestCase(test.TestCase):
cbk = mock.Mock(return_value=True) cbk = mock.Mock(return_value=True)
access = fake_share.fake_access() access = fake_share.fake_access()
export_dir_dict = mock.Mock() export_dir_dict = mock.Mock()
self.stubs.Set(self._helper, '_get_export_dir_dict', self.mock_object(self._helper, '_get_export_dir_dict',
mock.Mock(return_value=export_dir_dict)) mock.Mock(return_value=export_dir_dict))
ret = self._helper._manage_access(fake_share_name, ret = self._helper._manage_access(fake_share_name,
access['access_type'], access['access_type'],
access['access_to'], cbk) access['access_to'], cbk)
@ -740,8 +735,8 @@ class GlusterNFSHelperTestCase(test.TestCase):
export_str = '/example.com(10.0.0.1),/fakename(10.0.0.2|10.0.0.1)' 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, args = ('volume', 'set', self._helper.gluster_manager.volume,
NFS_EXPORT_DIR, export_str) NFS_EXPORT_DIR, export_str)
self.stubs.Set(self._helper, '_get_export_dir_dict', self.mock_object(self._helper, '_get_export_dir_dict',
mock.Mock(return_value=export_dir_dict)) mock.Mock(return_value=export_dir_dict))
ret = self._helper._manage_access(fake_share_name, ret = self._helper._manage_access(fake_share_name,
access['access_type'], access['access_type'],
access['access_to'], cbk) access['access_to'], cbk)
@ -766,11 +761,11 @@ class GlusterNFSHelperTestCase(test.TestCase):
export_str = '/example.com(10.0.0.1),/fakename(10.0.0.2|10.0.0.1)' 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, args = ('volume', 'set', self._helper.gluster_manager.volume,
NFS_EXPORT_DIR, export_str) NFS_EXPORT_DIR, export_str)
self.stubs.Set(self._helper, '_get_export_dir_dict', self.mock_object(self._helper, '_get_export_dir_dict',
mock.Mock(return_value=export_dir_dict)) mock.Mock(return_value=export_dir_dict))
self.stubs.Set(self._helper.gluster_manager, 'gluster_call', self.mock_object(self._helper.gluster_manager, 'gluster_call',
mock.Mock(side_effect=raise_exception)) mock.Mock(side_effect=raise_exception))
self.stubs.Set(glusterfs.LOG, 'error', mock.Mock()) self.mock_object(glusterfs.LOG, 'error')
self.assertRaises(exception.ProcessExecutionError, self.assertRaises(exception.ProcessExecutionError,
self._helper._manage_access, self._helper._manage_access,
fake_share_name, access['access_type'], fake_share_name, access['access_type'],
@ -789,8 +784,8 @@ class GlusterNFSHelperTestCase(test.TestCase):
args = ('volume', 'reset', self._helper.gluster_manager.volume, args = ('volume', 'reset', self._helper.gluster_manager.volume,
NFS_EXPORT_DIR) NFS_EXPORT_DIR)
export_dir_dict = {'fakename': ['10.0.0.1']} export_dir_dict = {'fakename': ['10.0.0.1']}
self.stubs.Set(self._helper, '_get_export_dir_dict', self.mock_object(self._helper, '_get_export_dir_dict',
mock.Mock(return_value=export_dir_dict)) mock.Mock(return_value=export_dir_dict))
ret = self._helper._manage_access(fake_share_name, ret = self._helper._manage_access(fake_share_name,
access['access_type'], access['access_type'],
access['access_to'], cbk) access['access_to'], cbk)
@ -806,8 +801,8 @@ class GlusterNFSHelperTestCase(test.TestCase):
export_str = '/example.com(10.0.0.1),/fakename(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, args = ('volume', 'set', self._helper.gluster_manager.volume,
NFS_EXPORT_DIR, export_str) NFS_EXPORT_DIR, export_str)
self.stubs.Set(self._helper, '_get_export_dir_dict', self.mock_object(self._helper, '_get_export_dir_dict',
mock.Mock(return_value=export_dir_dict)) mock.Mock(return_value=export_dir_dict))
self._helper.allow_access(None, share, access) self._helper.allow_access(None, share, access)
self._helper._get_export_dir_dict.assert_called_once_with() self._helper._get_export_dir_dict.assert_called_once_with()
self._helper.gluster_manager.gluster_call.assert_called_once_with( self._helper.gluster_manager.gluster_call.assert_called_once_with(
@ -817,8 +812,8 @@ class GlusterNFSHelperTestCase(test.TestCase):
access = fake_share.fake_access() access = fake_share.fake_access()
share = fake_share.fake_share() share = fake_share.fake_share()
export_dir_dict = {'fakename': ['10.0.0.1']} export_dir_dict = {'fakename': ['10.0.0.1']}
self.stubs.Set(self._helper, '_get_export_dir_dict', self.mock_object(self._helper, '_get_export_dir_dict',
mock.Mock(return_value=export_dir_dict)) mock.Mock(return_value=export_dir_dict))
self._helper.allow_access(None, share, access) self._helper.allow_access(None, share, access)
self._helper._get_export_dir_dict.assert_called_once_with() self._helper._get_export_dir_dict.assert_called_once_with()
self.assertFalse(self._helper.gluster_manager.gluster_call.called) self.assertFalse(self._helper.gluster_manager.gluster_call.called)
@ -827,8 +822,8 @@ class GlusterNFSHelperTestCase(test.TestCase):
access = fake_share.fake_access() access = fake_share.fake_access()
share = fake_share.fake_share() share = fake_share.fake_share()
export_dir_dict = {} export_dir_dict = {}
self.stubs.Set(self._helper, '_get_export_dir_dict', self.mock_object(self._helper, '_get_export_dir_dict',
mock.Mock(return_value=export_dir_dict)) mock.Mock(return_value=export_dir_dict))
self._helper.deny_access(None, share, access) self._helper.deny_access(None, share, access)
self._helper._get_export_dir_dict.assert_called_once_with() self._helper._get_export_dir_dict.assert_called_once_with()
self.assertFalse(self._helper.gluster_manager.gluster_call.called) self.assertFalse(self._helper.gluster_manager.gluster_call.called)
@ -843,8 +838,8 @@ class GlusterNFSHelperTestCase(test.TestCase):
export_str = '/example.com(10.0.0.1)' export_str = '/example.com(10.0.0.1)'
args = ('volume', 'set', self._helper.gluster_manager.volume, args = ('volume', 'set', self._helper.gluster_manager.volume,
NFS_EXPORT_DIR, export_str) NFS_EXPORT_DIR, export_str)
self.stubs.Set(self._helper, '_get_export_dir_dict', self.mock_object(self._helper, '_get_export_dir_dict',
mock.Mock(return_value=export_dir_dict)) mock.Mock(return_value=export_dir_dict))
self._helper.deny_access(None, share, access) self._helper.deny_access(None, share, access)
self._helper._get_export_dir_dict.assert_called_once_with() self._helper._get_export_dir_dict.assert_called_once_with()
self._helper.gluster_manager.gluster_call.assert_called_once_with( self._helper.gluster_manager.gluster_call.assert_called_once_with(

View File

@ -77,7 +77,7 @@ class GlusterfsNativeShareDriverTestCase(test.TestCase):
def setUp(self): def setUp(self):
super(GlusterfsNativeShareDriverTestCase, self).setUp() super(GlusterfsNativeShareDriverTestCase, self).setUp()
fake_utils.stub_out_utils_execute(self.stubs) fake_utils.stub_out_utils_execute(self)
self._execute = fake_utils.fake_execute self._execute = fake_utils.fake_execute
self._context = context.get_admin_context() self._context = context.get_admin_context()
@ -96,10 +96,9 @@ class GlusterfsNativeShareDriverTestCase(test.TestCase):
self._driver = glusterfs_native.GlusterfsNativeShareDriver( self._driver = glusterfs_native.GlusterfsNativeShareDriver(
self._db, execute=self._execute, self._db, execute=self._execute,
configuration=self.fake_conf) configuration=self.fake_conf)
self.stubs.Set(tempfile, 'mkdtemp', self.mock_object(tempfile, 'mkdtemp',
mock.Mock(return_value='/tmp/tmpKGHKJ')) mock.Mock(return_value='/tmp/tmpKGHKJ'))
self.stubs.Set(glusterfs.GlusterManager, 'make_gluster_call', self.mock_object(glusterfs.GlusterManager, 'make_gluster_call')
mock.Mock())
self.addCleanup(fake_utils.fake_execute_set_repliers, []) self.addCleanup(fake_utils.fake_execute_set_repliers, [])
self.addCleanup(fake_utils.fake_execute_clear_log) self.addCleanup(fake_utils.fake_execute_clear_log)
@ -188,8 +187,8 @@ class GlusterfsNativeShareDriverTestCase(test.TestCase):
self._driver.gluster_used_vols_dict = {gmgr1.export: gmgr1} self._driver.gluster_used_vols_dict = {gmgr1.export: gmgr1}
self._driver.gluster_unused_vols_dict = {gmgr2.export: gmgr2} self._driver.gluster_unused_vols_dict = {gmgr2.export: gmgr2}
self.stubs.Set(gmgr2, 'gluster_call', self.mock_object(gmgr2, 'gluster_call',
mock.Mock(side_effect=raise_exception)) mock.Mock(side_effect=raise_exception))
self.assertRaises(exception.GlusterfsException, self.assertRaises(exception.GlusterfsException,
self._driver._setup_gluster_vols) self._driver._setup_gluster_vols)
@ -214,8 +213,8 @@ class GlusterfsNativeShareDriverTestCase(test.TestCase):
self._driver.gluster_used_vols_dict = {gmgr1.export: gmgr1} self._driver.gluster_used_vols_dict = {gmgr1.export: gmgr1}
self._driver.gluster_unused_vols_dict = {gmgr2.export: gmgr2} self._driver.gluster_unused_vols_dict = {gmgr2.export: gmgr2}
self.stubs.Set(gmgr2, 'gluster_call', self.mock_object(gmgr2, 'gluster_call',
mock.Mock(side_effect=raise_exception)) mock.Mock(side_effect=raise_exception))
self.assertRaises(exception.GlusterfsException, self.assertRaises(exception.GlusterfsException,
self._driver._setup_gluster_vols) self._driver._setup_gluster_vols)
@ -242,8 +241,8 @@ class GlusterfsNativeShareDriverTestCase(test.TestCase):
self._driver.gluster_used_vols_dict = {gmgr1.export: gmgr1} self._driver.gluster_used_vols_dict = {gmgr1.export: gmgr1}
self._driver.gluster_unused_vols_dict = {gmgr2.export: gmgr2} self._driver.gluster_unused_vols_dict = {gmgr2.export: gmgr2}
self.stubs.Set(gmgr2, 'gluster_call', self.mock_object(gmgr2, 'gluster_call',
mock.Mock(side_effect=raise_exception)) mock.Mock(side_effect=raise_exception))
self.assertRaises(exception.GlusterfsException, self.assertRaises(exception.GlusterfsException,
self._driver._setup_gluster_vols) self._driver._setup_gluster_vols)
@ -273,8 +272,8 @@ class GlusterfsNativeShareDriverTestCase(test.TestCase):
if(args == test_args): if(args == test_args):
raise exception.ProcessExecutionError() raise exception.ProcessExecutionError()
self.stubs.Set(gmgr1, 'gluster_call', self.mock_object(gmgr1, 'gluster_call',
mock.Mock(side_effect=raise_exception)) mock.Mock(side_effect=raise_exception))
self.assertRaises(exception.GlusterfsException, self.assertRaises(exception.GlusterfsException,
self._driver._restart_gluster_vol, gmgr1) self._driver._restart_gluster_vol, gmgr1)
@ -292,8 +291,8 @@ class GlusterfsNativeShareDriverTestCase(test.TestCase):
if(args == test_args[1]): if(args == test_args[1]):
raise exception.ProcessExecutionError() raise exception.ProcessExecutionError()
self.stubs.Set(gmgr1, 'gluster_call', self.mock_object(gmgr1, 'gluster_call',
mock.Mock(side_effect=raise_exception)) mock.Mock(side_effect=raise_exception))
self.assertRaises(exception.GlusterfsException, self.assertRaises(exception.GlusterfsException,
self._driver._restart_gluster_vol, gmgr1) self._driver._restart_gluster_vol, gmgr1)
@ -446,8 +445,8 @@ class GlusterfsNativeShareDriverTestCase(test.TestCase):
gmgr = glusterfs.GlusterManager gmgr = glusterfs.GlusterManager
gmgr1 = gmgr(self.gluster_target1, self._execute, None, None) gmgr1 = gmgr(self.gluster_target1, self._execute, None, None)
self.stubs.Set(gmgr1, 'gluster_call', self.mock_object(gmgr1, 'gluster_call',
mock.Mock(side_effect=raise_exception)) mock.Mock(side_effect=raise_exception))
self.assertRaises(exception.GlusterfsException, self.assertRaises(exception.GlusterfsException,
self._driver._wipe_gluster_vol, gmgr1) self._driver._wipe_gluster_vol, gmgr1)
@ -474,8 +473,8 @@ class GlusterfsNativeShareDriverTestCase(test.TestCase):
gmgr = glusterfs.GlusterManager gmgr = glusterfs.GlusterManager
gmgr1 = gmgr(self.gluster_target1, self._execute, None, None) gmgr1 = gmgr(self.gluster_target1, self._execute, None, None)
self.stubs.Set(gmgr1, 'gluster_call', self.mock_object(gmgr1, 'gluster_call',
mock.Mock(side_effect=raise_exception)) mock.Mock(side_effect=raise_exception))
self.assertRaises(exception.GlusterfsException, self.assertRaises(exception.GlusterfsException,
self._driver._wipe_gluster_vol, gmgr1) self._driver._wipe_gluster_vol, gmgr1)
@ -504,8 +503,8 @@ class GlusterfsNativeShareDriverTestCase(test.TestCase):
gmgr = glusterfs.GlusterManager gmgr = glusterfs.GlusterManager
gmgr1 = gmgr(self.gluster_target1, self._execute, None, None) gmgr1 = gmgr(self.gluster_target1, self._execute, None, None)
self.stubs.Set(gmgr1, 'gluster_call', self.mock_object(gmgr1, 'gluster_call',
mock.Mock(side_effect=raise_exception)) mock.Mock(side_effect=raise_exception))
expected_exec = ['find /tmp/tmpKGHKJ -mindepth 1 -delete'] expected_exec = ['find /tmp/tmpKGHKJ -mindepth 1 -delete']
@ -539,8 +538,8 @@ class GlusterfsNativeShareDriverTestCase(test.TestCase):
gmgr = glusterfs.GlusterManager gmgr = glusterfs.GlusterManager
gmgr1 = gmgr(self.gluster_target1, self._execute, None, None) gmgr1 = gmgr(self.gluster_target1, self._execute, None, None)
self.stubs.Set(gmgr1, 'gluster_call', self.mock_object(gmgr1, 'gluster_call',
mock.Mock(side_effect=raise_exception)) mock.Mock(side_effect=raise_exception))
expected_exec = ['find /tmp/tmpKGHKJ -mindepth 1 -delete'] expected_exec = ['find /tmp/tmpKGHKJ -mindepth 1 -delete']
@ -779,8 +778,8 @@ class GlusterfsNativeShareDriverTestCase(test.TestCase):
self._driver.gluster_used_vols_dict = {gmgr1.export: gmgr1} self._driver.gluster_used_vols_dict = {gmgr1.export: gmgr1}
self._driver.gluster_unused_vols_dict = {gmgr2.export: gmgr2} self._driver.gluster_unused_vols_dict = {gmgr2.export: gmgr2}
self.stubs.Set(gmgr1, 'gluster_call', self.mock_object(gmgr1, 'gluster_call',
mock.Mock(side_effect=raise_exception)) mock.Mock(side_effect=raise_exception))
share = fake_db_share1()[0] share = fake_db_share1()[0]
self.assertRaises(exception.GlusterfsException, self.assertRaises(exception.GlusterfsException,
@ -834,8 +833,8 @@ class GlusterfsNativeShareDriverTestCase(test.TestCase):
self._driver.gluster_used_vols_dict = {gmgr1.export: gmgr1} self._driver.gluster_used_vols_dict = {gmgr1.export: gmgr1}
self._driver.gluster_unused_vols_dict = {gmgr2.export: gmgr2} self._driver.gluster_unused_vols_dict = {gmgr2.export: gmgr2}
self.stubs.Set(gmgr1, 'gluster_call', self.mock_object(gmgr1, 'gluster_call',
mock.Mock(side_effect=raise_exception)) mock.Mock(side_effect=raise_exception))
share = fake_db_share1()[0] share = fake_db_share1()[0]

View File

@ -83,9 +83,9 @@ class ServiceInstanceManagerTestCase(test.TestCase):
self._helper_cifs = mock.Mock() self._helper_cifs = mock.Mock()
self._helper_nfs = mock.Mock() self._helper_nfs = mock.Mock()
self._db = mock.Mock() self._db = mock.Mock()
self.stubs.Set(service_instance.neutron, 'API', fake_network.API) self.mock_object(service_instance.neutron, 'API', fake_network.API)
self.stubs.Set(service_instance.compute, 'API', fake_compute.API) self.mock_object(service_instance.compute, 'API', fake_compute.API)
self.stubs.Set(importutils, 'import_class', mock.Mock()) self.mock_object(importutils, 'import_class')
with mock.patch.object(service_instance.ServiceInstanceManager, with mock.patch.object(service_instance.ServiceInstanceManager,
'_setup_connectivity_with_service_instances', '_setup_connectivity_with_service_instances',
mock.Mock()): mock.Mock()):
@ -96,10 +96,10 @@ class ServiceInstanceManagerTestCase(test.TestCase):
self._manager.admin_context = self._context self._manager.admin_context = self._context
self._manager._execute = mock.Mock(return_value=('', '')) self._manager._execute = mock.Mock(return_value=('', ''))
self._manager.vif_driver = mock.Mock() self._manager.vif_driver = mock.Mock()
self.stubs.Set(utils, 'synchronized', self.mock_object(utils, 'synchronized',
mock.Mock(return_value=lambda f: f)) mock.Mock(return_value=lambda f: f))
self.stubs.Set(service_instance.os.path, 'exists', self.mock_object(service_instance.os.path, 'exists',
mock.Mock(return_value=True)) mock.Mock(return_value=True))
self._manager._helpers = { self._manager._helpers = {
'CIFS': self._helper_cifs, 'CIFS': self._helper_cifs,
'NFS': self._helper_nfs, 'NFS': self._helper_nfs,
@ -112,25 +112,25 @@ class ServiceInstanceManagerTestCase(test.TestCase):
net2 = copy.copy(fake_network.API.network) net2 = copy.copy(fake_network.API.network)
net1['name'] = self._manager.get_config_option('service_network_name') net1['name'] = self._manager.get_config_option('service_network_name')
net1['id'] = 'fake service network id' net1['id'] = 'fake service network id'
self.stubs.Set(self._manager.neutron_api, 'get_all_tenant_networks', self.mock_object(self._manager.neutron_api, 'get_all_tenant_networks',
mock.Mock(return_value=[net1, net2])) mock.Mock(return_value=[net1, net2]))
result = self._manager._get_service_network() result = self._manager._get_service_network()
self.assertEqual(net1['id'], result) self.assertEqual(net1['id'], result)
def test_get_service_network_net_does_not_exists(self): def test_get_service_network_net_does_not_exists(self):
net = fake_network.FakeNetwork() net = fake_network.FakeNetwork()
self.stubs.Set(self._manager.neutron_api, 'get_all_tenant_networks', self.mock_object(self._manager.neutron_api, 'get_all_tenant_networks',
mock.Mock(return_value=[])) mock.Mock(return_value=[]))
self.stubs.Set(self._manager.neutron_api, 'network_create', self.mock_object(self._manager.neutron_api, 'network_create',
mock.Mock(return_value=net)) mock.Mock(return_value=net))
result = self._manager._get_service_network() result = self._manager._get_service_network()
self.assertEqual(net['id'], result) self.assertEqual(net['id'], result)
def test_get_service_network_ambiguos(self): def test_get_service_network_ambiguos(self):
net = fake_network.FakeNetwork( net = fake_network.FakeNetwork(
name=self._manager.get_config_option('service_network_name')) name=self._manager.get_config_option('service_network_name'))
self.stubs.Set(self._manager.neutron_api, 'get_all_tenant_networks', self.mock_object(self._manager.neutron_api, 'get_all_tenant_networks',
mock.Mock(return_value=[net, net])) mock.Mock(return_value=[net, net]))
self.assertRaises(exception.ManilaException, self.assertRaises(exception.ManilaException,
self._manager._get_service_network) self._manager._get_service_network)
@ -184,8 +184,8 @@ class ServiceInstanceManagerTestCase(test.TestCase):
) )
def test_security_group_name_not_specified(self): def test_security_group_name_not_specified(self):
self.stubs.Set(self._manager, 'get_config_option', self.mock_object(self._manager, 'get_config_option',
mock.Mock(return_value=None)) mock.Mock(return_value=None))
result = self._manager._get_or_create_security_group(self._context) result = self._manager._get_or_create_security_group(self._context)
self.assertEqual(result, None) self.assertEqual(result, None)
self._manager.get_config_option.assert_called_once_with( self._manager.get_config_option.assert_called_once_with(
@ -193,10 +193,10 @@ class ServiceInstanceManagerTestCase(test.TestCase):
def test_security_group_name_from_config_and_sg_exist(self): def test_security_group_name_from_config_and_sg_exist(self):
fake_secgroup = fake_compute.FakeSecurityGroup(name="fake_sg_name") fake_secgroup = fake_compute.FakeSecurityGroup(name="fake_sg_name")
self.stubs.Set(self._manager, 'get_config_option', self.mock_object(self._manager, 'get_config_option',
mock.Mock(return_value="fake_sg_name")) mock.Mock(return_value="fake_sg_name"))
self.stubs.Set(self._manager.compute_api, 'security_group_list', self.mock_object(self._manager.compute_api, 'security_group_list',
mock.Mock(return_value=[fake_secgroup, ])) mock.Mock(return_value=[fake_secgroup, ]))
result = self._manager._get_or_create_security_group(self._context) result = self._manager._get_or_create_security_group(self._context)
self.assertEqual(result, fake_secgroup) self.assertEqual(result, fake_secgroup)
self._manager.get_config_option.assert_has_calls([ self._manager.get_config_option.assert_has_calls([
@ -210,14 +210,14 @@ class ServiceInstanceManagerTestCase(test.TestCase):
desc = "fake_sg_description" desc = "fake_sg_description"
fake_secgroup = fake_compute.FakeSecurityGroup(name=name, fake_secgroup = fake_compute.FakeSecurityGroup(name=name,
description=desc) description=desc)
self.stubs.Set(self._manager, 'get_config_option', self.mock_object(self._manager, 'get_config_option',
mock.Mock(return_value=name)) mock.Mock(return_value=name))
self.stubs.Set(self._manager.compute_api, 'security_group_list', self.mock_object(self._manager.compute_api, 'security_group_list',
mock.Mock(return_value=[])) mock.Mock(return_value=[]))
self.stubs.Set(self._manager.compute_api, 'security_group_create', self.mock_object(self._manager.compute_api, 'security_group_create',
mock.Mock(return_value=fake_secgroup)) mock.Mock(return_value=fake_secgroup))
self.stubs.Set(self._manager.compute_api, 'security_group_rule_create', self.mock_object(self._manager.compute_api,
mock.Mock()) 'security_group_rule_create')
result = self._manager._get_or_create_security_group( result = self._manager._get_or_create_security_group(
context=self._context, context=self._context,
name=None, name=None,
@ -237,12 +237,12 @@ class ServiceInstanceManagerTestCase(test.TestCase):
desc = "fake_sg_description" desc = "fake_sg_description"
fake_secgroup = fake_compute.FakeSecurityGroup(name=name, fake_secgroup = fake_compute.FakeSecurityGroup(name=name,
description=desc) description=desc)
self.stubs.Set(self._manager.compute_api, 'security_group_list', self.mock_object(self._manager.compute_api, 'security_group_list',
mock.Mock(return_value=[])) mock.Mock(return_value=[]))
self.stubs.Set(self._manager.compute_api, 'security_group_create', self.mock_object(self._manager.compute_api, 'security_group_create',
mock.Mock(return_value=fake_secgroup)) mock.Mock(return_value=fake_secgroup))
self.stubs.Set(self._manager.compute_api, 'security_group_rule_create', self.mock_object(self._manager.compute_api,
mock.Mock()) 'security_group_rule_create')
result = self._manager._get_or_create_security_group( result = self._manager._get_or_create_security_group(
context=self._context, context=self._context,
name=name, name=name,
@ -258,9 +258,9 @@ class ServiceInstanceManagerTestCase(test.TestCase):
name = "fake_name" name = "fake_name"
fake_secgroup1 = fake_compute.FakeSecurityGroup(name=name) fake_secgroup1 = fake_compute.FakeSecurityGroup(name=name)
fake_secgroup2 = fake_compute.FakeSecurityGroup(name=name) fake_secgroup2 = fake_compute.FakeSecurityGroup(name=name)
self.stubs.Set(self._manager.compute_api, 'security_group_list', self.mock_object(self._manager.compute_api, 'security_group_list',
mock.Mock(return_value=[fake_secgroup1, mock.Mock(return_value=[fake_secgroup1,
fake_secgroup2])) fake_secgroup2]))
self.assertRaises(exception.ServiceInstanceException, self.assertRaises(exception.ServiceInstanceException,
self._manager._get_or_create_security_group, self._manager._get_or_create_security_group,
self._context, self._context,
@ -282,8 +282,8 @@ class ServiceInstanceManagerTestCase(test.TestCase):
expected_details = fake_server.copy() expected_details = fake_server.copy()
expected_details.pop('pk_path') expected_details.pop('pk_path')
expected_details['instance_id'] = expected_details.pop('id') expected_details['instance_id'] = expected_details.pop('id')
self.stubs.Set(self._manager, '_create_service_instance', self.mock_object(self._manager, '_create_service_instance',
mock.Mock(return_value=fake_server)) mock.Mock(return_value=fake_server))
result = self._manager.set_up_service_instance( result = self._manager.set_up_service_instance(
self._context, 'fake-inst-name', 'fake-net-id', 'fake-subnet-id') self._context, 'fake-inst-name', 'fake-net-id', 'fake-subnet-id')
@ -296,10 +296,10 @@ class ServiceInstanceManagerTestCase(test.TestCase):
server_details = {'instance_id': 'fake_inst_id', server_details = {'instance_id': 'fake_inst_id',
'ip': '1.2.3.4'} 'ip': '1.2.3.4'}
fake_server = fake_compute.FakeServer() fake_server = fake_compute.FakeServer()
self.stubs.Set(self._manager, '_check_server_availability', self.mock_object(self._manager, '_check_server_availability',
mock.Mock(return_value=True)) mock.Mock(return_value=True))
self.stubs.Set(self._manager.compute_api, 'server_get', self.mock_object(self._manager.compute_api, 'server_get',
mock.Mock(return_value=fake_server)) mock.Mock(return_value=fake_server))
result = self._manager.ensure_service_instance(self._context, result = self._manager.ensure_service_instance(self._context,
server_details) server_details)
self._manager.compute_api.server_get.assert_called_once_with( self._manager.compute_api.server_get.assert_called_once_with(
@ -311,11 +311,11 @@ class ServiceInstanceManagerTestCase(test.TestCase):
def test_ensure_server_not_exists(self): def test_ensure_server_not_exists(self):
server_details = {'instance_id': 'fake_inst_id', server_details = {'instance_id': 'fake_inst_id',
'ip': '1.2.3.4'} 'ip': '1.2.3.4'}
self.stubs.Set(self._manager, '_check_server_availability', self.mock_object(self._manager, '_check_server_availability',
mock.Mock(return_value=True)) mock.Mock(return_value=True))
self.stubs.Set(self._manager.compute_api, 'server_get', self.mock_object(self._manager.compute_api, 'server_get',
mock.Mock(side_effect=exception.InstanceNotFound( mock.Mock(side_effect=exception.InstanceNotFound(
instance_id=server_details['instance_id']))) instance_id=server_details['instance_id'])))
result = self._manager.ensure_service_instance(self._context, result = self._manager.ensure_service_instance(self._context,
server_details) server_details)
self._manager.compute_api.server_get.assert_called_once_with( self._manager.compute_api.server_get.assert_called_once_with(
@ -326,10 +326,10 @@ class ServiceInstanceManagerTestCase(test.TestCase):
def test_ensure_server_exception(self): def test_ensure_server_exception(self):
server_details = {'instance_id': 'fake_inst_id', server_details = {'instance_id': 'fake_inst_id',
'ip': '1.2.3.4'} 'ip': '1.2.3.4'}
self.stubs.Set(self._manager, '_check_server_availability', self.mock_object(self._manager, '_check_server_availability',
mock.Mock(return_value=True)) mock.Mock(return_value=True))
self.stubs.Set(self._manager.compute_api, 'server_get', self.mock_object(self._manager.compute_api, 'server_get',
mock.Mock(side_effect=exception.ManilaException)) mock.Mock(side_effect=exception.ManilaException))
self.assertRaises(exception.ManilaException, self.assertRaises(exception.ManilaException,
self._manager.ensure_service_instance, self._manager.ensure_service_instance,
self._context, self._context,
@ -342,10 +342,10 @@ class ServiceInstanceManagerTestCase(test.TestCase):
server_details = {'instance_id': 'fake_inst_id', server_details = {'instance_id': 'fake_inst_id',
'ip': '1.2.3.4'} 'ip': '1.2.3.4'}
fake_server = fake_compute.FakeServer(status='ERROR') fake_server = fake_compute.FakeServer(status='ERROR')
self.stubs.Set(self._manager.compute_api, 'server_get', self.mock_object(self._manager.compute_api, 'server_get',
mock.Mock(return_value=fake_server)) mock.Mock(return_value=fake_server))
self.stubs.Set(self._manager, '_check_server_availability', self.mock_object(self._manager, '_check_server_availability',
mock.Mock(return_value=True)) mock.Mock(return_value=True))
result = self._manager.ensure_service_instance(self._context, result = self._manager.ensure_service_instance(self._context,
server_details) server_details)
self.assertFalse(self._manager._check_server_availability.called) self.assertFalse(self._manager._check_server_availability.called)
@ -355,10 +355,10 @@ class ServiceInstanceManagerTestCase(test.TestCase):
keypair_name = self._manager.get_config_option( keypair_name = self._manager.get_config_option(
'manila_service_keypair_name') 'manila_service_keypair_name')
fake_keypair = fake_compute.FakeKeypair(name=keypair_name) fake_keypair = fake_compute.FakeKeypair(name=keypair_name)
self.stubs.Set(self._manager.compute_api, 'keypair_list', self.mock_object(self._manager.compute_api, 'keypair_list',
mock.Mock(return_value=[])) mock.Mock(return_value=[]))
self.stubs.Set(self._manager.compute_api, 'keypair_import', self.mock_object(self._manager.compute_api, 'keypair_import',
mock.Mock(return_value=fake_keypair)) mock.Mock(return_value=fake_keypair))
result = self._manager._get_key(self._context) result = self._manager._get_key(self._context)
@ -377,12 +377,12 @@ class ServiceInstanceManagerTestCase(test.TestCase):
name=self._manager.get_config_option( name=self._manager.get_config_option(
'manila_service_keypair_name'), 'manila_service_keypair_name'),
public_key='fake_public_key') public_key='fake_public_key')
self.stubs.Set(self._manager.compute_api, 'keypair_list', self.mock_object(self._manager.compute_api, 'keypair_list',
mock.Mock(return_value=[fake_keypair])) mock.Mock(return_value=[fake_keypair]))
self.stubs.Set(self._manager.compute_api, 'keypair_import', self.mock_object(self._manager.compute_api, 'keypair_import',
mock.Mock(return_value=fake_keypair)) mock.Mock(return_value=fake_keypair))
self.stubs.Set(self._manager, '_execute', self.mock_object(self._manager, '_execute',
mock.Mock(return_value=('fake_public_key', ''))) mock.Mock(return_value=('fake_public_key', '')))
result = self._manager._get_key(self._context) result = self._manager._get_key(self._context)
@ -400,14 +400,13 @@ class ServiceInstanceManagerTestCase(test.TestCase):
name=self._manager.get_config_option( name=self._manager.get_config_option(
'manila_service_keypair_name'), 'manila_service_keypair_name'),
public_key='fake_public_key1') public_key='fake_public_key1')
self.stubs.Set(self._manager.compute_api, 'keypair_list', self.mock_object(self._manager.compute_api, 'keypair_list',
mock.Mock(return_value=[fake_keypair])) mock.Mock(return_value=[fake_keypair]))
self.stubs.Set(self._manager.compute_api, 'keypair_import', self.mock_object(self._manager.compute_api, 'keypair_import',
mock.Mock(return_value=fake_keypair)) mock.Mock(return_value=fake_keypair))
self.stubs.Set(self._manager.compute_api, 'keypair_delete', self.mock_object(self._manager.compute_api, 'keypair_delete')
mock.Mock()) self.mock_object(self._manager, '_execute',
self.stubs.Set(self._manager, '_execute', mock.Mock(return_value=('fake_public_key2', '')))
mock.Mock(return_value=('fake_public_key2', '')))
result = self._manager._get_key(self._context) result = self._manager._get_key(self._context)
@ -467,16 +466,16 @@ class ServiceInstanceManagerTestCase(test.TestCase):
fake_image1 = fake_compute.FakeImage( fake_image1 = fake_compute.FakeImage(
name=self._manager.get_config_option('service_image_name')) name=self._manager.get_config_option('service_image_name'))
fake_image2 = fake_compute.FakeImage(name='another-image') fake_image2 = fake_compute.FakeImage(name='another-image')
self.stubs.Set(self._manager.compute_api, 'image_list', self.mock_object(self._manager.compute_api, 'image_list',
mock.Mock(return_value=[fake_image1, fake_image2])) mock.Mock(return_value=[fake_image1, fake_image2]))
result = self._manager._get_service_image(self._context) result = self._manager._get_service_image(self._context)
self.assertEqual(fake_image1.id, result) self.assertEqual(fake_image1.id, result)
def test_get_service_image_not_found(self): def test_get_service_image_not_found(self):
self.stubs.Set(self._manager.compute_api, 'image_list', self.mock_object(self._manager.compute_api, 'image_list',
mock.Mock(return_value=[])) mock.Mock(return_value=[]))
self.assertRaises(exception.ManilaException, self.assertRaises(exception.ManilaException,
self._manager._get_service_image, self._manager._get_service_image,
@ -484,8 +483,8 @@ class ServiceInstanceManagerTestCase(test.TestCase):
def test_get_service_image_ambiguous(self): def test_get_service_image_ambiguous(self):
fake_image = fake_compute.FakeImage(name=CONF.service_image_name) fake_image = fake_compute.FakeImage(name=CONF.service_image_name)
self.stubs.Set(self._manager.compute_api, 'image_list', self.mock_object(self._manager.compute_api, 'image_list',
mock.Mock(return_value=[fake_image, fake_image])) mock.Mock(return_value=[fake_image, fake_image]))
self.assertRaises(exception.ManilaException, self.assertRaises(exception.ManilaException,
self._manager._get_service_image, self._manager._get_service_image,
@ -506,25 +505,24 @@ class ServiceInstanceManagerTestCase(test.TestCase):
'ports': [fake_port], 'ports': [fake_port],
} }
self.stubs.Set(self._manager, '_get_service_image', self.mock_object(self._manager, '_get_service_image',
mock.Mock(return_value='fake_image_id')) mock.Mock(return_value='fake_image_id'))
self.stubs.Set(self._manager, '_get_key', self.mock_object(self._manager, '_get_key',
mock.Mock( mock.Mock(
return_value=('fake_key_name', 'fake_key_path'))) return_value=('fake_key_name', 'fake_key_path')))
self.stubs.Set(self._manager, '_setup_network_for_instance', self.mock_object(self._manager, '_setup_network_for_instance',
mock.Mock(return_value=fake_network_data)) mock.Mock(return_value=fake_network_data))
self.stubs.Set(self._manager, self.mock_object(self._manager,
'_setup_connectivity_with_service_instances', '_setup_connectivity_with_service_instances')
mock.Mock()) self.mock_object(self._manager.compute_api, 'server_create',
self.stubs.Set(self._manager.compute_api, 'server_create', mock.Mock(return_value=fake_server))
mock.Mock(return_value=fake_server)) self.mock_object(self._manager, '_get_server_ip',
self.stubs.Set(self._manager, '_get_server_ip', mock.Mock(return_value='fake_ip'))
mock.Mock(return_value='fake_ip')) self.mock_object(self._manager, '_get_or_create_security_group',
self.stubs.Set(self._manager, '_get_or_create_security_group', mock.Mock(return_value=fake_security_group))
mock.Mock(return_value=fake_security_group)) self.mock_object(service_instance.socket, 'socket')
self.stubs.Set(service_instance.socket, 'socket', mock.Mock()) self.mock_object(self._manager, '_get_service_instance_name',
self.stubs.Set(self._manager, '_get_service_instance_name', mock.Mock(return_value=fake_instance_name))
mock.Mock(return_value=fake_instance_name))
result = self._manager._create_service_instance( result = self._manager._create_service_instance(
self._context, self._context,
@ -557,23 +555,22 @@ class ServiceInstanceManagerTestCase(test.TestCase):
'ports': [fake_port], 'ports': [fake_port],
} }
self.stubs.Set(self._manager, '_get_service_image', self.mock_object(self._manager, '_get_service_image',
mock.Mock(return_value='fake_image_id')) mock.Mock(return_value='fake_image_id'))
self.stubs.Set(self._manager, '_get_key', self.mock_object(self._manager, '_get_key',
mock.Mock( mock.Mock(
return_value=('fake_key_name', 'fake_key_path'))) return_value=('fake_key_name', 'fake_key_path')))
self.stubs.Set(self._manager, '_get_or_create_security_group', self.mock_object(self._manager, '_get_or_create_security_group',
mock.Mock(return_value=fake_security_group)) mock.Mock(return_value=fake_security_group))
self.stubs.Set(self._manager, '_setup_network_for_instance', self.mock_object(self._manager, '_setup_network_for_instance',
mock.Mock(return_value=fake_network_data)) mock.Mock(return_value=fake_network_data))
self.stubs.Set(self._manager, self.mock_object(self._manager,
'_setup_connectivity_with_service_instances', '_setup_connectivity_with_service_instances')
mock.Mock()) self.mock_object(self._manager.compute_api, 'server_create',
self.stubs.Set(self._manager.compute_api, 'server_create', mock.Mock(return_value=fake_server))
mock.Mock(return_value=fake_server)) self.mock_object(self._manager.compute_api, 'server_get',
self.stubs.Set(self._manager.compute_api, 'server_get', mock.Mock(return_value=fake_server))
mock.Mock(return_value=fake_server)) self.mock_object(service_instance.socket, 'socket')
self.stubs.Set(service_instance.socket, 'socket', mock.Mock())
self.assertRaises(exception.ManilaException, self.assertRaises(exception.ManilaException,
self._manager._create_service_instance, self._manager._create_service_instance,
@ -605,24 +602,24 @@ class ServiceInstanceManagerTestCase(test.TestCase):
'ports': [fake_port] 'ports': [fake_port]
} }
self.stubs.Set(self._manager, '_get_service_image', self.mock_object(self._manager, '_get_service_image',
mock.Mock(return_value='fake_image_id')) mock.Mock(return_value='fake_image_id'))
self.stubs.Set(self._manager, '_get_key', self.mock_object(self._manager, '_get_key',
mock.Mock( mock.Mock(
return_value=('fake_key_name', 'fake_key_path'))) return_value=('fake_key_name', 'fake_key_path')))
self.stubs.Set(self._manager, '_get_or_create_security_group', self.mock_object(self._manager, '_get_or_create_security_group',
mock.Mock(return_value=fake_security_group)) mock.Mock(return_value=fake_security_group))
self.stubs.Set(self._manager, '_setup_network_for_instance', self.mock_object(self._manager, '_setup_network_for_instance',
mock.Mock(return_value=fake_network_data)) mock.Mock(return_value=fake_network_data))
self.stubs.Set(self._manager, self.mock_object(self._manager,
'_setup_connectivity_with_service_instances', '_setup_connectivity_with_service_instances',
mock.Mock(side_effect=exception.ManilaException)) mock.Mock(side_effect=exception.ManilaException))
self.stubs.Set(self._manager.neutron_api, 'delete_port', mock.Mock()) self.mock_object(self._manager.neutron_api, 'delete_port')
self.stubs.Set(self._manager.compute_api, 'server_create', self.mock_object(self._manager.compute_api, 'server_create',
mock.Mock(return_value=fake_server)) mock.Mock(return_value=fake_server))
self.stubs.Set(self._manager.compute_api, 'server_get', self.mock_object(self._manager.compute_api, 'server_get',
mock.Mock(return_value=fake_server)) mock.Mock(return_value=fake_server))
self.stubs.Set(service_instance.socket, 'socket', mock.Mock()) self.mock_object(service_instance.socket, 'socket')
self.assertRaises(exception.ManilaException, self.assertRaises(exception.ManilaException,
self._manager._create_service_instance, self._manager._create_service_instance,
@ -638,10 +635,10 @@ class ServiceInstanceManagerTestCase(test.TestCase):
self.assertFalse(service_instance.socket.socket.called) self.assertFalse(service_instance.socket.socket.called)
def test_create_service_instance_no_key_and_password(self): def test_create_service_instance_no_key_and_password(self):
self.stubs.Set(self._manager, '_get_service_image', self.mock_object(self._manager, '_get_service_image',
mock.Mock(return_value='fake_image_id')) mock.Mock(return_value='fake_image_id'))
self.stubs.Set(self._manager, '_get_key', self.mock_object(self._manager, '_get_key',
mock.Mock(return_value=(None, None))) mock.Mock(return_value=(None, None)))
self.assertRaises(exception.ManilaException, self.assertRaises(exception.ManilaException,
self._manager._create_service_instance, self._manager._create_service_instance,
self._context, self._context,
@ -655,22 +652,20 @@ class ServiceInstanceManagerTestCase(test.TestCase):
FakeSubnet(name=self.share['share_network_id']) FakeSubnet(name=self.share['share_network_id'])
fake_router = fake_network.FakeRouter() fake_router = fake_network.FakeRouter()
fake_port = fake_network.FakePort() fake_port = fake_network.FakePort()
self.stubs.Set(self._manager, self._manager.connect_share_server_to_tenant_network = False
'connect_share_server_to_tenant_network', False) self.mock_object(self._manager.neutron_api, 'get_network',
self.stubs.Set(self._manager.neutron_api, 'get_network', mock.Mock(return_value=fake_service_net))
mock.Mock(return_value=fake_service_net)) self.mock_object(self._manager.neutron_api, 'subnet_create',
self.stubs.Set(self._manager.neutron_api, 'subnet_create', mock.Mock(return_value=fake_service_subnet))
mock.Mock(return_value=fake_service_subnet)) self.mock_object(self._manager.db, 'share_network_get',
self.stubs.Set(self._manager.db, 'share_network_get', mock.Mock(return_value='fake_share_network'))
mock.Mock(return_value='fake_share_network')) self.mock_object(self._manager, '_get_private_router',
self.stubs.Set(self._manager, '_get_private_router', mock.Mock(return_value=fake_router))
mock.Mock(return_value=fake_router)) self.mock_object(self._manager.neutron_api, 'router_add_interface')
self.stubs.Set(self._manager.neutron_api, 'router_add_interface', self.mock_object(self._manager.neutron_api, 'create_port',
mock.Mock()) mock.Mock(return_value=fake_port))
self.stubs.Set(self._manager.neutron_api, 'create_port', self.mock_object(self._manager, '_get_cidr_for_subnet',
mock.Mock(return_value=fake_port)) mock.Mock(return_value='fake_cidr'))
self.stubs.Set(self._manager, '_get_cidr_for_subnet',
mock.Mock(return_value='fake_cidr'))
network_data = self._manager._setup_network_for_instance( network_data = self._manager._setup_network_for_instance(
'fake-net', 'fake-subnet') 'fake-net', 'fake-subnet')
@ -706,16 +701,16 @@ class ServiceInstanceManagerTestCase(test.TestCase):
fake_network.FakePort(fixed_ips=[{'ip_address': '1.2.3.4'}]), fake_network.FakePort(fixed_ips=[{'ip_address': '1.2.3.4'}]),
fake_network.FakePort(fixed_ips=[{'ip_address': '5.6.7.8'}]), fake_network.FakePort(fixed_ips=[{'ip_address': '5.6.7.8'}]),
] ]
self.stubs.Set(self._manager, self.mock_object(self._manager,
'connect_share_server_to_tenant_network', True) 'connect_share_server_to_tenant_network', True)
self.stubs.Set(self._manager.neutron_api, 'get_network', self.mock_object(self._manager.neutron_api, 'get_network',
mock.Mock(return_value=fake_service_net)) mock.Mock(return_value=fake_service_net))
self.stubs.Set(self._manager.neutron_api, 'subnet_create', self.mock_object(self._manager.neutron_api, 'subnet_create',
mock.Mock(return_value=fake_service_subnet)) mock.Mock(return_value=fake_service_subnet))
self.stubs.Set(self._manager.neutron_api, 'create_port', self.mock_object(self._manager.neutron_api, 'create_port',
mock.Mock(side_effect=fake_ports)) mock.Mock(side_effect=fake_ports))
self.stubs.Set(self._manager, '_get_cidr_for_subnet', self.mock_object(self._manager, '_get_cidr_for_subnet',
mock.Mock(return_value='fake_cidr')) mock.Mock(return_value='fake_cidr'))
network_data = self._manager._setup_network_for_instance( network_data = self._manager._setup_network_for_instance(
'fake-net', 'fake-subnet') 'fake-net', 'fake-subnet')
@ -748,19 +743,19 @@ class ServiceInstanceManagerTestCase(test.TestCase):
fake_subnet = fake_network.FakeSubnet(gateway_ip='fake_ip') fake_subnet = fake_network.FakeSubnet(gateway_ip='fake_ip')
fake_share_network = {'neutron_net_id': fake_net['id'], fake_share_network = {'neutron_net_id': fake_net['id'],
'neutron_subnet_id': fake_subnet['id']} 'neutron_subnet_id': fake_subnet['id']}
self.stubs.Set(self._manager.db, 'share_network_get', self.mock_object(self._manager.db, 'share_network_get',
mock.Mock(return_value=fake_share_network)) mock.Mock(return_value=fake_share_network))
fake_port = fake_network.FakePort(fixed_ips=[ fake_port = fake_network.FakePort(fixed_ips=[
{'subnet_id': fake_subnet['id'], {'subnet_id': fake_subnet['id'],
'ip_address': fake_subnet['gateway_ip']}], 'ip_address': fake_subnet['gateway_ip']}],
device_id='fake_router_id') device_id='fake_router_id')
fake_router = fake_network.FakeRouter(id='fake_router_id') fake_router = fake_network.FakeRouter(id='fake_router_id')
self.stubs.Set(self._manager.neutron_api, 'get_subnet', self.mock_object(self._manager.neutron_api, 'get_subnet',
mock.Mock(return_value=fake_subnet)) mock.Mock(return_value=fake_subnet))
self.stubs.Set(self._manager.neutron_api, 'list_ports', self.mock_object(self._manager.neutron_api, 'list_ports',
mock.Mock(return_value=[fake_port])) mock.Mock(return_value=[fake_port]))
self.stubs.Set(self._manager.neutron_api, 'show_router', self.mock_object(self._manager.neutron_api, 'show_router',
mock.Mock(return_value=fake_router)) mock.Mock(return_value=fake_router))
result = self._manager._get_private_router(fake_net['id'], result = self._manager._get_private_router(fake_net['id'],
fake_subnet['id']) fake_subnet['id'])
@ -778,12 +773,12 @@ class ServiceInstanceManagerTestCase(test.TestCase):
fake_subnet = fake_network.FakeSubnet(gateway_ip='fake_ip') fake_subnet = fake_network.FakeSubnet(gateway_ip='fake_ip')
fake_share_network = {'neutron_net_id': fake_net['id'], fake_share_network = {'neutron_net_id': fake_net['id'],
'neutron_subnet_id': fake_subnet['id']} 'neutron_subnet_id': fake_subnet['id']}
self.stubs.Set(self._manager.db, 'share_network_get', self.mock_object(self._manager.db, 'share_network_get',
mock.Mock(return_value=fake_share_network)) mock.Mock(return_value=fake_share_network))
self.stubs.Set(self._manager.neutron_api, 'get_subnet', self.mock_object(self._manager.neutron_api, 'get_subnet',
mock.Mock(return_value=fake_subnet)) mock.Mock(return_value=fake_subnet))
self.stubs.Set(self._manager.neutron_api, 'list_ports', self.mock_object(self._manager.neutron_api, 'list_ports',
mock.Mock(return_value=[])) mock.Mock(return_value=[]))
self.assertRaises(exception.ManilaException, self.assertRaises(exception.ManilaException,
self._manager._get_private_router, self._manager._get_private_router,
@ -799,18 +794,17 @@ class ServiceInstanceManagerTestCase(test.TestCase):
{'subnet_id': fake_subnet['id'], 'ip_address': '10.254.0.2'}], {'subnet_id': fake_subnet['id'], 'ip_address': '10.254.0.2'}],
mac_address='fake_mac_address') mac_address='fake_mac_address')
self.stubs.Set(self._manager, '_get_service_port', self.mock_object(self._manager, '_get_service_port',
mock.Mock(return_value=fake_port)) mock.Mock(return_value=fake_port))
self.stubs.Set(self._manager.vif_driver, 'get_device_name', self.mock_object(self._manager.vif_driver, 'get_device_name',
mock.Mock(return_value=interface_name)) mock.Mock(return_value=interface_name))
self.stubs.Set(self._manager.neutron_api, 'get_subnet', self.mock_object(self._manager.neutron_api, 'get_subnet',
mock.Mock(return_value=fake_subnet)) mock.Mock(return_value=fake_subnet))
self.stubs.Set(self._manager, '_remove_outdated_interfaces', self.mock_object(self._manager, '_remove_outdated_interfaces')
mock.Mock()) self.mock_object(self._manager.vif_driver, 'plug')
self.stubs.Set(self._manager.vif_driver, 'plug', mock.Mock())
device_mock = mock.Mock() device_mock = mock.Mock()
self.stubs.Set(service_instance.ip_lib, 'IPDevice', self.mock_object(service_instance.ip_lib, 'IPDevice',
mock.Mock(return_value=device_mock)) mock.Mock(return_value=device_mock))
self._manager._setup_connectivity_with_service_instances() self._manager._setup_connectivity_with_service_instances()
@ -831,14 +825,14 @@ class ServiceInstanceManagerTestCase(test.TestCase):
def test_get_service_port(self): def test_get_service_port(self):
fake_service_port = fake_network.FakePort(device_id='manila-share') fake_service_port = fake_network.FakePort(device_id='manila-share')
self.stubs.Set(self._manager.neutron_api, 'list_ports', self.mock_object(self._manager.neutron_api, 'list_ports',
mock.Mock(return_value=[])) mock.Mock(return_value=[]))
self.stubs.Set(self._manager, '_execute', self.mock_object(self._manager, '_execute',
mock.Mock(return_value=('fake_host', ''))) mock.Mock(return_value=('fake_host', '')))
self.stubs.Set(self._manager.neutron_api, 'create_port', self.mock_object(self._manager.neutron_api, 'create_port',
mock.Mock(return_value=fake_service_port)) mock.Mock(return_value=fake_service_port))
self.stubs.Set(self._manager.neutron_api, 'update_port_fixed_ips', self.mock_object(self._manager.neutron_api, 'update_port_fixed_ips',
mock.Mock(return_value=fake_service_port)) mock.Mock(return_value=fake_service_port))
result = self._manager._get_service_port() result = self._manager._get_service_port()
@ -858,20 +852,20 @@ class ServiceInstanceManagerTestCase(test.TestCase):
def test_get_service_port_ambigious_ports(self): def test_get_service_port_ambigious_ports(self):
fake_service_port = fake_network.FakePort(device_id='manila-share') fake_service_port = fake_network.FakePort(device_id='manila-share')
self.stubs.Set(self._manager.neutron_api, 'list_ports', self.mock_object(self._manager.neutron_api, 'list_ports',
mock.Mock(return_value=[fake_service_port, mock.Mock(return_value=[fake_service_port,
fake_service_port])) fake_service_port]))
self.assertRaises(exception.ManilaException, self.assertRaises(exception.ManilaException,
self._manager._get_service_port) self._manager._get_service_port)
def test_get_service_port_exists(self): def test_get_service_port_exists(self):
fake_service_port = fake_network.FakePort(device_id='manila-share') fake_service_port = fake_network.FakePort(device_id='manila-share')
self.stubs.Set(self._manager.neutron_api, 'list_ports', self.mock_object(self._manager.neutron_api, 'list_ports',
mock.Mock(return_value=[fake_service_port])) mock.Mock(return_value=[fake_service_port]))
self.stubs.Set(self._manager.neutron_api, 'create_port', self.mock_object(self._manager.neutron_api, 'create_port',
mock.Mock(return_value=fake_service_port)) mock.Mock(return_value=fake_service_port))
self.stubs.Set(self._manager.neutron_api, 'update_port_fixed_ips', self.mock_object(self._manager.neutron_api, 'update_port_fixed_ips',
mock.Mock(return_value=fake_service_port)) mock.Mock(return_value=fake_service_port))
result = self._manager._get_service_port() result = self._manager._get_service_port()
@ -891,20 +885,20 @@ class ServiceInstanceManagerTestCase(test.TestCase):
cidrs = serv_cidr.subnet(fake_division_mask) cidrs = serv_cidr.subnet(fake_division_mask)
cidr1 = six.text_type(next(cidrs)) cidr1 = six.text_type(next(cidrs))
cidr2 = six.text_type(next(cidrs)) cidr2 = six.text_type(next(cidrs))
self.stubs.Set(self._manager, '_get_all_service_subnets', self.mock_object(self._manager, '_get_all_service_subnets',
mock.Mock(return_value=[])) mock.Mock(return_value=[]))
result = self._manager._get_cidr_for_subnet() result = self._manager._get_cidr_for_subnet()
self.assertEqual(result, cidr1) self.assertEqual(result, cidr1)
fake_subnet = fake_network.FakeSubnet(cidr=cidr1) fake_subnet = fake_network.FakeSubnet(cidr=cidr1)
self.stubs.Set(self._manager, '_get_all_service_subnets', self.mock_object(self._manager, '_get_all_service_subnets',
mock.Mock(return_value=[fake_subnet])) mock.Mock(return_value=[fake_subnet]))
result = self._manager._get_cidr_for_subnet() result = self._manager._get_cidr_for_subnet()
self.assertEqual(result, cidr2) self.assertEqual(result, cidr2)
def test__delete_server_not_found(self): def test__delete_server_not_found(self):
self.stubs.Set(self._manager.compute_api, 'server_delete', mock.Mock()) self.mock_object(self._manager.compute_api, 'server_delete')
self.stubs.Set( self.mock_object(
self._manager.compute_api, 'server_get', self._manager.compute_api, 'server_get',
mock.Mock(side_effect=exception.InstanceNotFound( mock.Mock(side_effect=exception.InstanceNotFound(
instance_id=self.instance_id))) instance_id=self.instance_id)))
@ -924,9 +918,9 @@ class ServiceInstanceManagerTestCase(test.TestCase):
else: else:
raise exception.InstanceNotFound(instance_id=self.instance_id) raise exception.InstanceNotFound(instance_id=self.instance_id)
self.stubs.Set(self._manager.compute_api, 'server_delete', mock.Mock()) self.mock_object(self._manager.compute_api, 'server_delete')
self.stubs.Set(self._manager.compute_api, 'server_get', self.mock_object(self._manager.compute_api, 'server_get',
mock.Mock(side_effect=fake_server_get)) mock.Mock(side_effect=fake_server_get))
self._manager._delete_server(self._context, self.instance_id) self._manager._delete_server(self._context, self.instance_id)
@ -945,14 +939,14 @@ class ServiceInstanceManagerTestCase(test.TestCase):
def fake_sleep(time): def fake_sleep(time):
self.fake_time += 1 self.fake_time += 1
self.stubs.Set(self._manager.compute_api, 'server_delete', mock.Mock()) self.mock_object(self._manager.compute_api, 'server_delete')
self.stubs.Set(self._manager.compute_api, 'server_get', mock.Mock()) self.mock_object(self._manager.compute_api, 'server_get')
self.stubs.Set(service_instance, 'time', mock.Mock()) self.mock_object(service_instance, 'time')
self.stubs.Set( self.mock_object(
service_instance.time, 'time', mock.Mock(side_effect=fake_time)) service_instance.time, 'time', mock.Mock(side_effect=fake_time))
self.stubs.Set( self.mock_object(
service_instance.time, 'sleep', mock.Mock(side_effect=fake_sleep)) service_instance.time, 'sleep', mock.Mock(side_effect=fake_sleep))
self.stubs.Set(self._manager, 'max_time_to_build_instance', 2) self.mock_object(self._manager, 'max_time_to_build_instance', 2)
self.assertRaises( self.assertRaises(
exception.ServiceInstanceException, self._manager._delete_server, exception.ServiceInstanceException, self._manager._delete_server,
@ -971,11 +965,9 @@ class ServiceInstanceManagerTestCase(test.TestCase):
instance_id = 'fake_instance_id' instance_id = 'fake_instance_id'
router_id = 'fake_router_id' router_id = 'fake_router_id'
subnet_id = 'fake_subnet_id' subnet_id = 'fake_subnet_id'
self.stubs.Set(self._manager, '_delete_server', mock.Mock()) self.mock_object(self._manager, '_delete_server')
self.stubs.Set(self._manager.neutron_api, 'router_remove_interface', self.mock_object(self._manager.neutron_api, 'router_remove_interface')
mock.Mock()) self.mock_object(self._manager.neutron_api, 'update_subnet')
self.stubs.Set(self._manager.neutron_api, 'update_subnet',
mock.Mock())
self._manager.delete_service_instance( self._manager.delete_service_instance(
self._context, instance_id, subnet_id, router_id) self._context, instance_id, subnet_id, router_id)

View File

@ -49,7 +49,7 @@ class ZFSSAApiTestCase(test.TestCase):
return response return response
def test_enable_service(self): def test_enable_service(self):
self.stubs.Set(self._zfssa.rclient, 'put', mock.Mock()) self.mock_object(self._zfssa.rclient, 'put')
self._zfssa.rclient.put.return_value = self._create_response( self._zfssa.rclient.put.return_value = self._create_response(
restclient.Status.ACCEPTED) restclient.Status.ACCEPTED)
@ -63,8 +63,8 @@ class ZFSSAApiTestCase(test.TestCase):
'nfs') 'nfs')
def test_verify_avail_space(self): def test_verify_avail_space(self):
self.stubs.Set(self._zfssa, 'verify_project', mock.Mock()) self.mock_object(self._zfssa, 'verify_project')
self.stubs.Set(self._zfssa, 'get_project_stats', mock.Mock()) self.mock_object(self._zfssa, 'get_project_stats')
self._zfssa.get_project_stats.return_value = 2000 self._zfssa.get_project_stats.return_value = 2000
self._zfssa.verify_avail_space(self.pool, self._zfssa.verify_avail_space(self.pool,
@ -86,9 +86,9 @@ class ZFSSAApiTestCase(test.TestCase):
1000) 1000)
def test_create_project(self): def test_create_project(self):
self.stubs.Set(self._zfssa, 'verify_pool', mock.Mock()) self.mock_object(self._zfssa, 'verify_pool')
self.stubs.Set(self._zfssa.rclient, 'get', mock.Mock()) self.mock_object(self._zfssa.rclient, 'get')
self.stubs.Set(self._zfssa.rclient, 'post', mock.Mock()) self.mock_object(self._zfssa.rclient, 'post')
arg = { arg = {
'name': self.project, 'name': self.project,
'sharesmb': 'off', 'sharesmb': 'off',
@ -115,9 +115,9 @@ class ZFSSAApiTestCase(test.TestCase):
arg) arg)
def test_create_share(self): def test_create_share(self):
self.stubs.Set(self._zfssa, 'verify_avail_space', mock.Mock()) self.mock_object(self._zfssa, 'verify_avail_space')
self.stubs.Set(self._zfssa.rclient, 'get', mock.Mock()) self.mock_object(self._zfssa.rclient, 'get')
self.stubs.Set(self._zfssa.rclient, 'post', mock.Mock()) self.mock_object(self._zfssa.rclient, 'post')
self._zfssa.rclient.get.return_value = self._create_response( self._zfssa.rclient.get.return_value = self._create_response(
restclient.Status.NOT_FOUND) restclient.Status.NOT_FOUND)
self._zfssa.rclient.post.return_value = self._create_response( self._zfssa.rclient.post.return_value = self._create_response(
@ -153,7 +153,7 @@ class ZFSSAApiTestCase(test.TestCase):
arg) arg)
def test_modify_share(self): def test_modify_share(self):
self.stubs.Set(self._zfssa.rclient, 'put', mock.Mock()) self.mock_object(self._zfssa.rclient, 'put')
self._zfssa.rclient.put.return_value = self._create_response( self._zfssa.rclient.put.return_value = self._create_response(
restclient.Status.ACCEPTED) restclient.Status.ACCEPTED)
arg = {"name": "dummyname"} arg = {"name": "dummyname"}
@ -173,7 +173,7 @@ class ZFSSAApiTestCase(test.TestCase):
arg) arg)
def test_delete_share(self): def test_delete_share(self):
self.stubs.Set(self._zfssa.rclient, 'delete', mock.Mock()) self.mock_object(self._zfssa.rclient, 'delete')
self._zfssa.rclient.delete.return_value = self._create_response( self._zfssa.rclient.delete.return_value = self._create_response(
restclient.Status.NO_CONTENT) restclient.Status.NO_CONTENT)
svc = self._zfssa.share_path % (self.pool, self.project, self.share) svc = self._zfssa.share_path % (self.pool, self.project, self.share)
@ -183,7 +183,7 @@ class ZFSSAApiTestCase(test.TestCase):
self._zfssa.rclient.delete.assert_called_with(svc) self._zfssa.rclient.delete.assert_called_with(svc)
def test_create_snapshot(self): def test_create_snapshot(self):
self.stubs.Set(self._zfssa.rclient, 'post', mock.Mock()) self.mock_object(self._zfssa.rclient, 'post')
self._zfssa.rclient.post.return_value = self._create_response( self._zfssa.rclient.post.return_value = self._create_response(
restclient.Status.CREATED) restclient.Status.CREATED)
arg = {"name": self.snap} arg = {"name": self.snap}
@ -208,7 +208,7 @@ class ZFSSAApiTestCase(test.TestCase):
self.snap) self.snap)
def test_delete_snapshot(self): def test_delete_snapshot(self):
self.stubs.Set(self._zfssa.rclient, 'delete', mock.Mock()) self.mock_object(self._zfssa.rclient, 'delete')
self._zfssa.rclient.delete.return_value = self._create_response( self._zfssa.rclient.delete.return_value = self._create_response(
restclient.Status.NO_CONTENT) restclient.Status.NO_CONTENT)
svc = self._zfssa.snapshot_path % (self.pool, svc = self._zfssa.snapshot_path % (self.pool,
@ -233,8 +233,8 @@ class ZFSSAApiTestCase(test.TestCase):
self.snap) self.snap)
def test_clone_snapshot(self): def test_clone_snapshot(self):
self.stubs.Set(self._zfssa, 'verify_avail_space', mock.Mock()) self.mock_object(self._zfssa, 'verify_avail_space')
self.stubs.Set(self._zfssa.rclient, 'put', mock.Mock()) self.mock_object(self._zfssa.rclient, 'put')
self._zfssa.rclient.put.return_value = self._create_response( self._zfssa.rclient.put.return_value = self._create_response(
restclient.Status.CREATED) restclient.Status.CREATED)
snapshot = { snapshot = {
@ -282,8 +282,8 @@ class ZFSSAApiTestCase(test.TestCase):
return arg return arg
def test_allow_access_nfs(self): def test_allow_access_nfs(self):
self.stubs.Set(self._zfssa, 'get_share', mock.Mock()) self.mock_object(self._zfssa, 'get_share')
self.stubs.Set(self._zfssa, 'modify_share', mock.Mock()) self.mock_object(self._zfssa, 'modify_share')
details = {"sharenfs": "off"} details = {"sharenfs": "off"}
access = { access = {
"access_type": "nonip", "access_type": "nonip",
@ -349,8 +349,8 @@ class ZFSSAApiTestCase(test.TestCase):
self.assertEqual(2, self._zfssa.modify_share.call_count) self.assertEqual(2, self._zfssa.modify_share.call_count)
def test_deny_access_nfs(self): def test_deny_access_nfs(self):
self.stubs.Set(self._zfssa, 'get_share', mock.Mock()) self.mock_object(self._zfssa, 'get_share')
self.stubs.Set(self._zfssa, 'modify_share', mock.Mock()) self.mock_object(self._zfssa, 'modify_share')
data1 = self._create_entry("off", "10.0.0.1") data1 = self._create_entry("off", "10.0.0.1")
access = { access = {
"access_type": "nonip", "access_type": "nonip",

View File

@ -93,8 +93,8 @@ class ZFSSAShareDriverTestCase(test.TestCase):
self.configuration.driver_handles_share_servers = False self.configuration.driver_handles_share_servers = False
def test_create_share(self): def test_create_share(self):
self.stubs.Set(self._driver.zfssa, 'create_share', mock.Mock()) self.mock_object(self._driver.zfssa, 'create_share')
self.stubs.Set(self._driver, '_export_location', mock.Mock()) self.mock_object(self._driver, '_export_location')
lcfg = self.configuration lcfg = self.configuration
arg = { arg = {
'host': lcfg.zfssa_data_ip, 'host': lcfg.zfssa_data_ip,
@ -115,8 +115,8 @@ class ZFSSAShareDriverTestCase(test.TestCase):
self.assertEqual(1, self._driver._export_location.call_count) self.assertEqual(1, self._driver._export_location.call_count)
def test_create_share_from_snapshot(self): def test_create_share_from_snapshot(self):
self.stubs.Set(self._driver.zfssa, 'clone_snapshot', mock.Mock()) self.mock_object(self._driver.zfssa, 'clone_snapshot')
self.stubs.Set(self._driver, '_export_location', mock.Mock()) self.mock_object(self._driver, '_export_location')
lcfg = self.configuration lcfg = self.configuration
arg = { arg = {
'host': lcfg.zfssa_data_ip, 'host': lcfg.zfssa_data_ip,
@ -145,7 +145,7 @@ class ZFSSAShareDriverTestCase(test.TestCase):
arg) arg)
def test_delete_share(self): def test_delete_share(self):
self.stubs.Set(self._driver.zfssa, 'delete_share', mock.Mock()) self.mock_object(self._driver.zfssa, 'delete_share')
self._driver.delete_share(self._context, self.share) self._driver.delete_share(self._context, self.share)
self.assertEqual(1, self._driver.zfssa.delete_share.call_count) self.assertEqual(1, self._driver.zfssa.delete_share.call_count)
lcfg = self.configuration lcfg = self.configuration
@ -154,7 +154,7 @@ class ZFSSAShareDriverTestCase(test.TestCase):
self.share['id']) self.share['id'])
def test_create_snapshot(self): def test_create_snapshot(self):
self.stubs.Set(self._driver.zfssa, 'create_snapshot', mock.Mock()) self.mock_object(self._driver.zfssa, 'create_snapshot')
lcfg = self.configuration lcfg = self.configuration
self._driver.create_snapshot(self._context, self.snapshot) self._driver.create_snapshot(self._context, self.snapshot)
self.assertEqual(1, self._driver.zfssa.create_snapshot.call_count) self.assertEqual(1, self._driver.zfssa.create_snapshot.call_count)
@ -165,12 +165,12 @@ class ZFSSAShareDriverTestCase(test.TestCase):
self.snapshot['id']) self.snapshot['id'])
def test_delete_snapshot(self): def test_delete_snapshot(self):
self.stubs.Set(self._driver.zfssa, 'delete_snapshot', mock.Mock()) self.mock_object(self._driver.zfssa, 'delete_snapshot')
self._driver.delete_snapshot(self._context, self.snapshot) self._driver.delete_snapshot(self._context, self.snapshot)
self.assertEqual(1, self._driver.zfssa.delete_snapshot.call_count) self.assertEqual(1, self._driver.zfssa.delete_snapshot.call_count)
def test_delete_snapshot_negative(self): def test_delete_snapshot_negative(self):
self.stubs.Set(self._driver.zfssa, 'has_clones', mock.Mock()) self.mock_object(self._driver.zfssa, 'has_clones')
self._driver.zfssa.has_clones.return_value = True self._driver.zfssa.has_clones.return_value = True
self.assertRaises(exception.ShareSnapshotIsBusy, self.assertRaises(exception.ShareSnapshotIsBusy,
self._driver.delete_snapshot, self._driver.delete_snapshot,
@ -178,7 +178,7 @@ class ZFSSAShareDriverTestCase(test.TestCase):
self.snapshot) self.snapshot)
def test_ensure_share(self): def test_ensure_share(self):
self.stubs.Set(self._driver.zfssa, 'get_share', mock.Mock()) self.mock_object(self._driver.zfssa, 'get_share')
lcfg = self.configuration lcfg = self.configuration
self._driver.ensure_share(self._context, self.share) self._driver.ensure_share(self._context, self.share)
self.assertEqual(1, self._driver.zfssa.get_share.call_count) self.assertEqual(1, self._driver.zfssa.get_share.call_count)
@ -194,7 +194,7 @@ class ZFSSAShareDriverTestCase(test.TestCase):
self.share) self.share)
def test_allow_access(self): def test_allow_access(self):
self.stubs.Set(self._driver.zfssa, 'allow_access_nfs', mock.Mock()) self.mock_object(self._driver.zfssa, 'allow_access_nfs')
lcfg = self.configuration lcfg = self.configuration
self._driver.allow_access(self._context, self.share, self.access) self._driver.allow_access(self._context, self.share, self.access)
self.assertEqual(1, self._driver.zfssa.allow_access_nfs.call_count) self.assertEqual(1, self._driver.zfssa.allow_access_nfs.call_count)
@ -205,7 +205,7 @@ class ZFSSAShareDriverTestCase(test.TestCase):
self.access) self.access)
def test_deny_access(self): def test_deny_access(self):
self.stubs.Set(self._driver.zfssa, 'deny_access_nfs', mock.Mock()) self.mock_object(self._driver.zfssa, 'deny_access_nfs')
lcfg = self.configuration lcfg = self.configuration
self._driver.deny_access(self._context, self.share, self.access) self._driver.deny_access(self._context, self.share, self.access)
self.assertEqual(1, self._driver.zfssa.deny_access_nfs.call_count) self.assertEqual(1, self._driver.zfssa.deny_access_nfs.call_count)

View File

@ -171,18 +171,20 @@ class ShareAPITestCase(test.TestCase):
self.scheduler_rpcapi = mock.Mock() self.scheduler_rpcapi = mock.Mock()
self.share_rpcapi = mock.Mock() self.share_rpcapi = mock.Mock()
self.api = share.API() self.api = share.API()
self.stubs.Set(self.api, 'scheduler_rpcapi', self.scheduler_rpcapi) self.mock_object(self.api, 'scheduler_rpcapi', self.scheduler_rpcapi)
self.stubs.Set(self.api, 'share_rpcapi', self.share_rpcapi) self.mock_object(self.api, 'share_rpcapi', self.share_rpcapi)
self.stubs.Set(quota.QUOTAS, 'reserve', lambda *args, **kwargs: None) self.mock_object(quota.QUOTAS, 'reserve',
lambda *args, **kwargs: None)
dt_utc = datetime.datetime.utcnow() dt_utc = datetime.datetime.utcnow()
self.stubs.Set(timeutils, 'utcnow', mock.Mock(return_value=dt_utc)) self.mock_object(timeutils, 'utcnow', mock.Mock(return_value=dt_utc))
self.stubs.Set(timeutils_old, 'utcnow', mock.Mock(return_value=dt_utc)) self.mock_object(timeutils_old, 'utcnow',
self.stubs.Set(share_api.policy, 'check_policy', mock.Mock()) mock.Mock(return_value=dt_utc))
self.mock_object(share_api.policy, 'check_policy')
def test_get_all_admin_no_filters(self): def test_get_all_admin_no_filters(self):
self.stubs.Set(db_driver, 'share_get_all_by_project', self.mock_object(db_driver, 'share_get_all_by_project',
mock.Mock(return_value=_FAKE_LIST_OF_ALL_SHARES[0])) mock.Mock(return_value=_FAKE_LIST_OF_ALL_SHARES[0]))
ctx = context.RequestContext('fake_uid', 'fake_pid_1', is_admin=True) ctx = context.RequestContext('fake_uid', 'fake_pid_1', is_admin=True)
shares = self.api.get_all(ctx) shares = self.api.get_all(ctx)
share_api.policy.check_policy.assert_called_once_with( share_api.policy.check_policy.assert_called_once_with(
@ -195,8 +197,8 @@ class ShareAPITestCase(test.TestCase):
def test_get_all_admin_filter_by_all_tenants(self): def test_get_all_admin_filter_by_all_tenants(self):
ctx = context.RequestContext('fake_uid', 'fake_pid_1', is_admin=True) ctx = context.RequestContext('fake_uid', 'fake_pid_1', is_admin=True)
self.stubs.Set(db_driver, 'share_get_all', self.mock_object(db_driver, 'share_get_all',
mock.Mock(return_value=_FAKE_LIST_OF_ALL_SHARES)) mock.Mock(return_value=_FAKE_LIST_OF_ALL_SHARES))
shares = self.api.get_all(ctx, {'all_tenants': 1}) shares = self.api.get_all(ctx, {'all_tenants': 1})
share_api.policy.check_policy.assert_called_once_with( share_api.policy.check_policy.assert_called_once_with(
ctx, 'share', 'get_all') ctx, 'share', 'get_all')
@ -211,8 +213,8 @@ class ShareAPITestCase(test.TestCase):
raise exception.NotAuthorized raise exception.NotAuthorized
ctx = context.RequestContext('fake_uid', 'fake_pid_1', is_admin=False) ctx = context.RequestContext('fake_uid', 'fake_pid_1', is_admin=False)
self.stubs.Set(share_api.policy, 'check_policy', self.mock_object(share_api.policy, 'check_policy',
mock.Mock(side_effect=fake_policy_checker)) mock.Mock(side_effect=fake_policy_checker))
self.assertRaises( self.assertRaises(
exception.NotAuthorized, exception.NotAuthorized,
self.api.get_all, self.api.get_all,
@ -228,10 +230,10 @@ class ShareAPITestCase(test.TestCase):
# NOTE(vponomaryov): if share_server_id provided, 'all_tenants' opt # NOTE(vponomaryov): if share_server_id provided, 'all_tenants' opt
# should not make any influence. # should not make any influence.
ctx = context.RequestContext('fake_uid', 'fake_pid_1', is_admin=True) ctx = context.RequestContext('fake_uid', 'fake_pid_1', is_admin=True)
self.stubs.Set(db_driver, 'share_get_all_by_share_server', self.mock_object(db_driver, 'share_get_all_by_share_server',
mock.Mock(return_value=_FAKE_LIST_OF_ALL_SHARES[2:])) mock.Mock(return_value=_FAKE_LIST_OF_ALL_SHARES[2:]))
self.stubs.Set(db_driver, 'share_get_all', mock.Mock()) self.mock_object(db_driver, 'share_get_all')
self.stubs.Set(db_driver, 'share_get_all_by_project', mock.Mock()) self.mock_object(db_driver, 'share_get_all_by_project')
shares = self.api.get_all( shares = self.api.get_all(
ctx, {'share_server_id': 'fake_server_3', 'all_tenants': 1}) ctx, {'share_server_id': 'fake_server_3', 'all_tenants': 1})
share_api.policy.check_policy.assert_has_calls([ share_api.policy.check_policy.assert_has_calls([
@ -248,8 +250,8 @@ class ShareAPITestCase(test.TestCase):
def test_get_all_admin_filter_by_name(self): def test_get_all_admin_filter_by_name(self):
ctx = context.RequestContext('fake_uid', 'fake_pid_2', is_admin=True) ctx = context.RequestContext('fake_uid', 'fake_pid_2', is_admin=True)
self.stubs.Set(db_driver, 'share_get_all_by_project', self.mock_object(db_driver, 'share_get_all_by_project',
mock.Mock(return_value=_FAKE_LIST_OF_ALL_SHARES[1:])) mock.Mock(return_value=_FAKE_LIST_OF_ALL_SHARES[1:]))
shares = self.api.get_all(ctx, {'name': 'bar'}) shares = self.api.get_all(ctx, {'name': 'bar'})
share_api.policy.check_policy.assert_has_calls([ share_api.policy.check_policy.assert_has_calls([
mock.call(ctx, 'share', 'get_all'), mock.call(ctx, 'share', 'get_all'),
@ -262,8 +264,8 @@ class ShareAPITestCase(test.TestCase):
def test_get_all_admin_filter_by_name_and_all_tenants(self): def test_get_all_admin_filter_by_name_and_all_tenants(self):
ctx = context.RequestContext('fake_uid', 'fake_pid_2', is_admin=True) ctx = context.RequestContext('fake_uid', 'fake_pid_2', is_admin=True)
self.stubs.Set(db_driver, 'share_get_all', self.mock_object(db_driver, 'share_get_all',
mock.Mock(return_value=_FAKE_LIST_OF_ALL_SHARES)) mock.Mock(return_value=_FAKE_LIST_OF_ALL_SHARES))
shares = self.api.get_all(ctx, {'name': 'foo', 'all_tenants': 1}) shares = self.api.get_all(ctx, {'name': 'foo', 'all_tenants': 1})
share_api.policy.check_policy.assert_has_calls([ share_api.policy.check_policy.assert_has_calls([
mock.call(ctx, 'share', 'get_all'), mock.call(ctx, 'share', 'get_all'),
@ -274,8 +276,8 @@ class ShareAPITestCase(test.TestCase):
def test_get_all_admin_filter_by_status(self): def test_get_all_admin_filter_by_status(self):
ctx = context.RequestContext('fake_uid', 'fake_pid_2', is_admin=True) ctx = context.RequestContext('fake_uid', 'fake_pid_2', is_admin=True)
self.stubs.Set(db_driver, 'share_get_all_by_project', self.mock_object(db_driver, 'share_get_all_by_project',
mock.Mock(return_value=_FAKE_LIST_OF_ALL_SHARES[1:])) mock.Mock(return_value=_FAKE_LIST_OF_ALL_SHARES[1:]))
shares = self.api.get_all(ctx, {'status': 'active'}) shares = self.api.get_all(ctx, {'status': 'active'})
share_api.policy.check_policy.assert_has_calls([ share_api.policy.check_policy.assert_has_calls([
mock.call(ctx, 'share', 'get_all'), mock.call(ctx, 'share', 'get_all'),
@ -288,8 +290,8 @@ class ShareAPITestCase(test.TestCase):
def test_get_all_admin_filter_by_status_and_all_tenants(self): def test_get_all_admin_filter_by_status_and_all_tenants(self):
ctx = context.RequestContext('fake_uid', 'fake_pid_2', is_admin=True) ctx = context.RequestContext('fake_uid', 'fake_pid_2', is_admin=True)
self.stubs.Set(db_driver, 'share_get_all', self.mock_object(db_driver, 'share_get_all',
mock.Mock(return_value=_FAKE_LIST_OF_ALL_SHARES)) mock.Mock(return_value=_FAKE_LIST_OF_ALL_SHARES))
shares = self.api.get_all(ctx, {'status': 'error', 'all_tenants': 1}) shares = self.api.get_all(ctx, {'status': 'error', 'all_tenants': 1})
share_api.policy.check_policy.assert_has_calls([ share_api.policy.check_policy.assert_has_calls([
mock.call(ctx, 'share', 'get_all'), mock.call(ctx, 'share', 'get_all'),
@ -301,8 +303,8 @@ class ShareAPITestCase(test.TestCase):
def test_get_all_non_admin_filter_by_all_tenants(self): def test_get_all_non_admin_filter_by_all_tenants(self):
# Expected share list only by project of non-admin user # Expected share list only by project of non-admin user
ctx = context.RequestContext('fake_uid', 'fake_pid_2', is_admin=False) ctx = context.RequestContext('fake_uid', 'fake_pid_2', is_admin=False)
self.stubs.Set(db_driver, 'share_get_all_by_project', self.mock_object(db_driver, 'share_get_all_by_project',
mock.Mock(return_value=_FAKE_LIST_OF_ALL_SHARES[1:])) mock.Mock(return_value=_FAKE_LIST_OF_ALL_SHARES[1:]))
shares = self.api.get_all(ctx, {'all_tenants': 1}) shares = self.api.get_all(ctx, {'all_tenants': 1})
share_api.policy.check_policy.assert_has_calls([ share_api.policy.check_policy.assert_has_calls([
mock.call(ctx, 'share', 'get_all'), mock.call(ctx, 'share', 'get_all'),
@ -315,8 +317,8 @@ class ShareAPITestCase(test.TestCase):
def test_get_all_non_admin_with_name_and_status_filters(self): def test_get_all_non_admin_with_name_and_status_filters(self):
ctx = context.RequestContext('fake_uid', 'fake_pid_2', is_admin=False) ctx = context.RequestContext('fake_uid', 'fake_pid_2', is_admin=False)
self.stubs.Set(db_driver, 'share_get_all_by_project', self.mock_object(db_driver, 'share_get_all_by_project',
mock.Mock(return_value=_FAKE_LIST_OF_ALL_SHARES[1:])) mock.Mock(return_value=_FAKE_LIST_OF_ALL_SHARES[1:]))
shares = self.api.get_all(ctx, {'name': 'bar', 'status': 'error'}) shares = self.api.get_all(ctx, {'name': 'bar', 'status': 'error'})
share_api.policy.check_policy.assert_has_calls([ share_api.policy.check_policy.assert_has_calls([
mock.call(ctx, 'share', 'get_all'), mock.call(ctx, 'share', 'get_all'),
@ -344,8 +346,8 @@ class ShareAPITestCase(test.TestCase):
]) ])
def test_get_all_with_sorting_valid(self): def test_get_all_with_sorting_valid(self):
self.stubs.Set(db_driver, 'share_get_all_by_project', self.mock_object(db_driver, 'share_get_all_by_project',
mock.Mock(return_value=_FAKE_LIST_OF_ALL_SHARES[0])) mock.Mock(return_value=_FAKE_LIST_OF_ALL_SHARES[0]))
ctx = context.RequestContext('fake_uid', 'fake_pid_1', is_admin=False) ctx = context.RequestContext('fake_uid', 'fake_pid_1', is_admin=False)
shares = self.api.get_all(ctx, sort_key='status', sort_dir='asc') shares = self.api.get_all(ctx, sort_key='status', sort_dir='asc')
share_api.policy.check_policy.assert_called_once_with( share_api.policy.check_policy.assert_called_once_with(
@ -357,8 +359,8 @@ class ShareAPITestCase(test.TestCase):
self.assertEqual(_FAKE_LIST_OF_ALL_SHARES[0], shares) self.assertEqual(_FAKE_LIST_OF_ALL_SHARES[0], shares)
def test_get_all_sort_key_invalid(self): def test_get_all_sort_key_invalid(self):
self.stubs.Set(db_driver, 'share_get_all_by_project', self.mock_object(db_driver, 'share_get_all_by_project',
mock.Mock(return_value=_FAKE_LIST_OF_ALL_SHARES[0])) mock.Mock(return_value=_FAKE_LIST_OF_ALL_SHARES[0]))
ctx = context.RequestContext('fake_uid', 'fake_pid_1', is_admin=False) ctx = context.RequestContext('fake_uid', 'fake_pid_1', is_admin=False)
self.assertRaises( self.assertRaises(
exception.InvalidInput, exception.InvalidInput,
@ -370,8 +372,8 @@ class ShareAPITestCase(test.TestCase):
ctx, 'share', 'get_all') ctx, 'share', 'get_all')
def test_get_all_sort_dir_invalid(self): def test_get_all_sort_dir_invalid(self):
self.stubs.Set(db_driver, 'share_get_all_by_project', self.mock_object(db_driver, 'share_get_all_by_project',
mock.Mock(return_value=_FAKE_LIST_OF_ALL_SHARES[0])) mock.Mock(return_value=_FAKE_LIST_OF_ALL_SHARES[0]))
ctx = context.RequestContext('fake_uid', 'fake_pid_1', is_admin=False) ctx = context.RequestContext('fake_uid', 'fake_pid_1', is_admin=False)
self.assertRaises( self.assertRaises(
exception.InvalidInput, exception.InvalidInput,
@ -383,8 +385,8 @@ class ShareAPITestCase(test.TestCase):
ctx, 'share', 'get_all') ctx, 'share', 'get_all')
def _get_all_filter_metadata_or_extra_specs_valid(self, key): def _get_all_filter_metadata_or_extra_specs_valid(self, key):
self.stubs.Set(db_driver, 'share_get_all_by_project', self.mock_object(db_driver, 'share_get_all_by_project',
mock.Mock(return_value=_FAKE_LIST_OF_ALL_SHARES[0])) mock.Mock(return_value=_FAKE_LIST_OF_ALL_SHARES[0]))
ctx = context.RequestContext('fake_uid', 'fake_pid_1', is_admin=False) ctx = context.RequestContext('fake_uid', 'fake_pid_1', is_admin=False)
search_opts = {key: {'foo1': 'bar1', 'foo2': 'bar2'}} search_opts = {key: {'foo1': 'bar1', 'foo2': 'bar2'}}
shares = self.api.get_all(ctx, search_opts=search_opts.copy()) shares = self.api.get_all(ctx, search_opts=search_opts.copy())
@ -402,8 +404,8 @@ class ShareAPITestCase(test.TestCase):
self._get_all_filter_metadata_or_extra_specs_valid(key='extra_specs') self._get_all_filter_metadata_or_extra_specs_valid(key='extra_specs')
def _get_all_filter_metadata_or_extra_specs_invalid(self, key): def _get_all_filter_metadata_or_extra_specs_invalid(self, key):
self.stubs.Set(db_driver, 'share_get_all_by_project', self.mock_object(db_driver, 'share_get_all_by_project',
mock.Mock(return_value=_FAKE_LIST_OF_ALL_SHARES[0])) mock.Mock(return_value=_FAKE_LIST_OF_ALL_SHARES[0]))
ctx = context.RequestContext('fake_uid', 'fake_pid_1', is_admin=False) ctx = context.RequestContext('fake_uid', 'fake_pid_1', is_admin=False)
search_opts = {key: "{'foo': 'bar'}"} search_opts = {key: "{'foo': 'bar'}"}
self.assertRaises(exception.InvalidInput, self.api.get_all, ctx, self.assertRaises(exception.InvalidInput, self.api.get_all, ctx,
@ -499,8 +501,8 @@ class ShareAPITestCase(test.TestCase):
server_returned = { server_returned = {
'id': 'fake_share_server_id', 'id': 'fake_share_server_id',
} }
self.stubs.Set(db_driver, 'share_server_update', self.mock_object(db_driver, 'share_server_update',
mock.Mock(return_value=server_returned)) mock.Mock(return_value=server_returned))
self.api.delete_share_server(self.context, server) self.api.delete_share_server(self.context, server)
db_driver.share_get_all_by_share_server.assert_called_once_with( db_driver.share_get_all_by_share_server.assert_called_once_with(
self.context, server['id']) self.context, server['id'])
@ -586,10 +588,10 @@ class ShareAPITestCase(test.TestCase):
'volume_type': None, 'volume_type': None,
'snapshot_id': share['snapshot_id'], 'snapshot_id': share['snapshot_id'],
} }
self.stubs.Set(db_driver, 'share_create', self.mock_object(db_driver, 'share_create',
mock.Mock(return_value=share)) mock.Mock(return_value=share))
self.stubs.Set(db_driver, 'share_update', self.mock_object(db_driver, 'share_update',
mock.Mock(return_value=share)) mock.Mock(return_value=share))
self.api.create(self.context, 'nfs', '1', 'fakename', 'fakedesc', self.api.create(self.context, 'nfs', '1', 'fakename', 'fakedesc',
snapshot=snapshot, availability_zone='fakeaz') snapshot=snapshot, availability_zone='fakeaz')
@ -633,10 +635,10 @@ class ShareAPITestCase(test.TestCase):
'volume_type': None, 'volume_type': None,
'snapshot_id': share['snapshot_id'], 'snapshot_id': share['snapshot_id'],
} }
self.stubs.Set(db_driver, 'share_create', self.mock_object(db_driver, 'share_create',
mock.Mock(return_value=share)) mock.Mock(return_value=share))
self.stubs.Set(db_driver, 'share_update', self.mock_object(db_driver, 'share_update',
mock.Mock(return_value=share)) mock.Mock(return_value=share))
self.api.create(self.context, 'nfs', '1', 'fakename', 'fakedesc', self.api.create(self.context, 'nfs', '1', 'fakename', 'fakedesc',
snapshot=snapshot, availability_zone='fakeaz') snapshot=snapshot, availability_zone='fakeaz')
@ -682,11 +684,12 @@ class ShareAPITestCase(test.TestCase):
'volume_type': volume_type, 'volume_type': volume_type,
'snapshot_id': share['snapshot_id'], 'snapshot_id': share['snapshot_id'],
} }
self.stubs.Set(db_driver, 'share_create', self.mock_object(db_driver, 'share_create',
mock.Mock(return_value=share)) mock.Mock(return_value=share))
self.stubs.Set(db_driver, 'share_update', self.mock_object(db_driver, 'share_update',
mock.Mock(return_value=share)) mock.Mock(return_value=share))
self.stubs.Set(db_driver, 'share_get', mock.Mock(return_value=share)) self.mock_object(db_driver, 'share_get',
mock.Mock(return_value=share))
# Call tested method # Call tested method
self.api.create(self.context, 'nfs', '1', 'fakename', 'fakedesc', self.api.create(self.context, 'nfs', '1', 'fakename', 'fakedesc',
@ -731,9 +734,10 @@ class ShareAPITestCase(test.TestCase):
for name in ('id', 'export_location', 'host', 'launched_at', for name in ('id', 'export_location', 'host', 'launched_at',
'terminated_at'): 'terminated_at'):
options.pop(name, None) options.pop(name, None)
self.stubs.Set(db_driver, 'share_create', self.mock_object(db_driver, 'share_create',
mock.Mock(return_value=share)) mock.Mock(return_value=share))
self.stubs.Set(db_driver, 'share_get', mock.Mock(return_value=share)) self.mock_object(db_driver, 'share_get',
mock.Mock(return_value=share))
# Call tested method # Call tested method
self.assertRaises(exception.InvalidInput, self.api.create, self.assertRaises(exception.InvalidInput, self.api.create,
@ -873,8 +877,8 @@ class ShareAPITestCase(test.TestCase):
search_opts = {'size': 'fakesize'} search_opts = {'size': 'fakesize'}
fake_objs = [{'name': 'fakename1'}, search_opts] fake_objs = [{'name': 'fakename1'}, search_opts]
ctx = context.RequestContext('fakeuid', 'fakepid', is_admin=False) ctx = context.RequestContext('fakeuid', 'fakepid', is_admin=False)
self.stubs.Set(db_driver, 'share_snapshot_get_all_by_project', self.mock_object(db_driver, 'share_snapshot_get_all_by_project',
mock.Mock(return_value=fake_objs)) mock.Mock(return_value=fake_objs))
result = self.api.get_all_snapshots(ctx, search_opts) result = self.api.get_all_snapshots(ctx, search_opts)
@ -886,8 +890,9 @@ class ShareAPITestCase(test.TestCase):
filters=search_opts) filters=search_opts)
def test_get_all_snapshots_with_sorting_valid(self): def test_get_all_snapshots_with_sorting_valid(self):
self.stubs.Set(db_driver, 'share_snapshot_get_all_by_project', self.mock_object(
mock.Mock(return_value=_FAKE_LIST_OF_ALL_SNAPSHOTS[0])) db_driver, 'share_snapshot_get_all_by_project',
mock.Mock(return_value=_FAKE_LIST_OF_ALL_SNAPSHOTS[0]))
ctx = context.RequestContext('fake_uid', 'fake_pid_1', is_admin=False) ctx = context.RequestContext('fake_uid', 'fake_pid_1', is_admin=False)
snapshots = self.api.get_all_snapshots( snapshots = self.api.get_all_snapshots(
ctx, sort_key='status', sort_dir='asc') ctx, sort_key='status', sort_dir='asc')
@ -898,8 +903,9 @@ class ShareAPITestCase(test.TestCase):
self.assertEqual(_FAKE_LIST_OF_ALL_SNAPSHOTS[0], snapshots) self.assertEqual(_FAKE_LIST_OF_ALL_SNAPSHOTS[0], snapshots)
def test_get_all_snapshots_sort_key_invalid(self): def test_get_all_snapshots_sort_key_invalid(self):
self.stubs.Set(db_driver, 'share_snapshot_get_all_by_project', self.mock_object(
mock.Mock(return_value=_FAKE_LIST_OF_ALL_SNAPSHOTS[0])) db_driver, 'share_snapshot_get_all_by_project',
mock.Mock(return_value=_FAKE_LIST_OF_ALL_SNAPSHOTS[0]))
ctx = context.RequestContext('fake_uid', 'fake_pid_1', is_admin=False) ctx = context.RequestContext('fake_uid', 'fake_pid_1', is_admin=False)
self.assertRaises( self.assertRaises(
exception.InvalidInput, exception.InvalidInput,
@ -911,8 +917,9 @@ class ShareAPITestCase(test.TestCase):
ctx, 'share', 'get_all_snapshots') ctx, 'share', 'get_all_snapshots')
def test_get_all_snapshots_sort_dir_invalid(self): def test_get_all_snapshots_sort_dir_invalid(self):
self.stubs.Set(db_driver, 'share_snapshot_get_all_by_project', self.mock_object(
mock.Mock(return_value=_FAKE_LIST_OF_ALL_SNAPSHOTS[0])) db_driver, 'share_snapshot_get_all_by_project',
mock.Mock(return_value=_FAKE_LIST_OF_ALL_SNAPSHOTS[0]))
ctx = context.RequestContext('fake_uid', 'fake_pid_1', is_admin=False) ctx = context.RequestContext('fake_uid', 'fake_pid_1', is_admin=False)
self.assertRaises( self.assertRaises(
exception.InvalidInput, exception.InvalidInput,
@ -932,8 +939,8 @@ class ShareAPITestCase(test.TestCase):
'access_to': 'fakeaccto', 'access_to': 'fakeaccto',
'access_level': level, 'access_level': level,
} }
self.stubs.Set(db_driver, 'share_access_create', self.mock_object(db_driver, 'share_access_create',
mock.Mock(return_value='fakeacc')) mock.Mock(return_value='fakeacc'))
access = self.api.allow_access(self.context, share, access = self.api.allow_access(self.context, share,
'fakeacctype', 'fakeaccto', 'fakeacctype', 'fakeaccto',
level) level)

View File

@ -47,10 +47,10 @@ class ShareDriverTestCase(test.TestCase):
def setUp(self): def setUp(self):
super(ShareDriverTestCase, self).setUp() super(ShareDriverTestCase, self).setUp()
self.utils = utils self.utils = utils
self.stubs.Set(self.utils, 'execute', fake_execute_with_raise) self.mock_object(self.utils, 'execute', fake_execute_with_raise)
self.time = time self.time = time
self.stubs.Set(self.time, 'sleep', fake_sleep) self.mock_object(self.time, 'sleep', fake_sleep)
self.stubs.Set(driver.CONF, 'driver_handles_share_servers', True) self.mock_object(driver.CONF, 'driver_handles_share_servers', True)
def test__try_execute(self): def test__try_execute(self):
execute_mixin = ShareDriverWithExecuteMixin( execute_mixin = ShareDriverWithExecuteMixin(
@ -66,7 +66,7 @@ class ShareDriverTestCase(test.TestCase):
def _instantiate_share_driver(self, network_config_group, def _instantiate_share_driver(self, network_config_group,
driver_handles_share_servers): driver_handles_share_servers):
self.stubs.Set(network, 'API', mock.Mock()) self.mock_object(network, 'API')
config = mock.Mock() config = mock.Mock()
config.append_config_values = mock.Mock() config.append_config_values = mock.Mock()
config.config_group = 'fake_config_group' config.config_group = 'fake_config_group'
@ -92,7 +92,7 @@ class ShareDriverTestCase(test.TestCase):
self._instantiate_share_driver("fake_network_config_group", True) self._instantiate_share_driver("fake_network_config_group", True)
def test_instantiate_share_driver_no_configuration(self): def test_instantiate_share_driver_no_configuration(self):
self.stubs.Set(network, 'API', mock.Mock()) self.mock_object(network, 'API')
share_driver = driver.ShareDriver(True, configuration=None) share_driver = driver.ShareDriver(True, configuration=None)
@ -138,7 +138,7 @@ class ShareDriverTestCase(test.TestCase):
@ddt.unpack @ddt.unpack
def test__verify_share_server_handling_valid_cases(self, opt, allowed): def test__verify_share_server_handling_valid_cases(self, opt, allowed):
conf = configuration.Configuration(None) conf = configuration.Configuration(None)
self.stubs.Set(conf, 'safe_get', mock.Mock(return_value=opt)) self.mock_object(conf, 'safe_get', mock.Mock(return_value=opt))
share_driver = driver.ShareDriver(allowed, configuration=conf) share_driver = driver.ShareDriver(allowed, configuration=conf)
self.assertTrue(conf.safe_get.celled) self.assertTrue(conf.safe_get.celled)
self.assertEqual(opt, share_driver.driver_handles_share_servers) self.assertEqual(opt, share_driver.driver_handles_share_servers)
@ -156,7 +156,7 @@ class ShareDriverTestCase(test.TestCase):
@ddt.unpack @ddt.unpack
def test__verify_share_server_handling_invalid_cases(self, opt, allowed): def test__verify_share_server_handling_invalid_cases(self, opt, allowed):
conf = configuration.Configuration(None) conf = configuration.Configuration(None)
self.stubs.Set(conf, 'safe_get', mock.Mock(return_value=opt)) self.mock_object(conf, 'safe_get', mock.Mock(return_value=opt))
self.assertRaises( self.assertRaises(
exception.ManilaException, exception.ManilaException,
driver.ShareDriver, allowed, configuration=conf) driver.ShareDriver, allowed, configuration=conf)

View File

@ -52,9 +52,8 @@ class ShareManagerTestCase(test.TestCase):
# to specific manager. # to specific manager.
self.share_manager = importutils.import_object( self.share_manager = importutils.import_object(
"manila.share.manager.ShareManager") "manila.share.manager.ShareManager")
self.stubs.Set(self.share_manager.driver, 'do_setup', mock.Mock()) self.mock_object(self.share_manager.driver, 'do_setup')
self.stubs.Set(self.share_manager.driver, 'check_for_setup_error', self.mock_object(self.share_manager.driver, 'check_for_setup_error')
mock.Mock())
self.context = context.get_admin_context() self.context = context.get_admin_context()
@staticmethod @staticmethod
@ -136,8 +135,8 @@ class ShareManagerTestCase(test.TestCase):
return service_ref return service_ref
def test_init_host_with_no_shares(self): def test_init_host_with_no_shares(self):
self.stubs.Set(self.share_manager.db, 'share_get_all_by_host', self.mock_object(self.share_manager.db, 'share_get_all_by_host',
mock.Mock(return_value=[])) mock.Mock(return_value=[]))
self.share_manager.init_host() self.share_manager.init_host()
@ -165,18 +164,19 @@ class ShareManagerTestCase(test.TestCase):
FakeAccessRule(state='error'), FakeAccessRule(state='error'),
] ]
share_server = 'fake_share_server_type_does_not_matter' share_server = 'fake_share_server_type_does_not_matter'
self.stubs.Set(self.share_manager.db, self.mock_object(self.share_manager.db,
'share_get_all_by_host', 'share_get_all_by_host',
mock.Mock(return_value=shares)) mock.Mock(return_value=shares))
self.stubs.Set(self.share_manager.driver, 'ensure_share', mock.Mock()) self.mock_object(self.share_manager.driver, 'ensure_share')
self.stubs.Set(self.share_manager, '_get_share_server', self.mock_object(self.share_manager, '_get_share_server',
mock.Mock(return_value=share_server)) mock.Mock(return_value=share_server))
self.stubs.Set(self.share_manager, 'publish_service_capabilities', self.mock_object(self.share_manager, 'publish_service_capabilities',
mock.Mock()) mock.Mock())
self.stubs.Set(self.share_manager.db, 'share_access_get_all_for_share', self.mock_object(self.share_manager.db,
mock.Mock(return_value=rules)) 'share_access_get_all_for_share',
self.stubs.Set(self.share_manager.driver, 'allow_access', mock.Mock(return_value=rules))
mock.Mock(side_effect=raise_share_access_exists)) self.mock_object(self.share_manager.driver, 'allow_access',
mock.Mock(side_effect=raise_share_access_exists))
# call of 'init_host' method # call of 'init_host' method
self.share_manager.init_host() self.share_manager.init_host()
@ -213,17 +213,16 @@ class ShareManagerTestCase(test.TestCase):
{'id': 'fake_id_3', 'status': 'available', 'name': 'fake_name_3'}, {'id': 'fake_id_3', 'status': 'available', 'name': 'fake_name_3'},
] ]
share_server = 'fake_share_server_type_does_not_matter' share_server = 'fake_share_server_type_does_not_matter'
self.stubs.Set(self.share_manager.db, self.mock_object(self.share_manager.db,
'share_get_all_by_host', 'share_get_all_by_host',
mock.Mock(return_value=shares)) mock.Mock(return_value=shares))
self.stubs.Set(self.share_manager.driver, 'ensure_share', self.mock_object(self.share_manager.driver, 'ensure_share',
mock.Mock(side_effect=raise_exception)) mock.Mock(side_effect=raise_exception))
self.stubs.Set(self.share_manager, '_get_share_server', self.mock_object(self.share_manager, '_get_share_server',
mock.Mock(return_value=share_server)) mock.Mock(return_value=share_server))
self.stubs.Set(self.share_manager, 'publish_service_capabilities', self.mock_object(self.share_manager, 'publish_service_capabilities')
mock.Mock()) self.mock_object(manager.LOG, 'error')
self.stubs.Set(manager.LOG, 'error', mock.Mock()) self.mock_object(manager.LOG, 'info')
self.stubs.Set(manager.LOG, 'info', mock.Mock())
# call of 'init_host' method # call of 'init_host' method
self.share_manager.init_host() self.share_manager.init_host()
@ -266,20 +265,20 @@ class ShareManagerTestCase(test.TestCase):
FakeAccessRule(state='error'), FakeAccessRule(state='error'),
] ]
share_server = 'fake_share_server_type_does_not_matter' share_server = 'fake_share_server_type_does_not_matter'
self.stubs.Set(self.share_manager.db, self.mock_object(self.share_manager.db,
'share_get_all_by_host', 'share_get_all_by_host',
mock.Mock(return_value=shares)) mock.Mock(return_value=shares))
self.stubs.Set(self.share_manager.driver, 'ensure_share', mock.Mock()) self.mock_object(self.share_manager.driver, 'ensure_share')
self.stubs.Set(self.share_manager, '_get_share_server', self.mock_object(self.share_manager, '_get_share_server',
mock.Mock(return_value=share_server)) mock.Mock(return_value=share_server))
self.stubs.Set(self.share_manager, 'publish_service_capabilities', self.mock_object(self.share_manager, 'publish_service_capabilities')
mock.Mock()) self.mock_object(manager.LOG, 'error')
self.stubs.Set(manager.LOG, 'error', mock.Mock()) self.mock_object(manager.LOG, 'info')
self.stubs.Set(manager.LOG, 'info', mock.Mock()) self.mock_object(self.share_manager.db,
self.stubs.Set(self.share_manager.db, 'share_access_get_all_for_share', 'share_access_get_all_for_share',
mock.Mock(return_value=rules)) mock.Mock(return_value=rules))
self.stubs.Set(self.share_manager.driver, 'allow_access', self.mock_object(self.share_manager.driver, 'allow_access',
mock.Mock(side_effect=raise_exception)) mock.Mock(side_effect=raise_exception))
# call of 'init_host' method # call of 'init_host' method
self.share_manager.init_host() self.share_manager.init_host()
@ -380,15 +379,16 @@ class ShareManagerTestCase(test.TestCase):
snapshot['progress'] = '99%' snapshot['progress'] = '99%'
return snapshot return snapshot
self.stubs.Set(self.share_manager.driver, "create_snapshot", self.mock_object(self.share_manager.driver, "create_snapshot",
_fake_create_snapshot) _fake_create_snapshot)
share = self._create_share() share = self._create_share()
share_id = share['id'] share_id = share['id']
snapshot = self._create_snapshot(share_id=share_id) snapshot = self._create_snapshot(share_id=share_id)
snapshot_id = snapshot['id'] snapshot_id = snapshot['id']
self.share_manager.create_snapshot(self.context, share_id, snapshot_id) self.share_manager.create_snapshot(self.context, share_id,
snapshot_id)
self.assertEqual(share_id, self.assertEqual(share_id,
db.share_snapshot_get(context.get_admin_context(), db.share_snapshot_get(context.get_admin_context(),
snapshot_id).share_id) snapshot_id).share_id)
@ -408,10 +408,10 @@ class ShareManagerTestCase(test.TestCase):
def _raise_not_found(self, *args, **kwargs): def _raise_not_found(self, *args, **kwargs):
raise exception.NotFound() raise exception.NotFound()
self.stubs.Set(self.share_manager.driver, "create_snapshot", self.mock_object(self.share_manager.driver, "create_snapshot",
mock.Mock(side_effect=_raise_not_found)) mock.Mock(side_effect=_raise_not_found))
self.stubs.Set(self.share_manager.driver, "delete_snapshot", self.mock_object(self.share_manager.driver, "delete_snapshot",
mock.Mock(side_effect=_raise_not_found)) mock.Mock(side_effect=_raise_not_found))
share = self._create_share() share = self._create_share()
share_id = share['id'] share_id = share['id']
@ -445,8 +445,8 @@ class ShareManagerTestCase(test.TestCase):
def _raise_share_snapshot_is_busy(self, *args, **kwargs): def _raise_share_snapshot_is_busy(self, *args, **kwargs):
raise exception.ShareSnapshotIsBusy(snapshot_name='fakename') raise exception.ShareSnapshotIsBusy(snapshot_name='fakename')
self.stubs.Set(self.share_manager.driver, "delete_snapshot", self.mock_object(self.share_manager.driver, "delete_snapshot",
mock.Mock(side_effect=_raise_share_snapshot_is_busy)) mock.Mock(side_effect=_raise_share_snapshot_is_busy))
share = self._create_share(status='ACTIVE') share = self._create_share(status='ACTIVE')
snapshot = self._create_snapshot(share_id=share['id']) snapshot = self._create_snapshot(share_id=share['id'])
snapshot_id = snapshot['id'] snapshot_id = snapshot['id']
@ -462,16 +462,16 @@ class ShareManagerTestCase(test.TestCase):
def test_create_share_with_share_network_driver_not_handles_servers(self): def test_create_share_with_share_network_driver_not_handles_servers(self):
manager.CONF.set_default('driver_handles_share_servers', False) manager.CONF.set_default('driver_handles_share_servers', False)
self.stubs.Set( self.mock_object(
self.share_manager.driver.configuration, 'safe_get', self.share_manager.driver.configuration, 'safe_get',
mock.Mock(return_value=False)) mock.Mock(return_value=False))
share_id = 'fake_share_id' share_id = 'fake_share_id'
share_network_id = 'fake_sn' share_network_id = 'fake_sn'
self.stubs.Set( self.mock_object(
self.share_manager.db, 'share_get', self.share_manager.db, 'share_get',
mock.Mock(return_value=self._create_share( mock.Mock(return_value=self._create_share(
share_network_id=share_network_id))) share_network_id=share_network_id)))
self.stubs.Set(self.share_manager.db, 'share_update', mock.Mock()) self.mock_object(self.share_manager.db, 'share_update')
self.assertRaises( self.assertRaises(
exception.ManilaException, exception.ManilaException,
@ -506,12 +506,12 @@ class ShareManagerTestCase(test.TestCase):
def test_create_share_with_share_network_server_creation_failed(self): def test_create_share_with_share_network_server_creation_failed(self):
fake_share = {'id': 'fake_share_id', 'share_network_id': 'fake_sn_id'} fake_share = {'id': 'fake_share_id', 'share_network_id': 'fake_sn_id'}
fake_server = {'id': 'fake_srv_id'} fake_server = {'id': 'fake_srv_id'}
self.stubs.Set(db, 'share_server_create', self.mock_object(db, 'share_server_create',
mock.Mock(return_value=fake_server)) mock.Mock(return_value=fake_server))
self.stubs.Set(db, 'share_update', self.mock_object(db, 'share_update',
mock.Mock(return_value=fake_share)) mock.Mock(return_value=fake_share))
self.stubs.Set(db, 'share_get', self.mock_object(db, 'share_get',
mock.Mock(return_value=fake_share)) mock.Mock(return_value=fake_share))
def raise_share_server_not_found(*args, **kwargs): def raise_share_server_not_found(*args, **kwargs):
raise exception.ShareServerNotFound( raise exception.ShareServerNotFound(
@ -520,10 +520,10 @@ class ShareManagerTestCase(test.TestCase):
def raise_manila_exception(*args, **kwargs): def raise_manila_exception(*args, **kwargs):
raise exception.ManilaException() raise exception.ManilaException()
self.stubs.Set(db, 'share_server_get_by_host_and_share_net_valid', self.mock_object(db, 'share_server_get_by_host_and_share_net_valid',
mock.Mock(side_effect=raise_share_server_not_found)) mock.Mock(side_effect=raise_share_server_not_found))
self.stubs.Set(self.share_manager, '_setup_server', self.mock_object(self.share_manager, '_setup_server',
mock.Mock(side_effect=raise_manila_exception)) mock.Mock(side_effect=raise_manila_exception))
self.assertRaises( self.assertRaises(
exception.ManilaException, exception.ManilaException,
@ -616,10 +616,10 @@ class ShareManagerTestCase(test.TestCase):
state='ERROR') state='ERROR')
share_id = share['id'] share_id = share['id']
fake_server = {'id': 'fake_srv_id'} fake_server = {'id': 'fake_srv_id'}
self.stubs.Set(db, 'share_server_create', self.mock_object(db, 'share_server_create',
mock.Mock(return_value=fake_server)) mock.Mock(return_value=fake_server))
self.stubs.Set(self.share_manager, '_setup_server', self.mock_object(self.share_manager, '_setup_server',
mock.Mock(return_value=fake_server)) mock.Mock(return_value=fake_server))
self.share_manager.create_share(self.context, share_id) self.share_manager.create_share(self.context, share_id)
@ -639,10 +639,10 @@ class ShareManagerTestCase(test.TestCase):
def _raise_not_found(self, *args, **kwargs): def _raise_not_found(self, *args, **kwargs):
raise exception.NotFound() raise exception.NotFound()
self.stubs.Set(self.share_manager.driver, "create_share", self.mock_object(self.share_manager.driver, "create_share",
mock.Mock(side_effect=_raise_not_found)) mock.Mock(side_effect=_raise_not_found))
self.stubs.Set(self.share_manager.driver, "delete_share", self.mock_object(self.share_manager.driver, "delete_share",
mock.Mock(side_effect=_raise_not_found)) mock.Mock(side_effect=_raise_not_found))
share = self._create_share() share = self._create_share()
share_id = share['id'] share_id = share['id']
@ -785,10 +785,10 @@ class ShareManagerTestCase(test.TestCase):
def _fake_deny_access(self, *args, **kwargs): def _fake_deny_access(self, *args, **kwargs):
raise exception.NotFound() raise exception.NotFound()
self.stubs.Set(self.share_manager.driver, "allow_access", self.mock_object(self.share_manager.driver, "allow_access",
_fake_allow_access) _fake_allow_access)
self.stubs.Set(self.share_manager.driver, "deny_access", self.mock_object(self.share_manager.driver, "deny_access",
_fake_deny_access) _fake_deny_access)
share = self._create_share() share = self._create_share()
share_id = share['id'] share_id = share['id']
@ -823,19 +823,17 @@ class ShareManagerTestCase(test.TestCase):
server_info = {'fake_server_info_key': 'fake_server_info_value'} server_info = {'fake_server_info_key': 'fake_server_info_value'}
# mock required stuff # mock required stuff
self.stubs.Set(self.share_manager.db, 'share_network_get', self.mock_object(self.share_manager.db, 'share_network_get',
mock.Mock(return_value=share_network)) mock.Mock(return_value=share_network))
self.stubs.Set(self.share_manager.driver, 'allocate_network', self.mock_object(self.share_manager.driver, 'allocate_network')
mock.Mock()) self.mock_object(self.share_manager, '_form_server_setup_info',
self.stubs.Set(self.share_manager, '_form_server_setup_info', mock.Mock(return_value=network_info))
mock.Mock(return_value=network_info)) self.mock_object(self.share_manager.driver, 'setup_server',
self.stubs.Set(self.share_manager.driver, 'setup_server', mock.Mock(return_value=server_info))
mock.Mock(return_value=server_info)) self.mock_object(self.share_manager.db,
self.stubs.Set(self.share_manager.db, 'share_server_backend_details_set')
'share_server_backend_details_set', self.mock_object(self.share_manager.db, 'share_server_update',
mock.Mock()) mock.Mock(return_value=share_server))
self.stubs.Set(self.share_manager.db, 'share_server_update',
mock.Mock(return_value=share_server))
# execute method _setup_server # execute method _setup_server
result = self.share_manager._setup_server( result = self.share_manager._setup_server(
@ -872,16 +870,15 @@ class ShareManagerTestCase(test.TestCase):
server_info = {} server_info = {}
# mock required stuff # mock required stuff
self.stubs.Set(self.share_manager.db, 'share_network_get', self.mock_object(self.share_manager.db, 'share_network_get',
mock.Mock(return_value=share_network)) mock.Mock(return_value=share_network))
self.stubs.Set(self.share_manager, '_form_server_setup_info', self.mock_object(self.share_manager, '_form_server_setup_info',
mock.Mock(return_value=network_info)) mock.Mock(return_value=network_info))
self.stubs.Set(self.share_manager.driver, 'setup_server', self.mock_object(self.share_manager.driver, 'setup_server',
mock.Mock(return_value=server_info)) mock.Mock(return_value=server_info))
self.stubs.Set(self.share_manager.db, 'share_server_update', self.mock_object(self.share_manager.db, 'share_server_update',
mock.Mock(return_value=share_server)) mock.Mock(return_value=share_server))
self.stubs.Set(self.share_manager.driver, 'allocate_network', self.mock_object(self.share_manager.driver, 'allocate_network')
mock.Mock())
# execute method _setup_server # execute method _setup_server
result = self.share_manager._setup_server( result = self.share_manager._setup_server(
@ -913,27 +910,24 @@ class ShareManagerTestCase(test.TestCase):
network_info = {'fake_network_info_key': 'fake_network_info_value'} network_info = {'fake_network_info_key': 'fake_network_info_value'}
if detail_data_proper: if detail_data_proper:
detail_data = {'server_details': server_info} detail_data = {'server_details': server_info}
self.stubs.Set(self.share_manager.db, self.mock_object(self.share_manager.db,
'share_server_backend_details_set', 'share_server_backend_details_set')
mock.Mock())
else: else:
detail_data = 'not dictionary detail data' detail_data = 'not dictionary detail data'
# Mock required parameters # Mock required parameters
self.stubs.Set(self.share_manager.db, 'share_network_get', self.mock_object(self.share_manager.db, 'share_network_get',
mock.Mock(return_value=share_network)) mock.Mock(return_value=share_network))
self.stubs.Set(self.share_manager.db, 'share_server_update', self.mock_object(self.share_manager.db, 'share_server_update')
mock.Mock())
for m in ['deallocate_network', 'allocate_network']: for m in ['deallocate_network', 'allocate_network']:
self.stubs.Set(self.share_manager.driver, m, mock.Mock()) self.mock_object(self.share_manager.driver, m)
self.stubs.Set(self.share_manager, '_form_server_setup_info', self.mock_object(self.share_manager, '_form_server_setup_info',
mock.Mock(return_value=network_info)) mock.Mock(return_value=network_info))
self.stubs.Set(self.share_manager.db, self.mock_object(self.share_manager.db,
'share_server_backend_details_set', 'share_server_backend_details_set')
mock.Mock()) self.mock_object(self.share_manager.driver, 'setup_server',
self.stubs.Set(self.share_manager.driver, 'setup_server', mock.Mock(side_effect=exception.ManilaException(
mock.Mock(side_effect=exception.ManilaException( detail_data=detail_data)))
detail_data=detail_data)))
# execute method _setup_server # execute method _setup_server
self.assertRaises( self.assertRaises(

View File

@ -106,8 +106,8 @@ class ShareRpcAPITestCase(test.TestCase):
if expected_retval: if expected_retval:
return expected_retval return expected_retval
self.stubs.Set(self.rpcapi.client, "prepare", _fake_prepare_method) self.mock_object(self.rpcapi.client, "prepare", _fake_prepare_method)
self.stubs.Set(self.rpcapi.client, rpc_method, _fake_rpc_method) self.mock_object(self.rpcapi.client, rpc_method, _fake_rpc_method)
retval = getattr(self.rpcapi, method)(self.ctxt, **kwargs) retval = getattr(self.rpcapi, method)(self.ctxt, **kwargs)

View File

@ -60,18 +60,18 @@ class VolumeTypesTestCase(test.TestCase):
@ddt.data({}, fake_type, fake_type_w_extra, fake_types) @ddt.data({}, fake_type, fake_type_w_extra, fake_types)
def test_get_all_types(self, vol_type): def test_get_all_types(self, vol_type):
self.stubs.Set(db, self.mock_object(db,
'volume_type_get_all', 'volume_type_get_all',
mock.Mock(return_value=vol_type)) mock.Mock(return_value=vol_type))
returned_type = volume_types.get_all_types(self.context) returned_type = volume_types.get_all_types(self.context)
self.assertItemsEqual(vol_type, returned_type) self.assertItemsEqual(vol_type, returned_type)
def test_get_all_types_filter(self): def test_get_all_types_filter(self):
vol_type = self.fake_type_w_extra vol_type = self.fake_type_w_extra
search_filter = {"extra_specs": {"gold": "True"}} search_filter = {"extra_specs": {"gold": "True"}}
self.stubs.Set(db, self.mock_object(db,
'volume_type_get_all', 'volume_type_get_all',
mock.Mock(return_value=vol_type)) mock.Mock(return_value=vol_type))
returned_type = volume_types.get_all_types(self.context, returned_type = volume_types.get_all_types(self.context,
search_opts=search_filter) search_opts=search_filter)
self.assertItemsEqual(vol_type, returned_type) self.assertItemsEqual(vol_type, returned_type)
@ -82,9 +82,9 @@ class VolumeTypesTestCase(test.TestCase):
def test_get_volume_type_extra_specs(self): def test_get_volume_type_extra_specs(self):
vol_type = self.fake_type_w_extra['test_with_extra'] vol_type = self.fake_type_w_extra['test_with_extra']
self.stubs.Set(db, self.mock_object(db,
'volume_type_get', 'volume_type_get',
mock.Mock(return_value=vol_type)) mock.Mock(return_value=vol_type))
id = vol_type['id'] id = vol_type['id']
extra_spec = volume_types.get_volume_type_extra_specs(id, key='gold') extra_spec = volume_types.get_volume_type_extra_specs(id, key='gold')
self.assertEqual(vol_type['extra_specs']['gold'], extra_spec) self.assertEqual(vol_type['extra_specs']['gold'], extra_spec)
@ -95,9 +95,9 @@ class VolumeTypesTestCase(test.TestCase):
vol_type1 = self.fake_type['test'] vol_type1 = self.fake_type['test']
vol_type2 = self.fake_type_w_extra['test_with_extra'] vol_type2 = self.fake_type_w_extra['test_with_extra']
expeted_diff = {'extra_specs': {u'gold': (None, u'True')}} expeted_diff = {'extra_specs': {u'gold': (None, u'True')}}
self.stubs.Set(db, self.mock_object(db,
'volume_type_get', 'volume_type_get',
mock.Mock(side_effect=[vol_type1, vol_type2])) mock.Mock(side_effect=[vol_type1, vol_type2]))
(diff, equal) = volume_types.volume_types_diff(self.context, (diff, equal) = volume_types.volume_types_diff(self.context,
vol_type1['id'], vol_type1['id'],
vol_type2['id']) vol_type2['id'])
@ -106,9 +106,9 @@ class VolumeTypesTestCase(test.TestCase):
def test_volume_types_diff_equal(self): def test_volume_types_diff_equal(self):
vol_type = self.fake_type['test'] vol_type = self.fake_type['test']
self.stubs.Set(db, self.mock_object(db,
'volume_type_get', 'volume_type_get',
mock.Mock(return_value=vol_type)) mock.Mock(return_value=vol_type))
(diff, equal) = volume_types.volume_types_diff(self.context, (diff, equal) = volume_types.volume_types_diff(self.context,
vol_type['id'], vol_type['id'],
vol_type['id']) vol_type['id'])

View File

@ -69,7 +69,7 @@ class ContextTestCase(test.TestCase):
def fake_warn(log_msg, other_args): def fake_warn(log_msg, other_args):
info['log_msg'] = log_msg % other_args info['log_msg'] = log_msg % other_args
self.stubs.Set(context.LOG, 'warn', fake_warn) self.mock_object(context.LOG, 'warn', fake_warn)
c = context.RequestContext('user', c = context.RequestContext('user',
'project', 'project',

View File

@ -658,7 +658,7 @@ class DbQuotaDriverTestCase(test.TestCase):
self.calls.append('quota_class_get_all_by_name') self.calls.append('quota_class_get_all_by_name')
self.assertEqual(quota_class, 'test_class') self.assertEqual(quota_class, 'test_class')
return dict(gigabytes=500, shares=10, ) return dict(gigabytes=500, shares=10, )
self.stubs.Set(db, 'quota_class_get_all_by_name', fake_qcgabn) self.mock_object(db, 'quota_class_get_all_by_name', fake_qcgabn)
def test_get_class_quotas(self): def test_get_class_quotas(self):
self._stub_quota_class_get_all_by_name() self._stub_quota_class_get_all_by_name()
@ -702,10 +702,10 @@ class DbQuotaDriverTestCase(test.TestCase):
return dict(shares=dict(in_use=2, reserved=0), return dict(shares=dict(in_use=2, reserved=0),
gigabytes=dict(in_use=10, reserved=0), ) gigabytes=dict(in_use=10, reserved=0), )
self.stubs.Set(db, 'quota_get_all_by_project_and_user', fake_qgabpu) self.mock_object(db, 'quota_get_all_by_project_and_user', fake_qgabpu)
self.stubs.Set(db, 'quota_get_all_by_project', fake_qgabp) self.mock_object(db, 'quota_get_all_by_project', fake_qgabp)
self.stubs.Set(db, 'quota_usage_get_all_by_project_and_user', self.mock_object(db, 'quota_usage_get_all_by_project_and_user',
fake_qugabpu) fake_qugabpu)
self._stub_quota_class_get_all_by_name() self._stub_quota_class_get_all_by_name()
@ -735,8 +735,8 @@ class DbQuotaDriverTestCase(test.TestCase):
return dict(shares=dict(in_use=2, reserved=0), return dict(shares=dict(in_use=2, reserved=0),
gigabytes=dict(in_use=10, reserved=0), ) gigabytes=dict(in_use=10, reserved=0), )
self.stubs.Set(db, 'quota_get_all_by_project', fake_qgabp) self.mock_object(db, 'quota_get_all_by_project', fake_qgabp)
self.stubs.Set(db, 'quota_usage_get_all_by_project', fake_qugabp) self.mock_object(db, 'quota_usage_get_all_by_project', fake_qugabp)
self._stub_quota_class_get_all_by_name() self._stub_quota_class_get_all_by_name()
@ -905,12 +905,12 @@ class DbQuotaDriverTestCase(test.TestCase):
self.calls.append('quota_get_all_by_project_and_user') self.calls.append('quota_get_all_by_project_and_user')
return {'shares': 2} return {'shares': 2}
self.stubs.Set(self.driver, 'get_project_quotas', self.mock_object(self.driver, 'get_project_quotas',
fake_get_project_quotas) fake_get_project_quotas)
self.stubs.Set(self.driver, 'get_user_quotas', self.mock_object(self.driver, 'get_user_quotas',
fake_get_user_quotas) fake_get_user_quotas)
self.stubs.Set(db, 'quota_get_all_by_project_and_user', self.mock_object(db, 'quota_get_all_by_project_and_user',
fake_qgabpau) fake_qgabpau)
def test_get_settable_quotas_with_user(self): def test_get_settable_quotas_with_user(self):
self._stub_get_settable_quotas() self._stub_get_settable_quotas()
@ -956,8 +956,8 @@ class DbQuotaDriverTestCase(test.TestCase):
return dict((k, dict(limit=v.default)) return dict((k, dict(limit=v.default))
for k, v in resources.items()) for k, v in resources.items())
self.stubs.Set(self.driver, 'get_project_quotas', self.mock_object(self.driver, 'get_project_quotas',
fake_get_project_quotas) fake_get_project_quotas)
def test_get_quotas_has_sync_unknown(self): def test_get_quotas_has_sync_unknown(self):
self._stub_get_project_quotas() self._stub_get_project_quotas()
@ -1009,7 +1009,7 @@ class DbQuotaDriverTestCase(test.TestCase):
self.calls.append(('quota_reserve', expire, until_refresh, self.calls.append(('quota_reserve', expire, until_refresh,
max_age)) max_age))
return ['resv-1', 'resv-2', 'resv-3'] return ['resv-1', 'resv-2', 'resv-3']
self.stubs.Set(db, 'quota_reserve', fake_quota_reserve) self.mock_object(db, 'quota_reserve', fake_quota_reserve)
def test_reserve_bad_expire(self): def test_reserve_bad_expire(self):
self._stub_get_project_quotas() self._stub_get_project_quotas()
@ -1100,8 +1100,8 @@ class DbQuotaDriverTestCase(test.TestCase):
def fake_quota_delete_all_by_project(context, project_id): def fake_quota_delete_all_by_project(context, project_id):
self.calls.append(('quota_destroy_all_by_project', project_id)) self.calls.append(('quota_destroy_all_by_project', project_id))
return None return None
self.stubs.Set(sqa_api, 'quota_destroy_all_by_project', self.mock_object(sqa_api, 'quota_destroy_all_by_project',
fake_quota_delete_all_by_project) fake_quota_delete_all_by_project)
def test_delete_by_project(self): def test_delete_by_project(self):
self._stub_quota_delete_all_by_project() self._stub_quota_delete_all_by_project()
@ -1196,13 +1196,15 @@ class QuotaReserveSqlAlchemyTestCase(test.TestCase):
return reservation_ref return reservation_ref
self.stubs.Set(sqa_api, 'get_session', fake_get_session) self.mock_object(sqa_api, 'get_session', fake_get_session)
self.stubs.Set(sqa_api, '_get_project_quota_usages', self.mock_object(sqa_api, '_get_project_quota_usages',
fake_get_project_quota_usages) fake_get_project_quota_usages)
self.stubs.Set(sqa_api, '_get_user_quota_usages', self.mock_object(sqa_api, '_get_user_quota_usages',
fake_get_user_quota_usages) fake_get_user_quota_usages)
self.stubs.Set(sqa_api, '_quota_usage_create', fake_quota_usage_create) self.mock_object(sqa_api, '_quota_usage_create',
self.stubs.Set(sqa_api, '_reservation_create', fake_reservation_create) fake_quota_usage_create)
self.mock_object(sqa_api, '_reservation_create',
fake_reservation_create)
self.patcher = mock.patch.object(timeutils, 'utcnow') self.patcher = mock.patch.object(timeutils, 'utcnow')
self.mock_utcnow = self.patcher.start() self.mock_utcnow = self.patcher.start()

View File

@ -233,7 +233,7 @@ class GenericUtilsTestCase(test.TestCase):
raise exception.ProcessExecutionError raise exception.ProcessExecutionError
return 'fakecontents', None return 'fakecontents', None
self.stubs.Set(utils, 'execute', fake_execute) self.mock_object(utils, 'execute', fake_execute)
contents = utils.read_file_as_root('good') contents = utils.read_file_as_root('good')
self.assertEqual(contents, 'fakecontents') self.assertEqual(contents, 'fakecontents')
self.assertRaises(exception.FileNotFound, self.assertRaises(exception.FileNotFound,
@ -243,7 +243,7 @@ class GenericUtilsTestCase(test.TestCase):
def fake_execute(*args, **kwargs): def fake_execute(*args, **kwargs):
if args[0] == 'chown': if args[0] == 'chown':
fake_execute.uid = args[1] fake_execute.uid = args[1]
self.stubs.Set(utils, 'execute', fake_execute) self.mock_object(utils, 'execute', fake_execute)
with tempfile.NamedTemporaryFile() as f: with tempfile.NamedTemporaryFile() as f:
with utils.temporary_chown(f.name, owner_uid=2): with utils.temporary_chown(f.name, owner_uid=2):

View File

@ -47,12 +47,12 @@ class CinderApiTestCase(test.TestCase):
self.api = cinder.API() self.api = cinder.API()
self.cinderclient = FakeCinderClient() self.cinderclient = FakeCinderClient()
self.ctx = context.get_admin_context() self.ctx = context.get_admin_context()
self.stubs.Set(cinder, 'cinderclient', self.mock_object(cinder, 'cinderclient',
mock.Mock(return_value=self.cinderclient)) mock.Mock(return_value=self.cinderclient))
self.stubs.Set(cinder, '_untranslate_volume_summary_view', self.mock_object(cinder, '_untranslate_volume_summary_view',
lambda ctx, vol: vol) lambda ctx, vol: vol)
self.stubs.Set(cinder, '_untranslate_snapshot_summary_view', self.mock_object(cinder, '_untranslate_snapshot_summary_view',
lambda ctx, snap: snap) lambda ctx, snap: snap)
def test_get(self): def test_get(self):
volume_id = 'volume_id1' volume_id = 'volume_id1'
@ -133,56 +133,52 @@ class CinderApiTestCase(test.TestCase):
self.api.update, self.ctx, '', '') self.api.update, self.ctx, '', '')
def test_reserve_volume(self): def test_reserve_volume(self):
self.stubs.Set(self.cinderclient.volumes, 'reserve', mock.Mock()) self.mock_object(self.cinderclient.volumes, 'reserve')
self.api.reserve_volume(self.ctx, 'id1') self.api.reserve_volume(self.ctx, 'id1')
self.cinderclient.volumes.reserve.assert_called_once_with('id1') self.cinderclient.volumes.reserve.assert_called_once_with('id1')
def test_unreserve_volume(self): def test_unreserve_volume(self):
self.stubs.Set(self.cinderclient.volumes, 'unreserve', mock.Mock()) self.mock_object(self.cinderclient.volumes, 'unreserve')
self.api.unreserve_volume(self.ctx, 'id1') self.api.unreserve_volume(self.ctx, 'id1')
self.cinderclient.volumes.unreserve.assert_called_once_with('id1') self.cinderclient.volumes.unreserve.assert_called_once_with('id1')
def test_begin_detaching(self): def test_begin_detaching(self):
self.stubs.Set(self.cinderclient.volumes, 'begin_detaching', self.mock_object(self.cinderclient.volumes, 'begin_detaching')
mock.Mock())
self.api.begin_detaching(self.ctx, 'id1') self.api.begin_detaching(self.ctx, 'id1')
self.cinderclient.volumes.begin_detaching.assert_called_once_with( self.cinderclient.volumes.begin_detaching.assert_called_once_with(
'id1') 'id1')
def test_roll_detaching(self): def test_roll_detaching(self):
self.stubs.Set(self.cinderclient.volumes, 'roll_detaching', self.mock_object(self.cinderclient.volumes, 'roll_detaching')
mock.Mock())
self.api.roll_detaching(self.ctx, 'id1') self.api.roll_detaching(self.ctx, 'id1')
self.cinderclient.volumes.roll_detaching.assert_called_once_with('id1') self.cinderclient.volumes.roll_detaching.assert_called_once_with('id1')
def test_attach(self): def test_attach(self):
self.stubs.Set(self.cinderclient.volumes, 'attach', mock.Mock()) self.mock_object(self.cinderclient.volumes, 'attach')
self.api.attach(self.ctx, 'id1', 'uuid', 'point') self.api.attach(self.ctx, 'id1', 'uuid', 'point')
self.cinderclient.volumes.attach.assert_called_once_with('id1', self.cinderclient.volumes.attach.assert_called_once_with('id1',
'uuid', 'uuid',
'point') 'point')
def test_detach(self): def test_detach(self):
self.stubs.Set(self.cinderclient.volumes, 'detach', mock.Mock()) self.mock_object(self.cinderclient.volumes, 'detach')
self.api.detach(self.ctx, 'id1') self.api.detach(self.ctx, 'id1')
self.cinderclient.volumes.detach.assert_called_once_with('id1') self.cinderclient.volumes.detach.assert_called_once_with('id1')
def test_initialize_connection(self): def test_initialize_connection(self):
self.stubs.Set(self.cinderclient.volumes, 'initialize_connection', self.mock_object(self.cinderclient.volumes, 'initialize_connection')
mock.Mock())
self.api.initialize_connection(self.ctx, 'id1', 'connector') self.api.initialize_connection(self.ctx, 'id1', 'connector')
self.cinderclient.volumes.initialize_connection.\ self.cinderclient.volumes.initialize_connection.\
assert_called_once_with('id1', 'connector') assert_called_once_with('id1', 'connector')
def test_terminate_connection(self): def test_terminate_connection(self):
self.stubs.Set(self.cinderclient.volumes, 'terminate_connection', self.mock_object(self.cinderclient.volumes, 'terminate_connection')
mock.Mock())
self.api.terminate_connection(self.ctx, 'id1', 'connector') self.api.terminate_connection(self.ctx, 'id1', 'connector')
self.cinderclient.volumes.terminate_connection.\ self.cinderclient.volumes.terminate_connection.\
assert_called_once_with('id1', 'connector') assert_called_once_with('id1', 'connector')
def test_delete(self): def test_delete(self):
self.stubs.Set(self.cinderclient.volumes, 'delete', mock.Mock()) self.mock_object(self.cinderclient.volumes, 'delete')
self.api.delete(self.ctx, 'id1') self.api.delete(self.ctx, 'id1')
self.cinderclient.volumes.delete.assert_called_once_with('id1') self.cinderclient.volumes.delete.assert_called_once_with('id1')
@ -212,8 +208,7 @@ class CinderApiTestCase(test.TestCase):
self.assertEqual(result['id'], 'created_id') self.assertEqual(result['id'], 'created_id')
def test_delete_snapshot(self): def test_delete_snapshot(self):
self.stubs.Set(self.cinderclient.volume_snapshots, self.mock_object(self.cinderclient.volume_snapshots, 'delete')
'delete', mock.Mock())
self.api.delete_snapshot(self.ctx, 'id1') self.api.delete_snapshot(self.ctx, 'id1')
self.cinderclient.volume_snapshots.delete.assert_called_once_with( self.cinderclient.volume_snapshots.delete.assert_called_once_with(
'id1') 'id1')