Tests: Don't assert on LOG.warn

Lots of code can use LOG.warn, tests wanting to
verify this should do a more robust check to ensure
that specific text is logged or not logged.

Change-Id: Id996ce761d90f1648f1f37c74a33df02d04cf3a3
Closes-bug: #1550102
This commit is contained in:
Eric Harney 2016-02-25 12:01:43 -05:00 committed by LisaLi
parent 68e7ae469d
commit f6306967e6

View File

@ -25,11 +25,12 @@ import copy
import uuid
import mock
from oslo_log import versionutils
from oslo_utils import units
import six
from cinder import exception
from cinder.i18n import _
from cinder.i18n import _, _LW
from cinder import test
from cinder.tests.unit.volume.drivers.netapp.dataontap import fakes as fake
import cinder.tests.unit.volume.drivers.netapp.fakes as na_fakes
@ -57,24 +58,24 @@ class NetAppBlockStorageLibraryTestCase(test.TestCase):
def get_config_base(self):
return na_fakes.create_configuration()
def test_get_reserved_percentage_default_multipler(self):
@mock.patch.object(versionutils, 'report_deprecated_feature')
def test_get_reserved_percentage_default_multipler(self, mock_report):
default = 1.2
reserved_percentage = 20.0
self.library.configuration.netapp_size_multiplier = default
self.library.configuration.reserved_percentage = reserved_percentage
self.mock_object(block_base, 'LOG')
result = self.library._get_reserved_percentage()
self.assertEqual(reserved_percentage, result)
self.assertFalse(block_base.LOG.warn.called)
self.assertFalse(mock_report.called)
def test_get_reserved_percentage(self):
@mock.patch.object(versionutils, 'report_deprecated_feature')
def test_get_reserved_percentage(self, mock_report):
multiplier = 2.0
self.library.configuration.netapp_size_multiplier = multiplier
self.mock_object(block_base, 'LOG')
result = self.library._get_reserved_percentage()
@ -82,7 +83,11 @@ class NetAppBlockStorageLibraryTestCase(test.TestCase):
reserved_percentage = 100 * int(reserved_ratio)
self.assertEqual(reserved_percentage, result)
self.assertTrue(block_base.LOG.warn.called)
msg = _LW('The "netapp_size_multiplier" configuration option is '
'deprecated and will be removed in the Mitaka release. '
'Please set "reserved_percentage = %d" instead.') % (
result)
mock_report.assert_called_once_with(block_base.LOG, msg)
@mock.patch.object(block_base.NetAppBlockStorageLibrary,
'_get_lun_attr',