Add standalone udevadm_settle function

Add a standalone udevadm_settle that can be called alone. This is
to enable it to be called by the ceph-osd charm. I think the
subprocess calls should be switched to check_call in the longer
term but that may be a disruptive change if udevadm does not
always return 0 so I propose to leave them as they are for the
moment.

Change-Id: Iec5932a4d819ad87e54c2af391abe1befe84f164
Partial-Bug: #1812925
This commit is contained in:
Liam Young 2019-01-23 14:40:42 +00:00
parent 414c4b9923
commit 76709c3a98
2 changed files with 46 additions and 2 deletions

View File

@ -935,6 +935,11 @@ def start_osds(devices):
subprocess.check_call(['ceph-disk', 'activate', dev_or_path])
def udevadm_settle():
cmd = ['udevadm', 'settle']
subprocess.call(cmd)
def rescan_osd_devices():
cmd = [
'udevadm', 'trigger',
@ -943,8 +948,7 @@ def rescan_osd_devices():
subprocess.call(cmd)
cmd = ['udevadm', 'settle']
subprocess.call(cmd)
udevadm_settle()
_bootstrap_keyring = "/var/lib/ceph/bootstrap-osd/ceph.keyring"

View File

@ -0,0 +1,40 @@
# Copyright 2019 Canonical Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import unittest
from mock import patch
import ceph.utils
class GeneralUtilsTestCase(unittest.TestCase):
def setUp(self):
super(GeneralUtilsTestCase, self).setUp()
@patch.object(ceph.utils.subprocess, 'call')
def test_udevadm_settle(self, _call):
ceph.utils.udevadm_settle()
_call.assert_called_once_with(['udevadm', 'settle'])
@patch.object(ceph.utils, 'udevadm_settle')
@patch.object(ceph.utils.subprocess, 'call')
def test_rescan_osd_devices(self, _call, _udevadm_settle):
ceph.utils.rescan_osd_devices()
_call.assert_called_once_with([
'udevadm',
'trigger',
'--subsystem-match=block',
'--action=add'])
_udevadm_settle.assert_called_once_with()