diff options
author | Jack Morgan <jack.morgan@intel.com> | 2016-10-25 11:45:14 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@opnfv.org> | 2016-10-25 11:45:14 +0000 |
commit | 026ae4994e15809d25bf9f62e36f6fe5b35b1542 (patch) | |
tree | 83d6f0bb4ee1594b3016ab67696af0f1acdb4d94 /pharos-validator/src/validation_tool/bin/pharos-validator-node | |
parent | 61f00f4110b1d33827e3bd19ffef34f10be8273a (diff) | |
parent | 4f0ecb702a601d122f261a134007377435e4aca1 (diff) |
Merge "Add pharos-validator tool"
Diffstat (limited to 'pharos-validator/src/validation_tool/bin/pharos-validator-node')
-rwxr-xr-x | pharos-validator/src/validation_tool/bin/pharos-validator-node | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/pharos-validator/src/validation_tool/bin/pharos-validator-node b/pharos-validator/src/validation_tool/bin/pharos-validator-node new file mode 100755 index 0000000..e81bc1b --- /dev/null +++ b/pharos-validator/src/validation_tool/bin/pharos-validator-node @@ -0,0 +1,92 @@ +#!/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() |