18 from CNCMTTTool
import *
21 def __init__(self, threadID, queue, status, lock, testDef):
22 threading.Thread.__init__(self)
31 self.testDef.logger.verbose_print(
"IPMITool: Thread " + str(self.
threadID) +
" is active")
34 if not self.queue.empty():
35 task = self.queue.get()
37 self.testDef.logger.verbose_print(
"IPMITool: Thread " + str(self.
threadID) +
" received task " +
' '.join(task[
'cmd']))
50 self.testDef.logger.verbose_print(
"IPMITool: Thread " + str(self.
threadID) +
" dryrun reset " + task[
'target'])
52 self.status.append((0,
' '.join(task[
'cmd']),
None))
59 status,stdout,stderr,_ = self.testDef.execmd.execute(
None, task[
'cmd'], self.
testDef)
60 if 0 == status
or ntries == task[
'maxtries']:
61 self.testDef.logger.verbose_print(
"IPMITool: node " + task[
'target'] +
" is back")
65 if 0 != status
and ntries >= task[
'maxtries']:
66 msg =
"Operation timed out on node " + task[
'target']
67 self.status.append((-1,
' '.join(task[
'cmd']), msg))
69 self.status.append((status,
' '.join(task[
'cmd']), stderr))
74 if task[
'cmd']
is not None:
77 self.testDef.logger.verbose_print(
"IPMITool: Thread " + str(self.
threadID) +
" dryrun " +
' '.join(task[
'cmd']))
79 self.status.append((0,
' '.join(task[
'cmd']),
None))
82 if task[
'target']
is not None:
86 ckcmd[
'cmd'] = [
"ping",
"-c",
"1", task[
'target']]
87 ckcmd[
'maxtries'] = task[
'maxtries']
88 ckcmd[
'target'] = task[
'target']
89 ckcmd[
'dryrun'] = dryrun
97 self.testDef.logger.verbose_print(
"IPMITool: " +
' '.join(task[
'cmd']))
98 st,stdout,stderr,_ = self.testDef.execmd.execute(
None, task[
'cmd'], self.
testDef)
100 self.status.append((st,
' '.join(task[
'cmd']), stderr))
102 if task[
'target']
is not None:
104 ckcmd[
'reset'] =
True
105 ckcmd[
'cmd'] = [
"ping",
"-c",
"1", task[
'target']]
106 ckcmd[
'maxtries'] = task[
'maxtries']
107 ckcmd[
'target'] = task[
'target']
108 ckcmd[
'dryrun'] = dryrun
110 self.queue.put(ckcmd)
118 self.status.append((2,
"NULL",
"Missing command"))
124 self.status.append((2,
"NULL",
"Missing command"))
150 CNCMTTTool.__init__(self)
152 self.
options[
'target'] = (
None,
"List of remote host names or LAN interfaces to monitor during reset operations")
153 self.
options[
'controller'] = (
None,
"List of IP addresses of remote node controllers/BMCs")
154 self.
options[
'username'] = (
None,
"Remote controller username")
155 self.
options[
'password'] = (
None,
"Remote controller password")
156 self.
options[
'pwfile'] = (
None,
"File containing remote controller password")
157 self.
options[
'command'] = (
None,
"Command to be sent")
158 self.
options[
'maxtries'] = (100,
"Max number of times to ping each host before declaring reset to fail")
159 self.
options[
'numthreads'] = (30,
"Number of worker threads to use")
160 self.
options[
'dryrun'] = (
False,
"Dryrun - print out commands but do not execute")
161 self.
options[
'sudo'] = (
False,
"Use sudo to execute privileged commands")
170 IPlugin.activate(self)
174 IPlugin.deactivate(self)
180 lines = testDef.printOptions(self.
options)
186 testDef.logger.verbose_print(
"IPMITool execute")
190 if keyvals[
'modules']
is not None:
191 if testDef.modcmd
is None:
193 log[
'stderr'] =
"No module support available"
197 mods = keyvals[
'modules'].split(
',')
199 status,stdout,stderr = testDef.modcmd.loadModules(mods, testDef)
201 log[
'status'] = status
202 log[
'stdout'] = stdout
203 log[
'stderr'] = stderr
211 testDef.parseOptions(log, self.
options, keyvals, cmds)
212 testDef.logger.verbose_print(
"IPMITool: " +
' '.join(cmds))
215 if cmds[
'controller']
is None:
217 log[
'stderr'] =
"No target controllers identified"
221 controllers = cmds[
'controller'].split(
',')
224 log[
'stderr'] =
"No target controllers identified"
228 if cmds[
'command']
is None:
230 log[
'stderr'] =
"No IPMI command given"
234 log[
'stderr'] =
"No IPMI command given"
239 if cmds[
'target']
is None:
241 log[
'stderr'] =
"No target nodes identified"
245 targets = cmds[
'target'].split(
",")
247 if len(targets) != len(controllers):
249 log[
'stderr'] =
"Number of targets doesn't equal number of controllers"
259 ipmiQueue =
Queue(2 * len(controllers))
261 ipmiQueue =
Queue(len(controllers))
265 for n
in range(0, len(controllers)):
268 ipmicmd = cmds[
'command']
269 ipmicmd.insert(0,
"chassis")
270 ipmicmd.insert(0,
"ipmitool")
272 ipmicmd.insert(0,
"sudo")
274 ipmicmd.append(controllers[n])
275 if cmds[
'username']
is not None:
277 ipmicmd.append(cmds[
'username'])
278 if cmds[
'password']
is not None:
280 ipmicmd.append(cmds[
'password'])
282 if cmds[
'pwfile']
is not None:
283 if os.path.exists(cmds[
'pwfile']):
284 f = open(cmds[
'pwfile'],
'r')
285 password = f.readline().strip()
287 ipmicmd.append(password)
292 log[
'stderr'] =
"Password file " + cmds[
'pwfile'] +
" does not exist"
298 cmd[
'target'] = targets[n]
299 cmd[
'maxtries'] = cmds[
'maxtries']
300 cmd[
'dryrun'] = cmds[
'dryrun']
309 if len(targets) < self.
options[
'numthreads']:
312 rng = self.
options[
'numthreads']
313 for n
in range(0, rng):
316 self.threads.append(thread)
319 while not ipmiQueue.empty():
332 log[
'status'] = st[0]
333 log[
'stdout'] = st[1]
334 log[
'stderr'] = st[2]
337 testDef.modcmd.unloadModules(mods, testDef)