Skip to content

Commit e17caa0

Browse files
committed
Dev: unittests: Adjust unit test for previous commit
1 parent 5ff7014 commit e17caa0

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
@@ -403,57 +403,6 @@ def test_enable_sbd_service(self, mock_list_cluster_nodes, mock_ServiceManager,
403403
call("Enable %s on node %s", constants.SBD_SERVICE, 'node2')
404404
])
405405

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

643592
@patch('crmsh.bootstrap.adjust_properties')
644-
@patch('crmsh.sbd.SBDManager.restart_cluster_if_possible')
593+
@patch('crmsh.bootstrap.restart_cluster')
645594
@patch('crmsh.sbd.SBDManager.enable_sbd_service')
646595
@patch('crmsh.sbd.ServiceManager')
647-
def test_init_and_deploy_sbd(self, mock_ServiceManager, mock_enable_sbd_service, mock_restart_cluster_if_possible, mock_adjust_properties):
596+
def test_init_and_deploy_sbd(self, mock_ServiceManager, mock_enable_sbd_service, mock_restart_cluster, mock_adjust_properties):
648597
mock_bootstrap_ctx = Mock(cluster_is_running=True)
649598
sbdmanager_instance = SBDManager(bootstrap_context=mock_bootstrap_ctx)
650599
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)