]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | #!/usr/bin/env python |
2 | ||
3 | import json | |
4 | import os | |
5 | import sys | |
6 | from time import sleep | |
7 | from subprocess import check_output | |
8 | ||
9 | rpc_py = os.path.dirname(os.path.realpath(__file__)) + '/../../../scripts/rpc.py' | |
10 | ||
11 | class spdk_rpc(object): | |
12 | ||
13 | def __init__(self, rpc_py): | |
14 | self.rpc_py = rpc_py | |
15 | ||
16 | def __getattr__(self, name): | |
17 | def call(*args): | |
18 | cmd = "python {} {}".format(self.rpc_py, name) | |
19 | for arg in args: | |
20 | cmd += " {}".format(arg) | |
21 | return check_output(cmd, shell=True) | |
22 | return call | |
23 | ||
24 | if __name__ == '__main__': | |
25 | ||
26 | if (len(sys.argv) < 2) or (sys.argv[1] != "idle" and sys.argv[1] != "active"): | |
27 | print "must specify \"idle\" or \"active\"" | |
28 | sys.exit(1) | |
29 | ||
30 | rpc = spdk_rpc(rpc_py) | |
31 | ||
32 | idle = 0 | |
33 | active = 0 | |
34 | ||
35 | # capture connection state 10 times, 10 ms apart and keep a | |
36 | # a running count of how many connections were found idle | |
37 | # and active | |
38 | for i in range(10): | |
39 | ||
40 | conns = json.loads(rpc.get_iscsi_connections()) | |
41 | num_conns = len(conns) | |
42 | ||
43 | for conn in conns: | |
44 | if conn['is_idle'] == 1: | |
45 | idle += 1 | |
46 | else: | |
47 | active += 1 | |
48 | ||
49 | # sleep 10ms | |
50 | sleep(0.01) | |
51 | ||
52 | active_pct = float(active) / (idle + active) | |
53 | ||
54 | # even when there is no active I/O on a connection, there could be | |
55 | # a nopin/nopout being processed which causes a connection to | |
56 | # temporarily go active; also even when fio is actively running | |
57 | # there could be a brief period of time where the initiator has | |
58 | # no active I/O to some connection | |
59 | # | |
60 | # so do not enforce that *all* connections must be idle or active; | |
61 | # allow for some percentage of anomalies | |
62 | anomaly_pct_allowed = 0.10 | |
63 | ||
64 | print "active = {}".format(active) | |
65 | print "idle = {}".format(idle) | |
66 | print "active_pct = {}".format(active_pct) | |
67 | ||
68 | if sys.argv[1] == "idle" and active_pct > anomaly_pct_allowed: | |
69 | sys.exit(1) | |
70 | ||
71 | if sys.argv[1] == "active" and active_pct < (1.00 - anomaly_pct_allowed): | |
72 | sys.exit(1) | |
73 | ||
74 | sys.exit(0) |