Skip to content

Commit a903b85

Browse files
authored
Merge pull request #1246 from liangxin1300/20230101_refactor_crm_report_crmsh46
[crmsh-4.6] Rewrite crm report module
2 parents 38304a7 + cdb94b1 commit a903b85

36 files changed

+3922
-3117
lines changed

.github/workflows/crmsh-ci.yml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,27 @@ jobs:
5454
timeout-minutes: 40
5555
steps:
5656
- uses: actions/checkout@v3
57-
- name: functional test for crm_report
57+
- name: functional test for crm_report bugs
5858
run: |
5959
echo '{ "exec-opts": ["native.cgroupdriver=systemd"] }' | sudo tee /etc/docker/daemon.json
6060
sudo systemctl restart docker.service
6161
index=`$GET_INDEX_OF crm_report_bugs`
6262
$DOCKER_SCRIPT $index && $DOCKER_SCRIPT -d && $DOCKER_SCRIPT $index -u
6363
- uses: codecov/codecov-action@v3
6464

65+
functional_test_crm_report_normal:
66+
runs-on: ubuntu-20.04
67+
timeout-minutes: 40
68+
steps:
69+
- uses: actions/checkout@v3
70+
- name: functional test for crm_report normal
71+
run: |
72+
echo '{ "exec-opts": ["native.cgroupdriver=systemd"] }' | sudo tee /etc/docker/daemon.json
73+
sudo systemctl restart docker.service
74+
index=`$GET_INDEX_OF crm_report_normal`
75+
$DOCKER_SCRIPT $index && $DOCKER_SCRIPT -d && $DOCKER_SCRIPT $index -u
76+
- uses: codecov/codecov-action@v3
77+
6578
functional_test_bootstrap_bugs:
6679
runs-on: ubuntu-20.04
6780
timeout-minutes: 40

codecov.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ coverage:
22
status:
33
project:
44
default:
5-
threshold: 0.1%
5+
threshold: 0.35%
66
patch:
77
default:
8-
threshold: 0.1%
8+
threshold: 0.35%
99
codecov:
1010
token: 16b01c29-3b23-4923-b33a-4d26a49d80c4
1111
notify:

crmsh/bootstrap.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,6 @@ def _validate_nodes_option(self):
228228
me = utils.this_node()
229229
was_localhost_already = False
230230
li = [utils.parse_user_at_host(x) for x in self.user_at_node_list]
231-
if utils.has_dup_value([node for user, node in li]):
232-
utils.fatal("Duplicated host in -N/--nodes options.")
233231
for user in (user for user, node in li if node == me and user is not None and user != self.current_user):
234232
utils.fatal(f"Overriding current user '{self.current_user}' by '{user}'. Ouch, don't do it.")
235233
self.user_at_node_list = [value for (user, node), value in zip(li, self.user_at_node_list) if node != me]
@@ -794,13 +792,6 @@ def start_pacemaker(node_list=[], enable_flag=False):
794792
return service_manager.start_service("pacemaker.service", enable=enable_flag, node_list=node_list)
795793

796794

797-
def install_tmp(tmpfile, to):
798-
with open(tmpfile, "r") as src:
799-
with utils.open_atomic(to, "w") as dst:
800-
for line in src:
801-
dst.write(line)
802-
803-
804795
def append(fromfile, tofile, remote=None):
805796
cmd = "cat {} >> {}".format(fromfile, tofile)
806797
sh.cluster_shell().get_stdout_or_raise_error(cmd, host=remote)

crmsh/config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,8 @@ def get(self, value):
295295
'from_time': opt_string('-12H'),
296296
'compress': opt_boolean('yes'),
297297
'speed_up': opt_boolean('no'),
298-
'collect_extra_logs': opt_string('/var/log/messages /var/log/pacemaker/pacemaker.log \
299-
/var/log/pacemaker.log /var/log/crmsh/crmsh.log /etc/crm/profiles.yml /etc/crm/crm.conf'),
298+
'collect_extra_logs': opt_string('/var/log/messages \
299+
/var/log/crmsh/crmsh.log /etc/crm/profiles.yml /etc/crm/crm.conf'),
300300
'remove_exist_dest': opt_boolean('no'),
301301
'single_node': opt_boolean('no'),
302302
'sanitize_rule': opt_string('passw.*'),

crmsh/corosync.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@ def cfgtool(*args):
3535
return ShellUtils().get_stdout(['corosync-cfgtool'] + list(args), shell=False)
3636

3737

38-
def quorumtool(*args):
39-
return ShellUtils().get_stdout(['corosync-quorumtool'] + list(args), shell=False)
40-
41-
4238
def query_status(status_type):
4339
"""
4440
Query status of corosync
@@ -369,13 +365,6 @@ def joiner(tstream):
369365
return ''.join(joiner(self._tokens))
370366

371367

372-
def logfile(conftext):
373-
'''
374-
Return corosync logfile (if set)
375-
'''
376-
return Parser(conftext).get('logging.logfile')
377-
378-
379368
def push_configuration(nodes):
380369
'''
381370
Push the local configuration to the list of remote nodes

crmsh/help.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ def paginate(self):
9696

9797
short_help = clidisplay.help_header(self.short)
9898
if self.from_cli and self.level and self.name:
99-
_, output, _ = ShellUtils().get_stdout_stderr(f"crm {self.level} {self.name} --help-without-redirect")
99+
level = '' if self.level == 'root' else self.level
100+
_, output, _ = ShellUtils().get_stdout_stderr(f"crm {level} {self.name} --help-without-redirect")
100101
page_string(short_help + '\n\n'+ output)
101102
return
102103

crmsh/history.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from . import utils
1616
from . import log
1717
from .sh import ShellUtils
18-
from crmsh.report import utillib
18+
from crmsh.report import core
1919

2020

2121
logger = log.setup_logger(__name__)
@@ -107,7 +107,7 @@ def mkarchive(idir):
107107
if not home:
108108
logger.error("no home directory, nowhere to pack report")
109109
return False
110-
_, ext = utillib.pick_first_compress()
110+
_, ext = core.pick_first_compress()
111111
if not ext:
112112
return False
113113
name = os.path.join(home, os.path.basename(idir))
@@ -469,7 +469,7 @@ def new_live_report(self):
469469
if not utils.is_path_sane(d):
470470
return None
471471
utils.rmdir_r(d)
472-
_, ext = utillib.pick_first_compress()
472+
_, ext = core.pick_first_compress()
473473
if not ext:
474474
return None
475475
tarball = f"{d}.tar{ext}"

crmsh/log.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ def format(self, record):
6464
msg = record.msg
6565
record.msg = "{}: {}".format(self.lineno, msg)
6666
record.levelname = levelname
67+
if record.levelname == "DEBUG2":
68+
msg = record.msg
69+
record.msg = f"{record.funcName}: {msg}"
6770
return super().format(record)
6871

6972

@@ -93,9 +96,21 @@ class DebugCustomFilter(logging.Filter):
9396
A custom filter for debug message
9497
"""
9598
def filter(self, record):
96-
from .config import core, report
99+
from .config import core
97100
if record.levelname == "DEBUG":
98-
return core.debug or int(report.verbosity) >= 1
101+
return core.debug
102+
else:
103+
return True
104+
105+
106+
class ReportDebugCustomFilter(logging.Filter):
107+
"""
108+
A custom filter for crm report debug message
109+
"""
110+
def filter(self, record):
111+
from .config import report
112+
if record.levelname == "DEBUG":
113+
return int(report.verbosity) >= 1
99114
if record.levelname == "DEBUG2":
100115
return int(report.verbosity) > 1
101116
else:
@@ -138,6 +153,9 @@ def _open(self):
138153
"filter": {
139154
"()": DebugCustomFilter
140155
},
156+
"filter_report": {
157+
"()": ReportDebugCustomFilter
158+
},
141159
},
142160
"handlers": {
143161
'null': {
@@ -146,7 +164,7 @@ def _open(self):
146164
"console_report": {
147165
"()": ConsoleCustomHandler,
148166
"formatter": "console_report",
149-
"filters": ["filter"]
167+
"filters": ["filter_report"]
150168
},
151169
"console": {
152170
"()": ConsoleCustomHandler,

crmsh/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ def compgen():
301301

302302
def parse_options():
303303
opts, args = option_parser.parse_known_args()
304-
utils.check_space_option_value(opts)
304+
utils.check_empty_option_value(opts)
305305
config.core.debug = "yes" if opts.debug else config.core.debug
306306
options.profile = opts.profile or options.profile
307307
options.regression_tests = opts.regression_tests or options.regression_tests

0 commit comments

Comments
 (0)