Skip to content

Commit

Permalink
Dev: unittest: Add unit test for previous changes
Browse files Browse the repository at this point in the history
  • Loading branch information
liangxin1300 committed Nov 24, 2021
1 parent 9d344e5 commit 3e221bc
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 286 deletions.
5 changes: 3 additions & 2 deletions test/unittests/test_bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,11 +263,12 @@ def tearDownClass(cls):

@mock.patch('crmsh.log.LoggerUtils.status_long')
@mock.patch('crmsh.utils.start_service')
@mock.patch('crmsh.sbd.SBDManager.get_suitable_sbd_systemd_timeout')
@mock.patch('crmsh.sbd.SBDManager.is_delay_start')
@mock.patch('crmsh.sbd.SBDTimeout.get_suitable_sbd_systemd_timeout')
@mock.patch('crmsh.sbd.SBDTimeout.is_delay_start')
@mock.patch('crmsh.utils.service_is_enabled')
@mock.patch('crmsh.utils.package_is_installed')
def test_start_pacemaker(self, mock_installed, mock_enabled, mock_delay_start, mock_timeout, mock_start, mock_long):
bootstrap._context = None
mock_installed.return_value = True
mock_enabled.return_value = True
mock_delay_start.return_value = True
Expand Down
26 changes: 6 additions & 20 deletions test/unittests/test_crashtest_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,44 +62,44 @@ def tearDownClass(cls):
Global tearDown.
"""

@mock.patch('crmsh.crash_test.utils.get_property')
@mock.patch('crmsh.crash_test.utils.crmshutils.get_property')
def test_fence_enabled_false(self, mock_get_property):
mock_get_property.return_value = None
res = self.fence_info_inst.fence_enabled
self.assertEqual(res, False)
mock_get_property.assert_called_once_with("stonith-enabled")

@mock.patch('crmsh.crash_test.utils.get_property')
@mock.patch('crmsh.crash_test.utils.crmshutils.get_property')
def test_fence_enabled_true(self, mock_get_property):
mock_get_property.return_value = "True"
res = self.fence_info_inst.fence_enabled
self.assertEqual(res, True)
mock_get_property.assert_called_once_with("stonith-enabled")

@mock.patch('crmsh.crash_test.utils.msg_error')
@mock.patch('crmsh.crash_test.utils.get_property')
@mock.patch('crmsh.crash_test.utils.crmshutils.get_property')
def test_fence_action_none(self, mock_get_property, mock_error):
mock_get_property.return_value = None
res = self.fence_info_inst.fence_action
self.assertEqual(res, None)
mock_get_property.assert_called_once_with("stonith-action")
mock_error.assert_called_once_with('Cluster property "stonith-action" should be reboot|off|poweroff')

@mock.patch('crmsh.crash_test.utils.get_property')
@mock.patch('crmsh.crash_test.utils.crmshutils.get_property')
def test_fence_action(self, mock_get_property):
mock_get_property.return_value = "reboot"
res = self.fence_info_inst.fence_action
self.assertEqual(res, "reboot")
mock_get_property.assert_called_once_with("stonith-action")

@mock.patch('crmsh.crash_test.utils.get_property')
@mock.patch('crmsh.crash_test.utils.crmshutils.get_property')
def test_fence_timeout(self, mock_get_property):
mock_get_property.return_value = "60s"
res = self.fence_info_inst.fence_timeout
self.assertEqual(res, "60")
mock_get_property.assert_called_once_with("stonith-timeout")

@mock.patch('crmsh.crash_test.utils.get_property')
@mock.patch('crmsh.crash_test.utils.crmshutils.get_property')
def test_fence_timeout_default(self, mock_get_property):
mock_get_property.return_value = None
res = self.fence_info_inst.fence_timeout
Expand Down Expand Up @@ -381,20 +381,6 @@ def test_online_nodes(self, mock_run):
self.assertEqual(res, ["15sp2-1", "15sp2-2"])
mock_run.assert_called_once_with("crm_mon -1")

@mock.patch('crmsh.crash_test.utils.crmshutils.get_stdout_stderr')
def test_get_property_none(self, mock_run):
mock_run.return_value = (1, None, "error")
res = utils.get_property("test")
self.assertEqual(res, None)
mock_run.assert_called_once_with("crm configure get_property test")

@mock.patch('crmsh.crash_test.utils.crmshutils.get_stdout_stderr')
def test_get_property(self, mock_run):
mock_run.return_value = (0, "data", None)
res = utils.get_property("test")
self.assertEqual(res, "data")
mock_run.assert_called_once_with("crm configure get_property test")

@mock.patch('crmsh.crash_test.utils.online_nodes')
def test_peer_node_list_empty(self, mock_online):
mock_online.return_value = None
Expand Down
Loading

0 comments on commit 3e221bc

Please sign in to comment.