Minor cleanup handoff mode warnings

* message is a little clearer
  * test is a little stronger

Change-Id: I745cde7f4a46dafc80ab42d39e6ccc92aa3b746e
This commit is contained in:
Clay Gerrard 2015-08-21 14:04:46 -07:00
parent ab163702de
commit 8b1df9918b
3 changed files with 32 additions and 18 deletions

View File

@ -100,9 +100,10 @@ class ObjectReplicator(Daemon):
self.handoff_delete = config_auto_int_value(
conf.get('handoff_delete', 'auto'), 0)
if any((self.handoff_delete, self.handoffs_first)):
self.logger.warn('handoffs_first and handoff_delete should be'
' changed back to the default before the next'
' normal rebalance')
self.logger.warn('Handoff only mode is not intended for normal '
'operation, please disable handoffs_first and '
'handoff_delete before the next '
'normal rebalance')
self._diskfile_mgr = DiskFileManager(conf, self.logger)
# Just exists for doc anchor point

View File

@ -510,6 +510,8 @@ class FakeLogger(logging.Logger, object):
self.lines_dict = {'critical': [], 'error': [], 'info': [],
'warning': [], 'debug': [], 'notice': []}
clear = _clear # this is a public interface
def get_lines_for_level(self, level):
if level not in self.lines_dict:
raise KeyError(

View File

@ -185,21 +185,32 @@ class TestObjectReplicator(unittest.TestCase):
rmtree(self.testdir, ignore_errors=1)
def test_handoff_replication_setting_warnings(self):
conf = {'handoffs_first': 'true'}
replicator = object_replicator.ObjectReplicator(
conf, logger=self.logger)
self.assertTrue(replicator.handoffs_first)
log_message = 'handoffs_first and handoff_delete should'\
' be changed back to the default before the'\
' next normal rebalance'
expected = [log_message]
self.assertEqual(self.logger.get_lines_for_level('warning'), expected)
conf = {'handoff_delete': '2'}
replicator = object_replicator.ObjectReplicator(
conf, logger=self.logger)
self.assertEqual(replicator.handoff_delete, 2)
expected.append(log_message)
self.assertEqual(self.logger.get_lines_for_level('warning'), expected)
conf_tests = [
# (config, expected_warning)
({}, False),
({'handoff_delete': 'auto'}, False),
({'handoffs_first': 'no'}, False),
({'handoff_delete': '2'}, True),
({'handoffs_first': 'yes'}, True),
({'handoff_delete': '1', 'handoffs_first': 'yes'}, True),
]
log_message = 'Handoff only mode is not intended for normal ' \
'operation, please disable handoffs_first and ' \
'handoff_delete before the next normal rebalance'
for config, expected_warning in conf_tests:
self.logger.clear()
object_replicator.ObjectReplicator(config, logger=self.logger)
warning_log_lines = self.logger.get_lines_for_level('warning')
if expected_warning:
expected_log_lines = [log_message]
else:
expected_log_lines = []
self.assertEqual(expected_log_lines, warning_log_lines,
'expected %s != %s for config %r' % (
expected_log_lines,
warning_log_lines,
config,
))
def _write_disk_data(self, disk_name):
os.mkdir(os.path.join(self.devices, disk_name))