VAT-to-PAPI: ContainerUtils 18/19918/7
authorTibor Frank <tifrank@cisco.com>
Mon, 3 Jun 2019 07:23:15 +0000 (09:23 +0200)
committerJan Gelety <jgelety@cisco.com>
Tue, 4 Jun 2019 12:03:30 +0000 (12:03 +0000)
Change-Id: Id186c3c280a6b876b8212e01b261ad8c65e5f40c
Signed-off-by: Tibor Frank <tifrank@cisco.com>
12 files changed:
resources/libraries/python/Constants.py
resources/libraries/python/ContainerUtils.py
resources/templates/container/memif_create_chain_functional.exec [new file with mode: 0644]
resources/templates/container/memif_create_chain_ip4.exec [new file with mode: 0644]
resources/templates/container/memif_create_chain_l2xc.exec [new file with mode: 0644]
resources/templates/container/memif_create_cross_horizon.exec [new file with mode: 0644]
resources/templates/container/memif_create_pipeline_ip4.exec [new file with mode: 0644]
resources/templates/vat/memif_create_chain_functional.vat [deleted file]
resources/templates/vat/memif_create_chain_ip4.vat [deleted file]
resources/templates/vat/memif_create_chain_l2xc.vat [deleted file]
resources/templates/vat/memif_create_cross_horizon.vat [deleted file]
resources/templates/vat/memif_create_pipeline_ip4.vat [deleted file]

index 4b8344a..62c5693 100644 (file)
@@ -40,6 +40,9 @@ class Constants(object):
     # KernelVM templates location
     RESOURCES_TPL_VM = 'resources/templates/vm'
 
+    # Container templates location
+    RESOURCES_TPL_CONTAINER = 'resources/templates/container'
+
     # OpenVPP VAT binary name
     VAT_BIN_NAME = 'vpp_api_test'
 
index 1530657..7d04b06 100644 (file)
@@ -16,6 +16,7 @@
 
 """Library to manipulate Containers."""
 
+from string import Template
 from collections import OrderedDict, Counter
 
 from resources.libraries.python.ssh import SSH
@@ -211,7 +212,7 @@ class ContainerManager(object):
         """
         self.engine.create_vpp_startup_config()
         self.engine.create_vpp_exec_config(
-            'memif_create_chain_l2xc.vat',
+            'memif_create_chain_l2xc.exec',
             mid1=kwargs['mid1'], mid2=kwargs['mid2'],
             sid1=kwargs['sid1'], sid2=kwargs['sid2'],
             socket1='{guest_dir}/memif-{c.name}-{sid1}'.
@@ -237,7 +238,7 @@ class ContainerManager(object):
                 self.engine.container.node, kwargs['dut2_if'])
         self.engine.create_vpp_startup_config_dpdk_dev(if_pci)
         self.engine.create_vpp_exec_config(
-            'memif_create_cross_horizon.vat',
+            'memif_create_cross_horizon.exec',
             mid1=kwargs['mid1'], sid1=kwargs['sid1'], if_name=if_name,
             socket1='{guest_dir}/memif-{c.name}-{sid1}'.
             format(c=self.engine.container, **kwargs))
@@ -250,7 +251,7 @@ class ContainerManager(object):
         """
         self.engine.create_vpp_startup_config_func_dev()
         self.engine.create_vpp_exec_config(
-            'memif_create_chain_functional.vat',
+            'memif_create_chain_functional.exec',
             mid1=kwargs['mid1'], mid2=kwargs['mid2'],
             sid1=kwargs['sid1'], sid2=kwargs['sid2'],
             socket1='{guest_dir}/memif-{c.name}-{sid1}'.
@@ -274,7 +275,7 @@ class ContainerManager(object):
             if (kwargs['mid2'] - 1) % kwargs['nodes'] + 1 == kwargs['nodes'] \
             else '52:54:00:00:{0:02X}:01'.format(kwargs['mid2'] + 1)
         self.engine.create_vpp_exec_config(
-            'memif_create_chain_ip4.vat',
+            'memif_create_chain_ip4.exec',
             mid1=kwargs['mid1'], mid2=kwargs['mid2'],
             sid1=kwargs['sid1'], sid2=kwargs['sid2'],
             socket1='{guest_dir}/memif-{c.name}-{sid1}'.
@@ -319,7 +320,7 @@ class ContainerManager(object):
             format(c=self.engine.container, **kwargs)
 
         self.engine.create_vpp_exec_config(
-            'memif_create_pipeline_ip4.vat',
+            'memif_create_pipeline_ip4.exec',
             mid1=kwargs['mid1'], mid2=kwargs['mid2'],
             sid1=kwargs['sid1'], sid2=kwargs['sid2'],
             socket1=socket1, socket2=socket2, role1=role1, role2=role2,
@@ -504,23 +505,23 @@ class ContainerEngine(object):
         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):
+    def create_vpp_exec_config(self, template_file, **kwargs):
         """Create VPP exec configuration on container.
 
-        :param vat_template_file: File name of a VAT template script.
-        :param kwargs: Parameters for VAT script.
-        :type vat_template_file: str
+        :param template_file: File name of a template script.
+        :param kwargs: Parameters for script.
+        :type template_file: str
         :type kwargs: dict
         """
-        vat_file_path = '{p}/{f}'.format(p=Constants.RESOURCES_TPL_VAT,
-                                         f=vat_template_file)
+        running = '/tmp/running.exec'
 
-        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(**kwargs)
-                self.execute('echo "{c}" >> /tmp/running.exec'
-                             .format(c=vat_cmd.replace('\n', '')))
+        template = '{res}/{tpl}'.format(
+            res=Constants.RESOURCES_TPL_CONTAINER, tpl=template_file)
+
+        with open(template, 'r') as src_file:
+            src = Template(src_file.read())
+            self.execute('echo "{out}" > {running}'.format(
+                out=src.safe_substitute(**kwargs), running=running))
 
     def is_container_running(self):
         """Check if container is running."""
@@ -846,7 +847,7 @@ class Docker(ContainerEngine):
 
         :param command: Command to run inside container.
         :type command: str
-        :raises RuntimeError: If runnig the command in a container failed.
+        :raises RuntimeError: If running the command in a container failed.
         """
         cmd = "docker exec --interactive {c.name} /bin/sh -c '{command}; "\
             "exit $?'".format(c=self.container, command=command)
diff --git a/resources/templates/container/memif_create_chain_functional.exec b/resources/templates/container/memif_create_chain_functional.exec
new file mode 100644 (file)
index 0000000..1f39093
--- /dev/null
@@ -0,0 +1,12 @@
+create memif socket id $sid1 filename $socket1
+create interface memif id $mid1 socket-id $sid1 master
+set interface rx-mode memif$sid1/$mid1 $rx_mode
+set int state memif$sid1/$mid1 up
+
+create memif socket id $sid2 filename $socket2
+create interface memif id $mid2 socket-id $sid2 master
+set interface rx-mode memif$sid2/$mid2 $rx_mode
+set int state memif$sid2/$mid2 up
+
+set interface l2 xconnect memif$sid2/$mid2 memif$sid1/$mid1
+set interface l2 xconnect memif$sid1/$mid1 memif$sid2/$mid2
diff --git a/resources/templates/container/memif_create_chain_ip4.exec b/resources/templates/container/memif_create_chain_ip4.exec
new file mode 100644 (file)
index 0000000..be425f5
--- /dev/null
@@ -0,0 +1,15 @@
+create memif socket id $sid1 filename $socket1
+create interface memif id $mid1 socket-id $sid1 hw-addr $mac1 master
+set interface ip address memif$sid1/$mid1 1.1.$sid1.1/24
+set interface state memif$sid1/$mid1 up
+
+create memif socket id $sid2 filename $socket2
+create interface memif id $mid2 socket-id $sid2 hw-addr $mac2 master
+set interface ip address memif$sid2/$mid2 1.1.$sid2.1/24
+set interface state memif$sid2/$mid2 up
+
+set ip arp static memif$sid1/$mid1 1.1.$sid1.2 $vif1_mac
+set ip arp static memif$sid2/$mid2 1.1.$sid2.2 $vif2_mac
+
+ip route add 10.0.0.0/8 via 1.1.$sid1.2
+ip route add 20.0.0.0/8 via 1.1.$sid2.2
diff --git a/resources/templates/container/memif_create_chain_l2xc.exec b/resources/templates/container/memif_create_chain_l2xc.exec
new file mode 100644 (file)
index 0000000..6b998d8
--- /dev/null
@@ -0,0 +1,10 @@
+create memif socket id $sid1 filename $socket1
+create interface memif id $mid1 socket-id $sid1 master
+set int state memif$sid1/$mid1 up
+
+create memif socket id $sid2 filename $socket2
+create interface memif id $mid2 socket-id $sid2 master
+set int state memif$sid2/$mid2 up
+
+set interface l2 xconnect memif$sid2/$mid2 memif$sid1/$mid1
+set interface l2 xconnect memif$sid1/$mid1 memif$sid2/$mid2
diff --git a/resources/templates/container/memif_create_cross_horizon.exec b/resources/templates/container/memif_create_cross_horizon.exec
new file mode 100644 (file)
index 0000000..4129aab
--- /dev/null
@@ -0,0 +1,8 @@
+create memif socket id $sid1 filename $socket1
+create interface memif id $mid1 socket-id $sid1 master
+
+set int state memif$sid1/$mid1 up
+set int state $if_name up
+
+set interface l2 xconnect $if_name memif$sid1/$mid1
+set interface l2 xconnect memif$sid1/$mid1 $if_name
diff --git a/resources/templates/container/memif_create_pipeline_ip4.exec b/resources/templates/container/memif_create_pipeline_ip4.exec
new file mode 100644 (file)
index 0000000..f0da245
--- /dev/null
@@ -0,0 +1,15 @@
+create memif socket id $sid1 filename $socket1
+create interface memif id $mid1 socket-id $sid1 hw-addr $mac1 $role1
+set interface ip address memif$sid1/$mid1 1.1.$sid1.1/24
+set interface state memif$sid1/$mid1 up
+
+create memif socket id $sid2 filename $socket2
+create interface memif id $mid2 socket-id $sid2 hw-addr $mac2 $role2
+set interface ip address memif$sid2/$mid2 1.1.$sid2.1/24
+set interface state memif$sid2/$mid2 up
+
+set ip arp static memif$sid1/$mid1 1.1.$sid1.2 $vif1_mac
+set ip arp static memif$sid2/$mid2 1.1.$sid2.2 $vif2_mac
+
+ip route add 10.0.0.0/8 via 1.1.$sid1.2
+ip route add 20.0.0.0/8 via 1.1.$sid2.2
diff --git a/resources/templates/vat/memif_create_chain_functional.vat b/resources/templates/vat/memif_create_chain_functional.vat
deleted file mode 100644 (file)
index c5db093..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-create memif socket id {sid1} filename {socket1}
-create interface memif id {mid1} socket-id {sid1} master
-set interface rx-mode memif{sid1}/{mid1} {rx_mode}
-set int state memif{sid1}/{mid1} up
-
-create memif socket id {sid2} filename {socket2}
-create interface memif id {mid2} socket-id {sid2} master
-set interface rx-mode memif{sid2}/{mid2} {rx_mode}
-set int state memif{sid2}/{mid2} up
-
-set interface l2 xconnect memif{sid2}/{mid2} memif{sid1}/{mid1}
-set interface l2 xconnect memif{sid1}/{mid1} memif{sid2}/{mid2}
diff --git a/resources/templates/vat/memif_create_chain_ip4.vat b/resources/templates/vat/memif_create_chain_ip4.vat
deleted file mode 100644 (file)
index 1c9205a..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-create memif socket id {sid1} filename {socket1}
-create interface memif id {mid1} socket-id {sid1} hw-addr {mac1} master
-set interface ip address memif{sid1}/{mid1} 1.1.{sid1}.1/24
-set interface state memif{sid1}/{mid1} up
-
-create memif socket id {sid2} filename {socket2}
-create interface memif id {mid2} socket-id {sid2} hw-addr {mac2} master
-set interface ip address memif{sid2}/{mid2} 1.1.{sid2}.1/24
-set interface state memif{sid2}/{mid2} up
-
-set ip arp static memif{sid1}/{mid1} 1.1.{sid1}.2 {vif1_mac}
-set ip arp static memif{sid2}/{mid2} 1.1.{sid2}.2 {vif2_mac}
-
-ip route add 10.0.0.0/8 via 1.1.{sid1}.2
-ip route add 20.0.0.0/8 via 1.1.{sid2}.2
diff --git a/resources/templates/vat/memif_create_chain_l2xc.vat b/resources/templates/vat/memif_create_chain_l2xc.vat
deleted file mode 100644 (file)
index 5275f84..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-create memif socket id {sid1} filename {socket1}
-create interface memif id {mid1} socket-id {sid1} master
-set int state memif{sid1}/{mid1} up
-
-create memif socket id {sid2} filename {socket2}
-create interface memif id {mid2} socket-id {sid2} master
-set int state memif{sid2}/{mid2} up
-
-set interface l2 xconnect memif{sid2}/{mid2} memif{sid1}/{mid1}
-set interface l2 xconnect memif{sid1}/{mid1} memif{sid2}/{mid2}
diff --git a/resources/templates/vat/memif_create_cross_horizon.vat b/resources/templates/vat/memif_create_cross_horizon.vat
deleted file mode 100644 (file)
index 40ff2c3..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-create memif socket id {sid1} filename {socket1}
-create interface memif id {mid1} socket-id {sid1} master
-
-set int state memif{sid1}/{mid1} up
-set int state {if_name} up
-
-set interface l2 xconnect {if_name} memif{sid1}/{mid1}
-set interface l2 xconnect memif{sid1}/{mid1} {if_name}
diff --git a/resources/templates/vat/memif_create_pipeline_ip4.vat b/resources/templates/vat/memif_create_pipeline_ip4.vat
deleted file mode 100644 (file)
index 1875a70..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-create memif socket id {sid1} filename {socket1}
-create interface memif id {mid1} socket-id {sid1} hw-addr {mac1} {role1}
-set interface ip address memif{sid1}/{mid1} 1.1.{sid1}.1/24
-set interface state memif{sid1}/{mid1} up
-
-create memif socket id {sid2} filename {socket2}
-create interface memif id {mid2} socket-id {sid2} hw-addr {mac2} {role2}
-set interface ip address memif{sid2}/{mid2} 1.1.{sid2}.1/24
-set interface state memif{sid2}/{mid2} up
-
-set ip arp static memif{sid1}/{mid1} 1.1.{sid1}.2 {vif1_mac}
-set ip arp static memif{sid2}/{mid2} 1.1.{sid2}.2 {vif2_mac}
-
-ip route add 10.0.0.0/8 via 1.1.{sid1}.2
-ip route add 20.0.0.0/8 via 1.1.{sid2}.2

©2016 FD.io a Linux Foundation Collaborative Project. All Rights Reserved.
Linux Foundation is a registered trademark of The Linux Foundation. Linux is a registered trademark of Linus Torvalds.
Please see our privacy policy and terms of use.