Revert "fix(jobspec): Delete ipsec nfv density tests"
[csit.git] / resources / libraries / python / ContainerUtils.py
index 7ec8258..fc32248 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (c) 2022 Cisco and/or its affiliates.
+# Copyright (c) 2024 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:
@@ -205,8 +205,8 @@ class ContainerManager:
         dut_cnt = len(
             Counter(
                 [
-                    self.containers[container].node[u"host"]
-                    for container in self.containers
+                    f"{container.node['host']}{container.node['port']}"
+                    for container in self.containers.values()
                 ]
             )
         )
@@ -256,6 +256,11 @@ class ContainerManager:
                 self._configure_vpp_chain_ipsec(
                     mid1=mid1, mid2=mid2, sid1=sid1, sid2=sid2,
                     guest_dir=guest_dir, nf_instance=idx, **kwargs)
+            elif chain_topology == u"chain_dma":
+                self._configure_vpp_chain_dma(
+                    mid1=mid1, mid2=mid2, sid1=sid1, sid2=sid2,
+                    guest_dir=guest_dir, **kwargs
+                )
             else:
                 raise RuntimeError(
                     f"Container topology {chain_topology} not implemented"
@@ -278,6 +283,25 @@ class ContainerManager:
             f"{self.engine.container.name}-{kwargs[u'sid2']}"
         )
 
+    def _configure_vpp_chain_dma(self, **kwargs):
+        """Configure VPP in chain topology with l2xc (dma).
+
+        :param kwargs: Named parameters.
+        :type kwargs: dict
+        """
+        dma_wqs = kwargs[f"dma_wqs"]
+        self.engine.create_vpp_startup_config_dma(dma_wqs)
+
+        self.engine.create_vpp_exec_config(
+            u"memif_create_chain_dma.exec",
+            mid1=kwargs[u"mid1"], mid2=kwargs[u"mid2"],
+            sid1=kwargs[u"sid1"], sid2=kwargs[u"sid2"],
+            socket1=f"{kwargs[u'guest_dir']}/memif-"
+            f"{self.engine.container.name}-{kwargs[u'sid1']}",
+            socket2=f"{kwargs[u'guest_dir']}/memif-"
+            f"{self.engine.container.name}-{kwargs[u'sid2']}"
+        )
+
     def _configure_vpp_cross_horiz(self, **kwargs):
         """Configure VPP in cross horizontal topology (single memif).
 
@@ -581,8 +605,7 @@ class ContainerEngine:
     def start_vpp(self, verify=True):
         """Start VPP inside a container."""
         self.execute(
-            u"setsid /usr/bin/vpp -c /etc/vpp/startup.conf "
-            u">/tmp/vppd.log 2>&1 < /dev/null &")
+            u"/usr/bin/vpp -c /etc/vpp/startup.conf")
 
         topo_instance = BuiltIn().get_library_instance(
             u"resources.libraries.python.topology.Topology"
@@ -636,7 +659,7 @@ class ContainerEngine:
                 # Execute puts the command into single quotes,
                 # so inner arguments are enclosed in qouble quotes here.
                 self.execute(
-                    u'vppctl show pci 2>&1 | '
+                    u'/usr/bin/vppctl show pci 2>&1 | '
                     u'fgrep -v "Connection refused" | '
                     u'fgrep -v "No such file or directory"'
                 )
@@ -694,7 +717,6 @@ class ContainerEngine:
         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(u"/tmp/running.exec")
         vpp_config.add_socksvr(socket=Constants.SOCKSVR_PATH)
         if cpuset_cpus:
@@ -770,6 +792,22 @@ class ContainerEngine:
             f'echo "{vpp_config.get_config_str()}" | tee /etc/vpp/startup.conf'
         )
 
+    def create_vpp_startup_config_dma(self, dma_devices):
+        """Create startup configuration of VPP DMA.
+
+        :param dma_devices: DMA devices list.
+        :type dma_devices: list
+        """
+        vpp_config = self.create_base_vpp_startup_config()
+        vpp_config.add_plugin(u"enable", u"dma_intel_plugin.so")
+        vpp_config.add_dma_dev(dma_devices)
+
+        # Apply configuration
+        self.execute(u"mkdir -p /etc/vpp/")
+        self.execute(
+            f'echo "{vpp_config.get_config_str()}" | tee /etc/vpp/startup.conf'
+        )
+
     def create_vpp_exec_config(self, template_file, **kwargs):
         """Create VPP exec configuration on container.
 
@@ -807,18 +845,6 @@ class ContainerEngine:
         :type name: str
         :raises RuntimeError: If applying cgroup settings via cgset failed.
         """
-        ret, _, _ = self.container.ssh.exec_command_sudo(
-            u"cgset -r cpuset.cpu_exclusive=0 /"
-        )
-        if int(ret) != 0:
-            raise RuntimeError(u"Failed to apply cgroup settings.")
-
-        ret, _, _ = self.container.ssh.exec_command_sudo(
-            u"cgset -r cpuset.mem_exclusive=0 /"
-        )
-        if int(ret) != 0:
-            raise RuntimeError(u"Failed to apply cgroup settings.")
-
         ret, _, _ = self.container.ssh.exec_command_sudo(
             f"cgcreate -g cpuset:/{name}"
         )
@@ -826,13 +852,13 @@ class ContainerEngine:
             raise RuntimeError(u"Failed to copy cgroup settings from root.")
 
         ret, _, _ = self.container.ssh.exec_command_sudo(
-            f"cgset -r cpuset.cpu_exclusive=0 /{name}"
+            f"cgset -r cpuset.cpus=0 /{name}"
         )
         if int(ret) != 0:
             raise RuntimeError(u"Failed to apply cgroup settings.")
 
         ret, _, _ = self.container.ssh.exec_command_sudo(
-            f"cgset -r cpuset.mem_exclusive=0 /{name}"
+            f"cgset -r cpuset.mems=0 /{name}"
         )
         if int(ret) != 0:
             raise RuntimeError(u"Failed to apply cgroup settings.")
@@ -863,7 +889,7 @@ class LXC(ContainerEngine):
             else u"amd64"
 
         image = self.container.image if self.container.image \
-            else f"-d ubuntu -r focal -a {target_arch}"
+            else f"-d ubuntu -r jammy -a {target_arch}"
 
         cmd = f"lxc-create -t download --name {self.container.name} " \
             f"-- {image} --no-validate"
@@ -1128,8 +1154,8 @@ class Docker(ContainerEngine):
             if self.container.mnt else u""
 
         cmd = f"docker run --privileged --detach --interactive --tty --rm " \
-            f"--cgroup-parent docker {cpuset_cpus} {cpuset_mems} {publish} " \
-            f"{env} {volume} --name {self.container.name} " \
+            f"--cgroup-parent docker.slice {cpuset_cpus} {cpuset_mems} " \
+            f"{publish} {env} {volume} --name {self.container.name} " \
             f"{self.container.image} {command}"
 
         ret, _, _ = self.container.ssh.exec_command_sudo(cmd)