Skip to content

Commit

Permalink
Merge pull request #929 from liangxin1300/20220118_dont_overwrite_sbd
Browse files Browse the repository at this point in the history
Fix: sbd: not overwrite SYSCONFIG_SBD and sbd-disk-metadata if input 'n'(bsc#1194870)
  • Loading branch information
liangxin1300 authored Feb 8, 2022
2 parents 84dd4fd + 4b0764c commit 5e6dca1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
25 changes: 24 additions & 1 deletion crmsh/sbd.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ def __init__(self, context):
self._context = context
self._delay_start = False
self.timeout_inst = None
self.no_overwrite = False

@staticmethod
def _get_device_uuid(dev, node=None):
Expand Down Expand Up @@ -345,6 +346,7 @@ def _get_sbd_device_interactive(self):

configured_dev_list = self._get_sbd_device_from_config()
if configured_dev_list and not bootstrap.confirm("SBD is already configured to use {} - overwrite?".format(';'.join(configured_dev_list))):
self.no_overwrite = True
return configured_dev_list

dev_list = []
Expand Down Expand Up @@ -391,7 +393,13 @@ def _initialize_sbd(self):
For diskless-sbd, set sbd_watchdog_timeout then return;
For disk-based-sbd, also calculate the msgwait value, then initialize the SBD device.
"""
logger.info("Initializing {}SBD".format("diskless " if self.diskless_sbd else ""))
msg = ""
if self.diskless_sbd:
msg = "Configuring diskless SBD"
elif not self.no_overwrite:
msg = "Initializing SBD"
if msg:
logger.info(msg)
self.timeout_inst = SBDTimeout(self._context)
self.timeout_inst.set_sbd_watchdog_timeout()
if self.diskless_sbd:
Expand All @@ -402,6 +410,8 @@ def _initialize_sbd(self):
opt = "-4 {} -1 {}".format(self.timeout_inst.sbd_msgwait, self.timeout_inst.sbd_watchdog_timeout)

for dev in self._sbd_devices:
if self.no_overwrite and SBDManager.has_sbd_device_already_initialized(dev):
continue
rc, _, err = bootstrap.invoke("sbd {} -d {} create".format(opt, dev))
if not rc:
utils.fatal("Failed to initialize SBD device {}: {}".format(dev, err))
Expand All @@ -410,6 +420,10 @@ def _update_sbd_configuration(self):
"""
Update /etc/sysconfig/sbd
"""
if self.no_overwrite:
bootstrap.csync2_update(SYSCONFIG_SBD)
return

shutil.copyfile(self.SYSCONFIG_SBD_TEMPLATE, SYSCONFIG_SBD)
sbd_config_dict = {
"SBD_WATCHDOG_DEV": self._watchdog_inst.watchdog_device_name,
Expand Down Expand Up @@ -587,3 +601,12 @@ def get_sbd_value_from_config(key):
conf = utils.parse_sysconfig(SYSCONFIG_SBD)
res = conf.get(key)
return res

@staticmethod
def has_sbd_device_already_initialized(dev):
"""
Check if sbd device already initialized
"""
cmd = "sbd -d {} dump".format(dev)
rc, _, _ = utils.get_stdout_stderr(cmd)
return rc == 0
2 changes: 1 addition & 1 deletion test/unittests/test_sbd.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ def test_initialize_sbd_return(self, mock_info, mock_sbd_timeout):
mock_inst.adjust_sbd_watchdog_timeout_with_diskless_and_qdevice = mock.Mock()
self.sbd_inst_diskless._context = mock.Mock(profiles_dict={})
self.sbd_inst_diskless._initialize_sbd()
mock_info.assert_called_once_with("Initializing diskless SBD")
mock_info.assert_called_once_with("Configuring diskless SBD")
mock_inst.adjust_sbd_watchdog_timeout_with_diskless_and_qdevice.assert_called_once_with()

@mock.patch('crmsh.utils.fatal')
Expand Down

0 comments on commit 5e6dca1

Please sign in to comment.