def test_empty_config(self): config = PbenchConfig(_config_path_prefix / "pbench.cfg") assert config.TZ == "UTC", f"Unexpected TZ value, {config.TZ!r}" assert (config.log_fmt is None), f"Unexpected log format value, {config.log_fmt!r}" assert ( config.default_logging_level == "INFO" ), f"Unexpected default logging level, {config.default_logging_level!r}" assert ( config.log_using_caller_directory is False ), f"Unexpected 'log using caller directory' boolean, {config.log_using_caller_directory!r}" assert config.log_dir is None, f"Unexpected log directory, {config.log_dir!r}" assert (config.logger_type == "devlog" ), f"Unexpected logger type, {config.logger_type!r}" with pytest.raises(AttributeError): print(f"{config.logger_host!r}") with pytest.raises(AttributeError): print(f"{config.logger_port!r}") assert "42" == config.get( "other", "foobar"), "Failed to fetch 'foobar' from 'DEFAULT' section" assert "43" == config.get( "other", "barfoo"), "Failed to fetch 'barfoo' from 'other' section" assert isinstance( config.files, list ), f"Unexpected object class for 'files', {config.files.__class__!r}"
def test_pbench_logger(): config = PbenchConfig(cfg_name) logger = get_pbench_logger(_NAME_, config) logger_type = config.get("logging", "logger_type") logger = mock_the_handler(logger, logger_type, log_files[logger_type]) logger.debug(log_msgs[logger_type]) if os.path.isfile(os.path.join(logdir,log_files[logger_type])): with open(os.path.join(logdir,log_files[logger_type]), 'r') as f: assert f.read()[:-1] == log_msgs[logger_type], "Mismatch: the file did not contain the expected message."
parser.add_argument( "file_to_index", nargs=1, help="The file containing the report to index") parsed = parser.parse_args() from pbench import report_status, PbenchConfig, BadConfig, get_es, \ get_pbench_logger, PbenchTemplates try: config = PbenchConfig(parsed.cfg_name) except BadConfig as e: print("{}: {}".format(_prog, e), file=sys.stderr) sys.exit(1) logger = get_pbench_logger(_prog, config) try: es = get_es(config, logger) idx_prefix = config.get('Indexing', 'index_prefix') except Exception: # If we don't have an Elasticsearch configuration just pass None es = None idx_prefix = None else: _dir = os.path.dirname(os.path.abspath(sys.argv[0])) templates = PbenchTemplates(_dir, idx_prefix, logger) templates.update_templates(es, 'server-reports') status = report_status(es, logger, config.LOGSDIR, idx_prefix, parsed.name, parsed.timestamp, parsed.doctype, parsed.file_to_index[0]) sys.exit(status)
def main(): cfg_name = os.environ.get("_PBENCH_SERVER_CONFIG") if not cfg_name: print( "{}: ERROR: No config file specified; set _PBENCH_SERVER_CONFIG env variable or" " use --config <file> on the command line".format(_NAME_), file=sys.stderr) return 2 try: config = PbenchConfig(cfg_name) except BadConfig as e: print("{}: {}".format(_NAME_, e), file=sys.stderr) return 1 logger = get_pbench_logger(_NAME_, config) # Add a BACKUP and QDIR field to the config object config.BACKUP = config.conf.get("pbench-server", "pbench-backup-dir") config.QDIR = config.get('pbench-server', 'pbench-quarantine-dir') # call the LocalBackupObject class lb_obj = LocalBackupObject(config) # call the S3Config class s3_obj = S3Config(config, logger) lb_obj, s3_obj = sanity_check(lb_obj, s3_obj, config, logger) if lb_obj is None and s3_obj is None: return 3 logger.info('start-{}'.format(config.TS)) # Initiate the backup counts = backup_data(lb_obj, s3_obj, config, logger) result_string = ("Total processed: {}," " Local backup successes: {}," " Local backup failures: {}," " S3 upload successes: {}," " S3 upload failures: {}," " Quarantined: {}".format(counts.ntotal, counts.nbackup_success, counts.nbackup_fail, counts.ns3_success, counts.ns3_fail, counts.nquaran)) logger.info(result_string) prog = os.path.basename(sys.argv[0]) # prepare and send report with tempfile.NamedTemporaryFile(mode='w+t', dir=config.TMP) as reportfp: reportfp.write("{}.{}({})\n{}\n".format(prog, config.timestamp(), config.PBENCH_ENV, result_string)) reportfp.seek(0) report = Report(config, _NAME_) report.init_report_template() try: report.post_status(config.timestamp(), "status", reportfp.name) except Exception: pass logger.info('end-{}'.format(config.TS)) return 0
parser.add_argument("file_to_index", nargs=1, help="The file containing the report to index") parsed = parser.parse_args() from pbench import report_status, PbenchConfig, BadConfig, get_es, \ get_pbench_logger, PbenchTemplates try: config = PbenchConfig(parsed.cfg_name) except BadConfig as e: print("{}: {}".format(_prog, e), file=sys.stderr) sys.exit(1) logger = get_pbench_logger(_prog, config) try: es = get_es(config, logger) idx_prefix = config.get('Indexing', 'index_prefix') except Exception: # If we don't have an Elasticsearch configuration just pass None es = None idx_prefix = None else: _dir = os.path.dirname(os.path.abspath(sys.argv[0])) templates = PbenchTemplates(_dir, idx_prefix, logger) templates.update_templates(es, 'server-reports') status = report_status(es, logger, config.LOGSDIR, idx_prefix, parsed.name, parsed.timestamp, parsed.doctype, parsed.file_to_index[0]) sys.exit(status)