Skip to content

Commit 5b80fde

Browse files
Merge pull request #1327 from liangxin1300/20240218_remove_unused_codes
Python 3.12 compatibility
2 parents e3d1170 + 7b18467 commit 5b80fde

22 files changed

+88
-145
lines changed

.github/workflows/crmsh-ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
runs-on: ubuntu-20.04
3333
strategy:
3434
matrix:
35-
python-version: ['3.10', '3.11']
35+
python-version: ['3.10', '3.11', '3.12']
3636
fail-fast: false
3737
timeout-minutes: 5
3838
steps:

crmsh.spec.in

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ Requires: /usr/bin/which
5353
Requires: python3 >= 3.4
5454
Requires: python3-PyYAML
5555
Requires: python3-lxml
56+
Requires: python3-packaging
5657
BuildRequires: python3-lxml
5758
BuildRequires: python3-pip
5859
BuildRequires: python3-wheel

crmsh/ra.py

-40
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,6 @@
2626
# Resource Agents interface (meta-data, parameters, etc)
2727
#
2828

29-
lrmadmin_prog = "lrmadmin"
30-
31-
32-
def lrmadmin(opts, xml=False):
33-
"""
34-
Get information directly from lrmd using lrmadmin.
35-
"""
36-
_rc, l = stdout2list("%s %s" % (lrmadmin_prog, opts))
37-
if l and not xml:
38-
l = l[1:] # skip the first line
39-
return l
40-
4129

4230
def crm_resource(opts):
4331
'''
@@ -47,26 +35,6 @@ def crm_resource(opts):
4735
return l
4836

4937

50-
@utils.memoize
51-
def can_use_lrmadmin():
52-
from distutils import version
53-
# after this glue release all users can get meta-data and
54-
# similar from lrmd
55-
minimum_glue = "1.0.10"
56-
_rc, glue_ver = get_stdout("%s -v" % lrmadmin_prog, stderr_on=False)
57-
if not glue_ver: # lrmadmin probably not found
58-
return False
59-
v_min = version.LooseVersion(minimum_glue)
60-
v_this = version.LooseVersion(glue_ver)
61-
if v_this < v_min:
62-
return False
63-
if userdir.getuser() not in ("root", config.path.crm_daemon_user):
64-
return False
65-
if not (is_program(lrmadmin_prog) and is_process(pacemaker_execd())):
66-
return False
67-
return utils.ext_cmd(">/dev/null 2>&1 %s -C" % lrmadmin_prog) == 0
68-
69-
7038
@utils.memoize
7139
def can_use_crm_resource():
7240
_rc, s = get_stdout("crm_resource --list-ocf-providers", stderr_on=False)
@@ -81,8 +49,6 @@ def ra_classes():
8149
return cache.retrieve("ra_classes")
8250
if can_use_crm_resource():
8351
l = crm_resource("--list-standards")
84-
elif can_use_lrmadmin():
85-
l = lrmadmin("-C")
8652
else:
8753
l = ["heartbeat", "lsb", "nagios", "ocf", "stonith", "systemd"]
8854
l.sort()
@@ -99,8 +65,6 @@ def ra_providers(ra_type, ra_class="ocf"):
9965
logger.error("no providers for class %s", ra_class)
10066
return []
10167
l = crm_resource("--list-ocf-alternatives %s" % ra_type)
102-
elif can_use_lrmadmin():
103-
l = lrmadmin("-P %s %s" % (ra_class, ra_type), True)
10468
else:
10569
l = []
10670
if ra_class == "ocf":
@@ -181,8 +145,6 @@ def find_types():
181145
"""
182146
if can_use_crm_resource():
183147
l = crm_resource("--list-agents %s" % ra_class)
184-
elif can_use_lrmadmin():
185-
l = lrmadmin("-T %s" % ra_class)
186148
else:
187149
l = os_types(ra_class)
188150
return l
@@ -211,8 +173,6 @@ def ra_meta(ra_class, ra_type, ra_provider):
211173
if ra_provider:
212174
return crm_resource("--show-metadata %s:%s:%s" % (ra_class, ra_provider, ra_type))
213175
return crm_resource("--show-metadata %s:%s" % (ra_class, ra_type))
214-
elif can_use_lrmadmin():
215-
return lrmadmin("-M %s %s %s" % (ra_class, ra_type, ra_provider), True)
216176
else:
217177
l = []
218178
if ra_class == "ocf":

crmsh/utils.py

+15-3
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@
2222
import random
2323
import string
2424
import grp
25+
import functools
2526
from pathlib import Path
2627
from contextlib import contextmanager, closing
2728
from stat import S_ISBLK
2829
from lxml import etree
30+
from packaging import version
2931

3032
import crmsh.parallax
3133
from . import corosync
@@ -34,7 +36,6 @@
3436
from . import constants
3537
from . import options
3638
from . import term
37-
from distutils.version import LooseVersion
3839
from .constants import SSH_OPTION
3940
from . import log
4041
from .prun import prun
@@ -86,6 +87,7 @@ def memoize(function):
8687
"Decorator to invoke a function once only for any argument"
8788
memoized = {}
8889

90+
@functools.wraps(function)
8991
def inner(*args):
9092
if args in memoized:
9193
return memoized[args]
@@ -1825,8 +1827,18 @@ def get_cib_attributes(cib_f, tag, attr_l, dflt_l):
18251827
return val_l
18261828

18271829

1828-
def is_larger_than_min_version(version, min_version):
1829-
return LooseVersion(version) >= LooseVersion(min_version)
1830+
def is_larger_than_min_version(this_version, min_version):
1831+
"""
1832+
Compare two version strings
1833+
"""
1834+
version_re = re.compile(version.VERSION_PATTERN, re.VERBOSE | re.IGNORECASE)
1835+
match_this_version = version_re.search(this_version)
1836+
if not match_this_version:
1837+
raise ValueError(f"Invalid version string: {this_version}")
1838+
match_min_version = version_re.search(min_version)
1839+
if not match_min_version:
1840+
raise ValueError(f"Invalid version string: {min_version}")
1841+
return version.parse(match_this_version.group(0)) >= version.parse(match_min_version.group(0))
18301842

18311843

18321844
def is_min_pcmk_ver(min_ver, cib_f=None):

requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
lxml
22
PyYAML
33
python-dateutil
4+
packaging

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
author_email='[email protected]',
1111
url='http://crmsh.github.io/',
1212
packages=['crmsh', 'crmsh.crash_test', 'crmsh.report', 'crmsh.prun'],
13-
install_requires=['lxml', 'PyYAML', 'python-dateutil'],
13+
install_requires=['lxml', 'PyYAML', 'python-dateutil', 'packaging'],
1414
scripts=['bin/crm'],
1515
data_files=[('/usr/share/crmsh', ['doc/crm.8.adoc'])],
1616
include_package_data=True)

test/run-functional-tests

+3-3
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,8 @@ create_custom_user() {
187187
user_name=$1
188188
user_id=$2
189189
docker_exec $node_name "useradd -m -s /bin/bash ${user_name} 2>/dev/null"
190-
docker_exec $node_name "chmod u+w /etc/sudoers"
191-
docker_exec $node_name "echo \"${user_name} ALL=(ALL) NOPASSWD: ALL\" >> /etc/sudoers"
192-
docker_exec $node_name "chmod u-w /etc/sudoers"
190+
docker_exec $node_name "echo \"${user_name} ALL=(ALL) NOPASSWD: ALL\" > /etc/sudoers.d/${user_name}"
191+
docker_exec $node_name "chmod 0440 /etc/sudoers.d/${user_name}"
193192
docker_exec $node_name "echo 'export PATH=\$PATH:/usr/sbin/' >> ~${user_name}/.bashrc"
194193
docker_exec $node_name "echo -e \"linux\\nlinux\" | passwd ${user_name} 2>/dev/null"
195194
docker_exec $node_name "cp -r /root/.ssh ~${user_name}/ && chown ${user_name}:haclient -R ~${user_name}/.ssh"
@@ -222,6 +221,7 @@ deploy_ha_node() {
222221
fi
223222
docker_exec $node_name "rm -rf /run/nologin"
224223
docker_exec $node_name "echo 'StrictHostKeyChecking no' >> /etc/ssh/ssh_config"
224+
docker_exec $node_name "systemctl start sshd.service"
225225

226226
if [ "$node_name" != "qnetd-node" ];then
227227
docker cp $PROJECT_PATH $node_name:/opt/crmsh

test/testcases/bugs.exp

+8-8
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ node node1
3131
primitive st stonith:null \
3232
params hostlist=node1 \
3333
meta description="some description here" requires=nothing \
34-
op monitor interval=60m timeout=20 \
35-
op start timeout=20 interval=0s \
34+
op monitor interval=60m timeout=20s \
35+
op start timeout=20s interval=0s \
3636
op stop timeout=15 interval=0s
3737
primitive p4 Dummy \
3838
op monitor timeout=20s interval=10s \
@@ -69,8 +69,8 @@ node node1
6969
primitive st stonith:null \
7070
params hostlist=node1 \
7171
meta description="some description here" requires=nothing \
72-
op monitor interval=60m timeout=20 \
73-
op start timeout=20 interval=0s \
72+
op monitor interval=60m timeout=20s \
73+
op start timeout=20s interval=0s \
7474
op stop timeout=15 interval=0s
7575
primitive p4 Dummy \
7676
op monitor timeout=20s interval=10s \
@@ -170,8 +170,8 @@ node node1
170170
primitive st stonith:null \
171171
params hostlist=node1 \
172172
meta description="some description here" requires=nothing \
173-
op monitor interval=60m timeout=20 \
174-
op start timeout=20 interval=0s \
173+
op monitor interval=60m timeout=20s \
174+
op start timeout=20s interval=0s \
175175
op stop timeout=15 interval=0s
176176
property SAPHanaSR: \
177177
hana_ha1_site_lss_WDF1=4
@@ -184,8 +184,8 @@ node node1
184184
primitive st stonith:null \
185185
params hostlist=node1 \
186186
meta description="some description here" requires=nothing \
187-
op monitor interval=60m timeout=20 \
188-
op start timeout=20 interval=0s \
187+
op monitor interval=60m timeout=20s \
188+
op start timeout=20s interval=0s \
189189
op stop timeout=15 interval=0s
190190
property SAPHanaSR: \
191191
hana_ha1_site_lss_WDF1=4

test/testcases/bundle.exp

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ primitive st stonith:ssh \
3939
op stop timeout=15 interval=0s
4040
primitive st2 stonith:ssh \
4141
params hostlist="node1 node2" \
42-
op monitor timeout=20 interval=3600 \
43-
op start timeout=20 interval=0s \
42+
op monitor timeout=20s interval=3600 \
43+
op start timeout=20s interval=0s \
4444
op stop timeout=15 interval=0s
4545
bundle bundle-test1 \
4646
docker image=test \

test/testcases/commit.exp

+2-2
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ primitive p3 Dummy \
7575
primitive st stonith:null \
7676
params hostlist=node1 \
7777
meta yoyo-meta="yoyo 2" requires=nothing \
78-
op monitor interval=60m timeout=20 \
79-
op start timeout=20 interval=0s \
78+
op monitor interval=60m timeout=20s \
79+
op start timeout=20s interval=0s \
8080
op stop timeout=15 interval=0s
8181
group g1 d1 p2
8282
group g2 d3

test/testcases/confbasic-xml.exp

+3-3
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@
4141
<nvpair name="hostlist" value="node1 node2" id="st2-instance_attributes-hostlist"/>
4242
</instance_attributes>
4343
<operations>
44-
<op name="monitor" timeout="20" interval="3600" id="st2-monitor-3600"/>
45-
<op name="start" timeout="20" interval="0s" id="st2-start-0s"/>
44+
<op name="monitor" timeout="20s" interval="3600" id="st2-monitor-3600"/>
45+
<op name="start" timeout="20s" interval="0s" id="st2-start-0s"/>
4646
<op name="stop" timeout="15" interval="0s" id="st2-stop-0s"/>
4747
</operations>
4848
</primitive>
@@ -67,7 +67,7 @@
6767
<operations>
6868
<op name="start" timeout="60s" interval="0s" id="d2-start-0s"/>
6969
<op name="stop" timeout="60s" interval="0s" id="d2-stop-0s"/>
70-
<op name="monitor" timeout="30s" interval="10s" id="d2-monitor-10s"/>
70+
<op name="monitor" timeout="40s" interval="10s" id="d2-monitor-10s"/>
7171
<op name="monitor" role="Started" interval="60s" timeout="30s" id="d2-monitor-60s"/>
7272
</operations>
7373
</primitive>

test/testcases/confbasic.exp

+3-3
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ primitive d2 Delay \
8989
params mondelay=45 \
9090
op start timeout=60s interval=0s \
9191
op stop timeout=60s interval=0s \
92-
op monitor timeout=30s interval=10s \
92+
op monitor timeout=40s interval=10s \
9393
op monitor role=Started interval=60s timeout=30s
9494
primitive d3 ocf:pacemaker:Dummy \
9595
op monitor timeout=20s interval=10s \
@@ -137,8 +137,8 @@ primitive st stonith:ssh \
137137
op stop timeout=15 interval=0s
138138
primitive st2 stonith:ssh \
139139
params hostlist="node1 node2" \
140-
op monitor timeout=20 interval=3600 \
141-
op start timeout=20 interval=0s \
140+
op monitor timeout=20s interval=3600 \
141+
op start timeout=20s interval=0s \
142142
op stop timeout=15 interval=0s
143143
group g1 d1 d2
144144
ms m d4

test/testcases/edit.exp

+10-10
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ primitive p2 Dummy
2525
primitive st stonith:null \
2626
params hostlist=node1 \
2727
meta description="some description here" requires=nothing \
28-
op monitor interval=60m timeout=20 \
29-
op start timeout=20 interval=0s \
28+
op monitor interval=60m timeout=20s \
29+
op start timeout=20s interval=0s \
3030
op stop timeout=15 interval=0s
3131
group g1 p1 p2
3232
op_defaults op-options: \
@@ -46,8 +46,8 @@ primitive p3 Dummy
4646
primitive st stonith:null \
4747
params hostlist=node1 \
4848
meta description="some description here" requires=nothing \
49-
op monitor interval=60m timeout=20 \
50-
op start timeout=20 interval=0s \
49+
op monitor interval=60m timeout=20s \
50+
op start timeout=20s interval=0s \
5151
op stop timeout=15 interval=0s
5252
group g1 p1 p3
5353
op_defaults op-options: \
@@ -182,8 +182,8 @@ primitive p3 Dummy
182182
primitive st stonith:null \
183183
params hostlist=node1 \
184184
meta description="some description here" requires=nothing \
185-
op monitor interval=60m timeout=20 \
186-
op start timeout=20 interval=0s \
185+
op monitor interval=60m timeout=20s \
186+
op start timeout=20s interval=0s \
187187
op stop timeout=15 interval=0s
188188
group g1 p1 p2 d3
189189
group g2 d1 d2
@@ -311,8 +311,8 @@ primitive p3 Dummy
311311
primitive st stonith:null \
312312
params hostlist=node1 \
313313
meta description="some description here" requires=nothing \
314-
op monitor interval=60m timeout=20 \
315-
op start timeout=20 interval=0s \
314+
op monitor interval=60m timeout=20s \
315+
op start timeout=20s interval=0s \
316316
op stop timeout=15 interval=0s
317317
group as a0 a1 a9 a2 a3 a4 a5 a6 a7 a8 aErr
318318
group g1 p1 p2 d3
@@ -418,8 +418,8 @@ primitive p3 Dummy
418418
primitive st stonith:null \
419419
params hostlist=node1 \
420420
meta description="some description here" requires=nothing \
421-
op monitor interval=60m timeout=20 \
422-
op start timeout=20 interval=0s \
421+
op monitor interval=60m timeout=20s \
422+
op start timeout=20s interval=0s \
423423
op stop timeout=15 interval=0s
424424
group as a0 a1 a9 a2 a3 a4 a5 a6 a7 a8 aErr
425425
group g1 p1 p2 d3

test/testcases/file.exp

+8-8
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ primitive p1 ocf:pacemaker:Dummy \
1111
op stop timeout=20s interval=0s
1212
primitive p2 Delay \
1313
params startdelay=2 mondelay=2 stopdelay=2 \
14-
op monitor timeout=30s interval=10s \
14+
op monitor timeout=40s interval=10s \
1515
op start timeout=30s interval=0s \
16-
op stop timeout=30s interval=0s
16+
op stop timeout=40s interval=0s
1717
primitive p3 ocf:pacemaker:Dummy \
1818
op monitor timeout=20s interval=10s \
1919
op start timeout=20s interval=0s \
2020
op stop timeout=20s interval=0s
2121
primitive st stonith:null \
2222
params hostlist=node1 \
23-
op monitor timeout=20 interval=3600 \
24-
op start timeout=20 interval=0s \
23+
op monitor timeout=20s interval=3600 \
24+
op start timeout=20s interval=0s \
2525
op stop timeout=15 interval=0s
2626
clone c1 p1 \
2727
meta interleave=true
@@ -56,17 +56,17 @@ primitive p0 ocf:pacemaker:Dummy \
5656
op stop timeout=20s interval=0s
5757
primitive p2 Delay \
5858
params startdelay=2 mondelay=2 stopdelay=2 \
59-
op monitor timeout=30s interval=10s \
59+
op monitor timeout=40s interval=10s \
6060
op start timeout=30s interval=0s \
61-
op stop timeout=30s interval=0s
61+
op stop timeout=40s interval=0s
6262
primitive p3 ocf:pacemaker:Dummy \
6363
op monitor timeout=20s interval=10s \
6464
op start timeout=20s interval=0s \
6565
op stop timeout=20s interval=0s
6666
primitive st stonith:null \
6767
params hostlist=node1 \
68-
op monitor timeout=20 interval=3600 \
69-
op start timeout=20 interval=0s \
68+
op monitor timeout=20s interval=3600 \
69+
op start timeout=20s interval=0s \
7070
op stop timeout=15 interval=0s
7171
property cib-bootstrap-options: \
7272
cluster-recheck-interval=10m

test/testcases/ra.exp

+3-3
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ pcmk_status_retries (integer, [2]): Advanced use only: The maximum number of tim
144144

145145
Operations' defaults (advisory minimum):
146146

147-
start timeout=20
147+
start timeout=20s
148148
stop timeout=15
149-
status timeout=20
150-
monitor timeout=20 interval=3600
149+
status timeout=20s
150+
monitor timeout=20s interval=3600

0 commit comments

Comments
 (0)