Skip to content

Commit 7c80f38

Browse files
authored
Merge pull request #1405 from liangxin1300/20240425_firewalld_issue
Fix: bootstrap: open corosync ports in firewalld
2 parents 42ad4f1 + 596d6b3 commit 7c80f38

File tree

6 files changed

+16
-91
lines changed

6 files changed

+16
-91
lines changed

crmsh/bootstrap.py

Lines changed: 7 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@
5959
SYSCONFIG_SBD = "/etc/sysconfig/sbd"
6060
SYSCONFIG_PCMK = "/etc/sysconfig/pacemaker"
6161
SYSCONFIG_NFS = "/etc/sysconfig/nfs"
62-
SYSCONFIG_FW = "/etc/sysconfig/SuSEfirewall2"
63-
SYSCONFIG_FW_CLUSTER = "/etc/sysconfig/SuSEfirewall2.d/services/cluster"
6462
PCMK_REMOTE_AUTH = "/etc/pacemaker/authkey"
6563
COROSYNC_CONF_ORIG = tmpfiles.create()[1]
6664
SERVICES_STOP_LIST = ["corosync-qdevice.service", "corosync.service", "hawk.service", CSYNC2_SERVICE]
@@ -659,35 +657,6 @@ def configure_firewall(tcp=None, udp=None):
659657
if udp is None:
660658
udp = []
661659

662-
def init_firewall_suse(tcp, udp):
663-
if os.path.exists(SYSCONFIG_FW_CLUSTER):
664-
cluster = utils.parse_sysconfig(SYSCONFIG_FW_CLUSTER)
665-
tcpcurr = set(cluster.get("TCP", "").split())
666-
tcpcurr.update(tcp)
667-
tcp = list(tcpcurr)
668-
udpcurr = set(cluster.get("UDP", "").split())
669-
udpcurr.update(udp)
670-
udp = list(udpcurr)
671-
672-
utils.sysconfig_set(SYSCONFIG_FW_CLUSTER, TCP=" ".join(tcp), UDP=" ".join(udp))
673-
674-
ext = ""
675-
if os.path.exists(SYSCONFIG_FW):
676-
fw = utils.parse_sysconfig(SYSCONFIG_FW)
677-
ext = fw.get("FW_CONFIGURATIONS_EXT", "")
678-
if "cluster" not in ext.split():
679-
ext = ext + " cluster"
680-
utils.sysconfig_set(SYSCONFIG_FW, FW_CONFIGURATIONS_EXT=ext)
681-
682-
# No need to do anything else if the firewall is inactive
683-
if not ServiceManager().service_is_active("SuSEfirewall2"):
684-
return
685-
686-
# Firewall is active, either restart or complain if we couldn't tweak it
687-
logger.info("Restarting firewall (tcp={}, udp={})".format(" ".join(tcp), " ".join(udp)))
688-
if not invokerc("rcSuSEfirewall2 restart"):
689-
utils.fatal("Failed to restart firewall (SuSEfirewall2)")
690-
691660
def init_firewall_firewalld(tcp, udp):
692661
has_firewalld = ServiceManager().service_is_active("firewalld")
693662
cmdbase = 'firewall-cmd --zone=public --permanent ' if has_firewalld else 'firewall-offline-cmd --zone=public '
@@ -719,8 +688,6 @@ def init_firewall_ufw(tcp, udp):
719688

720689
if utils.package_is_installed("firewalld"):
721690
init_firewall_firewalld(tcp, udp)
722-
elif utils.package_is_installed("SuSEfirewall2"):
723-
init_firewall_suse(tcp, udp)
724691
elif utils.package_is_installed("ufw"):
725692
init_firewall_ufw(tcp, udp)
726693

@@ -729,7 +696,11 @@ def firewall_open_basic_ports():
729696
"""
730697
Open ports for csync2, hawk & dlm respectively
731698
"""
732-
configure_firewall(tcp=["30865", "7630", "21064"])
699+
configure_firewall(tcp=[
700+
constants.CSYNC2_PORT,
701+
constants.HAWK_PORT,
702+
constants.DLM_PORT
703+
])
733704

734705

735706
def firewall_open_corosync_ports():
@@ -744,7 +715,7 @@ def firewall_open_corosync_ports():
744715
Also open QNetd/QDevice port if configured.
745716
"""
746717
# all mcastports defined in corosync config
747-
udp = corosync.get_values("totem.interface.mcastport")
718+
udp = corosync.get_values("totem.interface.mcastport") or [constants.COROSYNC_PORT]
748719
udp.extend([str(int(p) - 1) for p in udp])
749720

750721
tcp = corosync.get_values("totem.quorum.device.net.port")
@@ -757,8 +728,7 @@ def init_cluster_local():
757728
if ServiceManager().service_is_active("corosync.service"):
758729
utils.fatal("corosync service is running!")
759730

760-
# FIXME This is temporarily commentted out since issue from new corosync parser
761-
#firewall_open_corosync_ports()
731+
firewall_open_corosync_ports()
762732

763733
# reset password, but only if it's not already set
764734
# (We still need the hacluster for the hawk).

crmsh/constants.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,4 +520,9 @@
520520
NON_FUNCTIONAL_COMMANDS = {'help', 'cd', 'ls', 'quit', 'up'}
521521
NON_FUNCTIONAL_OPTIONS = {'--help', '--help-without-redirect'}
522522
COROSYNC_STATUS_TYPES = ("ring", "quorum", "qdevice", "qnetd", "cpg")
523+
524+
COROSYNC_PORT = 5405
525+
CSYNC2_PORT = 30865
526+
HAWK_PORT = 7630
527+
DLM_PORT = 21064
523528
# vim:ts=4:sw=4:et:

crmsh/crash_test/check.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,6 @@ def check_port_open(task, firewall_type):
164164
task.info("UDP port {} is opened in firewalld".format(p))
165165
else:
166166
task.error("UDP port {} should open in firewalld".format(p))
167-
elif firewall_type == "SuSEfirewall2":
168-
#TODO
169-
pass
170167

171168

172169
def check_firewall():
@@ -175,7 +172,7 @@ def check_firewall():
175172
"""
176173
task_inst = task.TaskCheck("Checking firewall")
177174
with task_inst.run():
178-
for item in ("firewalld", "SuSEfirewall2"):
175+
for item in ("firewalld", ):
179176
if crmshutils.package_is_installed(item):
180177
task_inst.info("{}.service is available".format(item))
181178
if ServiceManager().service_is_active(item):

scripts/health/collect.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,7 @@ def disk_info():
7979
'/etc/csync2/key_hagroup',
8080
'/etc/csync2/csync2.cfg',
8181
'/etc/corosync/corosync.conf',
82-
'/etc/sysconfig/sbd',
83-
'/etc/sysconfig/SuSEfirewall2',
84-
'/etc/sysconfig/SuSEfirewall2.d/services/cluster'
82+
'/etc/sysconfig/sbd'
8583
]
8684

8785

test/unittests/test_crashtest_check.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,7 @@ def test_check_firewall_not_intalled(self, mock_task, mock_installed):
164164
check.check_firewall()
165165

166166
mock_task.assert_called_once_with("Checking firewall")
167-
mock_installed.assert_has_calls([
168-
mock.call("firewalld"),
169-
mock.call("SuSEfirewall2")
170-
])
167+
mock_installed.assert_called_once_with("firewalld")
171168
mock_task_inst.warn.assert_called_once_with("Failed to detect firewall")
172169

173170
@mock.patch('crmsh.service_manager.ServiceManager.service_is_active')

utils/crm_init.py

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,12 @@
99
'fence-agents', 'gfs2', 'gfs2-utils', 'hawk', 'ocfs2',
1010
'ocfs2-tools', 'pacemaker', 'pacemaker-mgmt',
1111
'resource-agents', 'sbd']
12-
SERVICES = ['sshd', 'ntp', 'corosync', 'pacemaker', 'hawk', 'SuSEfirewall2_init']
12+
SERVICES = ['sshd', 'ntp', 'corosync', 'pacemaker', 'hawk']
1313
SSH_KEY = os.path.expanduser('~/.ssh/id_rsa')
1414
CSYNC2_KEY = '/etc/csync2/key_hagroup'
1515
CSYNC2_CFG = '/etc/csync2/csync2.cfg'
1616
COROSYNC_CONF = '/etc/corosync/corosync.conf'
1717
SYSCONFIG_SBD = '/etc/sysconfig/sbd'
18-
SYSCONFIG_FW = '/etc/sysconfig/SuSEfirewall2'
19-
SYSCONFIG_FW_CLUSTER = '/etc/sysconfig/SuSEfirewall2.d/services/cluster'
2018

2119

2220
def rpm_info():
@@ -85,8 +83,6 @@ def check(fn):
8583
'csync2_cfg': check(CSYNC2_CFG),
8684
'corosync_conf': check(COROSYNC_CONF),
8785
'sysconfig_sbd': check(SYSCONFIG_SBD),
88-
'sysconfig_fw': check(SYSCONFIG_FW),
89-
'sysconfig_fw_cluster': check(SYSCONFIG_FW_CLUSTER),
9086
}
9187

9288

@@ -206,46 +202,8 @@ def configure_firewall():
206202
rc, out, err = crm_script.call(['crm', 'corosync', 'get', 'totem.interface.mcastport'])
207203
if rc == 0:
208204
corosync_mcastport = out.strip()
209-
FW = '/etc/sysconfig/SuSEfirewall2'
210-
FW_CLUSTER = '/etc/sysconfig/SuSEfirewall2.d/services/cluster'
211205

212206
tcp_ports = '30865 5560 7630 21064'
213207
udp_ports = '%s %s' % (corosync_mcastport, int(corosync_mcastport) - 1)
214208

215-
if is_service_enabled('SuSEfirewall2'):
216-
if os.path.isfile(FW_CLUSTER):
217-
tmpl = open(FW_CLUSTER).read()
218-
tmpl = re.sub(r'^TCP="(.*)"', 'TCP="%s"' % (tcp_ports), tmpl, flags=re.M)
219-
tmpl = re.sub(r'^UDP="(.*)"', 'UDP="%s"' % (udp_ports), tmpl, flags=re.M)
220-
with open(FW_CLUSTER, 'w') as f:
221-
f.write(tmpl)
222-
elif os.path.isdir(os.path.dirname(FW_CLUSTER)):
223-
with open(FW_CLUSTER, 'w') as fwc:
224-
fwc.write(_SUSE_FW_TEMPLATE % {'tcp': tcp_ports,
225-
'udp': udp_ports})
226-
else:
227-
# neither the cluster file nor the services
228-
# directory exists
229-
crm_script.exit_fail("SUSE firewall is configured but %s does not exist" %
230-
os.path.dirname(FW_CLUSTER))
231-
232-
# add cluster to FW_CONFIGURATIONS_EXT
233-
if os.path.isfile(FW):
234-
txt = open(FW).read()
235-
m = re.search(r'^FW_CONFIGURATIONS_EXT="(.*)"', txt, re.M)
236-
if m:
237-
services = m.group(1).split()
238-
if 'cluster' not in services:
239-
services.append('cluster')
240-
txt = re.sub(r'^FW_CONFIGURATIONS_EXT="(.*)"',
241-
r'FW_CONFIGURATIONS_EXT="%s"' % (' '.join(services)),
242-
txt,
243-
flags=re.M)
244-
else:
245-
txt += '\nFW_CONFIGURATIONS_EXT="cluster"'
246-
with open(FW, 'w') as fw:
247-
fw.write(txt)
248-
if is_service_active('SuSEfirewall2'):
249-
crm_script.service('SuSEfirewall2', 'restart')
250-
251209
# TODO: other platforms

0 commit comments

Comments
 (0)