-
Notifications
You must be signed in to change notification settings - Fork 0
/
head.py
86 lines (72 loc) · 2.21 KB
/
head.py
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
#!/usr/bin/env python
from parser import load_json
import os
import ast
import re
def get_tests(directory):
tests=[]
for test_file in os.listdir(directory):
tests.append(load_json(directory+test_file))
for test in tests:
tes_type=test['type']
tes_name=test['test_name']
tes_params=ast.literal_eval(re.sub('\r\n','',test['test_params']))
tes_params=ast.literal_eval(re.sub('#','',test['test_params']))
test[tes_type]={tes_name:tes_params}
del(test['test_name'])
del(test['test_params'])
return tests
def get_hosts(directory):
hosts=[]
for host_file in os.listdir(directory):
hosts.append(load_json(directory+host_file))
for host in hosts:
hos_login=host['login']
hos_password=host['password']
host['credentials']={'login':hos_login,'password':hos_password}
del(host['login'])
del(host['password'])
return hosts
if __name__=='__main__':
tests=load_json("tests.json")
hosts=load_json("hosts.json")
else:
tests=get_tests("tests/")
hosts=get_hosts("hosts/")
result={}
for test in tests:
result[test['id']]=True
def test_results(hosts,tests):
hostnames=[x["hostname"] for x in hosts]
result={}
for test in tests:
result[test['id']]=True
for test in tests:
# Here should be called simple function from library
# for example: result[test['id']]=routing_table.max_entries('router1',4)
test_type=test['type']
test_name=test[test_type].keys()[0]
test_params=test[test_type][test_name]
hostname=test['host']
host=hosts[hostnames.index(hostname)]
id_number=test['id']
if not test.has_key('condition'):
test['condition']=True
# exec('"result[id_number]="+test_type+"."+test_name+"("+hostname+","+test_params+")"')
import_string = "from %s.%s import test_func" % ( test_type , test_name )
try:
exec import_string
except:
result[id_number]="Specified test missing."
try:
result[id_number]=test_func(host,test_params)
except:
result[id_number]="Test parameters are bad or test is improperly designed"
return result
if __name__=='__main__':
result=test_results(hosts,tests)
for test in tests:
print test['id']
print result[test['id']]
print
print