def test_success_used_forced(self, mock_net_destroy, mock_net_disable, mock_net_stop, mock_status): mock_status.return_value = 'Cluster "a_cluster":\n' lib.qdevice_destroy(self.lib_env, "net", proceed_if_used=True) mock_net_stop.assert_called_once_with("mock_runner", "corosync-qnetd") mock_net_disable.assert_called_once_with("mock_runner", "corosync-qnetd") mock_net_destroy.assert_called_once_with() assert_report_item_list_equal( self.mock_reporter.report_item_list, [(severity.WARNING, report_codes.QDEVICE_USED_BY_CLUSTERS, { "clusters": ["a_cluster"], }), (severity.INFO, report_codes.SERVICE_STOP_STARTED, { "service": "quorum device", }), (severity.INFO, report_codes.SERVICE_STOP_SUCCESS, { "service": "quorum device", }), (severity.INFO, report_codes.SERVICE_DISABLE_SUCCESS, { "service": "quorum device", }), (severity.INFO, report_codes.QDEVICE_DESTROY_SUCCESS, { "model": "net", })])
def test_success_not_used(self, mock_net_destroy, mock_status): mock_status.return_value = "" lib.qdevice_destroy(self.lib_env, "net") self.assertEqual( self.lib_env.service_manager.method_calls, [ mock.call.stop("corosync-qnetd"), mock.call.disable("corosync-qnetd"), ], ) mock_net_destroy.assert_called_once_with() assert_report_item_list_equal( self.mock_reporter.report_item_list, [ ( severity.INFO, reports.codes.SERVICE_ACTION_STARTED, { "action": reports.const.SERVICE_ACTION_STOP, "service": "quorum device", "instance": "", }, ), ( severity.INFO, reports.codes.SERVICE_ACTION_SUCCEEDED, { "action": reports.const.SERVICE_ACTION_STOP, "service": "quorum device", "node": "", "instance": "", }, ), ( severity.INFO, reports.codes.SERVICE_ACTION_SUCCEEDED, { "action": reports.const.SERVICE_ACTION_DISABLE, "service": "quorum device", "node": "", "instance": "", }, ), ( severity.INFO, report_codes.QDEVICE_DESTROY_SUCCESS, { "model": "net", }, ), ], )
def test_success_used_forced( self, mock_net_destroy, mock_net_disable, mock_net_stop, mock_status ): mock_status.return_value = 'Cluster "a_cluster":\n' lib.qdevice_destroy(self.lib_env, "net", proceed_if_used=True) mock_net_stop.assert_called_once_with("mock_runner", "corosync-qnetd") mock_net_disable.assert_called_once_with( "mock_runner", "corosync-qnetd" ) mock_net_destroy.assert_called_once_with() assert_report_item_list_equal( self.mock_reporter.report_item_list, [ ( severity.WARNING, report_codes.QDEVICE_USED_BY_CLUSTERS, { "clusters": ["a_cluster"], } ), ( severity.INFO, report_codes.SERVICE_STOP_STARTED, { "service": "quorum device", } ), ( severity.INFO, report_codes.SERVICE_STOP_SUCCESS, { "service": "quorum device", } ), ( severity.INFO, report_codes.SERVICE_DISABLE_SUCCESS, { "service": "quorum device", } ), ( severity.INFO, report_codes.QDEVICE_DESTROY_SUCCESS, { "model": "net", } ) ] )
def test_stop_failed( self, mock_net_destroy, mock_net_disable, mock_net_stop ): mock_net_stop.side_effect = StopServiceError( "test service", "test error" ) assert_raise_library_error( lambda: lib.qdevice_destroy(self.lib_env, "net"), ( severity.ERROR, report_codes.SERVICE_STOP_ERROR, { "service": "test service", "reason": "test error", } ) ) mock_net_stop.assert_called_once_with("mock_runner", "corosync-qnetd") mock_net_disable.assert_not_called() mock_net_destroy.assert_not_called() assert_report_item_list_equal( self.mock_reporter.report_item_list, [ ( severity.INFO, report_codes.SERVICE_STOP_STARTED, { "service": "quorum device", } ) ] )
def test_used_not_forced( self, mock_net_destroy, mock_net_disable, mock_net_stop, mock_status ): mock_status.return_value = 'Cluster "a_cluster":\n' assert_raise_library_error( lambda: lib.qdevice_destroy(self.lib_env, "net") ) assert_report_item_list_equal( self.mock_reporter.report_item_list, [ ( severity.ERROR, report_codes.QDEVICE_USED_BY_CLUSTERS, { "clusters": ["a_cluster"], }, report_codes.FORCE_QDEVICE_USED, ), ], ) mock_net_stop.assert_not_called() mock_net_disable.assert_not_called() mock_net_destroy.assert_not_called()
def test_disable_failed(self, mock_net_destroy, mock_net_disable, mock_net_stop, mock_status): mock_status.return_value = "" mock_net_disable.side_effect = DisableServiceError( "test service", "test error") assert_raise_library_error( lambda: lib.qdevice_destroy(self.lib_env, "net"), (severity.ERROR, report_codes.SERVICE_DISABLE_ERROR, { "service": "test service", "reason": "test error", })) mock_net_stop.assert_called_once_with("mock_runner", "corosync-qnetd") mock_net_disable.assert_called_once_with("mock_runner", "corosync-qnetd") mock_net_destroy.assert_not_called() assert_report_item_list_equal( self.mock_reporter.report_item_list, [(severity.INFO, report_codes.SERVICE_STOP_STARTED, { "service": "quorum device", }), (severity.INFO, report_codes.SERVICE_STOP_SUCCESS, { "service": "quorum device", })])
def test_success_not_used( self, mock_net_destroy, mock_net_disable, mock_net_stop, mock_status ): mock_status.return_value = "" lib.qdevice_destroy(self.lib_env, "net") mock_net_stop.assert_called_once_with("mock_runner", "corosync-qnetd") mock_net_disable.assert_called_once_with( "mock_runner", "corosync-qnetd" ) mock_net_destroy.assert_called_once_with() assert_report_item_list_equal( self.mock_reporter.report_item_list, [ ( severity.INFO, report_codes.SERVICE_STOP_STARTED, { "service": "quorum device", } ), ( severity.INFO, report_codes.SERVICE_STOP_SUCCESS, { "service": "quorum device", } ), ( severity.INFO, report_codes.SERVICE_DISABLE_SUCCESS, { "service": "quorum device", } ), ( severity.INFO, report_codes.QDEVICE_DESTROY_SUCCESS, { "model": "net", } ) ] )
def test_disable_failed(self, mock_net_destroy, mock_status): mock_status.return_value = "" self.lib_env.service_manager.disable.side_effect = DisableServiceError( "test service", "test error") assert_raise_library_error( lambda: lib.qdevice_destroy(self.lib_env, "net"), ( severity.ERROR, reports.codes.SERVICE_ACTION_FAILED, { "action": reports.const.SERVICE_ACTION_DISABLE, "service": "test service", "reason": "test error", "node": "", "instance": "", }, ), ) self.assertEqual( self.lib_env.service_manager.method_calls, [ mock.call.stop("corosync-qnetd"), mock.call.disable("corosync-qnetd"), ], ) mock_net_destroy.assert_not_called() assert_report_item_list_equal( self.mock_reporter.report_item_list, [ ( severity.INFO, reports.codes.SERVICE_ACTION_STARTED, { "action": reports.const.SERVICE_ACTION_STOP, "service": "quorum device", "instance": "", }, ), ( severity.INFO, reports.codes.SERVICE_ACTION_SUCCEEDED, { "action": reports.const.SERVICE_ACTION_STOP, "service": "quorum device", "node": "", "instance": "", }, ), ], )
def test_destroy_failed(self, mock_net_destroy, mock_status): mock_status.return_value = "" mock_net_destroy.side_effect = LibraryError("mock_report_item") self.assertRaises(LibraryError, lambda: lib.qdevice_destroy(self.lib_env, "net")) self.assertEqual( self.lib_env.service_manager.method_calls, [ mock.call.stop("corosync-qnetd"), mock.call.disable("corosync-qnetd"), ], ) mock_net_destroy.assert_called_once_with() assert_report_item_list_equal( self.mock_reporter.report_item_list, [ ( severity.INFO, reports.codes.SERVICE_ACTION_STARTED, { "action": reports.const.SERVICE_ACTION_STOP, "service": "quorum device", "instance": "", }, ), ( severity.INFO, reports.codes.SERVICE_ACTION_SUCCEEDED, { "action": reports.const.SERVICE_ACTION_STOP, "service": "quorum device", "node": "", "instance": "", }, ), ( severity.INFO, reports.codes.SERVICE_ACTION_SUCCEEDED, { "action": reports.const.SERVICE_ACTION_DISABLE, "service": "quorum device", "node": "", "instance": "", }, ), ], )
def test_destroy_failed( self, mock_net_destroy, mock_net_disable, mock_net_stop, mock_status ): mock_status.return_value = "" mock_net_destroy.side_effect = LibraryError("mock_report_item") self.assertRaises( LibraryError, lambda: lib.qdevice_destroy(self.lib_env, "net") ) mock_net_stop.assert_called_once_with("mock_runner", "corosync-qnetd") mock_net_disable.assert_called_once_with( "mock_runner", "corosync-qnetd" ) mock_net_destroy.assert_called_once_with() assert_report_item_list_equal( self.mock_reporter.report_item_list, [ ( severity.INFO, report_codes.SERVICE_STOP_STARTED, { "service": "quorum device", } ), ( severity.INFO, report_codes.SERVICE_STOP_SUCCESS, { "service": "quorum device", } ), ( severity.INFO, report_codes.SERVICE_DISABLE_SUCCESS, { "service": "quorum device", } ) ] )
def test_used_not_forced( self, mock_net_destroy, mock_net_disable, mock_net_stop, mock_status ): mock_status.return_value = 'Cluster "a_cluster":\n' assert_raise_library_error( lambda: lib.qdevice_destroy(self.lib_env, "net"), ( severity.ERROR, report_codes.QDEVICE_USED_BY_CLUSTERS, { "clusters": ["a_cluster"], }, report_codes.FORCE_QDEVICE_USED ), ) mock_net_stop.assert_not_called() mock_net_disable.assert_not_called() mock_net_destroy.assert_not_called()
def test_stop_failed( self, mock_net_destroy, mock_net_disable, mock_net_stop, mock_status ): mock_status.return_value = "" mock_net_stop.side_effect = StopServiceError( "test service", "test error" ) assert_raise_library_error( lambda: lib.qdevice_destroy(self.lib_env, "net"), ( severity.ERROR, reports.codes.SERVICE_ACTION_FAILED, { "action": reports.const.SERVICE_ACTION_STOP, "service": "test service", "reason": "test error", "node": "", "instance": "", }, ), ) mock_net_stop.assert_called_once_with("mock_runner", "corosync-qnetd") mock_net_disable.assert_not_called() mock_net_destroy.assert_not_called() assert_report_item_list_equal( self.mock_reporter.report_item_list, [ ( severity.INFO, reports.codes.SERVICE_ACTION_STARTED, { "action": reports.const.SERVICE_ACTION_STOP, "service": "quorum device", "instance": "", }, ) ], )
def test_destroy(self): self.base_test(lambda: lib.qdevice_destroy(self.lib_env, "bad model"))
def test_success_used_forced(self, mock_net_destroy, mock_status): mock_status.return_value = 'Cluster "a_cluster":\n' lib.qdevice_destroy(self.lib_env, "net", proceed_if_used=True) self.assertEqual( self.lib_env.service_manager.method_calls, [ mock.call.stop("corosync-qnetd"), mock.call.disable("corosync-qnetd"), ], ) mock_net_destroy.assert_called_once_with() assert_report_item_list_equal( self.mock_reporter.report_item_list, [ ( severity.WARNING, report_codes.QDEVICE_USED_BY_CLUSTERS, { "clusters": ["a_cluster"], }, ), ( severity.INFO, reports.codes.SERVICE_ACTION_STARTED, { "action": reports.const.SERVICE_ACTION_STOP, "service": "quorum device", "instance": "", }, ), ( severity.INFO, reports.codes.SERVICE_ACTION_SUCCEEDED, { "action": reports.const.SERVICE_ACTION_STOP, "service": "quorum device", "node": "", "instance": "", }, ), ( severity.INFO, reports.codes.SERVICE_ACTION_SUCCEEDED, { "action": reports.const.SERVICE_ACTION_DISABLE, "service": "quorum device", "node": "", "instance": "", }, ), ( severity.INFO, report_codes.QDEVICE_DESTROY_SUCCESS, { "model": "net", }, ), ], )
def test_destroy(self): self.base_test( lambda: lib.qdevice_destroy(self.lib_env, "bad model") )