-# Copyright (c) 2018 Cisco and/or its affiliates.
+# Copyright (c) 2019 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:
from resources.libraries.python.ssh import SSH
from resources.libraries.python.constants import Constants
-from resources.libraries.python.CpuUtils import CpuUtils
+from resources.libraries.python.topology import Topology
from resources.libraries.python.VppConfigGenerator import VppConfigGenerator
setattr(self.engine.container, 'env',
'MICROSERVICE_LABEL={label}'.format(label=kwargs['name']))
- # Set cpuset.cpus cgroup
- skip_cnt = kwargs['cpu_skip']
- if not kwargs['cpu_shared']:
- skip_cnt += kwargs['i'] * kwargs['cpu_count']
- self.engine.container.cpuset_cpus = \
- CpuUtils.cpu_slice_of_list_per_node(node=kwargs['node'],
- cpu_node=kwargs['cpuset_mems'],
- skip_cnt=skip_cnt,
- cpu_cnt=kwargs['cpu_count'],
- smt_used=kwargs['smt_used'])
-
# Store container instance
self.containers[kwargs['name']] = self.engine.container
self.engine.container = self.containers[container]
# We need to install supervisor client/server system to control VPP
# as a service
+ self.engine.execute('apt-get update')
self.engine.install_supervisor()
self.engine.install_vpp()
self.engine.restart_vpp()
self.engine.container = self.containers[container]
self.engine.restart_vpp()
- def configure_vpp_in_all_containers(self, vat_template_file):
+ def configure_vpp_in_all_containers(self, chain_topology, **kwargs):
"""Configure VPP in all containers.
- :param vat_template_file: Template file name of a VAT script.
- :type vat_template_file: str
+ :param chain_topology: Topology used for chaining containers can be
+ chain or cross_horiz. Chain topology is using 1 memif pair per
+ container. Cross_horiz topology is using 1 memif and 1 physical
+ interface in container (only single container can be configured).
+ :param kwargs: Named parameters.
+ :type chain_topology: str
+ :param kwargs: dict
"""
# Count number of DUTs based on node's host information
dut_cnt = len(Counter([self.containers[container].node['host']
for container in self.containers]))
- container_cnt = len(self.containers)
- mod = container_cnt/dut_cnt
+ mod = len(self.containers)/dut_cnt
+ container_vat_template = 'memif_create_{topology}.vat'.format(
+ topology=chain_topology)
for i, container in enumerate(self.containers):
mid1 = i % mod + 1
sid1 = i % mod * 2 + 1
sid2 = i % mod * 2 + 2
self.engine.container = self.containers[container]
- self.engine.create_vpp_startup_config()
- self.engine.create_vpp_exec_config(vat_template_file, mid1=mid1,
- mid2=mid2, sid1=sid1, sid2=sid2,
- socket1='memif-{c.name}-{sid}'
- .format(c=self.engine.container,
- sid=sid1),
- socket2='memif-{c.name}-{sid}'
- .format(c=self.engine.container,
- sid=sid2))
+ guest_dir = self.engine.container.mnt[0].split(':')[1]
+
+ if chain_topology == 'chain':
+ self.engine.create_vpp_startup_config()
+ self.engine.create_vpp_exec_config(
+ container_vat_template,
+ mid1=mid1, mid2=mid2, sid1=sid1, sid2=sid2,
+ socket1='{dir}/memif-{c.name}-{sid}'.
+ format(c=self.engine.container, sid=sid1, dir=guest_dir),
+ socket2='{dir}/memif-{c.name}-{sid}'.
+ format(c=self.engine.container, sid=sid2, dir=guest_dir))
+ elif chain_topology == 'cross_horiz':
+ try:
+ dut1_if = kwargs['dut1_if']
+ dut2_if = kwargs['dut2_if']
+ except KeyError:
+ raise AttributeError('DUT interfaces not specified!')
+ if 'DUT1' in self.engine.container.name:
+ if_pci = Topology.get_interface_pci_addr(
+ self.engine.container.node, dut1_if)
+ if_name = Topology.get_interface_name(
+ self.engine.container.node, dut1_if)
+ if 'DUT2' in self.engine.container.name:
+ if_pci = Topology.get_interface_pci_addr(
+ self.engine.container.node, dut2_if)
+ if_name = Topology.get_interface_name(
+ self.engine.container.node, dut2_if)
+ self.engine.create_vpp_startup_config_dpdk_dev(if_pci)
+ self.engine.create_vpp_exec_config(
+ container_vat_template,
+ mid1=mid1, sid1=sid1, if_name=if_name,
+ socket1='{dir}/memif-{c.name}-{sid}'.
+ format(c=self.engine.container, sid=sid1, dir=guest_dir))
+ elif chain_topology == 'chain_functional':
+ memif_rx_mode = 'interrupt'
+ self.engine.create_vpp_startup_config_func_dev()
+ self.engine.create_vpp_exec_config(
+ container_vat_template,
+ mid1=mid1, mid2=mid2, sid1=sid1, sid2=sid2,
+ socket1='{dir}/memif-{c.name}-{sid}'.
+ format(c=self.engine.container, sid=sid1, dir=guest_dir),
+ socket2='{dir}/memif-{c.name}-{sid}'.
+ format(c=self.engine.container, sid=sid2, dir=guest_dir),
+ rx_mode=memif_rx_mode)
+ elif chain_topology == 'chain_ip4':
+ self.engine.create_vpp_startup_config()
+ vif1_mac = kwargs['tg_if1_mac'] \
+ if (mid1 - 1) % kwargs['nodes'] + 1 == 1 \
+ else '52:54:00:00:{0:02X}:02'.format(mid1-1)
+ vif2_mac = kwargs['tg_if2_mac'] \
+ if (mid2 - 1) % kwargs['nodes'] + 1 == kwargs['nodes'] \
+ else '52:54:00:00:{0:02X}:01'.format(mid2+1)
+ self.engine.create_vpp_exec_config(
+ container_vat_template,
+ mid1=mid1, mid2=mid2, sid1=sid1, sid2=sid2,
+ socket1='{dir}/memif-{c.name}-{sid}'.
+ format(c=self.engine.container, sid=sid1, dir=guest_dir),
+ socket2='{dir}/memif-{c.name}-{sid}'.
+ format(c=self.engine.container, sid=sid2, dir=guest_dir),
+ mac1='52:54:00:00:{0:02X}:01'.format(mid1),
+ mac2='52:54:00:00:{0:02X}:02'.format(mid2),
+ vif1_mac=vif1_mac, vif2_mac=vif2_mac)
+ else:
+ raise RuntimeError('Container topology {topology} not '
+ 'implemented'.
+ format(topology=chain_topology))
def stop_all_containers(self):
"""Stop all containers."""
def install_supervisor(self):
"""Install supervisord inside a container."""
- self.execute('sleep 3')
- self.execute('apt-get update')
self.execute('apt-get install -y supervisor')
- self.execute('echo "{config}" > {config_file}'.
+ self.execute('echo "{config}" > {config_file} && '
+ 'supervisord -c {config_file}'.
format(
config='[unix_http_server]\n'
'file = /tmp/supervisor.sock\n\n'
'loglevel=debug\n'
'nodaemon=false\n\n',
config_file=SUPERVISOR_CONF))
- self.execute('supervisord -c {config_file}'.
- format(config_file=SUPERVISOR_CONF))
-
- def install_vpp(self, install_dkms=False):
- """Install VPP inside a container.
- :param install_dkms: If install dkms package. This will impact
- install time. Dkms is required for installation of vpp-dpdk-dkms.
- Default is false.
- :type install_dkms: bool
- """
+ def install_vpp(self):
+ """Install VPP inside a container."""
self.execute('ln -s /dev/null /etc/sysctl.d/80-vpp.conf')
- self.execute('apt-get update')
- if install_dkms:
- self.execute(
- 'apt-get install -y dkms && '
- 'dpkg -i --force-all {guest_dir}/install_dir/*.deb'.
- format(guest_dir=self.container.mnt[0].split(':')[1]))
- else:
- self.execute(
- 'for i in $(ls -I \"*dkms*\" {guest_dir}/install_dir/); do '
- 'dpkg -i --force-all {guest_dir}/install_dir/$i; done'.
- format(guest_dir=self.container.mnt[0].split(':')[1]))
+ # Workaround for install xenial vpp build on bionic ubuntu.
+ self.execute('apt-get install -y wget')
+ self.execute('deb=$(mktemp) && wget -O "${deb}" '
+ 'http://launchpadlibrarian.net/336117627/'
+ 'libmbedcrypto0_2.5.1-1ubuntu1_amd64.deb && '
+ 'dpkg -i "${deb}" && '
+ 'rm -f "${deb}"')
+ self.execute('deb=$(mktemp) && wget -O "${deb}" '
+ 'http://launchpadlibrarian.net/252876048/'
+ 'libboost-system1.58.0_1.58.0+dfsg-5ubuntu3_amd64.deb && '
+ 'dpkg -i "${deb}" && '
+ 'rm -f "${deb}"')
+ self.execute(
+ 'dpkg -i --force-all '
+ '{guest_dir}/openvpp-testing/download_dir/*.deb'.
+ format(guest_dir=self.container.mnt[0].split(':')[1]))
self.execute('apt-get -f install -y')
self.execute('apt-get install -y ca-certificates')
self.execute('echo "{config}" >> {config_file}'.
self.execute('supervisorctl restart vpp')
self.execute('cat /tmp/supervisord.log')
- def create_vpp_startup_config(self,
- config_filename='/etc/vpp/startup.conf'):
+ def create_base_vpp_startup_config(self):
"""Create base startup configuration of VPP on container.
- :param config_filename: Startup configuration file name.
- :type config_filename: str
+ :returns: Base VPP startup configuration.
+ :rtype: VppConfigGenerator
"""
cpuset_cpus = self.container.cpuset_cpus
vpp_config.add_unix_cli_listen()
vpp_config.add_unix_nodaemon()
vpp_config.add_unix_exec('/tmp/running.exec')
- # We will pop first core from list to be main core
+ # We will pop the first core from the list to be a main core
vpp_config.add_cpu_main_core(str(cpuset_cpus.pop(0)))
- # if this is not only core in list, the rest will be used as workers.
+ # If more cores in the list, the rest will be used as workers.
if cpuset_cpus:
corelist_workers = ','.join(str(cpu) for cpu in cpuset_cpus)
vpp_config.add_cpu_corelist_workers(corelist_workers)
+
+ return vpp_config
+
+ def create_vpp_startup_config(self):
+ """Create startup configuration of VPP without DPDK on container.
+ """
+ vpp_config = self.create_base_vpp_startup_config()
+ vpp_config.add_plugin('disable', 'dpdk_plugin.so')
+
+ # Apply configuration
+ self.execute('mkdir -p /etc/vpp/')
+ self.execute('echo "{config}" | tee /etc/vpp/startup.conf'
+ .format(config=vpp_config.get_config_str()))
+
+ def create_vpp_startup_config_dpdk_dev(self, *devices):
+ """Create startup configuration of VPP with DPDK on container.
+
+ :param devices: List of PCI devices to add.
+ :type devices: list
+ """
+ vpp_config = self.create_base_vpp_startup_config()
+ vpp_config.add_dpdk_dev(*devices)
+ vpp_config.add_dpdk_no_tx_checksum_offload()
+ vpp_config.add_dpdk_log_level('debug')
+ vpp_config.add_plugin('disable', 'default')
+ vpp_config.add_plugin('enable', 'dpdk_plugin.so')
+ vpp_config.add_plugin('enable', 'memif_plugin.so')
+
+ # Apply configuration
+ self.execute('mkdir -p /etc/vpp/')
+ self.execute('echo "{config}" | tee /etc/vpp/startup.conf'
+ .format(config=vpp_config.get_config_str()))
+
+ def create_vpp_startup_config_func_dev(self):
+ """Create startup configuration of VPP on container for functional
+ vpp_device tests.
+ """
+ # Create config instance
+ vpp_config = VppConfigGenerator()
+ vpp_config.set_node(self.container.node)
+ vpp_config.add_unix_cli_listen()
+ vpp_config.add_unix_nodaemon()
+ vpp_config.add_unix_exec('/tmp/running.exec')
vpp_config.add_plugin('disable', 'dpdk_plugin.so')
+ # Apply configuration
self.execute('mkdir -p /etc/vpp/')
- self.execute('echo "{c}" | tee {f}'
- .format(c=vpp_config.get_config_str(),
- f=config_filename))
+ self.execute('echo "{config}" | tee /etc/vpp/startup.conf'
+ .format(config=vpp_config.get_config_str()))
def create_vpp_exec_config(self, vat_template_file, **kwargs):
"""Create VPP exec configuration on container.
class LXC(ContainerEngine):
"""LXC implementation."""
- def __init__(self):
- """Initialize LXC object."""
- super(LXC, self).__init__()
+ # Implicit constructor is inherited.
def acquire(self, force=True):
"""Acquire a privileged system object where configuration is stored.
class Docker(ContainerEngine):
"""Docker implementation."""
- def __init__(self):
- """Initialize Docker object."""
- super(Docker, self).__init__()
+ # Implicit constructor is inherited.
def acquire(self, force=True):
"""Pull an image or a repository from a registry.
else:
return
- cmd = 'docker pull {c.image}'.format(c=self.container)
+ if not self.container.image:
+ setattr(self.container, 'image', 'snergster/csit-sut:latest')
+
+ cmd = 'docker pull {image}'.format(image=self.container.image)
ret, _, _ = self.container.ssh.exec_command_sudo(cmd, timeout=1800)
if int(ret) != 0:
raise RuntimeError('Failed to create container {c.name}.'
.format(c=self.container))
- self._configure_cgroup('docker')
+ if self.container.cpuset_cpus:
+ self._configure_cgroup('docker')
def create(self):
"""Create/deploy container.