Пример #1
0
 def test_expand_to_seconds_fail(self):
     try:
         tankcore.expand_to_seconds("100n")
         raise RuntimeError("Exception expected")
     except ValueError, ex:
         # it's ok, we have excpected exception
         print ex
Пример #2
0
 def test_expand_to_seconds_fail(self):
     try:
         tankcore.expand_to_seconds("100n")
         raise RuntimeError("Exception expected")
     except ValueError, ex:
         # it's ok, we have excpected exception
         print ex
Пример #3
0
    def __init__(self, autostop, param_str):
        AbstractCriteria.__init__(self)
        self.seconds_count = 0
        self.autostop = autostop
        self.threads_limit = 1

        level_str = param_str.split(',')[0].strip()
        if level_str[-1:] == '%':
            self.level = float(level_str[:-1]) / 100
            self.is_relative = True
        else:
            self.level = int(level_str)
            self.is_relative = False
        self.seconds_limit = tankcore.expand_to_seconds(
            param_str.split(',')[1])

        try:
            phantom = autostop.core.get_plugin_of_type(PhantomPlugin)
            info = phantom.get_info()
            if info:
                self.threads_limit = info.instances
            if not self.threads_limit:
                raise ValueError(
                    "Cannot create 'instances' criteria with zero instances limit")
        except KeyError:
            self.log.warning(
                "No phantom module, 'instances' autostop disabled")
Пример #4
0
    def configure(self):
        self.config = self.get_option("config", 'auto').strip()
        self.default_target = self.get_option("default_target", 'localhost')
        self.monitoring.ssh_timeout = tankcore.expand_to_seconds(
            self.get_option('ssh_timeout', "5s"))

        if self.config == 'none' or self.config == 'auto':
            self.die_on_fail = False
        else:
            if self.config[0] == '<':
                xmlfile = self.core.mkstemp(".xml", "monitoring_")
                self.core.add_artifact_file(xmlfile)
                xml = open(xmlfile, 'w')
                xml.write(self.config)
                xml.close()
                self.config = xmlfile

            if not os.path.exists(self.config):
                raise OSError("Monitoring config file not found: %s" %
                              self.config)

        if self.config == 'none':
            self.monitoring = None

        if self.config == 'auto':
            self.config = os.path.dirname(
                __file__) + '/monitoring_default_config.xml'

        try:
            autostop = self.core.get_plugin_of_type(AutostopPlugin)
            autostop.add_criteria_class(MetricHigherCriteria)
            autostop.add_criteria_class(MetricLowerCriteria)
        except KeyError:
            self.log.debug(
                "No autostop plugin found, not adding instances criteria")
Пример #5
0
    def __init__(self, autostop, param_str):
        AbstractCriteria.__init__(self)
        self.seconds_count = 0
        self.autostop = autostop

        level_str = param_str.split(',')[0].strip()
        if level_str[-1:] == '%':
            self.level = float(level_str[:-1]) / 100
            self.is_relative = True
        else:
            self.level = int(level_str)
            self.is_relative = False
        self.seconds_limit = tankcore.expand_to_seconds(
            param_str.split(',')[1])

        try:
            phantom = autostop.core.get_plugin_of_type(PhantomPlugin)
            self.threads_limit = phantom.phantom.instances
            if not self.threads_limit:
                raise ValueError(
                    "Cannot create 'instances' criteria with zero instances limit"
                )
        except KeyError:
            self.log.warning(
                "No phantom module, 'instances' autostop disabled")
Пример #6
0
    def configure(self):
        self.config = self.get_option("config", "auto").strip()
        self.default_target = self.get_option("default_target", "localhost")
        self.monitoring.ssh_timeout = tankcore.expand_to_seconds(self.get_option("ssh_timeout", "5s"))

        if self.config == "none" or self.config == "auto":
            self.die_on_fail = False
        else:
            if self.config[0] == "<":
                xmlfile = self.core.mkstemp(".xml", "monitoring_")
                self.core.add_artifact_file(xmlfile)
                xml = open(xmlfile, "w")
                xml.write(self.config)
                xml.close()
                self.config = xmlfile

            if not os.path.exists(self.config):
                raise OSError("Monitoring config file not found: %s" % self.config)

        if self.config == "none":
            self.monitoring = None

        if self.config == "auto":
            self.config = os.path.dirname(__file__) + "/monitoring_default_config.xml"

        try:
            autostop = self.core.get_plugin_of_type(AutostopPlugin)
            autostop.add_criteria_class(MetricHigherCriteria)
            autostop.add_criteria_class(MetricLowerCriteria)
        except KeyError:
            self.log.debug("No autostop plugin found, not adding instances criteria")
Пример #7
0
 def __init__(self, autostop, param_str):
     AbstractCriteria.__init__(self)
     self.seconds_count = 0
     self.quantile = float(param_str.split(',')[0])
     self.rt_limit = tankcore.expand_to_milliseconds(param_str.split(',')[1])
     self.seconds_limit = tankcore.expand_to_seconds(param_str.split(',')[2])
     self.autostop = autostop
Пример #8
0
def load_step(start, end, step, duration,):
    '''
    Stepping load pattern
    '''
    dur = tankcore.expand_to_seconds(duration)
    (steps, loads, total) = ([], '', 0)
    if end > start:
        for rps_level in range(start, end + 1, step):
            steps.append([rps_level, dur])
            loads += '%s,step,%s,%s,(%s,%s,%s,%s)\n' % (
                dur,
                rps_level,
                rps_level,
                start,
                end,
                step,
                duration,
                )
            total += rps_level * dur
    else:
        for rps_level in range(start, end - 1, -step):
            steps.append([rps_level, dur])
            loads += '%s,step,%s,%s,(%s,%s,%s,%s)\n' % (
                dur,
                rps_level,
                rps_level,
                start,
                end,
                step,
                duration,
                )
            total += rps_level * dur
    return [steps, loads, total]
Пример #9
0
def load_line(start, end, duration):
    '''
    Linear load pattern
    '''
    dur = tankcore.expand_to_seconds(duration)
    diff_k = float((end - start) / float(dur - 1))
    (cnt, last_x, total) = (1, start, 0)
    loads = '%s,line,%s,%s,(%s,%s,%s)\n' % (
        dur,
        start,
        end,
        start,
        end,
        duration,
        )
    steps = []
    for sec_i in range(1, dur + 1):
        cur_x = int(start + diff_k * sec_i)
        if cur_x == last_x:
            cnt += 1
        else:
            steps.append([last_x, cnt])
            total += cnt * last_x
            (cnt, last_x) = (1, cur_x)
    return [steps, loads, total]
Пример #10
0
 def __init__(self, autostop, param_str):
     AbstractCriteria.__init__(self)
     self.seconds_count = 0
     self.quantile = float(param_str.split(',')[0])
     self.rt_limit = tankcore.expand_to_milliseconds(param_str.split(',')[1])
     self.seconds_limit = tankcore.expand_to_seconds(param_str.split(',')[2])
     self.autostop = autostop
Пример #11
0
def load_step(start, end, step, duration,):
    '''
    Stepping load pattern
    '''
    dur = tankcore.expand_to_seconds(duration)
    (steps, loads, total) = ([], '', 0)
    if end > start:
        for rps_level in range(start, end + 1, step):
            steps.append([rps_level, dur])
            loads += '%s,step,%s,%s,(%s,%s,%s,%s)\n' % (
                dur,
                rps_level,
                rps_level,
                start,
                end,
                step,
                duration,
                )
            total += rps_level * dur
    else:
        for rps_level in range(start, end - 1, -step):
            steps.append([rps_level, dur])
            loads += '%s,step,%s,%s,(%s,%s,%s,%s)\n' % (
                dur,
                rps_level,
                rps_level,
                start,
                end,
                step,
                duration,
                )
            total += rps_level * dur
    return [steps, loads, total]
Пример #12
0
def load_line(start, end, duration):
    '''
    Linear load pattern
    '''
    dur = tankcore.expand_to_seconds(duration)
    diff_k = float((end - start) / float(dur - 1))
    (cnt, last_x, total) = (1, start, 0)
    loads = '%s,line,%s,%s,(%s,%s,%s)\n' % (
        dur,
        start,
        end,
        start,
        end,
        duration,
        )
    steps = []
    for sec_i in range(1, dur + 1):
        cur_x = int(start + diff_k * sec_i)
        if cur_x == last_x:
            cnt += 1
        else:
            steps.append([last_x, cnt])
            total += cnt * last_x
            (cnt, last_x) = (1, cur_x)
    return [steps, loads, total]
Пример #13
0
 def configure(self):
     self.port = int(self.get_option("port", self.port))
     self.interval = int(
         tankcore.expand_to_seconds(self.get_option("interval", '1m')))
     self.redirect = self.get_option("redirect", self.redirect)
     self.manual_stop = int(self.get_option('manual_stop',
                                            self.manual_stop))
Пример #14
0
 def __init__(self, autostop, param_str):
     AbstractCriteria.__init__(self)
     param = param_str.split(',')
     self.seconds_count = 0
     self.rt_limit = tankcore.expand_to_milliseconds(param[0])
     self.frac = param[1][:-1]
     self.seconds_limit = tankcore.expand_to_seconds(param[2])
     self.autostop = autostop
     self.data = deque()
Пример #15
0
 def __init__(self, autostop, param_str):
     AbstractCriteria.__init__(self)
     param = param_str.split(',')
     self.seconds_count = 0
     self.rt_limit = tankcore.expand_to_milliseconds(param[0])
     self.frac = param[1][:-1]
     self.seconds_limit = tankcore.expand_to_seconds(param[2])
     self.autostop = autostop
     self.data = deque()
     self.second_window = deque()
     self.real_frac = float()
Пример #16
0
def load_const(req, duration):
    """
    Constant load pattern
    """
    dur = tankcore.expand_to_seconds(duration)
    steps = []
    steps.append([req, dur])
    loads = "%s,const,%s,%s,(%s,%s)\n" % (dur, req, req, req, duration)
    time = dur * int(req)
    if int(req) == 0:
        time = dur
    return [steps, loads, time]
Пример #17
0
def load_const(req, duration):
    '''
    Constant load pattern
    '''
    dur = tankcore.expand_to_seconds(duration)
    steps = []
    steps.append([req, dur])
    loads = '%s,const,%s,%s,(%s,%s)\n' % (dur, req, req, req, duration)
    time = dur * int(req)
    if int(req) == 0:
        time = dur
    return [steps, loads, time]
Пример #18
0
    def __init__(self, autostop, param_str):
        AbstractCriteria.__init__(self)
        self.seconds_count = 0
        self.codes_mask = param_str.split(',')[0].lower()
        self.codes_regex = re.compile(self.codes_mask.replace("x", '.'))
        self.autostop = autostop
        self.tangents = deque()
        self.second_window = deque()
        self.total_tan = float()

        self.tangents.append(0)
        self.last = 0
        self.seconds_limit = tankcore.expand_to_seconds(param_str.split(',')[1])
        self.measurement_error = float()
Пример #19
0
    def __init__(self, autostop, param_str):
        AbstractCriteria.__init__(self)
        self.seconds_count = 0
        self.codes_mask = param_str.split(',')[0].lower()
        self.codes_regex = re.compile(self.codes_mask.replace("x", '.'))
        self.autostop = autostop
        self.tangents = deque()
        self.second_window = deque()
        self.total_tan = float()

        self.tangents.append(0)
        self.last = 0
        self.seconds_limit = tankcore.expand_to_seconds(param_str.split(',')[1])
        self.measurement_error = float()
Пример #20
0
    def __init__(self, autostop, param_str):
        AbstractCriteria.__init__(self)
        self.autostop = autostop
        self.data = deque()
        self.second_window = deque()

        params = param_str.split(',')
        # qunatile in ms
        self.timing = tankcore.expand_to_milliseconds(params[0])
        # width of time in seconds
        self.width = tankcore.expand_to_seconds(params[1])
        # max height of deviations in percents
        self.height = float(params[2].split('%')[0])
        # last deviation in percents
        self.deviation = float()
Пример #21
0
    def __init__(self, autostop, param_str):
        AbstractCriteria.__init__(self)
        self.seconds_count = 0
        self.codes_mask = param_str.split(',')[0].lower()
        self.codes_regex = re.compile(self.codes_mask.replace("x", '.'))
        self.autostop = autostop

        level_str = param_str.split(',')[1].strip()
        if level_str[-1:] == '%':
            self.level = float(level_str[:-1]) / 100
            self.is_relative = True
        else:
            self.level = int(level_str)
            self.is_relative = False
        self.seconds_limit = tankcore.expand_to_seconds(param_str.split(',')[2])
Пример #22
0
    def __init__(self, autostop, param_str):
        AbstractCriteria.__init__(self)
        self.seconds_count = 0
        self.codes_mask = param_str.split(',')[0].lower()
        self.codes_regex = re.compile(self.codes_mask.replace("x", '.'))
        self.autostop = autostop

        level_str = param_str.split(',')[1].strip()
        if level_str[-1:] == '%':
            self.level = float(level_str[:-1]) / 100
            self.is_relative = True
        else:
            self.level = int(level_str)
            self.is_relative = False
        self.seconds_limit = tankcore.expand_to_seconds(param_str.split(',')[2])
Пример #23
0
    def __init__(self, autostop, param_str):
        AbstractCriteria.__init__(self)
        self.autostop = autostop
        self.data = deque()
        self.second_window = deque()

        params = param_str.split(',')
        # qunatile in ms
        self.quantile = tankcore.expand_to_milliseconds(params[0])
        # width of time in seconds
        self.width = tankcore.expand_to_seconds(params[1])
        # max height of deviations in percents
        self.height = float(params[2][0:-1])
        # last deviation in percents
        self.deviation = float()
Пример #24
0
    def __init__(self, autostop, param_str):
        AbstractCriteria.__init__(self)
        MonitoringDataDecoder.__init__(self)

        try:
            self.mon = autostop.core.get_plugin_of_type(MonitoringPlugin)
            self.mon.monitoring.add_listener(self)
        except KeyError:
            self.log.warning("No monitoring module, mon autostop disabled")
        self.triggered = False
        self.autostop = autostop

        self.host = param_str.split(",")[0].strip()
        self.metric = param_str.split(",")[1].strip()
        self.value_limit = float(param_str.split(",")[2])
        self.seconds_limit = tankcore.expand_to_seconds(param_str.split(",")[3])
        self.last_second = None
        self.seconds_count = 0
Пример #25
0
    def __init__(self, autostop, param_str):
        AbstractCriteria.__init__(self)
        MonitoringDataDecoder.__init__(self)

        try:
            self.mon = autostop.core.get_plugin_of_type(MonitoringPlugin)
            self.mon.monitoring.add_listener(self)
        except KeyError:
            self.log.warning("No monitoring module, mon autostop disabled")
        self.triggered = False
        self.autostop = autostop

        self.host = param_str.split(',')[0].strip()
        self.metric = param_str.split(',')[1].strip()
        self.value_limit = float(param_str.split(',')[2])
        self.seconds_limit = tankcore.expand_to_seconds(
            param_str.split(',')[3])
        self.last_second = None
        self.seconds_count = 0
Пример #26
0
def constf(req, duration):
    """
    Float const load pattern
    """
    pattern = re.match("(\d+)\/(\d+)", req)
    if pattern:
        (a, b) = (int(pattern.group(1)), int(pattern.group(2)))
        (dur, e) = (tankcore.expand_to_seconds(duration), int(a / b))

        fract = "%.3f" % (float(a) / b)
        loads = "%s,const,%s,%s,(%s,%s)\n" % (dur, fract, fract, req, duration)
        a = a % b
        req = "%s/%s" % (a, b)
        out = []
        tail = dur % b
        for x in range(1, int(dur / b) + 1):
            out += frps(req)
        if tail:
            out += frps_cut(tail, req)
        if e > 0:
            out = frps_expand(out, e)
        return (out, loads, frps_ammo(out))
    else:
        raise RuntimeError("Error in 'const_f' function. rps: %s, duration: %s" % (req, duration))
Пример #27
0
def constf(req, duration):
    '''
    Float const load pattern
    '''
    pattern = re.match("(\d+)\/(\d+)", req)
    if pattern:
        (a, b) = (int(pattern.group(1)), int(pattern.group(2)))
        (dur, e) = (tankcore.expand_to_seconds(duration), int(a / b))

        fract = '%.3f' % (float(a) / b)
        loads = '%s,const,%s,%s,(%s,%s)\n' % (dur, fract, fract, req, duration)
        a = a % b
        req = '%s/%s' % (a, b)
        out = []
        tail = dur % b
        for x in range(1, int(dur / b) + 1):
            out += frps(req)
        if tail:
            out += frps_cut(tail, req)
        if e > 0:
            out = frps_expand(out, e)
        return (out, loads, frps_ammo(out))
    else:
        raise RuntimeError("Error in 'const_f' function. rps: %s, duration: %s" % (req, duration))
Пример #28
0
 def configure(self):
     self.port = int(self.get_option("port", self.port))
     self.interval = int(tankcore.expand_to_seconds(self.get_option("interval", '1m')))
     self.redirect = self.get_option("redirect", self.redirect)
     self.manual_stop = int(self.get_option('manual_stop', self.manual_stop))
Пример #29
0
 def __init__(self, autostop, param_str):
     AbstractCriteria.__init__(self)
     self.start_time = time.time()
     self.end_time = time.time()
     self.time_limit = tankcore.expand_to_seconds(param_str)
Пример #30
0
 def __init__(self, autostop, param_str):
     AbstractCriteria.__init__(self)
     self.seconds_count = 0
     self.hash = ""
     self.seconds_limit = tankcore.expand_to_seconds(param_str.split(',')[0])
     self.autostop = autostop
Пример #31
0
 def test_expand_to_seconds(self):
     for i in self.stest:
         self.assertEqual(tankcore.expand_to_seconds(i[0]), i[1])
Пример #32
0
 def configure(self):
     self.interval = tankcore.expand_to_seconds(self.get_option("interval", self.interval))
     self.disk_limit = int(self.get_option("disk_limit", self.disk_limit))
     self.mem_limit = int(self.get_option("mem_limit", self.mem_limit))
Пример #33
0
 def __init__(self, autostop, param_str):
     AbstractCriteria.__init__(self)
     self.seconds_count = 0
     self.hash = ""
     self.seconds_limit = tankcore.expand_to_seconds(param_str.split(',')[0])
     self.autostop = autostop
Пример #34
0
 def configure(self):
     self.interval = tankcore.expand_to_seconds(
         self.get_option("interval", self.interval))
     self.disk_limit = int(self.get_option("disk_limit", self.disk_limit))
     self.mem_limit = int(self.get_option("mem_limit", self.mem_limit))
Пример #35
0
 def test_expand_to_seconds(self):
     for i in self.stest:
         self.assertEqual(tankcore.expand_to_seconds(i[0]), i[1])