-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_x1.py
128 lines (93 loc) · 4.23 KB
/
main_x1.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# SPDX-FileCopyrightText: 2022-2024 Technology Innovation Institute (TII)
# SPDX-License-Identifier: Apache-2.0
import paramiko
import os
import time
from tools import *
target_ip = '192.168.100.35'
output_file = 'ssh.log'
test_run = 20
# This will be saved to root of the main result directory
long_build_description = """Re-testing PR#422 Add IDS-VM.
"""
# This could optionally be used as an arbitrary name of the ghaf build under test.
# Build labels could show on the x-axis of the plot produced by visualize_results.py
# May be left empty
# build_label = ""
def main():
start_time = time.time()
print('Sysbench test run started.')
try:
file = open(output_file, "a")
port = 22
# created client using paramiko
client = paramiko.SSHClient()
# here we are loading the system
# host keys
# client.load_system_host_keys()
# This is needed for paramiko to accept connection with unknown key (not using ssh keys)
client.set_missing_host_key_policy(paramiko.AutoAddPolicy)
# connecting paramiko using target_ip and password
client.connect(target_ip, port=port, username='ghaf', password='ghaf')
chan = client.invoke_shell()
scp = client.open_sftp()
scp.put('./sysbench_test', '/home/ghaf/sysbench_test')
time.sleep(2)
# Close the SCP client
scp.close()
# Passing the commands to run the tests on VMs depends on where the network interface is (ghaf-host / net-vm).
chan.send(b'hostname\n')
time.sleep(1)
resp = chan.recv(9999)
output = resp.decode('ascii').split(',')
print(''.join(output))
if check_hostname(''.join(output), 'ghaf-host'):
# Create directory for the test results and move there
result_dir(chan, file, test_run, long_build_description)
# Run test first on ghaf-host
run_test(chan, file, 'host', test_run, 20)
# Copy test_script to net-vm and ssh into net-vm
log_netvm(chan, file)
# Run test in ids-vm 192.168.100.3
# appvm_from_netvm(chan, file, '192.168.100.4', 'ids-vm', test_run, 1)
# Run test in net-vm
run_test(chan, file, 'net-vm', test_run, 1)
# Run test in other VMs
test_appvms_from_netvm(chan, output_file, test_run)
# Before enabling this ensure that IPs in tools.test_appvms_by_ip match with the hostnames.
# test_appvms_by_ip(chan, output_file, test_run)
# Pull the data from net-vm to host
time.sleep(2)
send_and_receive(chan, file, 'exit\n', 5, 9999)
if send_and_receive(chan, file, 'scp -r [email protected]:/home/ghaf/* ./\n', 5, 9999, 'assword'):
send_and_receive(chan, file, 'ghaf\n', 5, 9999)
time.sleep(3)
elif check_hostname(''.join(output), 'net-vm'):
# Create directory for the test results and move there
result_dir(chan, file, test_run, long_build_description)
# Run test in ids-vm 192.168.100.3
# appvm_from_netvm(chan, file, '192.168.100.3', 'ids-vm', test_run, 1)
test_appvms_from_netvm(chan, file, test_run)
run_test(chan, file, 'net-vm', test_run, 1)
# Test also on ghaf-host and pull data
appvm_from_netvm(chan, file, '192.168.101.2', 'host', test_run, 20)
else:
print("Unknown hostname.")
# Pull the data out
# Does not work with *
# Should zip the files first but no zip available on ghaf
# scp = client.open_sftp()
# scp.get('/home/ghaf/Test_run_{}', './../result_data/'.format(test_run))
# time.sleep(2)
# Close the SCP client
# scp.close()
finally:
file.close()
client.close()
end_time = time.time()
execution_time = end_time - start_time
print("Sysbench test finished.")
print("Elapsed time: " + str(execution_time))
main()
# Pull the result files out from the target machine.
os.system("sshpass -p 'ghaf' scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -r ghaf@{}:/home/ghaf/Test_run_{} ./../sysbench_result_data/lenovo-x1/\n".format(target_ip, test_run))