From 69c2a6782e075145918aa1a734032a7c3558ed1b Mon Sep 17 00:00:00 2001 From: "Alexey Lavrenuke (load testing)" Date: Wed, 14 Aug 2013 15:38:02 +0400 Subject: [PATCH] start BFG integration with stepper --- Tank/Plugins/BFG.py | 71 +++++++++++++++++++++++++++++++++++------- Tank/stepper/config.py | 1 + 2 files changed, 60 insertions(+), 12 deletions(-) diff --git a/Tank/Plugins/BFG.py b/Tank/Plugins/BFG.py index d707aed..327bf56 100644 --- a/Tank/Plugins/BFG.py +++ b/Tank/Plugins/BFG.py @@ -2,7 +2,9 @@ from Tank.Plugins.Aggregator import AggregatorPlugin from Tank.Plugins.ConsoleOnline import ConsoleOnlinePlugin from tankcore import AbstractPlugin +import logging import time +from Tank.stepper import Stepper class BFGPlugin(AbstractPlugin): @@ -11,23 +13,38 @@ class BFGPlugin(AbstractPlugin): SECTION = 'bfg' def __init__(self, core): + self.log = logging.getLogger(__name__) AbstractPlugin.__init__(self, core) self.gun_type = None self.start_time = time.time() + self.log.info("Initialized BFG") @staticmethod def get_key(): return __file__ def get_available_options(self): - return ["gun_type", "load", "ammo_limit", "loop_limit", "instances"] + return ["gun_type", "rps_schedule", "ammo_limit", "loop_limit", "instances", "ammo_file"] def configure(self): - self.gun_type = self.get_option("gun_type") - self.load = self.get_option("load") - self.ammo_limit = self.get_option("ammo_limit") - self.loop_limit = self.get_option("loop_limit") - self.instances = self.get_option("instances") + # TODO: move this elsewhere + def make_steps(schedule): + steps = [] + for step in " ".join(schedule.split("\n")).split(')'): + if step.strip(): + steps.append(step.strip() + ')') + return steps + self.conf = { + 'gun_type': self.get_option("gun_type"), + 'rps_schedule': make_steps(self.get_option("rps_schedule")), + 'ammo_limit': self.get_option("ammo_limit", '-1'), + 'loop_limit': self.get_option("loop_limit", '-1'), + 'instances': self.get_option("instances", '15'), + 'ammo_file': self.get_option("ammo_file", 'ammo'), + } + self.bfg = BFG(**self.conf) + self.log.info("Configured BFG") + def prepare_test(self): aggregator = None @@ -54,24 +71,54 @@ class BFGPlugin(AbstractPlugin): # if aggregator: # aggregator.add_result_listener(widget) pass + self.log.info("Prepared BFG") def start_test(self): self.log.info("Starting BFG") # TODO: start BFG here self.start_time = time.time() - # self.bfg = ... + self.bfg.start() def is_test_finished(self): - retcode = -1 # check if test is finished - if retcode != None: + if self.bfg.running: + return -1 + else: + retcode = self.bfg.retcode self.log.info( "BFG finished with exit code: %s", retcode) return retcode - else: - return -1 def end_test(self, retcode): - if self.bfg.running(): + if self.bfg.running: self.log.info("Terminating BFG") self.bfg.stop() return retcode + +class BFG(object): + def __init__( + self, + gun_type, + rps_schedule, + ammo_limit, + loop_limit, + instances, + ammo_file, + ): + self.gun_type = gun_type + self.instances = int(instances) + self.stepper = Stepper( + rps_schedule=rps_schedule, + ammo_file=ammo_file, + loop_limit=loop_limit, + ammo_limit=ammo_limit, + ammo_type = gun_type, + ) + self.running = False + self.retcode = None + + def start(self): + self.running = True + + def stop(self): + self.running = False + self.retcode = 0 diff --git a/Tank/stepper/config.py b/Tank/stepper/config.py index 2ff4266..d005e87 100644 --- a/Tank/stepper/config.py +++ b/Tank/stepper/config.py @@ -19,6 +19,7 @@ class ComponentFactory(): uris=None, headers=None, autocases=None, + ammo_type='phantom' ): self.rps_schedule = rps_schedule self.http_ver = http_ver