blob: eaa2428b9e63ac463f6b44c653ade3fe6c9de380 [file] [log] [blame]
Alex3ebc5632019-04-18 16:47:18 -05001from cfg_checker.common import logger_cli
Alexe0c5b9e2019-04-23 18:51:23 -05002from cfg_checker.modules.network.mapper import NetworkMapper
Alex3ebc5632019-04-18 16:47:18 -05003from cfg_checker.modules.network.network_errors import NetworkErrors
Alex Savatieievf526dc02019-03-06 10:11:32 -06004from cfg_checker.reports import reporter
Alex Savatieiev9b2f6512019-02-20 18:05:00 -06005
6
Alexe0c5b9e2019-04-23 18:51:23 -05007class NetworkChecker(object):
Alexe9908f72020-05-19 16:04:53 -05008 def __init__(
9 self,
Alex9a4ad212020-10-01 18:04:25 -050010 config,
Alexe9908f72020-05-19 16:04:53 -050011 skip_list=None,
12 skip_list_file=None
13 ):
Alexe0c5b9e2019-04-23 18:51:23 -050014 logger_cli.debug("... init error logs folder")
Alex3ebc5632019-04-18 16:47:18 -050015 self.errors = NetworkErrors()
Alexe9908f72020-05-19 16:04:53 -050016 self.mapper = NetworkMapper(
Alex9a4ad212020-10-01 18:04:25 -050017 config,
18 errors_class=self.errors,
Alexe9908f72020-05-19 16:04:53 -050019 skip_list=skip_list,
20 skip_list_file=skip_list_file
21 )
Alex3ebc5632019-04-18 16:47:18 -050022
Alex836fac82019-08-22 13:36:16 -050023 def check_networks(self, map=True):
Alexe0c5b9e2019-04-23 18:51:23 -050024 self.mapper.map_network(self.mapper.RECLASS)
25 self.mapper.map_network(self.mapper.RUNTIME)
Alex3ebc5632019-04-18 16:47:18 -050026
Alex836fac82019-08-22 13:36:16 -050027 self.mapper.create_map()
28 if map:
29 self.mapper.print_map()
Alex Savatieiev42b89fa2019-03-07 18:45:26 -060030
Alex3ebc5632019-04-18 16:47:18 -050031 def print_summary(self):
Alex3ebc5632019-04-18 16:47:18 -050032 logger_cli.info(self.errors.get_summary(print_zeros=False))
Alex3ebc5632019-04-18 16:47:18 -050033
34 def print_error_details(self):
35 # Detailed errors
Alexb151fbe2019-04-22 16:53:30 -050036 logger_cli.info(
37 "\n{}\n".format(
38 self.errors.get_errors()
39 )
40 )
Alex3ebc5632019-04-18 16:47:18 -050041
Alex Savatieiev9b2f6512019-02-20 18:05:00 -060042 def create_html_report(self, filename):
43 """
44 Create static html showing network schema-like report
45
46 :return: none
47 """
48 logger_cli.info("### Generating report to '{}'".format(filename))
49 _report = reporter.ReportToFile(
Alex9a4ad212020-10-01 18:04:25 -050050 reporter.HTMLNetworkReport(self.mapper.salt_master),
Alex Savatieiev9b2f6512019-02-20 18:05:00 -060051 filename
52 )
Alex9a4ad212020-10-01 18:04:25 -050053 _report(
54 {
55 "domain": self.mapper.domain,
56 "nodes": self.mapper.nodes,
57 "map": self.mapper.map,
58 "mcp_release": self.mapper.cluster['mcp_release'],
59 "openstack_release": self.mapper.cluster['openstack_release']
60 }
61 )
Alex Savatieiev9b2f6512019-02-20 18:05:00 -060062 logger_cli.info("-> Done")