-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathexperiment.py
More file actions
75 lines (60 loc) · 2.22 KB
/
Copy pathexperiment.py
File metadata and controls
75 lines (60 loc) · 2.22 KB
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
from csv import writer as wt
from subprocess import Popen, PIPE
from sys import stderr, stdout
from timeit import default_timer
from requests import request
from os import path
import sys
script_dir = path.dirname(path.abspath(__file__))
cmd = "deployCC -ccn basic -ccp ../GurkhaContracts/asset-transfer-basic/chaincode-go/ -ccl go"
def shut_Fabric():
url = "http://localhost:8080/fabric/network/down"
response = request("POST", url)
if response.status_code != 200:
sys.exit(response.text)
def start_Fabric():
url = "http://localhost:8080/fabric/network/up"
response = request("POST", url)
if response.status_code != 200:
sys.exit(response.text)
def automated_cURL():
shut_Fabric()
start_Fabric()
benchmark_start = default_timer()
session = Popen(
[script_dir + "/automation.sh"], shell=True, stdout=PIPE, stderr=PIPE)
session.wait()
benchmark_end = default_timer()
return (benchmark_end - benchmark_start)
def deployCC():
shut_Fabric()
start_Fabric()
benchmark_start = default_timer()
session = Popen(
[script_dir + "/network.sh deployCC -ccn basic -ccp ../GurkhaContracts/asset-transfer-basic/chaincode-go/ -ccl go" ], shell=True, stdout=PIPE, stderr=PIPE) # TODO: This needs changing!!!
session.wait()
benchmark_end = default_timer()
return (benchmark_end - benchmark_start)
def curl_test(repeats):
with open('automation_cURL_r' + str(repeats) + '.csv', 'w', newline='')as file:
writer = wt(file)
writer.writerow(["Run", "automated cURL"])
for i in range(repeats):
benchmark = automated_cURL()
writer.writerow([i+1, benchmark])
print(i+1, benchmark)
def deployCC_test(repeats):
with open('deployCC_r' + str(repeats) + '.csv', 'w', newline='')as file:
writer = wt(file)
writer.writerow(["Run", "deployCC"])
for i in range(repeats):
benchmark = deployCC()
writer.writerow([i+1, benchmark])
print(i+1, benchmark)
if __name__ == "__main__":
if sys.argv[1] == "curl":
curl_test(int(sys.argv[2]))
elif sys.argv[1] == "deployCC":
deployCC_test(int(sys.argv[2]))
else:
print(sys.argv)