Skip to content

Commit c6112cc

Browse files
committed
Dev: unittests: Adjust unit test for previous commit
1 parent e6fbbaf commit c6112cc

File tree

2 files changed

+7
-57
lines changed

2 files changed

+7
-57
lines changed

test/unittests/test_sbd.py

Lines changed: 2 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -406,57 +406,6 @@ def test_enable_sbd_service(self, mock_list_cluster_nodes, mock_ServiceManager,
406406
call("Enable %s on node %s", constants.SBD_SERVICE, 'node2')
407407
])
408408

409-
@patch('crmsh.xmlutil.CrmMonXmlParser')
410-
@patch('crmsh.sbd.ServiceManager')
411-
def test_restart_cluster_if_possible_return(self, mock_ServiceManager, mock_CrmMonXmlParser):
412-
mock_ServiceManager.return_value.service_is_active.return_value = False
413-
SBDManager.restart_cluster_if_possible()
414-
mock_ServiceManager.return_value.service_is_active.assert_called_once_with(constants.PCMK_SERVICE)
415-
mock_CrmMonXmlParser.assert_not_called()
416-
417-
@patch('logging.Logger.warning')
418-
@patch('crmsh.utils.is_dlm_running')
419-
@patch('crmsh.xmlutil.CrmMonXmlParser')
420-
@patch('crmsh.sbd.ServiceManager')
421-
def test_restart_cluster_if_possible_manually(
422-
self, mock_ServiceManager, mock_CrmMonXmlParser, mock_is_dlm_running, mock_logger_warning,
423-
):
424-
mock_ServiceManager.return_value.service_is_active.return_value = True
425-
mock_CrmMonXmlParser.return_value.is_non_stonith_resource_running.return_value = True
426-
mock_is_dlm_running.return_value = False
427-
SBDManager.restart_cluster_if_possible()
428-
mock_ServiceManager.return_value.service_is_active.assert_called_once_with(constants.PCMK_SERVICE)
429-
mock_logger_warning.assert_has_calls([
430-
call("Resource is running, need to restart cluster service manually on each node"),
431-
call("Or, run with `crm -F` or `--force` option, the `sbd` subcommand will leverage maintenance mode for any changes that require restarting sbd.service"),
432-
call("Understand risks that running RA has no cluster protection while the cluster is in maintenance mode and restarting")
433-
])
434-
435-
@patch('logging.Logger.warning')
436-
@patch('crmsh.utils.is_dlm_running')
437-
@patch('crmsh.xmlutil.CrmMonXmlParser')
438-
@patch('crmsh.sbd.ServiceManager')
439-
def test_restart_cluster_if_possible_dlm_running(
440-
self, mock_ServiceManager, mock_CrmMonXmlParser, mock_is_dlm_running, mock_logger_warning,
441-
):
442-
mock_ServiceManager.return_value.service_is_active.return_value = True
443-
mock_CrmMonXmlParser.return_value.is_non_stonith_resource_running.return_value = True
444-
mock_is_dlm_running.return_value = True
445-
SBDManager.restart_cluster_if_possible(with_maintenance_mode=True)
446-
mock_ServiceManager.return_value.service_is_active.assert_called_once_with(constants.PCMK_SERVICE)
447-
mock_logger_warning.assert_called_once_with("Resource is running, need to restart cluster service manually on each node")
448-
449-
@patch('crmsh.bootstrap.restart_cluster')
450-
@patch('logging.Logger.warning')
451-
@patch('crmsh.xmlutil.CrmMonXmlParser')
452-
@patch('crmsh.sbd.ServiceManager')
453-
def test_restart_cluster_if_possible(self, mock_ServiceManager, mock_CrmMonXmlParser, mock_logger_warning, mock_restart_cluster):
454-
mock_ServiceManager.return_value.service_is_active.return_value = True
455-
mock_CrmMonXmlParser.return_value.is_non_stonith_resource_running.return_value = False
456-
SBDManager.restart_cluster_if_possible()
457-
mock_ServiceManager.return_value.service_is_active.assert_called_once_with(constants.PCMK_SERVICE)
458-
mock_restart_cluster.assert_called_once()
459-
460409
@patch('crmsh.bootstrap.prompt_for_string')
461410
def test_prompt_for_sbd_device_diskless(self, mock_prompt_for_string):
462411
mock_prompt_for_string.return_value = "none"
@@ -644,10 +593,10 @@ def test_init_and_deploy_sbd_not_config_sbd(self, mock_ServiceManager):
644593
sbdmanager_instance._load_attributes_from_bootstrap.assert_not_called()
645594

646595
@patch('crmsh.bootstrap.adjust_properties')
647-
@patch('crmsh.sbd.SBDManager.restart_cluster_if_possible')
596+
@patch('crmsh.bootstrap.restart_cluster')
648597
@patch('crmsh.sbd.SBDManager.enable_sbd_service')
649598
@patch('crmsh.sbd.ServiceManager')
650-
def test_init_and_deploy_sbd(self, mock_ServiceManager, mock_enable_sbd_service, mock_restart_cluster_if_possible, mock_adjust_properties):
599+
def test_init_and_deploy_sbd(self, mock_ServiceManager, mock_enable_sbd_service, mock_restart_cluster, mock_adjust_properties):
651600
mock_bootstrap_ctx = Mock(cluster_is_running=True)
652601
sbdmanager_instance = SBDManager(bootstrap_context=mock_bootstrap_ctx)
653602
sbdmanager_instance.get_sbd_device_from_bootstrap = Mock()

test/unittests/test_ui_sbd.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -469,14 +469,14 @@ def test_device_remove_last_dev(self):
469469
self.sbd_instance_diskbased._device_remove(["/dev/sda1"])
470470
self.assertEqual(str(e.exception), "Not allowed to remove all devices")
471471

472-
@mock.patch('crmsh.sbd.SBDManager.restart_cluster_if_possible')
472+
@mock.patch('crmsh.bootstrap.restart_cluster')
473473
@mock.patch('crmsh.sbd.SBDManager.update_sbd_configuration')
474474
@mock.patch('logging.Logger.info')
475-
def test_device_remove(self, mock_logger_info, mock_update_sbd_configuration, mock_restart_cluster_if_possible):
475+
def test_device_remove(self, mock_logger_info, mock_update_sbd_configuration, mock_restart_cluster):
476476
self.sbd_instance_diskbased.device_list_from_config = ["/dev/sda1", "/dev/sda2"]
477477
self.sbd_instance_diskbased._device_remove(["/dev/sda1"])
478478
mock_update_sbd_configuration.assert_called_once_with({"SBD_DEVICE": "/dev/sda2"})
479-
mock_restart_cluster_if_possible.assert_called_once()
479+
mock_restart_cluster.assert_called_once()
480480
mock_logger_info.assert_called_once_with("Remove devices: %s", "/dev/sda1")
481481

482482
def test_do_device_no_service(self):
@@ -571,9 +571,10 @@ def test_do_purge_no_service(self, mock_purge_sbd_from_cluster):
571571
self.assertFalse(res)
572572
mock_purge_sbd_from_cluster.assert_not_called()
573573

574+
@mock.patch('crmsh.bootstrap.restart_cluster')
574575
@mock.patch('crmsh.utils.check_all_nodes_reachable')
575576
@mock.patch('crmsh.sbd.purge_sbd_from_cluster')
576-
def test_do_purge(self, mock_purge_sbd_from_cluster, mock_check_all_nodes_reachable):
577+
def test_do_purge(self, mock_purge_sbd_from_cluster, mock_check_all_nodes_reachable, mock_restart_cluster):
577578
self.sbd_instance_diskbased._load_attributes = mock.Mock()
578579
self.sbd_instance_diskbased._service_is_active = mock.Mock(return_value=True)
579580
res = self.sbd_instance_diskbased.do_purge(mock.Mock())

0 commit comments

Comments
 (0)