Added debug option
diff --git a/cfg_checker/cfg_check.py b/cfg_checker/cfg_check.py
index 78436d6..b2e3886 100644
--- a/cfg_checker/cfg_check.py
+++ b/cfg_checker/cfg_check.py
@@ -1,6 +1,7 @@
import argparse
import os
import sys
+from logging import INFO, DEBUG
import reporter
from cfg_checker.common import utils, const
@@ -19,7 +20,6 @@
self.print_help()
-
def help_message():
print"""
Please, use following examples to generate info reports:\n
@@ -61,6 +61,12 @@
def config_check_entrypoint():
# Main entrypointр
parser = MyParser(prog="Cloud configuration checker")
+ parser.add_argument(
+ "-d",
+ "--debug",
+ action="store_true", default=False,
+ help="Set CLI logging level to DEBUG"
+ )
subparsers = parser.add_subparsers(dest='command')
# packages
pkg_parser = subparsers.add_parser(
@@ -107,6 +113,12 @@
#parse arguments
args = parser.parse_args()
+ # Handle options
+ if args.debug:
+ logger_cli.setLevel(DEBUG)
+ else:
+ logger_cli.setLevel(INFO)
+
# Execute the command
result = args.func(args)
diff --git a/cfg_checker/common/log.py b/cfg_checker/common/log.py
index af52cac..9b29ba4 100644
--- a/cfg_checker/common/log.py
+++ b/cfg_checker/common/log.py
@@ -79,7 +79,7 @@
logger.addHandler(fh)
logger_cli = logging.getLogger(name + ".cli")
- logger_cli.setLevel(logging.DEBUG)
+ logger_cli.setLevel(logging.INFO)
if len(logger_cli.handlers) == 0:
logger_cli.addHandler(sh)
diff --git a/cfg_checker/pkg_check.py b/cfg_checker/pkg_check.py
index a2f64ac..fe34f60 100644
--- a/cfg_checker/pkg_check.py
+++ b/cfg_checker/pkg_check.py
@@ -21,7 +21,7 @@
class CloudPackageChecker(object):
def __init__(self):
- logger_cli.info("Collecting nodes for package check")
+ logger_cli.info("### Collecting nodes for package check")
# simple salt rest client
self.salt = salt_utils.SaltRemote()
@@ -29,14 +29,14 @@
# this is not working in scope of 2016.8.3, will overide with list
# cls.node_keys = cls.salt.list_keys()
- logger_cli.info("Collecting node names existing in the cloud")
+ logger_cli.info("### Collecting node names existing in the cloud")
self.node_keys = {
'minions': config.all_nodes
}
# all that answer ping
_active = self.salt.get_active_nodes()
- logger_cli.info("Nodes responded: {}".format(_active))
+ logger_cli.debug("-> Nodes responded: {}".format(_active))
# just inventory for faster interaction
# iterate through all accepted nodes and create a dict for it
self.nodes = {}
@@ -51,7 +51,7 @@
self.nodes[_name]['role'] = _role
self.nodes[_name]['status'] = _status
- logger_cli.info("{} nodes collected".format(len(self.nodes)))
+ logger_cli.info("-> {} nodes collected".format(len(self.nodes)))
def collect_installed_packages(self):
"""
@@ -60,7 +60,7 @@
:return: none
"""
- logger_cli.info("Collecting installed packages")
+ logger_cli.info("### Collecting installed packages")
# form an all nodes compound string to use in salt
_active_nodes_string = self.salt.compound_string_from_list(
filter(
@@ -76,8 +76,8 @@
_storage_path = os.path.join(
config.salt_file_root, config.salt_scripts_folder
)
- logger_cli.info(
- "Uploading script {} to master's file cache folder: '{}'".format(
+ logger_cli.debug(
+ "# Uploading script {} to master's file cache folder: '{}'".format(
_script_filename,
_storage_path
)
@@ -96,11 +96,11 @@
_script_filename
)
- logger.debug("Creating file in cache '{}'".format(_cache_path))
+ logger_cli.debug("# Creating file in cache '{}'".format(_cache_path))
_result = self.salt.f_touch_master(_cache_path)
_result = self.salt.f_append_master(_cache_path, _script)
# command salt to copy file to minions
- logger.debug("Creating script target folder '{}'".format(_cache_path))
+ logger_cli.debug("# Creating script target folder '{}'".format(_cache_path))
_result = self.salt.mkdir(
_active_nodes_string,
os.path.join(
@@ -109,7 +109,7 @@
),
tgt_type="compound"
)
- logger_cli.info("Running script to all active nodes")
+ logger_cli.info("-> Running script to all active nodes")
_result = self.salt.get_file(
_active_nodes_string,
_source_path,
@@ -133,10 +133,11 @@
self.nodes[key]['packages'] = _dict
else:
self.nodes[key]['packages'] = {}
- logger_cli.info("{} has {} packages installed".format(
+ logger_cli.debug("# {} has {} packages installed".format(
key,
len(self.nodes[key]['packages'].keys())
))
+ logger_cli.info("-> Done")
def collect_packages(self):
"""
@@ -161,6 +162,7 @@
:return: buff with html
"""
+ logger_cli.info("### Generating report to '{}'".format(filename))
_report = reporter.ReportToFile(
reporter.HTMLPackageCandidates(),
filename
@@ -169,6 +171,7 @@
"nodes": self.nodes,
"diffs": {}
})
+ logger_cli.info("-> Done")
if __name__ == '__main__':