yandex-tank/Tank/stepper/config.py

94 lines
3.1 KiB
Python
Raw Normal View History

2013-07-15 11:51:50 +00:00
from module_exceptions import StepperConfigurationError
2013-05-27 13:06:28 +00:00
import load_plan as lp
2013-06-28 13:45:26 +00:00
import instance_plan as ip
2013-05-27 13:06:28 +00:00
import missile
2013-07-15 13:38:50 +00:00
from mark import get_marker
2013-07-16 13:21:55 +00:00
import info
2013-05-27 13:06:28 +00:00
class ComponentFactory():
def __init__(
self,
rps_schedule=None,
http_ver='1.1',
ammo_file=None,
instances_schedule=None,
loop_limit=0,
ammo_limit=0,
uris=None,
headers=None,
autocases=None,
2013-08-14 11:38:02 +00:00
ammo_type='phantom'
2013-05-27 13:06:28 +00:00
):
2013-08-14 11:56:24 +00:00
generators = {
'phantom': missile.AmmoFileReader,
2013-08-14 13:38:43 +00:00
'slowlog': missile.SlowLogReader,
'line': missile.LineReader,
2013-08-14 11:56:24 +00:00
}
if ammo_type in generators:
self.ammo_generator_class = generators[ammo_type]
else:
raise NotImplementedError(
'No such ammo type implemented: "%s"' % ammo_type)
2013-05-27 13:06:28 +00:00
self.rps_schedule = rps_schedule
self.http_ver = http_ver
self.ammo_file = ammo_file
self.instances_schedule = instances_schedule
2013-07-16 12:18:46 +00:00
loop_limit = int(loop_limit)
if loop_limit == -1: # -1 means infinite
2013-07-30 14:40:47 +00:00
loop_limit = None
2013-07-16 12:18:46 +00:00
ammo_limit = int(ammo_limit)
if ammo_limit == -1: # -1 means infinite
2013-07-30 14:40:47 +00:00
ammo_limit = None
if loop_limit is None and ammo_limit is None and instances_schedule:
loop_limit = 1 # we should have only one loop if we have instance_schedule
2013-07-16 13:21:55 +00:00
info.status.loop_limit = loop_limit
info.status.ammo_limit = ammo_limit
2013-05-27 13:06:28 +00:00
self.uris = uris
self.headers = headers
2013-07-15 13:38:50 +00:00
self.marker = get_marker(autocases)
2013-05-27 13:06:28 +00:00
def get_load_plan(self):
"""
return load plan (timestamps generator)
"""
if self.rps_schedule and self.instances_schedule:
2013-06-25 11:22:51 +00:00
raise StepperConfigurationError(
'Both rps and instances schedules specified. You must specify only one of them')
2013-05-27 13:06:28 +00:00
elif self.rps_schedule:
2013-07-16 13:21:55 +00:00
info.status.publish('loadscheme', self.rps_schedule)
2013-05-27 13:06:28 +00:00
return lp.create(self.rps_schedule)
elif self.instances_schedule:
2013-07-16 13:21:55 +00:00
info.status.publish('loadscheme', self.instances_schedule)
2013-06-28 13:45:26 +00:00
return ip.create(self.instances_schedule)
2013-05-27 13:06:28 +00:00
else:
2013-08-01 12:37:11 +00:00
#raise StepperConfigurationError('Schedule is not specified')
self.instances_schedule = []
info.status.publish('loadscheme', self.instances_schedule)
return ip.create(self.instances_schedule)
2013-05-27 13:06:28 +00:00
def get_ammo_generator(self):
"""
return ammo generator
"""
if self.uris and self.ammo_file:
2013-06-25 11:22:51 +00:00
raise StepperConfigurationError(
'Both uris and ammo file specified. You must specify only one of them')
2013-07-15 13:38:50 +00:00
elif self.uris:
ammo_gen = missile.UriStyleGenerator(
self.uris,
self.headers,
http_ver=self.http_ver
)
elif self.ammo_file:
2013-08-14 11:56:24 +00:00
ammo_gen = self.ammo_generator_class(self.ammo_file)
2013-05-27 13:06:28 +00:00
else:
2013-07-15 13:38:50 +00:00
raise StepperConfigurationError(
'Ammo not found. Specify uris or ammo file')
2013-07-16 12:18:46 +00:00
return ammo_gen
2013-05-27 13:06:28 +00:00
def get_marker(self):
2013-07-15 13:38:50 +00:00
return self.marker