From 58fcc07523978306cd3889ada73af5d9e664cf59 Mon Sep 17 00:00:00 2001 From: Christian Schwede Date: Wed, 2 Sep 2015 10:52:34 +0000 Subject: [PATCH] Test if container_sweep is executed on unmounted devices This change ensures that container_sweep is not run if a device is not mounted and mount_check is set to True. Change-Id: I823083c8431d9e61fd426508033ec9188503957b --- test/unit/container/test_updater.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/test/unit/container/test_updater.py b/test/unit/container/test_updater.py index 507daf992a..c2ad673236 100644 --- a/test/unit/container/test_updater.py +++ b/test/unit/container/test_updater.py @@ -75,7 +75,8 @@ class TestContainerUpdater(unittest.TestCase): 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.patch.object(container_updater.ContainerUpdater, 'container_sweep') + def test_run_once_with_device_unmounted(self, mock_sweep, mock_ismount): mock_ismount.return_value = False cu = container_updater.ContainerUpdater({ @@ -89,9 +90,17 @@ class TestContainerUpdater(unittest.TestCase): }) containers_dir = os.path.join(self.sda1, DATADIR) os.mkdir(containers_dir) + partition_dir = os.path.join(containers_dir, "a") + os.mkdir(partition_dir) + cu.run_once() self.assertTrue(os.path.exists(containers_dir)) # sanity check + # only called if a partition dir exists + self.assertTrue(mock_sweep.called) + + mock_sweep.reset_mock() + cu = container_updater.ContainerUpdater({ 'devices': self.devices_dir, 'mount_check': 'true', @@ -107,6 +116,8 @@ class TestContainerUpdater(unittest.TestCase): self.assertTrue(len(log_lines) > 0) msg = 'sda1 is not mounted' self.assertEqual(log_lines[0], msg) + # Ensure that the container_sweep did not run + self.assertFalse(mock_sweep.called) def test_run_once(self): cu = container_updater.ContainerUpdater({