Skip to content

Commit

Permalink
[crmsh-4.6] Improve configure schema command (#1691)
Browse files Browse the repository at this point in the history
backport #1690
  • Loading branch information
liangxin1300 authored Feb 18, 2025
2 parents c736573 + d59ea7a commit 34cf2a4
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 16 deletions.
5 changes: 3 additions & 2 deletions crmsh/cibconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -2518,7 +2518,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())
Expand Down Expand Up @@ -3367,7 +3368,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():
Expand Down
5 changes: 3 additions & 2 deletions crmsh/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@


logger = log.setup_logger(__name__)
PCMK_MIN_SCHEMA_VERSION = 1.0


def is_supported(name):
Expand All @@ -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):
Expand Down
3 changes: 2 additions & 1 deletion crmsh/ui_configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -972,7 +972,8 @@ def do_upgrade(self, context, force=None):
@command.completers(schema_completer)
def do_schema(self, context, schema_st=None):
"usage: schema [<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)
Expand Down
24 changes: 13 additions & 11 deletions doc/crm.8.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -3799,24 +3799,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 +<TAB><TAB>+ 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>]
schema [<pacemaker-schema_version>]
...............
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]]
Expand Down
13 changes: 13 additions & 0 deletions test/features/configure_bugs.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
17 changes: 17 additions & 0 deletions test/features/steps/step_implementation.py
Original file line number Diff line number Diff line change
Expand Up @@ -597,3 +597,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

0 comments on commit 34cf2a4

Please sign in to comment.