From 5b01c5eadc3a13607d2581a55007700fca0b00af Mon Sep 17 00:00:00 2001 From: Bill Huber Date: Fri, 7 Aug 2015 16:24:28 -0500 Subject: [PATCH] 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 --- test/unit/container/test_updater.py | 35 ++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/test/unit/container/test_updater.py b/test/unit/container/test_updater.py index c682967046..507daf992a 100644 --- a/test/unit/container/test_updater.py +++ b/test/unit/container/test_updater.py @@ -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()