#!/usr/bin/env/python3 ############################################################################## # Copyright (c) 2015 Todd Gaunt and others. # # All rights reserved. This program and the accompanying materials # are made available under the terms of the Apache License, Version 2.0 # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## import argparse import os import sys import logging from pharosvalidator import node def main(): """Run validation tests on machine, then send results back to server on jump host""" args = parse_args() logger = configure_root_logger(0) if args["test"] == "hardware": result = node.hardware_test() elif args["test"] == "network": result = node.network_test() else: logger.error("Invalid test name chosen, please choose \"hardware\" or \"network\"") quit() logger.debug("TEST RESULTS\n" + "#"*50 + '\n' + result + "#"*50 + '\n') logger.info("Sending results to host...") node.send_result(args["host"], args["port"], result) def configure_root_logger(loglevel): # Add a file handler to the default logger formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s") # Configure the root logger stdout_handler = logging.StreamHandler(sys.stdout) stdout_handler.setLevel(loglevel) stdout_handler.setFormatter(formatter) root_logger = logging.getLogger() root_logger.addHandler(stdout_handler) root_logger.setLevel(loglevel) return root_logger def parse_args(): """ parse_args: parse the commandline arguments and configuration file into a dictionary that can be easily passed and referenced by other functions input: None output: Dictionary of all commandline arguments and configuration file settings """ logger = logging.getLogger(__name__) parser = argparse.ArgumentParser( \ description='evaluates a system against the pharos specification') parser.add_argument('--version', action="store_true", default=False, help='display version then exit') # Address that the client should connect to parser.add_argument('-H', '--host', type=str, default="0.0.0.0", help='Address of the server results should be \ uploaded to') # Port that the client should connect to parser.add_argument('-p', '--port', type=str, default=0, help='Port of the server results will be uploaded to') # Specify which test to run on the node parser.add_argument('test', metavar='test', type=str, help='Which test should be run ["hardware", "network"]') args = vars(parser.parse_args()) return args if __name__ == "__main__": main()