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_error_some_nodes(self): nodes = ("node1", "node2", "node3", "node4") for i, n in enumerate(nodes, 1): self.fixture_add_node_status(self.fixture_get_node_status(n, i)) mock_runner = mock.MagicMock(spec_set=CommandRunner) call_list = [mock.call(self.crm_mon_cmd())] call_list += [ mock.call([self.path("crm_standby"), "-v", "on", "-N", n]) for n in nodes ] return_value_list = [ (str(self.status), "", 0), ("dummy1", "", 0), ("dummy2", "error2", 1), ("dummy3", "", 0), ("dummy4", "error4", 1), ] mock_runner.run.side_effect = return_value_list assert_raise_library_error( lambda: lib.nodes_standby(mock_runner, all_nodes=True), (Severity.ERROR, report_codes.COMMON_ERROR, { "text": "error2\ndummy2", }), (Severity.ERROR, report_codes.COMMON_ERROR, { "text": "error4\ndummy4", })) self.assertEqual(len(return_value_list), len(call_list)) self.assertEqual(len(return_value_list), mock_runner.run.call_count) mock_runner.run.assert_has_calls(call_list)
def test_standby_local(self): expected_retval = 0 mock_runner = mock.MagicMock(spec_set=CommandRunner) mock_runner.run.return_value = ("dummy", "", expected_retval) output = lib.nodes_standby(mock_runner) mock_runner.run.assert_called_once_with( [self.path("crm_standby"), "-v", "on"]) self.assertEqual(None, output)
def test_standby_local(self): expected_retval = 0 mock_runner = mock.MagicMock(spec_set=CommandRunner) mock_runner.run.return_value = ("dummy", "", expected_retval) output = lib.nodes_standby(mock_runner) mock_runner.run.assert_called_once_with( [self.path("crm_standby"), "-v", "on"] ) self.assertEqual(None, output)
def test_standby_unknown_node(self): self.fixture_add_node_status( self.fixture_get_node_status("node_1", "id_1")) mock_runner = mock.MagicMock(spec_set=CommandRunner) mock_runner.run.return_value = (str(self.status), "", 0) assert_raise_library_error( lambda: lib.nodes_standby(mock_runner, ["node_2"]), (Severity.ERROR, report_codes.NODE_NOT_FOUND, { "node": "node_2" })) mock_runner.run.assert_called_once_with(self.crm_mon_cmd())
def test_standby_unknown_node(self): self.fixture_add_node_status( self.fixture_get_node_status("node_1", "id_1") ) mock_runner = mock.MagicMock(spec_set=CommandRunner) mock_runner.run.return_value = (str(self.status), "", 0) assert_raise_library_error( lambda: lib.nodes_standby(mock_runner, ["node_2"]), ( Severity.ERROR, report_codes.NODE_NOT_FOUND, {"node": "node_2"} ) ) mock_runner.run.assert_called_once_with(self.crm_mon_cmd())
def test_error_some_nodes(self): nodes = ("node1", "node2", "node3", "node4") for i, n in enumerate(nodes, 1): self.fixture_add_node_status( self.fixture_get_node_status(n, i) ) mock_runner = mock.MagicMock(spec_set=CommandRunner) call_list = [mock.call(self.crm_mon_cmd())] call_list += [ mock.call([self.path("crm_standby"), "-v", "on", "-N", n]) for n in nodes ] return_value_list = [ (str(self.status), "", 0), ("dummy1", "", 0), ("dummy2", "error2", 1), ("dummy3", "", 0), ("dummy4", "error4", 1), ] mock_runner.run.side_effect = return_value_list assert_raise_library_error( lambda: lib.nodes_standby(mock_runner, all_nodes=True), ( Severity.ERROR, report_codes.COMMON_ERROR, { "text": "error2\ndummy2", } ), ( Severity.ERROR, report_codes.COMMON_ERROR, { "text": "error4\ndummy4", } ) ) self.assertEqual(len(return_value_list), len(call_list)) self.assertEqual(len(return_value_list), mock_runner.run.call_count) mock_runner.run.assert_has_calls(call_list)
def test_standby_nodes(self): nodes = ("node1", "node2", "node3") for i, n in enumerate(nodes, 1): self.fixture_add_node_status(self.fixture_get_node_status(n, i)) mock_runner = mock.MagicMock(spec_set=CommandRunner) call_list = [mock.call(self.crm_mon_cmd())] call_list += [ mock.call([self.path("crm_standby"), "-v", "on", "-N", n]) for n in nodes[1:] ] return_value_list = [(str(self.status), "", 0)] return_value_list += [("dummy", "", 0) for n in nodes[1:]] mock_runner.run.side_effect = return_value_list output = lib.nodes_standby(mock_runner, node_list=nodes[1:]) self.assertEqual(len(return_value_list), len(call_list)) self.assertEqual(len(return_value_list), mock_runner.run.call_count) mock_runner.run.assert_has_calls(call_list) self.assertEqual(None, output)
def test_standby_nodes(self): nodes = ("node1", "node2", "node3") for i, n in enumerate(nodes, 1): self.fixture_add_node_status( self.fixture_get_node_status(n, i) ) mock_runner = mock.MagicMock(spec_set=CommandRunner) call_list = [mock.call(self.crm_mon_cmd())] call_list += [ mock.call([self.path("crm_standby"), "-v", "on", "-N", n]) for n in nodes[1:] ] return_value_list = [(str(self.status), "", 0)] return_value_list += [("dummy", "", 0) for n in nodes[1:]] mock_runner.run.side_effect = return_value_list output = lib.nodes_standby(mock_runner, node_list=nodes[1:]) self.assertEqual(len(return_value_list), len(call_list)) self.assertEqual(len(return_value_list), mock_runner.run.call_count) mock_runner.run.assert_has_calls(call_list) self.assertEqual(None, output)