From 523d76db440c56a416e25ca669ac71aae5408916 Mon Sep 17 00:00:00 2001 From: Chris MacNaughton Date: Mon, 12 Feb 2018 10:14:18 +0100 Subject: [PATCH] Allow udev events to complete It is possible that the udev events will be triggered, the hook execution finished, another hook fires, and a second attempt to mount the devices happens despite a check if a device is mounted. By allowing udev events to settle, any mounts desired should be attempted before completing hook execution. Change-Id: Iaf8f0edf31084894fdd73fab99f750905476c4cf Partial-Bug: #1746118 --- ceph/utils.py | 3 +++ unit_tests/test_utils.py | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/ceph/utils.py b/ceph/utils.py index 2915225..ea70d95 100644 --- a/ceph/utils.py +++ b/ceph/utils.py @@ -1008,6 +1008,9 @@ def rescan_osd_devices(): subprocess.call(cmd) + cmd = ['udevadm', 'settle'] + subprocess.call(cmd) + _bootstrap_keyring = "/var/lib/ceph/bootstrap-osd/ceph.keyring" _upgrade_keyring = "/var/lib/ceph/osd/ceph.client.osd-upgrade.keyring" diff --git a/unit_tests/test_utils.py b/unit_tests/test_utils.py index 8955c81..82d2462 100644 --- a/unit_tests/test_utils.py +++ b/unit_tests/test_utils.py @@ -46,6 +46,27 @@ class CephTestCase(unittest.TestCase): def setUp(self): super(CephTestCase, self).setUp() + @patch.object(utils, 'cmp_pkgrevno') + @patch.object(utils.subprocess, 'call') + @patch.object(utils.os.path, 'exists') + @patch.object(utils.os.path, 'isdir') + def test_start_osd(self, + _isdir, + _exists, + _call, + _pkgrevno): + _pkgrevno.return_value = True + _isdir.return_value = False + utils.start_osds(['/dev/sdb']) + _isdir.assert_called_once_with('/dev/sdb') + _exists.assert_called_once_with('/dev/sdb') + _call.assert_has_calls([ + call(['udevadm', 'trigger', + '--subsystem-match=block', '--action=add' + ]), + call(['udevadm', 'settle']), + ]) + @patch.object(utils.subprocess, 'check_call') @patch.object(utils.os.path, 'exists') @patch.object(utils, 'is_device_mounted')