Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve configure schema command #1690

Merged
merged 4 commits into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions crmsh/cibconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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():
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 @@ -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 [<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 @@ -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 +<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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
schema
schema


# To set the new schema version
schema pacemaker-4.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
schema pacemaker-4.0
schema pacemaker-4.0


# Then need to run `commit` to make the change effective
# if it's on interactive mode
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# if it's on interactive mode
# if it's on interactive mode
commit

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 @@ -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