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
|
##############################################################################
# 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 logging
import socket
import yaml
import os
import pharosvalidator.test.probe as probe
import pharosvalidator.test.evaluate as evaluate
from pharosvalidator.util import send_msg
def hardware_test():
"""
hardware_test: Run hardware probing/testing functions
input: None
output: String in YAML format of the tests that were run
"""
logger = logging.getLogger(__name__)
logger.info("Beginning hardware test")
# Run test scripts
results = []
results.append(testinterpreter("CPU test", evaluate.cpu, probe.cpu()))
results.append(testinterpreter("Memory test", evaluate.memory, probe.memory()))
results.append(testinterpreter("Storage test", evaluate.storage, probe.storage()))
# Start generating the yaml file
yamltext = ""
for result in results:
yamltext += yaml.dump(result, default_flow_style=False)
return yamltext
def network_test(networkfile):
logger = logging.getLogger(__name__)
logger.info("Beginning network test")
logger.info("Ending network test")
pass
def send_result(host, port, result):
"""
send_result: Send the final test result to the central test server
input: Host address of target; Port of target; String to send to server
output: None
"""
logger = logging.getLogger(__name__)
logger.info("Sending test result")
# Format the results properly
linecount = 0
for c in result:
if c == "\n":
linecount += 1
result = str(linecount) + "\n" + result
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((host, int(port)))
send_msg(sock, result)
def testinterpreter(name, test, dataset):
"""High level function for test functions within this module to print out
their results in an ordered function while also writing out logs,
expects a list of testresults objects"""
# Start the yaml file contents
data = {name:[]}
# test the dataset
results = test(dataset)
for result in results:
data[name].append(result)
return data
|