-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsuite-util.lua
85 lines (76 loc) · 2.29 KB
/
suite-util.lua
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
-- TODO: get homedir from os.getenv?
local BASEDIR <const> = "/home/buildbot/test/conf"
-- FIXME: should load these during config stage via callouts to dig.
-- they don't change in practice though, so low priority.
local NODE_IPS <const> = { '10.191.24.56', '10.191.24.4', '10.191.24.178' }
function nodectrl(a)
local result, term, code = os.execute(BASEDIR .. "/node-ctrl.sh " .. a)
if result == nil then
plog("LOG", "ERROR", "node control:" .. term .. "_" .. code)
end
end
function nodestop(host, sleep)
if TESTENV("external") then
plog("LOG", "INFO", string.format("skipping node control: stop %s %s", host, arg))
return
end
nodectrl(string.format("stop %s", host))
if sleep then
os.execute("sleep " .. tostring(sleep))
end
end
function nodestart(host, arg, sleep, debug)
if TESTENV("external") then
plog("LOG", "INFO", string.format("skipping node control: start %s %s", host, arg))
return
end
if TESTENV("debugbin") or debug then
plog("LOG", "INFO", "nodectrl: debugbin", host, arg)
nodectrl(string.format("startdbg %s %s", host, arg))
else
plog("LOG", "INFO", "nodectrl: start", host, arg)
nodectrl(string.format("start %s %s", host, arg))
end
if sleep then
os.execute("sleep " .. tostring(sleep))
end
end
function nodestartdbg(host, arg, sleep)
nodestart(host, arg, sleep, true)
end
function nodeips()
return NODE_IPS
end
function plog(...)
local first = ...
if type(first) == "string" and first == "DEBUG" then
if not _TESTENV["debug"] then
return
end
end
io.write(os.date("%a %b %e %H:%M:%S | "))
io.write(table.concat({...}, " | "))
io.write("\n")
io.flush()
end
function shallow_copy(a)
local c = {}
for key, val in pairs(a) do
c[key] = val
end
return c
end
-- https://stackoverflow.com/questions/9168058/how-to-dump-a-table-to-console
-- should probably get a really nice one of these for the library instead.
function dump(o)
if type(o) == 'table' then
local s = '{ '
for k,v in pairs(o) do
if type(k) ~= 'number' then k = '"'..k..'"' end
s = s .. '['..k..'] = ' .. dump(v) .. ','
end
return s .. '} '
else
return tostring(o)
end
end