Skip to content

Commit

Permalink
Merge pull request #1246 from liangxin1300/20230101_refactor_crm_repo…
Browse files Browse the repository at this point in the history
…rt_crmsh46

[crmsh-4.6] Rewrite crm report module
  • Loading branch information
liangxin1300 committed Dec 6, 2023
2 parents 38304a7 + cdb94b1 commit a903b85
Show file tree
Hide file tree
Showing 36 changed files with 3,922 additions and 3,117 deletions.
15 changes: 14 additions & 1 deletion .github/workflows/crmsh-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,27 @@ jobs:
timeout-minutes: 40
steps:
- uses: actions/checkout@v3
- name: functional test for crm_report
- name: functional test for crm_report bugs
run: |
echo '{ "exec-opts": ["native.cgroupdriver=systemd"] }' | sudo tee /etc/docker/daemon.json
sudo systemctl restart docker.service
index=`$GET_INDEX_OF crm_report_bugs`
$DOCKER_SCRIPT $index && $DOCKER_SCRIPT -d && $DOCKER_SCRIPT $index -u
- uses: codecov/codecov-action@v3

functional_test_crm_report_normal:
runs-on: ubuntu-20.04
timeout-minutes: 40
steps:
- uses: actions/checkout@v3
- name: functional test for crm_report normal
run: |
echo '{ "exec-opts": ["native.cgroupdriver=systemd"] }' | sudo tee /etc/docker/daemon.json
sudo systemctl restart docker.service
index=`$GET_INDEX_OF crm_report_normal`
$DOCKER_SCRIPT $index && $DOCKER_SCRIPT -d && $DOCKER_SCRIPT $index -u
- uses: codecov/codecov-action@v3

functional_test_bootstrap_bugs:
runs-on: ubuntu-20.04
timeout-minutes: 40
Expand Down
4 changes: 2 additions & 2 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ coverage:
status:
project:
default:
threshold: 0.1%
threshold: 0.35%
patch:
default:
threshold: 0.1%
threshold: 0.35%
codecov:
token: 16b01c29-3b23-4923-b33a-4d26a49d80c4
notify:
Expand Down
9 changes: 0 additions & 9 deletions crmsh/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,6 @@ def _validate_nodes_option(self):
me = utils.this_node()
was_localhost_already = False
li = [utils.parse_user_at_host(x) for x in self.user_at_node_list]
if utils.has_dup_value([node for user, node in li]):
utils.fatal("Duplicated host in -N/--nodes options.")
for user in (user for user, node in li if node == me and user is not None and user != self.current_user):
utils.fatal(f"Overriding current user '{self.current_user}' by '{user}'. Ouch, don't do it.")
self.user_at_node_list = [value for (user, node), value in zip(li, self.user_at_node_list) if node != me]
Expand Down Expand Up @@ -794,13 +792,6 @@ def start_pacemaker(node_list=[], enable_flag=False):
return service_manager.start_service("pacemaker.service", enable=enable_flag, node_list=node_list)


def install_tmp(tmpfile, to):
with open(tmpfile, "r") as src:
with utils.open_atomic(to, "w") as dst:
for line in src:
dst.write(line)


def append(fromfile, tofile, remote=None):
cmd = "cat {} >> {}".format(fromfile, tofile)
sh.cluster_shell().get_stdout_or_raise_error(cmd, host=remote)
Expand Down
4 changes: 2 additions & 2 deletions crmsh/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,8 @@ def get(self, value):
'from_time': opt_string('-12H'),
'compress': opt_boolean('yes'),
'speed_up': opt_boolean('no'),
'collect_extra_logs': opt_string('/var/log/messages /var/log/pacemaker/pacemaker.log \
/var/log/pacemaker.log /var/log/crmsh/crmsh.log /etc/crm/profiles.yml /etc/crm/crm.conf'),
'collect_extra_logs': opt_string('/var/log/messages \
/var/log/crmsh/crmsh.log /etc/crm/profiles.yml /etc/crm/crm.conf'),
'remove_exist_dest': opt_boolean('no'),
'single_node': opt_boolean('no'),
'sanitize_rule': opt_string('passw.*'),
Expand Down
11 changes: 0 additions & 11 deletions crmsh/corosync.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ def cfgtool(*args):
return ShellUtils().get_stdout(['corosync-cfgtool'] + list(args), shell=False)


def quorumtool(*args):
return ShellUtils().get_stdout(['corosync-quorumtool'] + list(args), shell=False)


def query_status(status_type):
"""
Query status of corosync
Expand Down Expand Up @@ -369,13 +365,6 @@ def joiner(tstream):
return ''.join(joiner(self._tokens))


def logfile(conftext):
'''
Return corosync logfile (if set)
'''
return Parser(conftext).get('logging.logfile')


def push_configuration(nodes):
'''
Push the local configuration to the list of remote nodes
Expand Down
3 changes: 2 additions & 1 deletion crmsh/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ def paginate(self):

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

Expand Down
6 changes: 3 additions & 3 deletions crmsh/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from . import utils
from . import log
from .sh import ShellUtils
from crmsh.report import utillib
from crmsh.report import core


logger = log.setup_logger(__name__)
Expand Down Expand Up @@ -107,7 +107,7 @@ def mkarchive(idir):
if not home:
logger.error("no home directory, nowhere to pack report")
return False
_, ext = utillib.pick_first_compress()
_, ext = core.pick_first_compress()
if not ext:
return False
name = os.path.join(home, os.path.basename(idir))
Expand Down Expand Up @@ -469,7 +469,7 @@ def new_live_report(self):
if not utils.is_path_sane(d):
return None
utils.rmdir_r(d)
_, ext = utillib.pick_first_compress()
_, ext = core.pick_first_compress()
if not ext:
return None
tarball = f"{d}.tar{ext}"
Expand Down
24 changes: 21 additions & 3 deletions crmsh/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ def format(self, record):
msg = record.msg
record.msg = "{}: {}".format(self.lineno, msg)
record.levelname = levelname
if record.levelname == "DEBUG2":
msg = record.msg
record.msg = f"{record.funcName}: {msg}"
return super().format(record)


Expand Down Expand Up @@ -93,9 +96,21 @@ class DebugCustomFilter(logging.Filter):
A custom filter for debug message
"""
def filter(self, record):
from .config import core, report
from .config import core
if record.levelname == "DEBUG":
return core.debug or int(report.verbosity) >= 1
return core.debug
else:
return True


class ReportDebugCustomFilter(logging.Filter):
"""
A custom filter for crm report debug message
"""
def filter(self, record):
from .config import report
if record.levelname == "DEBUG":
return int(report.verbosity) >= 1
if record.levelname == "DEBUG2":
return int(report.verbosity) > 1
else:
Expand Down Expand Up @@ -138,6 +153,9 @@ def _open(self):
"filter": {
"()": DebugCustomFilter
},
"filter_report": {
"()": ReportDebugCustomFilter
},
},
"handlers": {
'null': {
Expand All @@ -146,7 +164,7 @@ def _open(self):
"console_report": {
"()": ConsoleCustomHandler,
"formatter": "console_report",
"filters": ["filter"]
"filters": ["filter_report"]
},
"console": {
"()": ConsoleCustomHandler,
Expand Down
2 changes: 1 addition & 1 deletion crmsh/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ def compgen():

def parse_options():
opts, args = option_parser.parse_known_args()
utils.check_space_option_value(opts)
utils.check_empty_option_value(opts)
config.core.debug = "yes" if opts.debug else config.core.debug
options.profile = opts.profile or options.profile
options.regression_tests = opts.regression_tests or options.regression_tests
Expand Down
Loading

0 comments on commit a903b85

Please sign in to comment.