summaryrefslogtreecommitdiffstats
path: root/tools/pharos-validator/src/validation_tool/bin/pharos-validator-node
blob: e81bc1bfa2023bf66df27b6d82eb5cc92e777d4c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
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()