From b438fe5c0eb4e6fa738e21287540c0d8f6b91c68 Mon Sep 17 00:00:00 2001 From: Ivan Devat Date: Fri, 19 Aug 2016 02:57:39 +0200 Subject: [PATCH] squash bz1315371 [RFE] Provide configurable alerts 25a25c534ff6 show help when unknown subcommand of 'pcs alert recipient' was given c352ce184093 make syntax of command 'pcs alert recipient add' more consistent 8c6ec586d57c fix error handling when upgrading cib schema --- pcs/alert.py | 9 +++-- pcs/lib/cib/tools.py | 36 +++++++++-------- pcs/pcs.8 | 2 +- pcs/test/test_alert.py | 44 +++++++++++++------- pcs/test/test_lib_cib_tools.py | 91 ++++++++++++++++++++++++++++++++++++++++++ pcs/usage.py | 2 +- 6 files changed, 147 insertions(+), 37 deletions(-) diff --git a/pcs/alert.py b/pcs/alert.py index 693bb8d..17f4e8d 100644 --- a/pcs/alert.py +++ b/pcs/alert.py @@ -63,6 +63,8 @@ def recipient_cmd(*args): recipient_update(*args) elif sub_cmd == "remove": recipient_remove(*args) + else: + raise CmdLineInputError() except CmdLineInputError as e: utils.exit_on_cmdline_input_errror( e, "alert", "recipient {0}".format(sub_cmd) @@ -127,15 +129,14 @@ def recipient_add(lib, argv, modifiers): raise CmdLineInputError() alert_id = argv[0] - recipient_value = argv[1] - sections = parse_cmd_sections(argv[2:], set(["options", "meta"])) + sections = parse_cmd_sections(argv[1:], set(["options", "meta"])) main_args = prepare_options(sections["main"]) - ensure_only_allowed_options(main_args, ["description", "id"]) + ensure_only_allowed_options(main_args, ["description", "id", "value"]) lib.alert.add_recipient( alert_id, - recipient_value, + main_args.get("value", None), prepare_options(sections["options"]), prepare_options(sections["meta"]), recipient_id=main_args.get("id", None), diff --git a/pcs/lib/cib/tools.py b/pcs/lib/cib/tools.py index d8ce57a..8141360 100644 --- a/pcs/lib/cib/tools.py +++ b/pcs/lib/cib/tools.py @@ -176,29 +176,31 @@ def upgrade_cib(cib, runner): cib -- cib etree runner -- CommandRunner """ - temp_file = tempfile.NamedTemporaryFile("w+", suffix=".pcs") - temp_file.write(etree.tostring(cib).decode()) - temp_file.flush() - output, retval = runner.run( - [ - os.path.join(settings.pacemaker_binaries, "cibadmin"), - "--upgrade", - "--force" - ], - env_extend={"CIB_file": temp_file.name} - ) + temp_file = None + try: + temp_file = tempfile.NamedTemporaryFile("w+", suffix=".pcs") + temp_file.write(etree.tostring(cib).decode()) + temp_file.flush() + output, retval = runner.run( + [ + os.path.join(settings.pacemaker_binaries, "cibadmin"), + "--upgrade", + "--force" + ], + env_extend={"CIB_file": temp_file.name} + ) - if retval != 0: - temp_file.close() - LibraryError(reports.cib_upgrade_failed(output)) + if retval != 0: + temp_file.close() + raise LibraryError(reports.cib_upgrade_failed(output)) - try: temp_file.seek(0) return etree.fromstring(temp_file.read()) except (EnvironmentError, etree.XMLSyntaxError, etree.DocumentInvalid) as e: - LibraryError(reports.cib_upgrade_failed(str(e))) + raise LibraryError(reports.cib_upgrade_failed(str(e))) finally: - temp_file.close() + if temp_file: + temp_file.close() def ensure_cib_version(runner, cib, version): diff --git a/pcs/pcs.8 b/pcs/pcs.8 index 7a054ca..b3c4877 100644 --- a/pcs/pcs.8 +++ b/pcs/pcs.8 @@ -727,7 +727,7 @@ Update existing alert handler with specified id. remove Remove alert handler with specified id. .TP -recipient add [id=] [description=] [options [