Merge "Use mock instead of fixtures when appropriate"

This commit is contained in:
Jenkins 2015-03-03 01:27:54 +00:00 committed by Gerrit Code Review
commit 947edccabe
4 changed files with 13 additions and 33 deletions

View File

@ -20,8 +20,8 @@ import os
import shutil import shutil
import stat import stat
import tempfile import tempfile
import time
import fixtures
import mock import mock
from oslo_concurrency import processutils from oslo_concurrency import processutils
from oslo_config import cfg from oslo_config import cfg
@ -132,16 +132,9 @@ image=kernel
""" """
@mock.patch.object(time, 'sleep', lambda seconds: None)
class PhysicalWorkTestCase(tests_base.TestCase): class PhysicalWorkTestCase(tests_base.TestCase):
def setUp(self):
super(PhysicalWorkTestCase, self).setUp()
def noop(*args, **kwargs):
pass
self.useFixture(fixtures.MonkeyPatch('time.sleep', noop))
def _mock_calls(self, name_list): def _mock_calls(self, name_list):
patch_list = [mock.patch.object(utils, name) for name in name_list] patch_list = [mock.patch.object(utils, name) for name in name_list]
mock_list = [patcher.start() for patcher in patch_list] mock_list = [patcher.start() for patcher in patch_list]

View File

@ -20,7 +20,6 @@
import os import os
import tempfile import tempfile
import fixtures
import mock import mock
from oslo_concurrency import processutils from oslo_concurrency import processutils
from oslo_config import cfg from oslo_config import cfg
@ -703,9 +702,10 @@ class PXEDriverTestCase(db_base.DbTestCase):
@mock.patch.object(deploy_utils, 'notify_deploy_complete') @mock.patch.object(deploy_utils, 'notify_deploy_complete')
@mock.patch.object(deploy_utils, 'switch_pxe_config') @mock.patch.object(deploy_utils, 'switch_pxe_config')
@mock.patch.object(iscsi_deploy, 'InstanceImageCache') @mock.patch.object(iscsi_deploy, 'InstanceImageCache')
def _test_continue_deploy(self, is_localboot, mock_image_cache, @mock.patch.object(deploy_utils, 'deploy')
mock_switch_config, notify_mock, def _test_continue_deploy(self, is_localboot, mock_deploy,
mock_node_boot_dev, mock_clean_pxe): mock_image_cache, mock_switch_config,
notify_mock, mock_node_boot_dev, mock_clean_pxe):
token_path = self._create_token_file() token_path = self._create_token_file()
# set local boot # set local boot
@ -720,15 +720,9 @@ class PXEDriverTestCase(db_base.DbTestCase):
self.node.save() self.node.save()
root_uuid = "12345678-1234-1234-1234-1234567890abcxyz" root_uuid = "12345678-1234-1234-1234-1234567890abcxyz"
mock_deploy.return_value = root_uuid
boot_mode = None boot_mode = None
def fake_deploy(**kwargs):
return root_uuid
self.useFixture(fixtures.MonkeyPatch(
'ironic.drivers.modules.deploy_utils.deploy',
fake_deploy))
with task_manager.acquire(self.context, self.node.uuid) as task: with task_manager.acquire(self.context, self.node.uuid) as task:
task.driver.vendor._continue_deploy( task.driver.vendor._continue_deploy(
task, address='123456', iqn='aaa-bbb', key='fake-56789') task, address='123456', iqn='aaa-bbb', key='fake-56789')

View File

@ -15,7 +15,8 @@
"""Test class for Ironic SSH power driver.""" """Test class for Ironic SSH power driver."""
import fixtures import tempfile
import mock import mock
from oslo_concurrency import processutils from oslo_concurrency import processutils
from oslo_config import cfg from oslo_config import cfg
@ -74,8 +75,8 @@ class SSHValidateParametersTestCase(db_base.DbTestCase):
def test__parse_driver_info_good_file(self): def test__parse_driver_info_good_file(self):
# make sure we get back the expected things # make sure we get back the expected things
d_info = db_utils.get_test_ssh_info('file') d_info = db_utils.get_test_ssh_info('file')
tempdir = self.useFixture(fixtures.TempDir()) tempdir = tempfile.mkdtemp()
key_path = tempdir.path + '/foo' key_path = tempdir + '/foo'
open(key_path, 'wt').close() open(key_path, 'wt').close()
d_info['ssh_key_filename'] = key_path d_info['ssh_key_filename'] = key_path
node = obj_utils.get_test_node( node = obj_utils.get_test_node(

View File

@ -13,7 +13,7 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import fixtures import eventlet
import mock import mock
from testtools.matchers import HasLength from testtools.matchers import HasLength
@ -23,17 +23,9 @@ from ironic.common import utils
from ironic.tests import base from ironic.tests import base
@mock.patch.object(eventlet.greenthread, 'sleep', lambda seconds: None)
class DiskPartitionerTestCase(base.TestCase): class DiskPartitionerTestCase(base.TestCase):
def setUp(self):
super(DiskPartitionerTestCase, self).setUp()
def noop(*args, **kwargs):
pass
self.useFixture(fixtures.MonkeyPatch('eventlet.greenthread.sleep',
noop))
def test_add_partition(self): def test_add_partition(self):
dp = disk_partitioner.DiskPartitioner('/dev/fake') dp = disk_partitioner.DiskPartitioner('/dev/fake')
dp.add_partition(1024) dp.add_partition(1024)