Add unit test for container_update for unmounted device

This unit test case gains coverage for container/update.py
where a device (i.e. sda1) is not mounted and the code
responds with a warning logger that the device is not
mounted and continues.  Coverage increases 2% as a result.

Change-Id: I33d247a930b28604093df4ade1ce7dbbd24aac54
This commit is contained in:
Bill Huber 2015-08-07 16:24:28 -05:00
parent 640ce70987
commit 5b01c5eadc

View File

@ -74,6 +74,40 @@ class TestContainerUpdater(unittest.TestCase):
self.assertEqual(cu.node_timeout, 5)
self.assertTrue(cu.get_account_ring() is not None)
@mock.patch.object(container_updater, 'ismount')
def test_run_once_with_device_unmounted(self, mock_ismount):
mock_ismount.return_value = False
cu = container_updater.ContainerUpdater({
'devices': self.devices_dir,
'mount_check': 'false',
'swift_dir': self.testdir,
'interval': '1',
'concurrency': '1',
'node_timeout': '15',
'account_suppression_time': 0
})
containers_dir = os.path.join(self.sda1, DATADIR)
os.mkdir(containers_dir)
cu.run_once()
self.assertTrue(os.path.exists(containers_dir)) # sanity check
cu = container_updater.ContainerUpdater({
'devices': self.devices_dir,
'mount_check': 'true',
'swift_dir': self.testdir,
'interval': '1',
'concurrency': '1',
'node_timeout': '15',
'account_suppression_time': 0
})
cu.logger = FakeLogger()
cu.run_once()
log_lines = cu.logger.get_lines_for_level('warning')
self.assertTrue(len(log_lines) > 0)
msg = 'sda1 is not mounted'
self.assertEqual(log_lines[0], msg)
def test_run_once(self):
cu = container_updater.ContainerUpdater({
'devices': self.devices_dir,
@ -255,6 +289,5 @@ class TestContainerUpdater(unittest.TestCase):
self.assertEqual(info['reported_object_count'], 1)
self.assertEqual(info['reported_bytes_used'], 3)
if __name__ == '__main__':
unittest.main()