aboutsummaryrefslogtreecommitdiffstats
path: root/resources/libraries
diff options
context:
space:
mode:
Diffstat (limited to 'resources/libraries')
-rw-r--r--resources/libraries/python/LXCUtils.py60
-rw-r--r--resources/libraries/python/VppConfigGenerator.py5
-rw-r--r--resources/libraries/robot/lxc.robot12
3 files changed, 67 insertions, 10 deletions
diff --git a/resources/libraries/python/LXCUtils.py b/resources/libraries/python/LXCUtils.py
index 3f251a0db1..9f42540986 100644
--- a/resources/libraries/python/LXCUtils.py
+++ b/resources/libraries/python/LXCUtils.py
@@ -14,8 +14,10 @@
"""Library to manipulate LXC."""
from resources.libraries.python.ssh import SSH
+from resources.libraries.python.constants import Constants
from resources.libraries.python.topology import NodeType
+
__all__ = ["LXCUtils"]
class LXCUtils(object):
@@ -25,6 +27,8 @@ class LXCUtils(object):
# LXC container name
self._container_name = container_name
self._node = None
+ # Host hugepages dir that will be mounted inside LXC
+ self._host_hugepages_dir = '/dev/hugepages'
# Host dir that will be mounted inside LXC
self._host_dir = '/tmp/'
# Guest dir to mount host dir to
@@ -251,7 +255,7 @@ class LXCUtils(object):
"""
if self.is_container_present():
if force_create:
- self.container_destroy()
+ self.destroy_container()
else:
return
@@ -296,7 +300,7 @@ class LXCUtils(object):
self.stop_container()
self.start_container()
- def container_destroy(self):
+ def destroy_container(self):
"""Stop and destroy a container."""
self._lxc_destroy()
@@ -329,11 +333,10 @@ class LXCUtils(object):
ssh = SSH()
ssh.connect(self._node)
- self.lxc_attach('mkdir -p {0}'.format(self._guest_dir))
-
mnt_cfg = 'lxc.mount.entry = {0} /var/lib/lxc/{1}/rootfs{2} ' \
- 'none bind 0 0'.format(self._host_dir, self._container_name,
- self._guest_dir)
+ 'none bind,create=dir 0 0'.format(self._host_dir,
+ self._container_name,
+ self._guest_dir)
ret, _, _ = ssh.exec_command_sudo(
"sh -c 'echo \"{0}\" >> /var/lib/lxc/{1}/config'"
.format(mnt_cfg, self._container_name))
@@ -343,6 +346,27 @@ class LXCUtils(object):
self.restart_container()
+ def mount_hugepages_in_container(self):
+ """Mount hugepages inside container.
+
+ :raises RuntimeError: If failed to mount hugepages in a container.
+ """
+
+ ssh = SSH()
+ ssh.connect(self._node)
+
+ mnt_cfg = 'lxc.mount.entry = {0} dev/hugepages ' \
+ 'none bind,create=dir 0 0'.format(self._host_hugepages_dir)
+ ret, _, _ = ssh.exec_command_sudo(
+ "sh -c 'echo \"{0}\" >> /var/lib/lxc/{1}/config'"
+ .format(mnt_cfg, self._container_name))
+ if int(ret) != 0:
+ raise RuntimeError('Failed to mount {0} in lxc: {1}'
+ .format(self._host_hugepages_dir,
+ self._container_name))
+
+ self.restart_container()
+
def install_vpp_in_container(self, install_dkms=False):
"""Install vpp inside a container.
@@ -373,3 +397,27 @@ class LXCUtils(object):
ssh.connect(self._node)
self.lxc_attach('service vpp restart')
+
+ def create_vpp_cfg_in_container(self, vat_template_file, **args):
+ """Create VPP exec config for a container on given node.
+
+ :param vat_template_file: Template file name of a VAT script.
+ :param args: Parameters for VAT script.
+ :type vat_template_file: str
+ :type args: dict
+ """
+ ssh = SSH()
+ ssh.connect(self._node)
+
+ vat_file_path = '{}/{}'.format(Constants.RESOURCES_TPL_VAT,
+ vat_template_file)
+
+ with open(vat_file_path, 'r') as template_file:
+ cmd_template = template_file.readlines()
+ for line_tmpl in cmd_template:
+ vat_cmd = line_tmpl.format(**args)
+ ssh.exec_command('echo "{0}" | '
+ 'sudo lxc-attach --name {1} -- '
+ '/bin/sh -c "/bin/cat >> /tmp/running.exec"'
+ .format(vat_cmd.replace('\n', ''),
+ self._container_name))
diff --git a/resources/libraries/python/VppConfigGenerator.py b/resources/libraries/python/VppConfigGenerator.py
index 31defd6704..eb628de587 100644
--- a/resources/libraries/python/VppConfigGenerator.py
+++ b/resources/libraries/python/VppConfigGenerator.py
@@ -129,6 +129,11 @@ class VppConfigGenerator(object):
path = ['unix', 'nodaemon']
self.add_config_item(self._nodeconfig, '', path)
+ def add_unix_exec(self, value):
+ """Add UNIX exec configuration."""
+ path = ['unix', 'exec']
+ self.add_config_item(self._nodeconfig, value, path)
+
def add_dpdk_dev(self, *devices):
"""Add DPDK PCI device configuration.
diff --git a/resources/libraries/robot/lxc.robot b/resources/libraries/robot/lxc.robot
index b4dd1d117d..83bd5c1837 100644
--- a/resources/libraries/robot/lxc.robot
+++ b/resources/libraries/robot/lxc.robot
@@ -36,7 +36,7 @@
| | Import Library | resources.libraries.python.LXCUtils
| | ... | container_name=${lxc_name} | WITH NAME | ${lxc_name}
| | Run keyword | ${lxc_name}.Set node | ${dut_node}
-| | Run keyword | ${lxc_name}.Container create | force_create=${TRUE}
+| | Run keyword | ${lxc_name}.Create container | force_create=${TRUE}
| | Run keyword | ${lxc_name}.Mount host dir in container
| Create LXC container on DUT node with cpuset
@@ -63,10 +63,11 @@
| | ... | ${dut1_if1} | ${dut1_if2}
| | ${lxc_cpus}= | CPU list per node str | ${dut_node} | ${dut_numa}
| | ... | skip_cnt=${skip} | cpu_cnt=${count} | smt_used=${False}
+| | Set Suite Variable | ${lxc_cpus}
| | Run keyword | ${lxc_name}.Set node | ${dut_node}
-| | Run keyword | ${lxc_name}.Container create | force_create=${TRUE}
+| | Run keyword | ${lxc_name}.Create container | force_create=${TRUE}
| | Run keyword | ${lxc_name}.Mount host dir in container
-| | Run keyword | ${lxc_name}.Container cpuset cpus | ${lxc_cpus}
+| | Run keyword | ${lxc_name}.Container cpuset cpus | 0,${lxc_cpus}
| Create '${nr}' LXC containers on '${dut}' node
| | [Documentation] | Create and start multiple lxc containers on DUT node.
@@ -136,7 +137,7 @@
| | Import Library | resources.libraries.python.LXCUtils
| | ... | container_name=${lxc_name} | WITH NAME | ${lxc_name}
| | Run keyword | ${lxc_name}.Set node | ${dut_node}
-| | Run keyword | ${lxc_name}.Container destroy
+| | Run keyword | ${lxc_name}.Destroy container
| Destroy '${nr}' LXC containers on '${dut}' node
| | [Documentation] | Stop and destroy multiple LXC containers on DUT node.
@@ -223,6 +224,9 @@
| | Run keyword | ${lxc_name}_conf.Set node | ${dut_node}
| | Run keyword | ${lxc_name}_conf.Add unix CLI listen
| | Run keyword | ${lxc_name}_conf.Add unix nodaemon
+| | Run keyword | ${lxc_name}_conf.Add unix exec | "/tmp/running.exec"
+| | Run keyword | ${lxc_name}_conf.Add CPU main core | "0"
+| | Run keyword | ${lxc_name}_conf.Add CPU corelist workers | ${lxc_cpus}
| | Run keyword | ${lxc_name}_conf.Add plugin disable | "dpdk_plugin.so"
| | Run Keyword | ${lxc_name}_conf.Apply config LXC | ${lxc_name}