mirror of
https://github.com/valitydev/yandex-tank.git
synced 2024-11-06 10:25:17 +00:00
start moving to global status
This commit is contained in:
parent
ab3748a1f1
commit
21502dff28
@ -4,6 +4,7 @@ import instance_plan as ip
|
||||
import missile
|
||||
import util
|
||||
from mark import get_marker
|
||||
from info import STATUS
|
||||
|
||||
|
||||
class ComponentFactory():
|
||||
@ -44,8 +45,10 @@ class ComponentFactory():
|
||||
raise StepperConfigurationError(
|
||||
'Both rps and instances schedules specified. You must specify only one of them')
|
||||
elif self.rps_schedule:
|
||||
STATUS.publish('loadscheme', self.rps_schedule)
|
||||
return lp.create(self.rps_schedule)
|
||||
elif self.instances_schedule:
|
||||
STATUS.publish('loadscheme', self.instances_schedule)
|
||||
return ip.create(self.instances_schedule)
|
||||
else:
|
||||
raise StepperConfigurationError('Schedule is not specified')
|
||||
|
@ -1,4 +1,6 @@
|
||||
from progressbar import ProgressBar, ETA, ReverseBar, Bar
|
||||
from collections import namedtuple
|
||||
import logging
|
||||
|
||||
|
||||
class DefaultProgressBar(ProgressBar):
|
||||
@ -42,7 +44,36 @@ def progress(gen, caption='', pb_class=DefaultProgressBar):
|
||||
pbar.finish()
|
||||
|
||||
|
||||
StepperInfo = namedtuple(
|
||||
'StepperInfo',
|
||||
'loop_count,steps,loadscheme,duration,ammo_count'
|
||||
)
|
||||
|
||||
|
||||
class StepperStatus(object):
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
self.log = logging.getLogger(__name__)
|
||||
self.info = {
|
||||
'loop_count': None,
|
||||
'steps': None,
|
||||
'loadscheme': None,
|
||||
'duration': None,
|
||||
'ammo_count': None,
|
||||
}
|
||||
|
||||
def publish(self, key, value):
|
||||
if key not in self.info:
|
||||
raise RuntimeError(
|
||||
"Tryed to publish to a non-existent key: %s" % key)
|
||||
self.log.info('Published %s to %s', (value, key))
|
||||
self.info[key] = value
|
||||
|
||||
def get_stepper_info(self):
|
||||
for key in self.info:
|
||||
if self.info[key] is None:
|
||||
raise RuntimeError(
|
||||
"Information for %s is not published yet." % key)
|
||||
return StepperInfo(**self.info)
|
||||
|
||||
STATUS = StepperStatus()
|
||||
|
@ -5,6 +5,7 @@ import math
|
||||
import re
|
||||
from util import parse_duration
|
||||
from itertools import chain, groupby
|
||||
from info import STATUS
|
||||
|
||||
|
||||
class Const(object):
|
||||
@ -187,7 +188,7 @@ class StepFactory(object):
|
||||
|
||||
def create(rps_schedule):
|
||||
'''
|
||||
Create Load Plan as defined in schedule
|
||||
Create Load Plan as defined in schedule. Publish info about its duration.
|
||||
|
||||
>>> from util import take
|
||||
|
||||
@ -204,6 +205,9 @@ def create(rps_schedule):
|
||||
[0, 1000, 2000, 2500, 3000, 3500]
|
||||
'''
|
||||
if len(rps_schedule) > 1:
|
||||
return Composite([StepFactory.produce(step_config) for step_config in rps_schedule])
|
||||
lp = Composite([StepFactory.produce(step_config)
|
||||
for step_config in rps_schedule])
|
||||
else:
|
||||
return StepFactory.produce(rps_schedule[0])
|
||||
lp = StepFactory.produce(rps_schedule[0])
|
||||
STATUS.publish('duration', lp.get_duration())
|
||||
return lp
|
||||
|
@ -5,7 +5,6 @@ from itertools import izip
|
||||
import format as fmt
|
||||
from info import progress
|
||||
from config import ComponentFactory
|
||||
from collections import namedtuple
|
||||
|
||||
|
||||
class AmmoFactory(object):
|
||||
@ -71,26 +70,19 @@ class AmmoFactory(object):
|
||||
return self.load_plan.get_duration() / 1000
|
||||
|
||||
|
||||
StepperInfo = namedtuple(
|
||||
'StepperInfo',
|
||||
'loop_count,steps,loadscheme,duration,ammo_count'
|
||||
)
|
||||
|
||||
|
||||
class Stepper(object):
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
self.af = AmmoFactory(ComponentFactory(**kwargs))
|
||||
self.rps_schedule = kwargs['rps_schedule']
|
||||
self.ammo = fmt.Stpd(progress(self.af, 'Ammo: '))
|
||||
|
||||
def write(self, f):
|
||||
for missile in self.ammo:
|
||||
f.write(missile)
|
||||
self.info = StepperInfo(
|
||||
loop_count=self.af.get_loop_count(),
|
||||
steps=self.af.get_steps(),
|
||||
loadscheme=self.rps_schedule,
|
||||
duration=self.af.get_duration(),
|
||||
ammo_count=len(self.af),
|
||||
)
|
||||
# self.info = StepperInfo(
|
||||
# loop_count=self.af.get_loop_count(),
|
||||
# steps=self.af.get_steps(),
|
||||
# loadscheme=self.rps_schedule,
|
||||
# duration=self.af.get_duration(),
|
||||
# ammo_count=len(self.af),
|
||||
# )
|
||||
|
Loading…
Reference in New Issue
Block a user