Skip to content

Commit

Permalink
Dev: migration: implement multicast to knet migration (jsc#PED-8252)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholasyang2022 committed May 22, 2024
1 parent 4ce0593 commit 6b8ae7f
Showing 1 changed file with 65 additions and 10 deletions.
75 changes: 65 additions & 10 deletions crmsh/migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
import os
import re
import shutil
import tempfile
import typing

Check warning on line 6 in crmsh/migration.py

View check run for this annotation

Codecov / codecov/patch

crmsh/migration.py#L1-L6

Added lines #L1 - L6 were not covered by tests

import lxml.etree

Check warning on line 8 in crmsh/migration.py

View check run for this annotation

Codecov / codecov/patch

crmsh/migration.py#L8

Added line #L8 was not covered by tests

from crmsh import constants
from crmsh import corosync
from crmsh import corosync_config_format
from crmsh import parallax
from crmsh import service_manager
from crmsh import sh
from crmsh import utils

Check warning on line 16 in crmsh/migration.py

View check run for this annotation

Codecov / codecov/patch

crmsh/migration.py#L10-L16

Added lines #L10 - L16 were not covered by tests
Expand Down Expand Up @@ -88,8 +90,8 @@ def migrate_corosync_conf_impl(config):
corosync.ConfParser.transform_dom_with_list_schema(config)
ensure_node_id(config)
migrate_transport(config)
migrate_crypto(config)
migrate_rrp(config)

Check warning on line 94 in crmsh/migration.py

View check run for this annotation

Codecov / codecov/patch

crmsh/migration.py#L87-L94

Added lines #L87 - L94 were not covered by tests
# TODO: migrate from multicast to unicast
# TODO: other migrations


Expand All @@ -112,17 +114,23 @@ def ensure_node_id(dom):


def migrate_transport(dom):
if dom['totem'].get('transport', None) == 'knet':
return
match dom['totem'].get('transport', None):
case 'knet':
return
case 'udpu':
migrate_udpu(dom)
case 'udp':
migrate_multicast(dom)
case _:

Check warning on line 124 in crmsh/migration.py

View check run for this annotation

Codecov / codecov/patch

crmsh/migration.py#L116-L124

Added lines #L116 - L124 were not covered by tests
# corosync 2 defaults to "udp"
# FIXME: what if an already migrated config if provided
migrate_multicast(dom)
pass

Check warning on line 128 in crmsh/migration.py

View check run for this annotation

Codecov / codecov/patch

crmsh/migration.py#L127-L128

Added lines #L127 - L128 were not covered by tests


def migrate_udpu(dom):
dom['totem']['transport'] = 'knet'
dom['totem']['knet_compression_model'] = 'none'
try:
# corosync 3 change the default hash algorithm to sha256 when `secauth` is enabled
if dom['totem'].get('crypto_hash', None) == 'sha1':
dom['totem']['crypto_hash'] = 'sha256'
logger.info('Change totem.crypto_hash from "sha1" to "sha256".')
except KeyError:
dom['totem']['crypto_hash'] = 'sha256'
if 'interface' in dom['totem']:
for interface in dom['totem']['interface']:

Check warning on line 135 in crmsh/migration.py

View check run for this annotation

Codecov / codecov/patch

crmsh/migration.py#L131-L135

Added lines #L131 - L135 were not covered by tests
# remove udp-only items
Expand All @@ -137,6 +145,53 @@ def migrate_transport(dom):
logger.info("Change totem.transport to knet.")

Check warning on line 145 in crmsh/migration.py

View check run for this annotation

Codecov / codecov/patch

crmsh/migration.py#L137-L145

Added lines #L137 - L145 were not covered by tests


def migrate_multicast(dom):
dom['totem']['transport'] = 'knet'
dom['totem']['knet_compression_model'] = 'none'
for interface in dom['totem']['interface']:

Check warning on line 151 in crmsh/migration.py

View check run for this annotation

Codecov / codecov/patch

crmsh/migration.py#L148-L151

Added lines #L148 - L151 were not covered by tests
# remove udp-only items
interface.pop('mcastaddr', None)
interface.pop('bindnetaddr', None)
interface.pop('broadcast', None)
interface.pop('ttl', None)
ringnumber = interface.pop('ringnumber', None)
if ringnumber is not None:
interface['linknumber'] = ringnumber
with open(constants.CIB_RAW_FILE, 'rb') as f:
cib = Cib(f)
cib_nodes = cib.nodes()
assert 'nodelist' not in dom
nodelist = list()
with tempfile.TemporaryDirectory(prefix='crmsh-migration-') as dir_name:
node_configs = {

Check warning on line 166 in crmsh/migration.py

View check run for this annotation

Codecov / codecov/patch

crmsh/migration.py#L153-L166

Added lines #L153 - L166 were not covered by tests
x[0]: x[1]
for x in parallax.parallax_slurp([x.uname for x in cib_nodes], dir_name, corosync.conf())
}
for node in cib_nodes:
assert node.uname in node_configs
with open(node_configs[node.uname], 'r', encoding='utf-8') as f:
root = corosync_config_format.DomParser(f).dom()
corosync.ConfParser.transform_dom_with_list_schema(root)
interfaces = root['totem']['interface']
nodelist.append({

Check warning on line 176 in crmsh/migration.py

View check run for this annotation

Codecov / codecov/patch

crmsh/migration.py#L170-L176

Added lines #L170 - L176 were not covered by tests
'nodeid': node.node_id,
'name': node.uname
} | {
f'ring{i}_addr': x['bindnetaddr'] for i, x in enumerate(interfaces)
})
dom['nodelist'] = {'node': nodelist}

Check warning on line 182 in crmsh/migration.py

View check run for this annotation

Codecov / codecov/patch

crmsh/migration.py#L182

Added line #L182 was not covered by tests


def migrate_crypto(dom):
try:

Check warning on line 186 in crmsh/migration.py

View check run for this annotation

Codecov / codecov/patch

crmsh/migration.py#L185-L186

Added lines #L185 - L186 were not covered by tests
# corosync 3 change the default hash algorithm to sha256 when `secauth` is enabled
if dom['totem'].get('crypto_hash', None) == 'sha1':
dom['totem']['crypto_hash'] = 'sha256'
logger.info('Change totem.crypto_hash from "sha1" to "sha256".')
except KeyError:
dom['totem']['crypto_hash'] = 'sha256'

Check warning on line 192 in crmsh/migration.py

View check run for this annotation

Codecov / codecov/patch

crmsh/migration.py#L188-L192

Added lines #L188 - L192 were not covered by tests


def migrate_rrp(dom):
try:
nodes = dom['nodelist']['node']
Expand Down

0 comments on commit 6b8ae7f

Please sign in to comment.