Blame SOURCES/bz1786964-02-make-booth-ticket-mode-value-case-insensitive.patch

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