def test_wait(self): resource.resource_disable_cmd(self.lib, ["R1", "R2"], dict_to_modifiers(dict(wait="10"))) self.report_processor.suppress_reports_of_severity.assert_not_called() self.resource.disable.assert_called_once_with(["R1", "R2"], "10") self.resource.disable_safe.assert_not_called() self.resource.disable_simulate.assert_not_called()
def test_one_resource(self): resource.resource_disable_cmd(self.lib, ["R1"], dict_to_modifiers(dict())) self.resource.disable.assert_called_once_with(["R1"], False) self.report_processor.suppress_reports_of_severity.assert_not_called() self.resource.disable_safe.assert_not_called() self.resource.disable_simulate.assert_not_called()
def stonith_cmd(argv): if len(argv) < 1: sub_cmd, argv_next = "show", [] else: sub_cmd, argv_next = argv[0], argv[1:] lib = utils.get_library_wrapper() modifiers = utils.get_modifiers() try: if sub_cmd == "help": usage.stonith([" ".join(argv_next)] if argv_next else []) elif sub_cmd == "list": stonith_list_available(lib, argv_next, modifiers) elif sub_cmd == "describe": stonith_list_options(lib, argv_next, modifiers) elif sub_cmd == "create": stonith_create(lib, argv_next, modifiers) elif sub_cmd == "update": if len(argv_next) > 1: stn_id = argv_next.pop(0) resource.resource_update(stn_id, argv_next) else: raise CmdLineInputError() elif sub_cmd == "delete": if len(argv_next) == 1: stn_id = argv_next.pop(0) resource.resource_remove(stn_id) else: raise CmdLineInputError() elif sub_cmd == "show": resource.resource_show(argv_next, True) levels = stonith_level_config_to_str( lib.fencing_topology.get_config()) if levels: print("\n".join(indent(levels, 1))) elif sub_cmd == "level": stonith_level_cmd(lib, argv_next, modifiers) elif sub_cmd == "fence": stonith_fence(argv_next) elif sub_cmd == "cleanup": resource.resource_cleanup(argv_next) elif sub_cmd == "refresh": resource.resource_refresh(argv_next) elif sub_cmd == "confirm": stonith_confirm(argv_next) elif sub_cmd == "get_fence_agent_info": get_fence_agent_info(argv_next) elif sub_cmd == "sbd": sbd_cmd(lib, argv_next, modifiers) elif sub_cmd == "enable": resource.resource_enable_cmd(lib, argv_next, modifiers) elif sub_cmd == "disable": resource.resource_disable_cmd(lib, argv_next, modifiers) else: raise CmdLineInputError() except LibraryError as e: utils.process_library_reports(e.args) except CmdLineInputError as e: utils.exit_on_cmdline_input_errror(e, "stonith", sub_cmd)
def test_wait(self): resource.resource_disable_cmd( self.lib, ["R1", "R2"], dict_to_modifiers(dict(wait="10")) ) self.resource.disable.assert_called_once_with(["R1", "R2"], "10") self.resource.disable_safe.assert_not_called() self.resource.disable_simulate.assert_not_called()
def test_more_resources(self): resource.resource_disable_cmd( self.lib, ["R1", "R2"], dict_to_modifiers(dict()) ) self.resource.disable.assert_called_once_with(["R1", "R2"], False) self.resource.disable_safe.assert_not_called() self.resource.disable_simulate.assert_not_called()
def test_safe_no_strict(self): resource.resource_disable_cmd(self.lib, ["R1", "R2"], dict_to_modifiers({"no-strict": True})) self.resource.disable_safe.assert_called_once_with(["R1", "R2"], False, False) self.report_processor.suppress_reports_of_severity.assert_not_called() self.resource.disable.assert_not_called() self.resource.disable_simulate.assert_not_called()
def test_simulate(self, mock_print): self.resource.disable_simulate.return_value = "simulate output" resource.resource_disable_cmd( self.lib, ["R1", "R2"], dict_to_modifiers(dict(simulate=True)) ) self.resource.disable_simulate.assert_called_once_with(["R1", "R2"]) self.resource.disable.assert_not_called() self.resource.disable_safe.assert_not_called() mock_print.assert_called_once_with("simulate output")
def stonith_cmd(lib, argv, modifiers): if argv: sub_cmd, argv_next = argv[0], argv[1:] else: sub_cmd, argv_next = "status", [] try: if sub_cmd == "help": usage.stonith([" ".join(argv_next)] if argv_next else []) elif sub_cmd == "list": stonith_list_available(lib, argv_next, modifiers) elif sub_cmd == "describe": stonith_list_options(lib, argv_next, modifiers) elif sub_cmd == "create": stonith_create(lib, argv_next, modifiers) elif sub_cmd == "update": resource.resource_update(lib, argv_next, modifiers) elif sub_cmd in {"delete", "remove"}: resource.resource_remove_cmd(lib, argv_next, modifiers) # TODO remove, deprecated command # replaced with 'stonith status' and 'stonith config' elif sub_cmd == "show": resource.resource_show(lib, argv_next, modifiers, stonith=True) print_stonith_levels(lib) elif sub_cmd == "status": resource.resource_status(lib, argv_next, modifiers, stonith=True) print_stonith_levels(lib) elif sub_cmd == "config": resource.resource_config(lib, argv_next, modifiers, stonith=True) print_stonith_levels(lib) elif sub_cmd == "level": stonith_level_cmd(lib, argv_next, modifiers) elif sub_cmd == "fence": stonith_fence(lib, argv_next, modifiers) elif sub_cmd == "cleanup": resource.resource_cleanup(lib, argv_next, modifiers) elif sub_cmd == "refresh": resource.resource_refresh(lib, argv_next, modifiers) elif sub_cmd == "confirm": stonith_confirm(lib, argv_next, modifiers) elif sub_cmd == "get_fence_agent_info": get_fence_agent_info(lib, argv_next, modifiers) elif sub_cmd == "sbd": sbd_cmd(lib, argv_next, modifiers) elif sub_cmd == "enable": resource.resource_enable_cmd(lib, argv_next, modifiers) elif sub_cmd == "disable": resource.resource_disable_cmd(lib, argv_next, modifiers) elif sub_cmd == "history": stonith_history_cmd(lib, argv_next, modifiers) else: raise CmdLineInputError() except LibraryError as e: utils.process_library_reports(e.args) except CmdLineInputError as e: utils.exit_on_cmdline_input_errror(e, "stonith", sub_cmd)
def test_simulate(self, mock_print): self.resource.disable_simulate.return_value = self._fixture_output() resource.resource_disable_cmd(self.lib, ["R1", "R2"], dict_to_modifiers(dict(simulate=True))) self.resource.disable_simulate.assert_called_once_with(["R1", "R2"], True) self.report_processor.suppress_reports_of_severity.assert_not_called() self.resource.disable.assert_not_called() self.resource.disable_safe.assert_not_called() mock_print.assert_called_once_with("simulate output")
def test_no_args(self): with self.assertRaises(CmdLineInputError) as cm: resource.resource_disable_cmd(self.lib, [], dict_to_modifiers(dict())) self.assertEqual(cm.exception.message, "You must specify resource(s) to disable") self.report_processor.suppress_reports_of_severity.assert_not_called() self.resource.disable.assert_not_called() self.resource.disable_safe.assert_not_called() self.resource.disable_simulate.assert_not_called()
def test_safe_no_strict_wait(self): resource.resource_disable_cmd( self.lib, ["R1", "R2"], dict_to_modifiers({"no-strict": True, "wait": "10"}), ) self.resource.disable_safe.assert_called_once_with( ["R1", "R2"], False, "10" ) self.resource.disable.assert_not_called() self.resource.disable_simulate.assert_not_called()
def test_safe_brief(self): resource.resource_disable_cmd( self.lib, ["R1", "R2"], dict_to_modifiers(dict(safe=True, brief=True)), ) self.resource.disable_safe.assert_called_once_with(["R1", "R2"], True, False) self.report_processor.suppress_reports_of_severity.assert_called_once_with( [ReportItemSeverity.INFO]) self.resource.disable.assert_not_called() self.resource.disable_simulate.assert_not_called()
def test_simulate_wait(self): with self.assertRaises(CmdLineInputError) as cm: resource.resource_disable_cmd( self.lib, ["R1"], dict_to_modifiers(dict(simulate=True, wait=True)), ) self.assertEqual( cm.exception.message, "Only one of '--simulate', '--wait' can be used", ) self.resource.disable.assert_not_called() self.resource.disable_safe.assert_not_called() self.resource.disable_simulate.assert_not_called()
def test_simulate_safe(self): with self.assertRaises(CmdLineInputError) as cm: resource.resource_disable_cmd( self.lib, ["R1"], dict_to_modifiers( {"no-strict": True, "simulate": True, "safe": True} ), ) self.assertEqual( cm.exception.message, "'--simulate' cannot be used with '--safe'" ) self.resource.disable.assert_not_called() self.resource.disable_safe.assert_not_called() self.resource.disable_simulate.assert_not_called()