From 367b12a58db4e2ae767d6753c97c0a9c61edbc67 Mon Sep 17 00:00:00 2001 From: xin liang Date: Fri, 14 Feb 2025 13:26:25 +0800 Subject: [PATCH 1/4] Dev: schema: Make sure schema changed after setting new schema by `configure schema` Also return False if schema is not supported. --- crmsh/cibconfig.py | 5 +++-- crmsh/schema.py | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/crmsh/cibconfig.py b/crmsh/cibconfig.py index 455fc51ea3..42bc590e5d 100644 --- a/crmsh/cibconfig.py +++ b/crmsh/cibconfig.py @@ -2516,7 +2516,8 @@ def change_schema(self, schema_st): logger.info("already using schema %s", schema_st) return True if not schema.is_supported(schema_st): - logger.warning("schema %s is not supported by the shell", schema_st) + logger.error("schema %s is not supported", schema_st) + return False self.cib_elem.set("validate-with", schema_st) if not schema.test_schema(self.cib_elem): self.cib_elem.set("validate-with", self.get_schema()) @@ -3338,7 +3339,7 @@ def has_cib_changed(self): elif not self.is_cib_sane(): return False else: - return self.modified_elems() or self.remove_queue + return self.modified_elems() or self.remove_queue or self.new_schema def ensure_cib_updated(self): if options.interactive and not self.has_cib_changed(): diff --git a/crmsh/schema.py b/crmsh/schema.py index a53c16936e..8dc7afa90f 100644 --- a/crmsh/schema.py +++ b/crmsh/schema.py @@ -8,6 +8,7 @@ logger = log.setup_logger(__name__) +PCMK_MIN_SCHEMA_VERSION = 1.0 def is_supported(name): @@ -23,8 +24,8 @@ def is_supported(name): """ name = re.match(r'pacemaker-(\d+\.\d+)$', name) if name: - return float(name.group(1)) > 0.9 - return True + return float(name.group(1)) >= PCMK_MIN_SCHEMA_VERSION + return False def get_attrs(schema, name): From d18356f31bc51e2fb586fb3e6c8177180c34e671 Mon Sep 17 00:00:00 2001 From: xin liang Date: Mon, 17 Feb 2025 21:35:10 +0800 Subject: [PATCH 2/4] Dev: ui_configure: Get schema statically when cluster is not running --- crmsh/ui_configure.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crmsh/ui_configure.py b/crmsh/ui_configure.py index 4700cd1590..1a6b7eed3c 100644 --- a/crmsh/ui_configure.py +++ b/crmsh/ui_configure.py @@ -978,7 +978,8 @@ def do_upgrade(self, context, force=None): @command.completers(schema_completer) def do_schema(self, context, schema_st=None): "usage: schema []" - if not schema_st: + utils.load_cib_file_env() + if not schema_st and cib_factory.is_cib_sane(): print(cib_factory.get_schema()) return True return cib_factory.change_schema(schema_st) From de50f0efc0234dff1e0a42356393942f8a24d4c5 Mon Sep 17 00:00:00 2001 From: xin liang Date: Fri, 14 Feb 2025 17:08:35 +0800 Subject: [PATCH 3/4] Dev: doc: Improve documentation for `configure schema` command --- doc/crm.8.adoc | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/doc/crm.8.adoc b/doc/crm.8.adoc index 3b5e73794f..7a165f56c0 100644 --- a/doc/crm.8.adoc +++ b/doc/crm.8.adoc @@ -3885,24 +3885,26 @@ save web-server server-config.txt ==== `schema` CIB's content is validated by a RNG schema. Pacemaker supports -several, depending on version. At least the following schemas are -accepted by `crmsh`: +several, depending on version. You can see all supported schemas by +typing ++ after `crm configure schema`. -* +pacemaker-1.0+ -* +pacemaker-1.1+ -* +pacemaker-1.2+ -* +pacemaker-1.3+ -* +pacemaker-2.0+ - -Use this command to display or switch to another RNG schema. +Note that it is highly recommended to use the latest schema version. Usage: ............... -schema [] +schema [] ............... Example: ............... -schema pacemaker-1.1 +# To get the schema version of the current CIB, or the latest version if no cluster configured yet +schema + +# To set the new schema version +schema pacemaker-4.0 + +# Then need to run `commit` to make the change effective +# if it's on interactive mode +commit ............... [[cmdhelp.configure.set,set an attribute value]] From 9b1bfe5ff7a20826da90212220f3d7dc7b905afa Mon Sep 17 00:00:00 2001 From: xin liang Date: Fri, 14 Feb 2025 16:50:34 +0800 Subject: [PATCH 4/4] Dev: behave: Add test case for schema change --- test/features/configure_bugs.feature | 13 +++++++++++++ test/features/steps/step_implementation.py | 17 +++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/test/features/configure_bugs.feature b/test/features/configure_bugs.feature index 7fdbbe58eb..be239e2a92 100644 --- a/test/features/configure_bugs.feature +++ b/test/features/configure_bugs.feature @@ -52,3 +52,16 @@ Feature: Functional test for configure sub level And Try "crm configure show|grep -E "@vip.0|qwertyui"" Then Expected return code is "1" And Show crm configure + + @clean + Scenario: Setting schema + Given Cluster service is "stopped" on "hanode1" + And Cluster service is "stopped" on "hanode2" + When Run "crm cluster init -y" on "hanode1" + Then Cluster service is "started" on "hanode1" + When Run "crm cluster join -c hanode1 -y" on "hanode2" + Then Cluster service is "started" on "hanode2" + And Online nodes are "hanode1 hanode2" + Then Test schema change + When Try "crm configure schema xxx" on "hanode1" + Then Except "schema xxx is not supported" in stderr diff --git a/test/features/steps/step_implementation.py b/test/features/steps/step_implementation.py index b87b52c31e..0a8a5063d6 100644 --- a/test/features/steps/step_implementation.py +++ b/test/features/steps/step_implementation.py @@ -605,3 +605,20 @@ def step_impl(context, nodes): EOF''', user='root', ) + + +@then('Test schema change') +def step_impl(context): + rc, schema, _ = ShellUtils().get_stdout_stderr("crm configure schema") + if rc != 0 or not schema: + return False + ver = re.search(r'pacemaker-(\d+\.\d+)', schema).group(1) + expected_ver = float(ver) - 0.1 + expected_schema = f"pacemaker-{expected_ver:.1f}" + rc, _, _ = ShellUtils().get_stdout_stderr(f"crm configure schema {expected_schema}") + if rc != 0: + return False + rc, schema, _ = ShellUtils().get_stdout_stderr("crm configure schema") + if rc != 0 or not schema: + return False + assert schema == expected_schema