Alex | 3ebc563 | 2019-04-18 16:47:18 -0500 | [diff] [blame] | 1 | from cfg_checker.common import logger_cli |
Alex | e0c5b9e | 2019-04-23 18:51:23 -0500 | [diff] [blame] | 2 | from cfg_checker.modules.network.mapper import NetworkMapper |
Alex | 3ebc563 | 2019-04-18 16:47:18 -0500 | [diff] [blame] | 3 | from cfg_checker.modules.network.network_errors import NetworkErrors |
Alex Savatieiev | f526dc0 | 2019-03-06 10:11:32 -0600 | [diff] [blame] | 4 | from cfg_checker.reports import reporter |
Alex Savatieiev | 9b2f651 | 2019-02-20 18:05:00 -0600 | [diff] [blame] | 5 | |
| 6 | |
Alex | e0c5b9e | 2019-04-23 18:51:23 -0500 | [diff] [blame] | 7 | class NetworkChecker(object): |
Alex | e9908f7 | 2020-05-19 16:04:53 -0500 | [diff] [blame] | 8 | def __init__( |
| 9 | self, |
Alex | 9a4ad21 | 2020-10-01 18:04:25 -0500 | [diff] [blame^] | 10 | config, |
Alex | e9908f7 | 2020-05-19 16:04:53 -0500 | [diff] [blame] | 11 | skip_list=None, |
| 12 | skip_list_file=None |
| 13 | ): |
Alex | e0c5b9e | 2019-04-23 18:51:23 -0500 | [diff] [blame] | 14 | logger_cli.debug("... init error logs folder") |
Alex | 3ebc563 | 2019-04-18 16:47:18 -0500 | [diff] [blame] | 15 | self.errors = NetworkErrors() |
Alex | e9908f7 | 2020-05-19 16:04:53 -0500 | [diff] [blame] | 16 | self.mapper = NetworkMapper( |
Alex | 9a4ad21 | 2020-10-01 18:04:25 -0500 | [diff] [blame^] | 17 | config, |
| 18 | errors_class=self.errors, |
Alex | e9908f7 | 2020-05-19 16:04:53 -0500 | [diff] [blame] | 19 | skip_list=skip_list, |
| 20 | skip_list_file=skip_list_file |
| 21 | ) |
Alex | 3ebc563 | 2019-04-18 16:47:18 -0500 | [diff] [blame] | 22 | |
Alex | 836fac8 | 2019-08-22 13:36:16 -0500 | [diff] [blame] | 23 | def check_networks(self, map=True): |
Alex | e0c5b9e | 2019-04-23 18:51:23 -0500 | [diff] [blame] | 24 | self.mapper.map_network(self.mapper.RECLASS) |
| 25 | self.mapper.map_network(self.mapper.RUNTIME) |
Alex | 3ebc563 | 2019-04-18 16:47:18 -0500 | [diff] [blame] | 26 | |
Alex | 836fac8 | 2019-08-22 13:36:16 -0500 | [diff] [blame] | 27 | self.mapper.create_map() |
| 28 | if map: |
| 29 | self.mapper.print_map() |
Alex Savatieiev | 42b89fa | 2019-03-07 18:45:26 -0600 | [diff] [blame] | 30 | |
Alex | 3ebc563 | 2019-04-18 16:47:18 -0500 | [diff] [blame] | 31 | def print_summary(self): |
Alex | 3ebc563 | 2019-04-18 16:47:18 -0500 | [diff] [blame] | 32 | logger_cli.info(self.errors.get_summary(print_zeros=False)) |
Alex | 3ebc563 | 2019-04-18 16:47:18 -0500 | [diff] [blame] | 33 | |
| 34 | def print_error_details(self): |
| 35 | # Detailed errors |
Alex | b151fbe | 2019-04-22 16:53:30 -0500 | [diff] [blame] | 36 | logger_cli.info( |
| 37 | "\n{}\n".format( |
| 38 | self.errors.get_errors() |
| 39 | ) |
| 40 | ) |
Alex | 3ebc563 | 2019-04-18 16:47:18 -0500 | [diff] [blame] | 41 | |
Alex Savatieiev | 9b2f651 | 2019-02-20 18:05:00 -0600 | [diff] [blame] | 42 | 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( |
Alex | 9a4ad21 | 2020-10-01 18:04:25 -0500 | [diff] [blame^] | 50 | reporter.HTMLNetworkReport(self.mapper.salt_master), |
Alex Savatieiev | 9b2f651 | 2019-02-20 18:05:00 -0600 | [diff] [blame] | 51 | filename |
| 52 | ) |
Alex | 9a4ad21 | 2020-10-01 18:04:25 -0500 | [diff] [blame^] | 53 | _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 Savatieiev | 9b2f651 | 2019-02-20 18:05:00 -0600 | [diff] [blame] | 62 | logger_cli.info("-> Done") |