aboutsummaryrefslogtreecommitdiffstats
path: root/tests/suites
diff options
context:
space:
mode:
authorJan Gelety <jgelety@cisco.com>2016-02-25 17:54:12 +0100
committerGerrit Code Review <gerrit@fd.io>2016-02-27 08:24:23 +0000
commit994580369f92db56c79bab13c75180c9f38b9187 (patch)
tree4cac8eef32a2980b5cb182560604a1eda0b0f584 /tests/suites
parent0a8f41c2178c4b3b6de8ba93ee499d234a8b208c (diff)
Test both traffic directions for bidirectional topology
- l2 bridge domain - l2 cross connects Change-Id: I45b4c1e5aa72e55ff05ed84f4748a0ea41c99a18 Signed-off-by: Jan Gelety <jgelety@cisco.com>
Diffstat (limited to 'tests/suites')
-rw-r--r--tests/suites/bridge_domain/test.robot23
-rw-r--r--tests/suites/l2_xconnect/l2_xconnect_untagged.robot7
2 files changed, 17 insertions, 13 deletions
diff --git a/tests/suites/bridge_domain/test.robot b/tests/suites/bridge_domain/test.robot
index 071e375ff4..a7f1104224 100644
--- a/tests/suites/bridge_domain/test.robot
+++ b/tests/suites/bridge_domain/test.robot
@@ -30,42 +30,45 @@
| | [Tags] | 3_NODE_DOUBLE_LINK_TOPO
| | Append Nodes | ${nodes['TG']} | ${nodes['DUT1']} | ${nodes['TG']}
| | Compute Path | always_same_link=${FALSE}
-| | ${src_if} | ${tmp}= | First Interface
-| | ${dst_if} | ${tmp}= | Last Interface
+| | ${tg_if1} | ${tmp}= | First Interface
+| | ${tg_if2} | ${tmp}= | Last Interface
| | ${bd_if1} | ${tmp}= | First Ingress Interface
| | ${bd_if2} | ${tmp}= | Last Egress Interface
| | Vpp l2bd forwarding setup | ${nodes['DUT1']} | ${bd_if1} | ${bd_if2}
-| | Send and receive traffic | ${nodes['TG']} | ${src_if} | ${dst_if}
+| | Send and receive traffic | ${nodes['TG']} | ${tg_if1} | ${tg_if2}
+| | Send and receive traffic | ${nodes['TG']} | ${tg_if2} | ${tg_if1}
| Vpp forwards packets via L2 bridge domain in circular topology
| | [Tags] | 3_NODE_SINGLE_LINK_TOPO
| | Append Nodes | ${nodes['TG']} | ${nodes['DUT1']} | ${nodes['DUT2']}
| | ... | ${nodes['TG']}
| | Compute Path
-| | ${src_if} | ${tg}= | Next Interface
+| | ${tg_if1} | ${tg}= | Next Interface
| | ${dut1_if1} | ${dut1}= | Next Interface
| | ${dut1_if2} | ${dut1}= | Next Interface
| | ${dut2_if1} | ${dut2}= | Next Interface
| | ${dut2_if2} | ${dut2}= | Next Interface
-| | ${dst_if} | ${tg}= | Next Interface
+| | ${tg_if2} | ${tg}= | Next Interface
| | Vpp l2bd forwarding setup | ${dut1} | ${dut1_if1} | ${dut1_if2}
| | Vpp l2bd forwarding setup | ${dut2} | ${dut2_if1} | ${dut2_if2}
-| | Send and receive traffic | ${tg} | ${src_if} | ${dst_if}
+| | Send and receive traffic | ${tg} | ${tg_if1} | ${tg_if2}
+| | Send and receive traffic | ${tg} | ${tg_if2} | ${tg_if1}
| Vpp forwards packets via L2 bridge domain in circular topology with static L2FIB entries
| | [Tags] | 3_NODE_SINGLE_LINK_TOPO
| | Append Nodes | ${nodes['TG']} | ${nodes['DUT1']} | ${nodes['DUT2']}
| | ... | ${nodes['TG']}
| | Compute Path
-| | ${src_if} | ${tg}= | Next Interface
+| | ${tg_if1} | ${tg}= | Next Interface
| | ${dut1_if1} | ${dut1}= | Next Interface
| | ${dut1_if2} | ${dut1}= | Next Interface
| | ${dut2_if1} | ${dut2}= | Next Interface
| | ${dut2_if2} | ${dut2}= | Next Interface
-| | ${dst_if} | ${tg}= | Next Interface
-| | ${mac}= | Get Interface Mac | ${tg} | ${dst_if}
+| | ${tg_if2} | ${tg}= | Next Interface
+| | ${mac}= | Get Interface Mac | ${tg} | ${tg_if2}
| | Vpp l2bd forwarding setup | ${dut1} | ${dut1_if1} | ${dut1_if2} | ${FALSE}
| | ... | ${mac}
| | Vpp l2bd forwarding setup | ${dut2} | ${dut2_if1} | ${dut2_if2} | ${FALSE}
| | ... | ${mac}
-| | Send and receive traffic | ${tg} | ${src_if} | ${dst_if}
+| | Send and receive traffic | ${tg} | ${tg_if1} | ${tg_if2}
+| | Send and receive traffic | ${tg} | ${tg_if2} | ${tg_if1}
diff --git a/tests/suites/l2_xconnect/l2_xconnect_untagged.robot b/tests/suites/l2_xconnect/l2_xconnect_untagged.robot
index 033a109ef1..0dd3251aca 100644
--- a/tests/suites/l2_xconnect/l2_xconnect_untagged.robot
+++ b/tests/suites/l2_xconnect/l2_xconnect_untagged.robot
@@ -27,13 +27,14 @@
| Vpp forwards packets via L2 xconnect in circular topology
| | Append Nodes | ${nodes['TG']} | ${nodes['DUT1']} | ${nodes['DUT2']} | ${nodes['TG']}
| | Compute Path
-| | ${src_if} | ${tg}= | Next Interface
+| | ${tg_if1} | ${tg}= | Next Interface
| | ${dut1_if1} | ${dut1}= | Next Interface
| | ${dut1_if2} | ${dut1}= | Next Interface
| | ${dut2_if1} | ${dut2}= | Next Interface
| | ${dut2_if2} | ${dut2}= | Next Interface
-| | ${dst_if} | ${tg}= | Next Interface
+| | ${tg_if2} | ${tg}= | Next Interface
| | L2 setup xconnect on DUT | ${dut1} | ${dut1_if1} | ${dut1_if2}
| | L2 setup xconnect on DUT | ${dut2} | ${dut2_if1} | ${dut2_if2}
| | All Vpp Interfaces Ready Wait | ${nodes}
-| | Send and receive traffic | ${tg} | ${src_if} | ${dst_if}
+| | Send and receive traffic | ${tg} | ${tg_if1} | ${tg_if2}
+| | Send and receive traffic | ${tg} | ${tg_if2} | ${tg_if1}
ont-weight: bold } /* Keyword.Constant */ .highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */ .highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */ .highlight .kp { color: #008800 } /* Keyword.Pseudo */ .highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
# Copyright (c) 2018 Cisco and/or its affiliates.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at:
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""General purpose utilities.
"""

import multiprocessing
import subprocess
import numpy as np
import pandas as pd
import logging

from os import walk, makedirs, environ
from os.path import join, isdir
from shutil import move, Error
from math import sqrt

from errors import PresentationError
from jumpavg.BitCountingClassifier import BitCountingClassifier


def mean(items):
    """Calculate mean value from the items.

    :param items: Mean value is calculated from these items.
    :type items: list
    :returns: MEan value.
    :rtype: float
    """

    return float(sum(items)) / len(items)


def stdev(items):
    """Calculate stdev from the items.

    :param items: Stdev is calculated from these items.
    :type items: list
    :returns: Stdev.
    :rtype: float
    """

    avg = mean(items)
    variance = [(x - avg) ** 2 for x in items]
    stddev = sqrt(mean(variance))
    return stddev


def relative_change(nr1, nr2):
    """Compute relative change of two values.

    :param nr1: The first number.
    :param nr2: The second number.
    :type nr1: float
    :type nr2: float
    :returns: Relative change of nr1.
    :rtype: float
    """

    return float(((nr2 - nr1) / nr1) * 100)


def get_files(path, extension=None, full_path=True):
    """Generates the list of files to process.

    :param path: Path to files.
    :param extension: Extension of files to process. If it is the empty string,
        all files will be processed.
    :param full_path: If True, the files with full path are generated.
    :type path: str
    :type extension: str
    :type full_path: bool
    :returns: List of files to process.
    :rtype: list
    """

    file_list = list()
    for root, _, files in walk(path):
        for filename in files:
            if extension:
                if filename.endswith(extension):
                    if full_path:
                        file_list.append(join(root, filename))
                    else:
                        file_list.append(filename)
            else:
                file_list.append(join(root, filename))

    return file_list


def get_rst_title_char(level):
    """Return character used for the given title level in rst files.

    :param level: Level of the title.
    :type: int
    :returns: Character used for the given title level in rst files.
    :rtype: str
    """
    chars = ('=', '-', '`', "'", '.', '~', '*', '+', '^')
    if level < len(chars):
        return chars[level]
    else:
        return chars[-1]


def execute_command(cmd):
    """Execute the command in a subprocess and log the stdout and stderr.

    :param cmd: Command to execute.
    :type cmd: str
    :returns: Return code of the executed command.
    :rtype: int
    """

    env = environ.copy()
    proc = subprocess.Popen(
        [cmd],
        stdout=subprocess.PIPE,
        stderr=subprocess.PIPE,
        shell=True,
        env=env)

    stdout, stderr = proc.communicate()

    if stdout:
        logging.info(stdout)
    if stderr:
        logging.info(stderr)

    if proc.returncode != 0:
        logging.error("    Command execution failed.")
    return proc.returncode, stdout, stderr


def get_last_successful_build_number(jenkins_url, job_name):
    """Get the number of the last successful build of the given job.

    :param jenkins_url: Jenkins URL.
    :param job_name: Job name.
    :type jenkins_url: str
    :type job_name: str
    :returns: The build number as a string.
    :rtype: str
    """

    url = "{}/{}/lastSuccessfulBuild/buildNumber".format(jenkins_url, job_name)
    cmd = "wget -qO- {url}".format(url=url)

    return execute_command(cmd)


def get_last_completed_build_number(jenkins_url, job_name):
    """Get the number of the last completed build of the given job.

    :param jenkins_url: Jenkins URL.
    :param job_name: Job name.
    :type jenkins_url: str
    :type job_name: str
    :returns: The build number as a string.
    :rtype: str
    """

    url = "{}/{}/lastCompletedBuild/buildNumber".format(jenkins_url, job_name)
    cmd = "wget -qO- {url}".format(url=url)

    return execute_command(cmd)


def archive_input_data(spec):
    """Archive the report.

    :param spec: Specification read from the specification file.
    :type spec: Specification
    :raises PresentationError: If it is not possible to archive the input data.
    """

    logging.info("    Archiving the input data files ...")

    extension = spec.input["file-format"]
    data_files = get_files(spec.environment["paths"]["DIR[WORKING,DATA]"],
                           extension=extension)
    dst = spec.environment["paths"]["DIR[STATIC,ARCH]"]
    logging.info("      Destination: {0}".format(dst))

    try:
        if not isdir(dst):
            makedirs(dst)

        for data_file in data_files:
            logging.info("      Moving the file: {0} ...".format(data_file))
            move(data_file, dst)

    except (Error, OSError) as err:
        raise PresentationError("Not possible to archive the input data.",
                                str(err))

    logging.info("    Done.")


def classify_anomalies(data):
    """Process the data and return anomalies and trending values.

    Gather data into groups with average as trend value.
    Decorate values within groups to be normal,
    the first value of changed average as a regression, or a progression.

    :param data: Full data set with unavailable samples replaced by nan.
    :type data: pandas.Series
    :returns: Classification and trend values
    :rtype: 2-tuple, list of strings and list of floats
    """
    # Nan mean something went wrong.
    # Use 0.0 to cause that being reported as a severe regression.
    bare_data = [0.0 if np.isnan(sample) else sample
                 for _, sample in data.iteritems()]
    # TODO: Put analogous iterator into jumpavg library.
    groups = BitCountingClassifier.classify(bare_data)
    groups.reverse()  # Just to use .pop() for FIFO.
    classification = []
    avgs = []
    active_group = None
    values_left = 0
    avg = 0.0
    for _, sample in data.iteritems():
        if np.isnan(sample):
            classification.append("outlier")
            avgs.append(sample)
            continue
        if values_left < 1 or active_group is None:
            values_left = 0
            while values_left < 1:  # To ignore empty groups.
                active_group = groups.pop()
                values_left = len(active_group.values)
            avg = active_group.metadata.avg
            classification.append(active_group.metadata.classification)
            avgs.append(avg)
            values_left -= 1
            continue
        classification.append("normal")
        avgs.append(avg)
        values_left -= 1
    return classification, avgs


class Worker(multiprocessing.Process):
    """Worker class used to process tasks in separate parallel processes.
    """

    def __init__(self, work_queue, data_queue, func):
        """Initialization.

        :param work_queue: Queue with items to process.
        :param data_queue: Shared memory between processes. Queue which keeps
            the result data. This data is then read by the main process and used
            in further processing.
        :param func: Function which is executed by the worker.
        :type work_queue: multiprocessing.JoinableQueue
        :type data_queue: multiprocessing.Manager().Queue()
        :type func: Callable object
        """
        super(Worker, self).__init__()
        self._work_queue = work_queue
        self._data_queue = data_queue
        self._func = func

    def run(self):
        """Method representing the process's activity.
        """

        while True:
            try:
                self.process(self._work_queue.get())
            finally:
                self._work_queue.task_done()

    def process(self, item_to_process):
        """Method executed by the runner.

        :param item_to_process: Data to be processed by the function.
        :type item_to_process: tuple
        """
        self._func(self.pid, self._data_queue, *item_to_process)