def validate(self, full_configuration, logger): config_results = {} connectivity_results = {} try: if self.validate_config: config_results = yield self._validate_config( full_configuration, logger) connectivity_tests_skipped = False if self.validate_connectivity: # If both config and connectivity are being validated, only run the # connectivity tests if there were no configuration errors. if self.validate_config and not all_sections_successful( config_results): connectivity_tests_skipped = True else: connectivity_results = yield self._validate_connectivity( full_configuration, logger) self._log_summary_section(config_results, connectivity_results, connectivity_tests_skipped, logger) defer.returnValue((config_results, connectivity_results)) except Exception as error: util.set_stdout_color('red') logger.error( "There was a problem running the connectivity tool: {error}", error=error) util.set_stdout_color('reset') defer.returnValue(({}, {}))
def _log_summary_section(self, config_results, connectivity_results, connectivity_tests_skipped, logger): """ Logs the summary section of the results. Args: config_results (dict): map of section name to section result for the config validation connectivity_results (dict): map of section name to section result for the connectivity validation connectivity_tests_skipped (bool): True if the connectivity tests were skipped due to config errors logger (Logger): the Twisted logger to write to """ logger.info("SUMMARY") successful = all_sections_successful( config_results) and all_sections_successful(connectivity_results) has_warnings = any_section_is_warning( config_results) or any_section_is_warning(connectivity_results) if successful and not has_warnings: util.set_stdout_color('green') logger.info("No issues detected") util.set_stdout_color('reset') else: if connectivity_tests_skipped: logger.warn(CONNECTIVITY_TESTS_SKIPPED_MESSAGE) logger.info(" ") self._log_summary_for_results(config_results, connectivity_results, logger)
def _output_results(self, all_results, sections, logger): """ Output the results into a Logger Args: all_results (OrderedDict): map of section name -> ReportableResult subclass appropriate to the section logger (Logger): the twisted Logger to output into """ for section_name, section_result in all_results.items(): logger.info( "Testing section \'{section_name}\' with configuration:", section_name=section_name) logger.info( "{cfg}", cfg=_sanitize_config( sections[section_name], lambda x: x.startswith( 'radius_secret') or x.startswith('secret') or x in ('skey', 'skey_protected', 'service_account_password', 'service_account_password_protected'))) if not section_result.is_successful() or section_result.is_warning( ): util.set_stdout_color('red') else: util.set_stdout_color('green') section_result.to_log_output(logger) util.set_stdout_color('reset') logger.info("-----------------------------")
def _log_section_summary(self, results, logger, filtering_predicate, header): """ Prints the results for a single config section in the summary. Only warnings and errors are printed. Args: results (list of BaseResult): Results to print in the section logger (Logger): the Twisted logger to write to filtering_predicate (ILogFilterPredicate): Predicate used to filter the output to only include warnings and errors header (str): The section header """ logger.info(header) # Set the predicate to filter anything that isn't a warning or error # while we log the section result. Then clear predicate log level # once we're done. filtering_predicate.setLogLevelForNamespace(None, LogLevel.warn) util.set_stdout_color('red') for result in results: result.to_log_output(logger) util.set_stdout_color('reset') filtering_predicate.clearLogLevels() logger.info(" ")