From de4845ea2d22c7dd9f4539360b44a900b1cea193 Mon Sep 17 00:00:00 2001 From: Tomas Jelinek Date: Thu, 14 Jul 2022 16:46:33 +0200 Subject: [PATCH 2/3] make booth ticket mode value case insensitive --- pcs/lib/booth/config_validators.py | 10 ++++++++ pcs/lib/commands/booth.py | 14 +++++++++--- pcs_test/tier0/lib/commands/test_booth.py | 28 ++++++++++++++++------- 3 files changed, 41 insertions(+), 11 deletions(-) diff --git a/pcs/lib/booth/config_validators.py b/pcs/lib/booth/config_validators.py index 99badc46..6c4a4ddc 100644 --- a/pcs/lib/booth/config_validators.py +++ b/pcs/lib/booth/config_validators.py @@ -100,6 +100,16 @@ def remove_ticket(conf_facade, ticket_name): return [] +def ticket_options_normalization() -> validate.TypeNormalizeFunc: + return validate.option_value_normalization( + { + "mode": ( + lambda value: value.lower() if isinstance(value, str) else value + ) + } + ) + + def validate_ticket_name(ticket_name: str) -> reports.ReportItemList: if not __TICKET_NAME_RE.search(ticket_name): return [ diff --git a/pcs/lib/commands/booth.py b/pcs/lib/commands/booth.py index e7891fbe..fc1454ce 100644 --- a/pcs/lib/commands/booth.py +++ b/pcs/lib/commands/booth.py @@ -23,7 +23,10 @@ from pcs.common.reports.item import ( ) from pcs.common.services.errors import ManageServiceError from pcs.common.str_tools import join_multilines -from pcs.lib import tools +from pcs.lib import ( + tools, + validate, +) from pcs.lib.booth import ( config_files, config_validators, @@ -329,17 +332,22 @@ def config_ticket_add( booth_env = env.get_booth_env(instance_name) try: booth_conf = booth_env.config.read_to_facade() + options_pairs = validate.values_to_pairs( + options, config_validators.ticket_options_normalization() + ) report_processor.report_list( config_validators.add_ticket( booth_conf, ticket_name, - options, + options_pairs, allow_unknown_options=allow_unknown_options, ) ) if report_processor.has_errors: raise LibraryError() - booth_conf.add_ticket(ticket_name, options) + booth_conf.add_ticket( + ticket_name, validate.pairs_to_values(options_pairs) + ) booth_env.config.write_facade(booth_conf, can_overwrite=True) except RawFileError as e: report_processor.report(raw_file_error_report(e)) diff --git a/pcs_test/tier0/lib/commands/test_booth.py b/pcs_test/tier0/lib/commands/test_booth.py index 2b20a199..12b169c2 100644 --- a/pcs_test/tier0/lib/commands/test_booth.py +++ b/pcs_test/tier0/lib/commands/test_booth.py @@ -1194,7 +1194,7 @@ class ConfigTicketAdd(TestCase, FixtureMixin): }, ) - def test_success_ticket_options(self): + def assert_success_ticket_options(self, options_command, options_config): self.config.raw_file.read( file_type_codes.BOOTH_CONFIG, self.fixture_cfg_path(), @@ -1203,17 +1203,29 @@ class ConfigTicketAdd(TestCase, FixtureMixin): self.config.raw_file.write( file_type_codes.BOOTH_CONFIG, self.fixture_cfg_path(), - self.fixture_cfg_content( - ticket_list=[ - ["ticketA", [("retries", "10"), ("timeout", "20")]] - ] - ), + self.fixture_cfg_content(ticket_list=[["ticketA", options_config]]), can_overwrite=True, ) commands.config_ticket_add( - self.env_assist.get_env(), - "ticketA", + self.env_assist.get_env(), "ticketA", options_command + ) + + def test_success_ticket_options(self): + self.assert_success_ticket_options( {"timeout": "20", "retries": "10"}, + [("retries", "10"), ("timeout", "20")], + ) + + def test_success_ticket_options_mode(self): + self.assert_success_ticket_options( + {"timeout": "20", "retries": "10", "mode": "manual"}, + [("mode", "manual"), ("retries", "10"), ("timeout", "20")], + ) + + def test_success_ticket_options_mode_case_insensitive(self): + self.assert_success_ticket_options( + {"timeout": "20", "retries": "10", "mode": "MaNuAl"}, + [("mode", "manual"), ("retries", "10"), ("timeout", "20")], ) def test_ticket_already_exists(self): -- 2.35.3