-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathldmsd_auth_ovis_test
executable file
·275 lines (242 loc) · 7.95 KB
/
ldmsd_auth_ovis_test
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
#!/usr/bin/env python3
#
# Test auth_ovis authentication plugin
import os
import re
import pdb
import pwd
import sys
import json
import time
import argparse
import TADA
import logging
import atexit
from distutils.spawn import find_executable
from LDMS_Test import LDMSDCluster, LDMSDContainer, process_args, \
add_common_args, jprint, parse_ldms_ls
if __name__ != "__main__":
raise RuntimeError("This should not be impoarted as a module.")
logging.basicConfig(format = "%(asctime)s %(name)s %(levelname)s %(message)s",
level = logging.INFO)
log = logging.getLogger(__name__)
exec(open(os.getenv("PYTHONSTARTUP", "/dev/null")).read())
#### default values #### ---------------------------------------------
sbin_ldmsd = find_executable("ldmsd")
if sbin_ldmsd:
default_prefix, a, b = sbin_ldmsd.rsplit('/', 2)
else:
default_prefix = "/opt/ovis"
#### argument parsing #### -------------------------------------------
ap = argparse.ArgumentParser(description = "Test auth_ovis plugin" )
add_common_args(ap)
args = ap.parse_args()
process_args(args)
#### config variables #### ------------------------------
USER = args.user
PREFIX = args.prefix
COMMIT_ID = args.commit_id
SRC = args.src
CLUSTERNAME = args.clustername
DB = args.data_root
LDMSD_PORT = 10000
#### spec helpers #### ------------------------------------------------------
def dom_name(num):
return "dom{}".format(num)
def dom_sock(num):
return "/munge/{}/sock".format(dom_name(num))
def dom_key(num):
return str(num)*4096
#### spec #### -------------------------------------------------------
common_plugin_config = [
"component_id=%component_id%",
"instance=%hostname%/%plugin%",
"producer=%hostname%",
"perm=0600",
]
spec = {
"name" : CLUSTERNAME,
"description" : "{}'s test_agg cluster".format(USER),
"type" : "NA",
"templates" : { # generic template can apply to any object by "!extends"
"compute-node" : {
"daemons" : [
{
"name" : "sshd", # for debugging
"type" : "sshd",
},
{
"name" : "sampler-daemon",
"!extends" : "ldmsd-sampler",
},
],
},
"sampler_plugin" : {
"interval" : 1000000,
"offset" : 0,
"config" : common_plugin_config,
"start" : True,
},
"ldmsd-base" : {
"type" : "ldmsd",
"auth" : [
{
"name" : "ovis",
"plugin" : "ovis",
"conf" : "/db/auth0.conf",
},
],
"listen" : [
{
"xprt" : "sock",
"port" : 10000,
"auth" : "ovis",
},
],
},
"ldmsd-sampler" : {
"!extends" : "ldmsd-base",
"samplers" : [
{
"plugin" : "meminfo",
"!extends" : "sampler_plugin",
},
{
"plugin" : "vmstat",
"!extends" : "sampler_plugin",
},
],
},
}, # templates
"nodes" : [
{
"hostname" : "node-1",
"component_id" : 1,
"!extends" : "compute-node",
},
{
"hostname" : "headnode",
"daemons" : [
{
"name" : "sshd",
"type" : "sshd",
},
]
},
], # nodes
"cap_add": [ "SYS_PTRACE", "SYS_ADMIN" ],
"image": args.image,
"ovis_prefix": PREFIX,
"env" : { "FOO": "BAR" },
"mounts": [
"{}:/db:rw".format(DB),
] + args.mount +
( ["{0}:{0}:ro".format(SRC)] if SRC else [] ),
}
#### test definition ####
test = TADA.Test(test_suite = "LDMSD",
test_type = "FVT",
test_name = "ldmsd_auth_ovis_test",
test_desc = "Test auth_ovis plugin",
test_user = args.user,
commit_id = COMMIT_ID,
tada_addr = args.tada_addr)
test.add_assertion(1, "ldms_ls with auth none")
test.add_assertion(2, "ldms_ls with wrong secret")
test.add_assertion(3, "ldms_ls 'dir' with right secret")
test.add_assertion(4, "ldms_ls 'read' with right secret")
#### Helper Functions ####
def ldms_ls(cont, host = None, port = LDMSD_PORT, l = False, auth = None,
auth_args=None, user="root"):
try:
args = "-l -v" if l else ""
_host = "-h {}".format(host) if host else ""
if auth:
_auth = "-a {}".format(auth)
if auth_args:
_auth += "".join([" -A {}={}".format(k, v) \
for k,v in auth_args.items()])
else:
_auth = ""
rc, out = cont.exec_run("bash -c 'ldms_ls {args} -x sock -p {port}" \
" {_host} " \
" {_auth} " \
"2>/dev/null'" \
.format(_host=_host, _auth=_auth,
port=port, args=args),
user=user)
if l:
return parse_ldms_ls(out)
else:
return out.splitlines()
except:
raise
#### Start! ####
cluster = None
test.start()
@atexit.register
def at_exit():
rc = test.finish()
if cluster is not None:
cluster.remove()
os._exit(rc)
log.info("-- Get or create the cluster --")
cluster = LDMSDCluster.get(spec["name"], create = True, spec = spec)
headnode = cluster.get_container("headnode")
node1 = cluster.get_container("node-1")
#### Prep auth files ####
path = "{}/auth0.conf".format(DB)
with open(path, "w") as f:
f.write("secretword=0000000000000000")
os.chmod(path, 0o600)
path = "{}/auth1.conf".format(DB)
with open(path, "w") as f:
f.write("secretword=1111111111111111")
os.chmod(path, 0o600)
log.info("-- Start daemons --")
cluster.start_daemons()
cluster.make_known_hosts()
log.info("... wait a bit to make sure ldmsd's are up")
time.sleep(5)
#test.add_assertion(1, "ldms_ls with auth none")
sets = ldms_ls(headnode, host="node-1", port=10000)
sets = set(sets)
expect = set(["Connection failed/rejected."])
if sets == expect:
test.assert_test(1, True, "verified")
else:
test.assert_test(1, False, "result({}) != expect({})".format(sets, expect))
#test.add_assertion(2, "ldms_ls with wrong secret")
sets = ldms_ls(headnode, host="node-1", port=10000,
auth="ovis", auth_args={"conf": "/db/auth1.conf"})
sets = set(sets)
expect = set(["Connection failed/rejected."])
if sets == expect:
test.assert_test(2, True, "verified")
else:
test.assert_test(2, False, "result({}) != expect({})".format(sets, expect))
#test.add_assertion(3, "ldms_ls 'dir' with right secret")
sets = ldms_ls(headnode, host="node-1", port=10000,
auth="ovis", auth_args={"conf": "/db/auth0.conf"})
sets = set(sets)
expect = set(["node-1/{}".format(name) for name in ["vmstat", "meminfo"]])
if sets == expect:
test.assert_test(3, True, "verified")
else:
test.assert_test(3, False, "result({}) != expect({})".format(sets, expect))
#test.add_assertion(4, "ldms_ls 'read' with right secret")
while True:
lsets = ldms_ls(headnode, l=True, host="node-1", port=10000,
auth="ovis", auth_args={"conf": "/db/auth0.conf"})
sets = set(lsets)
expect = set(["node-1/{}".format(name) for name in ["vmstat", "meminfo"]])
if sets != expect:
test.assert_test(4, False, "result({}) != expect({})".format(sets, expect))
break
for s in lsets.values():
if 'data' not in s or len(s['data']) == 0:
test.assert_test(4, False, "{} has no data".format(s['name']))
break
test.assert_test(4, True, "verified")
break
# see at_exit()