Fake out sleeps in unit tests

Just a minor cleanup, had a few tests that were doing sleeps
(or looping calls for those that prefer it) that were being
executed to test timeouts in the unit tests.  No value in
actually *waiting* for these, so this patch just mocks them
out so we still test the procedure but don't actually have
to wait.

This shaves about 30 seconds or so off of the unit test run,
not a huge deal, but every little bit helps IMO.

Also noticed a LOG.debug message in the test_extensions file
that wasn't picked up in other cleanup work so I removed that
debug log call as well.

Change-Id: I415ac75816e8a0f4c48c61b23391df1a9a016d62
This commit is contained in:
John Griffith 2015-05-01 10:35:30 -06:00
parent 7a4dd75265
commit 85b9a70a41
4 changed files with 17 additions and 5 deletions

View File

@ -16,11 +16,13 @@ import os
import os.path
import string
import mock
from oslo_log import log as logging
from cinder.brick import exception
from cinder.brick.initiator import linuxscsi
from cinder import test
from cinder.tests.unit import utils
LOG = logging.getLogger(__name__)
@ -68,6 +70,8 @@ class LinuxSCSITestCase(test.TestCase):
('tee -a /sys/block/sdc/device/delete')]
self.assertEqual(expected_commands, self.cmds)
@mock.patch('cinder.openstack.common.loopingcall.FixedIntervalLoopingCall',
new=utils.ZeroIntervalLoopingCall)
def test_wait_for_volume_removal(self):
fake_path = '/dev/disk/by-path/fake-iscsi-iqn-lun-0'
self.stubs.Set(os.path, "exists", lambda x: True)

View File

@ -37,5 +37,4 @@ class ExtensionsTest(integrated_helpers._IntegratedTestBase):
"""Simple check that fox-n-socks works."""
response = self.api.api_request('/foxnsocks')
foxnsocks = response.text
LOG.debug("foxnsocks: %s" % foxnsocks)
self.assertEqual('Try to say this Mr. Knox, sir...', foxnsocks)

View File

@ -24,6 +24,7 @@ import shutil
import socket
import sys
import tempfile
import time
import eventlet
import mock
@ -39,7 +40,7 @@ from taskflow.engines.action_engine import engine
from cinder.backup import driver as backup_driver
from cinder.brick.local_dev import lvm as brick_lvm
from cinder import compute
from cinder.compute import nova
from cinder import context
from cinder import db
from cinder import exception
@ -2632,6 +2633,8 @@ class VolumeTestCase(BaseVolumeTestCase):
self.assertNotIn(iscsi_target, targets)
targets.append(iscsi_target)
# FIXME(jdg): What is this actually testing?
# We never call the internal _check method?
for _index in xrange(100):
tests_utils.create_volume(self.context, **self.volume_params)
for volume_id in volume_ids:
@ -3818,7 +3821,7 @@ class VolumeTestCase(BaseVolumeTestCase):
self.assertIsNone(volume['migration_status'])
self.assertEqual('available', volume['status'])
@mock.patch.object(compute.nova.API, 'update_server_volume')
@mock.patch.object(nova.API, 'update_server_volume')
@mock.patch('cinder.volume.manager.VolumeManager.'
'migrate_volume_completion')
@mock.patch('cinder.db.volume_get')
@ -3843,7 +3846,7 @@ class VolumeTestCase(BaseVolumeTestCase):
fake_new_volume['id'],
error=False)
@mock.patch.object(compute.nova.API, 'update_server_volume')
@mock.patch.object(nova.API, 'update_server_volume')
@mock.patch('cinder.volume.manager.VolumeManager.'
'migrate_volume_completion')
@mock.patch('cinder.db.volume_get')
@ -4020,7 +4023,8 @@ class VolumeTestCase(BaseVolumeTestCase):
mock.patch.object(volume_rpcapi.VolumeAPI, 'create_volume') as \
mock_create_volume, \
mock.patch.object(self.volume, '_clean_temporary_volume') as \
clean_temporary_volume:
clean_temporary_volume, \
mock.patch.object(time, 'sleep'):
# Exception case at the timeout of the volume creation
mock_create_volume.side_effect = fake_create_volume

View File

@ -19,6 +19,7 @@ from oslo_log import log as logging
from cinder import context
from cinder import exception
from cinder import test
from cinder.tests.unit import utils
from cinder.volume.drivers import xio
from cinder.volume import qos_specs
from cinder.volume import volume_types
@ -1194,6 +1195,8 @@ class XIOISEDriverTestCase(object):
self.setup_driver()
self.driver.create_snapshot(SNAPSHOT1)
@mock.patch('cinder.openstack.common.loopingcall.FixedIntervalLoopingCall',
new=utils.ZeroIntervalLoopingCall)
def test_negative_create_snapshot_invalid_state_recover(self, mock_req):
ctxt = context.get_admin_context()
extra_specs = {"Feature:Pool": "1",
@ -1218,6 +1221,8 @@ class XIOISEDriverTestCase(object):
self.setup_driver()
self.driver.create_snapshot(SNAPSHOT1)
@mock.patch('cinder.openstack.common.loopingcall.FixedIntervalLoopingCall',
new=utils.ZeroIntervalLoopingCall)
def test_negative_create_snapshot_invalid_state_norecover(self, mock_req):
ctxt = context.get_admin_context()
extra_specs = {"Feature:Pool": "1",