Skip to content

Commit

Permalink
Dev: ui_corosync: sync and reload corosync.conf after changes (jsc#PE…
Browse files Browse the repository at this point in the history
…D-8083)

Both updating link options and adding/removing links are hot reloadable.
Updating the address of existing nodes is not hot reloadable.
  • Loading branch information
nicholasyang2022 committed Jul 24, 2024
1 parent 9e453a4 commit da37610
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
19 changes: 16 additions & 3 deletions crmsh/ui_corosync.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import dataclasses
import ipaddress
import json
import subprocess
import sys
import typing

Expand Down Expand Up @@ -164,6 +165,7 @@ def do_update(self, context, *argv):
self.__save_changed_config(
lm,
lm.update_node_addr(args.linknumber, node_addresses),
reload=not args.nodes, # changes to node addresses are not hot reloadable
)

def do_add(self, context, *argv):
Expand All @@ -185,6 +187,7 @@ def do_add(self, context, *argv):
self.__save_changed_config(
lm,
lm.add_link(node_addresses, args.options),
reload=True,
)

@command.completer(completers.call(lambda: [
Expand All @@ -200,6 +203,7 @@ def do_remove(self, context, linknumber: str):
self.__save_changed_config(
lm,
lm.remove_link(linknumber),
reload=True,
)

@staticmethod
Expand All @@ -225,10 +229,19 @@ def __load_and_validate_links():
return lm

@staticmethod
def __save_changed_config(linkmanager, dom):
def __save_changed_config(linkmanager, dom, reload: bool):
linkmanager.write_config_file(dom)
logger.info("Use \"crm corosync diff\" to show the difference")
logger.info("Use \"crm corosync push\" to sync")
nodes = utils.list_cluster_nodes()
nodes.remove(utils.this_node())
logger.info('Synchronizing corosync.conf in the cluster...')
if not corosync.push_configuration(nodes):
raise ValueError('Failed to synchronize corosync.conf in the cluster.')
if reload:
result = subprocess.run(['corosync-cfgtool', '-R'])
if 0 != result.returncode:
raise ValueError('Failed to reload corosync.conf.')
else:
logger.info('Please restart corosync.service in the cluster to apply the changes.')


class Corosync(command.UI):
Expand Down
13 changes: 4 additions & 9 deletions test/features/corosync_ui.feature
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,14 @@ Feature: crm corosync ui test cases
When Run "crm corosync link update 0" on "hanode1"
Then Expected "Nothing is updated." in stdout
When Run "crm corosync link update 0 [email protected] [email protected] options knet_link_priority=10" on "hanode1"
Then Expected "crm corosync diff" in stdout
When Run "crm corosync diff" on "hanode1"
Then Expected "knet_link_priority: 10" in stdout
Then Expected "Please restart corosync.service in the cluster to apply the changes." in stdout
Given Run "systemctl restart corosync.service" OK on "hanode1,hanode2"
When Try "crm corosync link add [email protected] [email protected] options knet_link_priority=" on "hanode1"
Then Expected "invalid option" in stderr
When Run "crm corosync link add [email protected] [email protected] options knet_link_priority=11" on "hanode1"
Then Expected "crm corosync diff" in stdout
When Run "crm corosync diff" on "hanode1"
Then Expected "linknumber: 1" in stdout
Given Run "crm corosync link add [email protected] [email protected] options knet_link_priority=11" OK on "hanode1"
When Try "crm corosync link update 1 [email protected]" on "hanode1"
Then Expected "Duplicated" in stderr
When Run "crm corosync link remove 1" on "hanode1"
Then Expected "crm corosync diff" in stdout
Given Run "crm corosync link remove 1" OK on "hanode1"
When Try "crm corosync link add [email protected] [email protected]" on "hanode1"
Then Expected "Duplicated" in stderr
When Try "crm corosync link add hanode1=192.0.2.101 hanode2=192.0.2.102 options knet_link_priority=10" on "hanode1"
Expand Down

0 comments on commit da37610

Please sign in to comment.