11 from __future__
import print_function
14 from HarasserMTTTool
import *
16 import multiprocessing
30 HarasserMTTTool.__init__(self)
36 self.
options[
'trigger_scripts'] = (
None,
"Scripts to run to launch harassers")
37 self.
options[
'stop_scripts'] = (
None,
"Scripts to run to stop and clean-up harassers")
38 self.
options[
'join_timeout'] = (
None,
"Seconds to wait for processes to finish")
55 IPlugin.activate(self)
64 IPlugin.deactivate(self)
67 self.testDef.logger.verbose_print(
"Harasser plugin stopped while harassers were running. Cleaning up harassers...")
68 self.
stop(self.running_harassers.keys(), self.
testDef)
69 self.testDef.logger.verbose_print(
"Harassers were cleaned up.")
79 lines = testDef.printOptions(self.
options)
94 status,stdout,stderr,time = testDef.execmd.execute(cmds, cmdargs, testDef)
101 trigger_scripts = self.
options[
'trigger_scripts'][0]
102 if trigger_scripts
is None or trigger_scripts ==
'':
105 trigger_scripts = trigger_scripts.split(
',')
106 stop_scripts = self.
options[
'stop_scripts'][0]
107 if stop_scripts
is None or stop_scripts ==
'':
110 stop_scripts = stop_scripts.split(
',')
115 for trigger_script,stop_script
in zip(trigger_scripts,stop_scripts):
116 trigger_script = trigger_script.strip()
117 stop_script = stop_script.strip()
118 ops = {(k[:-1]
if k.endswith(
'_scripts')
else k):\
119 (trigger_script
if k ==
'trigger_scripts' else (\
120 stop_script
if k ==
'stop_scripts' \
122 for k,v
in self.options.items()}
124 cmdargs = trigger_script.split()
128 args=({k:v[0]
for k,v
in self.options.items()},cmdargs,testDef))
142 for exec_id
in exec_ids:
147 process_run_info = self.
stop(exec_ids, testDef)
148 return dead_processes, process_run_info
154 def stop(self, exec_ids, testDef):
156 for exec_id
in exec_ids:
160 for process,ops,starttime
in process_info:
161 cmdargs = ops[
'stop_script'].split()
162 status,stdout,stderr,time = testDef.execmd.execute({k:v[0]
for k,v
in self.options.items()}, cmdargs, testDef)
163 return_info.append((status,stdout,stderr,datetime.datetime.now()-starttime))
165 for (process,ops,starttime),(status,stdout,stderr,time)
in zip(process_info,return_info):
167 if self.
options[
'join_timeout'][0]
is None:
170 process.join(int(self.
options[
'join_timeout'][0]))
182 testDef.logger.verbose_print(
"Harasser Execute")
187 if log[
'section']
is not None:
188 if "Default" in log[
'section']:
192 testDef.parseOptions(log, self.
options, keyvals, myopts)
194 keys = list(self.options.keys())
195 optkeys = list(myopts.keys())
196 for optkey
in optkeys:
208 log[
'stderr'] =
"Section not specified"
212 log[
'stderr'] =
"Must be used in a Default stage"
def check
A check to see if harassers are working properly.
def activate
Activates plugin.
def get_running_harassers
Returns information about what harassers are currently running.
def parallel_execute
This function is passed into multiprocessing as a target.
def config
Configures plugin outside of INI file.
def deactivate
Deactivates plugin.
def start
Harassment is started on the system.
def stop
Calls the stop-scripts provided with harasser scripts to stop and clean up harassment.
def print_options
Prints current configuration of plugin.
def execute
Configure the harasser plugin on whether to run and what to run.