def node_standby(argv, standby=True): if (len(argv) > 1) or (len(argv) > 0 and "--all" in utils.pcs_options): usage.node(["standby" if standby else "unstandby"]) sys.exit(1) all_nodes = "--all" in utils.pcs_options node_list = [argv[0]] if argv else [] wait = False timeout = None if "--wait" in utils.pcs_options: wait = True timeout = utils.pcs_options["--wait"] try: if wait: lib_pacemaker.ensure_resource_wait_support(utils.cmd_runner()) valid_timeout = get_valid_timeout_seconds(timeout) if standby: lib_pacemaker.nodes_standby(utils.cmd_runner(), node_list, all_nodes) else: lib_pacemaker.nodes_unstandby(utils.cmd_runner(), node_list, all_nodes) if wait: lib_pacemaker.wait_for_resources(utils.cmd_runner(), valid_timeout) except LibraryError as e: utils.process_library_reports(e.args)
def node_standby(argv, standby=True): if (len(argv) > 1) or (len(argv) > 0 and "--all" in utils.pcs_options): usage.node(["standby" if standby else "unstandby"]) sys.exit(1) all_nodes = "--all" in utils.pcs_options node_list = [argv[0]] if argv else [] wait = False timeout = None if "--wait" in utils.pcs_options: wait = True timeout = utils.pcs_options["--wait"] try: if wait: lib_pacemaker.ensure_resource_wait_support(utils.cmd_runner()) valid_timeout = get_valid_timeout_seconds(timeout) if standby: lib_pacemaker.nodes_standby( utils.cmd_runner(), node_list, all_nodes ) else: lib_pacemaker.nodes_unstandby( utils.cmd_runner(), node_list, all_nodes ) if wait: lib_pacemaker.wait_for_resources(utils.cmd_runner(), valid_timeout) except LibraryError as e: utils.process_library_reports(e.args)
def test_wait_error_timeout(self): expected_stdout = "some info" expected_stderr = "some error" expected_retval = 62 mock_runner = mock.MagicMock(spec_set=CommandRunner) mock_runner.run.return_value = ( expected_stdout, expected_stderr, expected_retval ) assert_raise_library_error( lambda: lib.wait_for_resources(mock_runner), ( Severity.ERROR, report_codes.RESOURCE_WAIT_TIMED_OUT, { "reason": expected_stderr + "\n" + expected_stdout, } ) ) mock_runner.run.assert_called_once_with( [self.path("crm_resource"), "--wait"] )
def test_wait_success(self): expected_output = "expected output" expected_retval = 0 mock_runner = mock.MagicMock(spec_set=CommandRunner) mock_runner.run.return_value = (expected_output, expected_retval) self.assertEqual(None, lib.wait_for_resources(mock_runner)) mock_runner.run.assert_called_once_with( [self.path("crm_resource"), "--wait"] )
def test_wait_success(self): expected_stdout = "expected output" expected_stderr = "expected stderr" expected_retval = 0 mock_runner = mock.MagicMock(spec_set=CommandRunner) mock_runner.run.return_value = (expected_stdout, expected_stderr, expected_retval) self.assertEqual(None, lib.wait_for_resources(mock_runner)) mock_runner.run.assert_called_once_with( [self.path("crm_resource"), "--wait"])
def test_wait_error_timeout(self): expected_stdout = "some info" expected_stderr = "some error" expected_retval = 62 mock_runner = mock.MagicMock(spec_set=CommandRunner) mock_runner.run.return_value = (expected_stdout, expected_stderr, expected_retval) assert_raise_library_error( lambda: lib.wait_for_resources(mock_runner), (Severity.ERROR, report_codes.RESOURCE_WAIT_TIMED_OUT, { "reason": expected_stderr + "\n" + expected_stdout, })) mock_runner.run.assert_called_once_with( [self.path("crm_resource"), "--wait"])
def test_wait_timeout_success(self): expected_stdout = "expected output" expected_stderr = "expected stderr" expected_retval = 0 timeout = 10 mock_runner = mock.MagicMock(spec_set=CommandRunner) mock_runner.run.return_value = ( expected_stdout, expected_stderr, expected_retval ) self.assertEqual(None, lib.wait_for_resources(mock_runner, timeout)) mock_runner.run.assert_called_once_with( [ self.path("crm_resource"), "--wait", "--timeout={0}".format(timeout) ] )
def test_wait_error(self): expected_error = "some error" expected_retval = 1 mock_runner = mock.MagicMock(spec_set=CommandRunner) mock_runner.run.return_value = (expected_error, expected_retval) assert_raise_library_error( lambda: lib.wait_for_resources(mock_runner), ( Severity.ERROR, report_codes.RESOURCE_WAIT_ERROR, { "return_value": expected_retval, "stdout": expected_error, } ) ) mock_runner.run.assert_called_once_with( [self.path("crm_resource"), "--wait"] )