diff --git a/crmsh/sbd.py b/crmsh/sbd.py index f1e7c571bf..aa62caae8f 100644 --- a/crmsh/sbd.py +++ b/crmsh/sbd.py @@ -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): @@ -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 = [] @@ -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: @@ -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)) @@ -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, @@ -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 diff --git a/test/unittests/test_sbd.py b/test/unittests/test_sbd.py index b06bcac884..0dfb45cc66 100644 --- a/test/unittests/test_sbd.py +++ b/test/unittests/test_sbd.py @@ -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')