aboutsummaryrefslogtreecommitdiffstats
path: root/tests/opnfv/test_suites/opnfv_os-odl_l2-nofeature-noha_daily.yaml
blob: cd352cc1bd3e28f9f437ef19b8b7d07cb645c180 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
##############################################################################
# Copyright (c) 2017 Huawei Technologies Co.,Ltd and others.
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
---
# os-odl_l2-nofeature-noha daily task suite

schema: "yardstick:suite:0.1"

name: "os-odl_l2-nofeature-noha"
test_cases_dir: "tests/opnfv/test_cases/"
test_cases:
-
  file_name: opnfv_yardstick_tc002.yaml
-
  file_name: opnfv_yardstick_tc005.yaml
-
  file_name: opnfv_yardstick_tc010.yaml
-
  file_name: opnfv_yardstick_tc011.yaml
  constraint:
      installer: compass
-
  file_name: opnfv_yardstick_tc012.yaml
-
  file_name: opnfv_yardstick_tc014.yaml
-
  file_name: opnfv_yardstick_tc037.yaml
-
  file_name: opnfv_yardstick_tc055.yaml
  constraint:
      installer: compass
      pod: huawei-pod1
  task_args:
      huawei-pod1: '{"file": "etc/yardstick/nodes/compass_sclab_physical/pod.yaml",
      "host": "node5.yardstick-TC055"}'
-
  file_name: opnfv_yardstick_tc063.yaml
  constraint:
      installer: compass
      pod: huawei-pod1
  task_args:
      huawei-pod1: '{"file": "etc/yardstick/nodes/compass_sclab_physical/pod.yaml",
      "host": "node5.yardstick-TC063"}'
-
  file_name: opnfv_yardstick_tc069.yaml
-
  file_name: opnfv_yardstick_tc070.yaml
-
  file_name: opnfv_yardstick_tc071.yaml
-
  file_name: opnfv_yardstick_tc072.yaml
-
  file_name: opnfv_yardstick_tc075.yaml
  constraint:
      installer: compass
      pod: huawei-pod1
  task_args:
      huawei-pod1: '{"file": "etc/yardstick/nodes/compass_sclab_physical/pod.yaml",
      "host": "node1.LF"}'
ct */ .highlight .sa { color: #e6db74 } /* Literal.String.Affix */ .highlight .sb { color: #e6db74 } /* Literal.String.Backtick */ .highlight .sc { color: #e6db74 } /* Literal.String.Char */ .highlight .dl { color: #e6db74 } /* Literal.String.Delimiter */ .highlight .sd { color: #e6db74 } /* Literal.String.Doc */ .highlight .s2 { color: #e6db74 } /* Literal.String.Double */ .highlight .se { color: #ae81ff } /* Literal.String.Escape */ .highlight .sh { color: #e6db74 } /* Literal.String.Heredoc */ .highlight .si { color: #e6db74 } /* Literal.String.Interpol */ .highlight .sx { color: #e6db74 } /* Literal.String.Other */ .highlight .sr { color: #e6db74 } /* Literal.String.Regex */ .highlight .s1 { color: #e6db74 } /* Literal.String.Single */ .highlight .ss { color: #e6db74 } /* Literal.String.Symbol */ .highlight .bp { color: #f8f8f2 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #a6e22e } /* Name.Function.Magic */ .highlight .vc { color: #f8f8f2 } /* Name.Variable.Class */ .highlight .vg { color: #f8f8f2 } /* Name.Variable.Global */ .highlight .vi { color: #f8f8f2 } /* Name.Variable.Instance */ .highlight .vm { color: #f8f8f2 } /* Name.Variable.Magic */ .highlight .il { color: #ae81ff } /* Literal.Number.Integer.Long */ } @media (prefers-color-scheme: light) { .highlight .hll { background-color: #ffffcc } .highlight .c { color: #888888 } /* Comment */ .highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */ .highlight .k { color: #008800; font-weight: bold } /* Keyword */ .highlight .ch { color: #888888 } /* Comment.Hashbang */ .highlight .cm { color: #888888 } /* Comment.Multiline */ .highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */ .highlight .cpf { color: #888888 } /* Comment.PreprocFile */ .highlight .c1 { color: #888888 } /* Comment.Single */ .highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */ .highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */ .highlight .ge { font-style: italic } /* Generic.Emph */ .highlight .gr { color: #aa0000 } /* Generic.Error */ .highlight .gh { color: #333333 } /* Generic.Heading */ .highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */ .highlight .go { color: #888888 } /* Generic.Output */ .highlight .gp { color: #555555 } /* Generic.Prompt */ .highlight .gs { font-weight: bold } /* Generic.Strong */ .highlight .gu { color: #666666 } /* Generic.Subheading */ .highlight .gt { color: #aa0000 } /* Generic.Traceback */ .highlight .kc { color: #008800; font-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 */ }
#!/usr/bin/env python
# Copyright 2016 Cisco Systems, Inc.  All rights reserved.
#
#    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.
#
"""Test Chaining functions."""

from mock_trex import no_op

from mock import MagicMock
from mock import patch
import pytest

from nfvbench.chain_runner import ChainRunner
from nfvbench.chaining import ChainException
from nfvbench.chaining import ChainVnfPort
from nfvbench.chaining import InstancePlacer
from nfvbench.compute import Compute
import nfvbench.credentials
from nfvbench.factory import BasicFactory
import nfvbench.log
from nfvbench.nfvbench import load_default_config
from nfvbench.nfvbench import NFVBench
from nfvbench.packet_stats import InterfaceStats
from nfvbench.specs import ChainType
from nfvbench.specs import OpenStackSpec
from nfvbench.specs import Specs
from nfvbench.summarizer import _annotate_chain_stats
from nfvbench.traffic_client import TrafficClient
from nfvbench.traffic_gen.traffic_base import Latency
from nfvbench.traffic_gen.trex_gen import TRex


# just to get rid of the unused function warning
no_op()


def setup_module(module):
    """Enable log."""
    nfvbench.log.setup(mute_stdout=False)
    nfvbench.log.set_level(debug=True)

def _get_chain_config(sc=ChainType.PVP, scc=1, shared_net=True, rate='1Mpps'):
    config, _ = load_default_config()
    config.vm_image_file = 'nfvbenchvm-0.0.qcow2'
    config.service_chain_count = scc
    config.service_chain = sc
    config.service_chain_shared_net = shared_net
    config.rate = rate
    config['traffic_generator']['generator_profile'] = [{'name': 'dummy',
                                                         'tool': 'dummy',
                                                         'ip': '127.0.0.1',
                                                         'intf_speed': '10Gbps',
                                                         'interfaces': [{'port': 0, 'pci': '0.0'},
                                                                        {'port': 1, 'pci': '0.0'}]}]
    config.ndr_run = False
    config.pdr_run = False
    config.single_run = True
    config.generator_profile = 'dummy'
    config.duration_sec = 2
    config.interval_sec = 1
    config.openrc_file = "dummy.rc"
    return config

def test_chain_runner_ext_no_openstack():
    """Test ChainRunner EXT no openstack."""
    config = _get_chain_config(sc=ChainType.EXT)
    specs = Specs()
    config.vlans = [100, 200]
    config['traffic_generator']['mac_addrs_left'] = ['00:00:00:00:00:00']
    config['traffic_generator']['mac_addrs_right'] = ['00:00:00:00:01:00']

    for shared_net in [True, False]:
        for no_arp in [False, True]:
            for vlan_tag in [False, True]:
                for scc in [1, 2]:
                    config = _get_chain_config(ChainType.EXT, scc, shared_net)
                    config.no_arp = no_arp
                    if no_arp:
                        # If EXT and no arp, the config must provide mac (1 pair per chain)
                        config['traffic_generator']['mac_addrs_left'] = ['00:00:00:00:00:00'] * scc
                        config['traffic_generator']['mac_addrs_right'] = ['00:00:00:00:01:00'] * scc
                    config['vlan_tagging'] = vlan_tag
                    if vlan_tag:
                        # these are the 2 valid forms of vlan ranges
                        if scc == 1:
                            config.vlans = [100, 200]
                        else:
                            config.vlans = [[port * 100 + index for index in range(scc)]
                                            for port in range(2)]
                    runner = ChainRunner(config, None, specs, BasicFactory())
                    runner.close()


def _mock_find_image(self, image_name):
    return MagicMock()

@patch.object(Compute, 'find_image', _mock_find_image)
@patch('nfvbench.chaining.Client')
@patch('nfvbench.chaining.neutronclient')
@patch('nfvbench.chaining.glanceclient')
def _test_pvp_chain(config, cred, mock_glance, mock_neutron, mock_client):
    # instance = self.novaclient.servers.create(name=vmname,...)
    # instance.status == 'ACTIVE'
    mock_client.return_value.servers.create.return_value.status = 'ACTIVE'
    netw = {'id': 0, 'provider:network_type': 'vlan', 'provider:segmentation_id': 1000}
    mock_neutron.Client.return_value.create_network.return_value = {'network': netw}
    mock_neutron.Client.return_value.list_networks.return_value = {'networks': None}
    specs = Specs()
    openstack_spec = OpenStackSpec()
    specs.set_openstack_spec(openstack_spec)
    cred = MagicMock(spec=nfvbench.credentials.Credentials)
    cred.is_admin = True
    runner = ChainRunner(config, cred, specs, BasicFactory())
    runner.close()

def test_pvp_chain_runner():
    """Test PVP chain runner."""
    cred = MagicMock(spec=nfvbench.credentials.Credentials)
    cred.is_admin = True
    for shared_net in [True, False]:
        for sc in [ChainType.PVP]:
            for scc in [1, 2]:
                config = _get_chain_config(sc, scc, shared_net)
                _test_pvp_chain(config, cred)


# Test not admin exception with empty value is raised
@patch.object(Compute, 'find_image', _mock_find_image)
@patch('nfvbench.chaining.Client')
@patch('nfvbench.chaining.neutronclient')
@patch('nfvbench.chaining.glanceclient')
def _test_pvp_chain_no_admin_no_config_values(config, cred, mock_glance, mock_neutron, mock_client):
    # instance = self.novaclient.servers.create(name=vmname,...)
    # instance.status == 'ACTIVE'
    mock_client.return_value.servers.create.return_value.status = 'ACTIVE'
    netw = {'id': 0, 'provider:network_type': 'vlan', 'provider:segmentation_id': 1000}
    mock_neutron.Client.return_value.create_network.return_value = {'network': netw}
    mock_neutron.Client.return_value.list_networks.return_value = {'networks': None}
    specs = Specs()
    openstack_spec = OpenStackSpec()
    specs.set_openstack_spec(openstack_spec)
    runner = ChainRunner(config, cred, specs, BasicFactory())
    runner.close()

def test_pvp_chain_runner_no_admin_no_config_values():
    """Test PVP chain runner."""
    cred = MagicMock(spec=nfvbench.credentials.Credentials)
    cred.is_admin = False
    for shared_net in [True, False]:
        for sc in [ChainType.PVP]:
            for scc in [1, 2]:
                config = _get_chain_config(sc, scc, shared_net)
                with pytest.raises(ChainException):
                    _test_pvp_chain_no_admin_no_config_values(config, cred)

# Test not admin with mandatory parameters values in config file
@patch.object(Compute, 'find_image', _mock_find_image)
@patch('nfvbench.chaining.Client')
@patch('nfvbench.chaining.neutronclient')
@patch('nfvbench.chaining.glanceclient')
def _test_pvp_chain_no_admin_config_values(config, cred, mock_glance, mock_neutron, mock_client):
    # instance = self.novaclient.servers.create(name=vmname,...)
    # instance.status == 'ACTIVE'
    mock_client.return_value.servers.create.return_value.status = 'ACTIVE'
    netw = {'id': 0, 'provider:network_type': 'vlan', 'provider:segmentation_id': 1000}
    mock_neutron.Client.return_value.create_network.return_value = {'network': netw}
    mock_neutron.Client.return_value.list_networks.return_value = {'networks': None}
    specs = Specs()
    openstack_spec = OpenStackSpec()
    specs.set_openstack_spec(openstack_spec)
    runner = ChainRunner(config, cred, specs, BasicFactory())
    runner.close()

def test_pvp_chain_runner_no_admin_config_values():
    """Test PVP chain runner."""
    cred = MagicMock(spec=nfvbench.credentials.Credentials)
    cred.is_admin = False
    for shared_net in [True, False]:
        for sc in [ChainType.PVP]:
            for scc in [1, 2]:
                config = _get_chain_config(sc, scc, shared_net)
                config.availability_zone = "az"
                config.hypervisor_hostname = "server"
                # these are the 2 valid forms of vlan ranges
                if scc == 1:
                    config.vlans = [100, 200]
                else:
                    config.vlans = [[port * 100 + index for index in range(scc)]
                                    for port in range(2)]
                _test_pvp_chain_no_admin_config_values(config, cred)


@patch.object(Compute, 'find_image', _mock_find_image)
@patch('nfvbench.chaining.Client')
@patch('nfvbench.chaining.neutronclient')
@patch('nfvbench.chaining.glanceclient')
def _test_ext_chain(config, cred, mock_glance, mock_neutron, mock_client):
    # instance = self.novaclient.servers.create(name=vmname,...)
    # instance.status == 'ACTIVE'
    mock_client.return_value.servers.create.return_value.status = 'ACTIVE'
    netw = {'id': 0, 'provider:network_type': 'vlan', 'provider:segmentation_id': 1000}
    mock_neutron.Client.return_value.list_networks.return_value = {'networks': [netw]}
    specs = Specs()
    openstack_spec = OpenStackSpec()
    specs.set_openstack_spec(openstack_spec)
    cred = MagicMock(spec=nfvbench.credentials.Credentials)
    cred.is_admin = True
    runner = ChainRunner(config, cred, specs, BasicFactory())
    runner.close()

def test_ext_chain_runner():
    """Test openstack+EXT chain runner.

    Test 8 combinations of configs:
    shared/not shared net x arp/no_arp x scc 1 or 2
    """
    cred = MagicMock(spec=nfvbench.credentials.Credentials)
    cred.is_admin = True
    for shared_net in [True, False]:
        for no_arp in [False, True]:
            for scc in [1, 2]:
                config = _get_chain_config(ChainType.EXT, scc, shared_net)
                config.no_arp = no_arp
                # this time use a tuple of network names
                config['external_networks']['left'] = ('ext-lnet00', 'ext-lnet01')
                config['external_networks']['right'] = ('ext-rnet00', 'ext-rnet01')
                if no_arp:
                    # If EXT and no arp, the config must provide mac addresses (1 pair per chain)
                    config['traffic_generator']['mac_addrs_left'] = ['00:00:00:00:00:00'] * scc
                    config['traffic_generator']['mac_addrs_right'] = ['00:00:00:00:01:00'] * scc
                _test_ext_chain(config, cred)

def _check_nfvbench_openstack(sc=ChainType.PVP, l2_loopback=False):
    for scc in range(1, 3):
        config = _get_chain_config(sc, scc=scc, shared_net=True)
        if l2_loopback:
            config.l2_loopback = True
            config.vlans = [[100], [200]]
        if sc == ChainType.EXT:
            config['external_networks']['left'] = 'ext-lnet'
            config['external_networks']['right'] = 'ext-rnet'
        factory = BasicFactory()
        config_plugin = factory.get_config_plugin_class()(config)
        config = config_plugin.get_config()
        openstack_spec = config_plugin.get_openstack_spec()
        nfvb = NFVBench(config, openstack_spec, config_plugin, factory)
        res = nfvb.run({}, 'pytest')
        if res['status'] != 'OK':
            print res
        assert res['status'] == 'OK'


mac_seq = 0

def _mock_get_mac(dummy):
    global mac_seq
    mac_seq += 1
    return '01:00:00:00:00:%02x' % mac_seq

@patch.object(Compute, 'find_image', _mock_find_image)
@patch.object(TrafficClient, 'skip_sleep', lambda x: True)
@patch.object(ChainVnfPort, 'get_mac', _mock_get_mac)
@patch.object(TrafficClient, 'is_udp', lambda x, y: True)
@patch('nfvbench.chaining.Client')
@patch('nfvbench.chaining.neutronclient')
@patch('nfvbench.chaining.glanceclient')
@patch('nfvbench.nfvbench.credentials')
def test_nfvbench_run(mock_cred, mock_glance, mock_neutron, mock_client):
    """Test NFVbench class with openstack+PVP."""
    # instance = self.novaclient.servers.create(name=vmname,...)
    # instance.status == 'ACTIVE'
    mock_client.return_value.servers.create.return_value.status = 'ACTIVE'
    netw = {'id': 0, 'provider:network_type': 'vlan', 'provider:segmentation_id': 1000}
    mock_neutron.Client.return_value.create_network.return_value = {'network': netw}
    mock_neutron.Client.return_value.list_networks.return_value = {'networks': None}
    _check_nfvbench_openstack()

@patch.object(Compute, 'find_image', _mock_find_image)
@patch.object(TrafficClient, 'skip_sleep', lambda x: True)
@patch.object(TrafficClient, 'is_udp', lambda x, y: True)
@patch('nfvbench.chaining.Client')
@patch('nfvbench.chaining.neutronclient')
@patch('nfvbench.chaining.glanceclient')
@patch('nfvbench.nfvbench.credentials')
def test_nfvbench_ext_arp(mock_cred, mock_glance, mock_neutron, mock_client):
    """Test NFVbench class with openstack+EXT+ARP."""
    # instance = self.novaclient.servers.create(name=vmname,...)
    # instance.status == 'ACTIVE'
    mock_client.return_value.servers.create.return_value.status = 'ACTIVE'
    netw = {'id': 0, 'provider:network_type': 'vlan', 'provider:segmentation_id': 1000}
    mock_neutron.Client.return_value.list_networks.return_value = {'networks': [netw]}
    _check_nfvbench_openstack(sc=ChainType.EXT)

@patch.object(Compute, 'find_image', _mock_find_image)
@patch.object(TrafficClient, 'skip_sleep', lambda x: True)
@patch.object(TrafficClient, 'is_udp', lambda x, y: True)
@patch('nfvbench.chaining.Client')
@patch('nfvbench.chaining.neutronclient')
@patch('nfvbench.chaining.glanceclient')
@patch('nfvbench.nfvbench.credentials')
def test_nfvbench_l2_loopback(mock_cred, mock_glance, mock_neutron, mock_client):
    """Test NFVbench class with l2-loopback."""
    # instance = self.novaclient.servers.create(name=vmname,...)
    # instance.status == 'ACTIVE'
    mock_client.return_value.servers.create.return_value.status = 'ACTIVE'
    _check_nfvbench_openstack(l2_loopback=True)


# This is a reduced version of flow stats coming from Trex
# with 2 chains and latency for a total of 8 packet groups
# Random numbers with random losses
CH0_P0_TX = 1234
CH0_P1_RX = 1200
CH0_P1_TX = 28900
CH0_P0_RX = 28000
LCH0_P0_TX = 167
LCH0_P1_RX = 130
LCH0_P1_TX = 523
LCH0_P0_RX = 490
CH1_P0_TX = 132344
CH1_P1_RX = 132004
CH1_P1_TX = 1289300
CH1_P0_RX = 1280400
LCH1_P0_TX = 51367
LCH1_P1_RX = 5730
LCH1_P1_TX = 35623
LCH1_P0_RX = 67

TREX_STATS = {
    'flow_stats': {
        # chain 0 port 0 normal stream
        0: {'rx_pkts': {0: 0, 1: CH0_P1_RX, 'total': CH0_P1_RX},
            'tx_pkts': {0: CH0_P0_TX, 1: 0, 'total': CH0_P0_TX}},
        # chain 1 port 0 normal stream
        1: {'rx_pkts': {0: 0, 1: CH1_P1_RX, 'total': CH1_P1_RX},
            'tx_pkts': {0: CH1_P0_TX, 1: 0, 'total': CH1_P0_TX}},
        # chain 0 port 1 normal stream
        128: {'rx_pkts': {0: CH0_P0_RX, 1: 0, 'total': CH0_P0_RX},
              'tx_pkts': {0: 0, 1: CH0_P1_TX, 'total': CH0_P1_TX}},
        # chain 1 port 1 normal stream
        129: {'rx_pkts': {0: CH1_P0_RX, 1: 0, 'total': CH1_P0_RX},
              'tx_pkts': {0: 0, 1: CH1_P1_TX, 'total': CH1_P1_TX}},
        # chain 0 port 0 latency stream
        256: {'rx_pkts': {0: 0, 1: LCH0_P1_RX, 'total': LCH0_P1_RX},
              'tx_pkts': {0: LCH0_P0_TX, 1: 0, 'total': LCH0_P0_TX}},
        # chain 1 port 0 latency stream
        257: {'rx_pkts': {0: 0, 1: LCH1_P1_RX, 'total': LCH1_P1_RX},
              'tx_pkts': {0: LCH1_P0_TX, 1: 0, 'total': LCH1_P0_TX}},
        # chain 0 port 1 latency stream
        384: {'rx_pkts': {0: LCH0_P0_RX, 1: 0, 'total': LCH0_P0_RX},
              'tx_pkts': {0: 0, 1: LCH0_P1_TX, 'total': LCH0_P1_TX}},
        # chain 1 port 1 latency stream
        385: {'rx_pkts': {0: LCH1_P0_RX, 1: 0, 'total': LCH1_P0_RX},
              'tx_pkts': {0: 0, 1: LCH1_P1_TX, 'total': LCH1_P1_TX}}}}

def test_trex_streams_stats():
    """Test TRex stats for chains 0 and 1."""
    traffic_client = MagicMock()
    trex = TRex(traffic_client)
    if_stats = [InterfaceStats("p0", "dev0"), InterfaceStats("p1", "dev1")]
    latencies = [Latency()] * 2
    trex.get_stream_stats(TREX_STATS, if_stats, latencies, 0)
    assert if_stats[0].tx == CH0_P0_TX + LCH0_P0_TX
    assert if_stats[0].rx == CH0_P0_RX + LCH0_P0_RX
    assert if_stats[1].tx == CH0_P1_TX + LCH0_P1_TX
    assert if_stats[1].rx == CH0_P1_RX + LCH0_P1_RX

    trex.get_stream_stats(TREX_STATS, if_stats, latencies, 1)
    assert if_stats[0].tx == CH1_P0_TX + LCH1_P0_TX
    assert if_stats[0].rx == CH1_P0_RX + LCH1_P0_RX
    assert if_stats[1].tx == CH1_P1_TX + LCH1_P1_TX
    assert if_stats[1].rx == CH1_P1_RX + LCH1_P1_RX

def check_placer(az, hyp, req_az, resolved=False):
    """Combine multiple combinatoons of placer tests."""
    placer = InstancePlacer(az, hyp)
    assert placer.is_resolved() == resolved
    assert placer.get_required_az() == req_az
    assert placer.register_full_name('nova:comp1')
    assert placer.is_resolved()
    assert placer.get_required_az() == 'nova:comp1'

def test_placer_no_user_pref():
    """Test placement when user does not provide any preference."""
    check_placer(None, None, '')

def test_placer_user_az():
    """Test placement when user only provides an az."""
    check_placer('nova', None, 'nova:')
    check_placer(None, 'nova:', 'nova:')
    check_placer('nebula', 'nova:', 'nova:')

def test_placer_user_hyp():
    """Test placement when user provides a hypervisor."""
    check_placer(None, 'comp1', ':comp1')
    check_placer('nova', 'comp1', 'nova:comp1', resolved=True)
    check_placer(None, 'nova:comp1', 'nova:comp1', resolved=True)
    # hyp overrides az
    check_placer('nebula', 'nova:comp1', 'nova:comp1', resolved=True)
    # also check for cases of extra parts (more than 1 ':')
    check_placer('nova:nebula', 'comp1', 'nova:comp1', resolved=True)


def test_placer_negative():
    """Run negative tests on placer."""
    # AZ mismatch
    with pytest.raises(Exception):
        placer = InstancePlacer('nova', None)
        placer.register('nebula:comp1')
    # comp mismatch
    with pytest.raises(Exception):
        placer = InstancePlacer(None, 'comp1')
        placer.register('nebula:comp2')


# without total, with total and only 2 col
CHAIN_STATS = [{0: {'packets': [2000054, 1999996, 1999996]}},
               {0: {'packets': [2000054, 1999996, 1999996]},
                1: {'packets': [2000054, 2000054, 2000054]},
                'total': {'packets': [4000108, 4000050, 4000050]}},
               {0: {'packets': [2000054, 2000054]}},
               {0: {'packets': [2000054, 1999996]}},
               # shared networks no drops, shared nets will have empty strings
               {0: {'packets': [15000002, '', 15000002, 15000002, '', 15000002]},
                1: {'packets': [15000002, '', 15000002, 15000002, '', 15000002]},
                'total': {'packets': [30000004, 30000004, 30000004, 30000004, 30000004, 30000004]}},
               {0: {'packets': [15000002, '', 14000002, 14000002, '', 13000002]},
                1: {'packets': [15000002, '', 15000002, 15000002, '', 15000002]},
                'total': {'packets': [30000004, 29000004, 29000004, 29000004, 29000004, 28000004]}},
               # example with non-available rx count in last position
               {0: {'packets': [2000054, 1999996, None]},
                1: {'packets': [2000054, 2000054, None]},
                'total': {'packets': [4000108, 4000050, 4000050]}}]
XP_CHAIN_STATS = [{0: {'packets': [2000054, '-58 (-0.0029%)', 1999996]}},
                  {0: {'packets': [2000054, '-58 (-0.0029%)', 1999996]},
                   1: {'packets': [2000054, '=>', 2000054]},
                   'total': {'packets': [4000108, '-58 (-0.0014%)', 4000050]}},
                  {0: {'packets': [2000054, 2000054]}},
                  {0: {'packets': [2000054, '-58 (-0.0029%)']}},
                  # shared net, leave spaces alone
                  {0: {'packets': [15000002, '', '=>', '=>', '', 15000002]},
                   1: {'packets': [15000002, '', '=>', '=>', '', 15000002]},
                   'total': {'packets': [30000004, '=>', '=>', '=>', '=>', 30000004]}},
                  {0: {'packets': [15000002, '', '-1,000,000 (-6.6667%)', '=>', '',
                                   '-1,000,000 (-7.1429%)']},
                   1: {'packets': [15000002, '', '=>', '=>', '', 15000002]},
                   'total': {'packets': [30000004, '-1,000,000 (-3.3333%)', '=>', '=>', '=>',
                                         '-1,000,000 (-3.4483%)']}},
                  {0: {'packets': [2000054, '-58 (-0.0029%)', 'n/a']},
                   1: {'packets': [2000054, '=>', 'n/a']},
                   'total': {'packets': [4000108, '-58 (-0.0014%)', 4000050]}}]


def test_summarizer():
    """Test Summarizer class."""
    for stats, exp_stats in zip(CHAIN_STATS, XP_CHAIN_STATS):
        _annotate_chain_stats(stats)
        assert stats == exp_stats

@patch.object(TrafficClient, 'skip_sleep', lambda x: True)
@patch.object(TrafficClient, 'is_udp', lambda x, y: True)
def test_fixed_rate_no_openstack():
    """Test FIxed Rate run - no openstack."""
    config = _get_chain_config(ChainType.EXT, 1, True, rate='100%')
    specs = Specs()
    config.vlans = [100, 200]
    config['traffic_generator']['mac_addrs_left'] = ['00:00:00:00:00:00']
    config['traffic_generator']['mac_addrs_right'] = ['00:00:00:00:01:00']
    config.no_arp = True
    config['vlan_tagging'] = True
    config['traffic'] = {'profile': 'profile_64',
                         'bidirectional': True}
    config['traffic_profile'] = [{'name': 'profile_64', 'l2frame_size': ['64']}]

    runner = ChainRunner(config, None, specs, BasicFactory())
    tg = runner.traffic_client.gen

    tg.set_response_curve(lr_dr=0, ndr=100, max_actual_tx=50, max_11_tx=50)
    # tx packets should be 50% at requested 50% line rate or higher for 64B and no drops...
    results = runner.run()
    assert results
    # pprint.pprint(results['EXT']['result']['result']['64'])
    runner.close()