Soft Patch Panel
 help / color / mirror / Atom feed
From: Yasufumi Ogawa <yasufum.o@gmail.com>
To: spp@dpdk.org, ferruh.yigit@intel.com, yasufum.o@gmail.com
Subject: [spp] [PATCH 3/5] tools/sppc: refactor container image names
Date: Thu, 13 Feb 2020 21:10:27 +0900
Message-ID: <20200213121029.27702-4-yasufum.o@gmail.com> (raw)
In-Reply-To: <20200213121029.27702-1-yasufum.o@gmail.com>

A set of base names of container image is defined in `conf/env.py`
considering user uses any of container image name. However, build script
was changed to create image with default name and it is modified via
options. It means that user doesn't need to define the name anymore.
This update is to move the definition of base names from conf to common
because it is no need to edit usually.

Signed-off-by: Yasufumi Ogawa <yasufum.o@gmail.com>
---
 tools/sppc/app/helloworld.py    | 12 +++++++++---
 tools/sppc/app/l2fwd.py         | 12 +++++++++---
 tools/sppc/app/l3fwd-acl.py     | 12 +++++++++---
 tools/sppc/app/l3fwd.py         | 12 +++++++++---
 tools/sppc/app/load-balancer.py | 12 +++++++++---
 tools/sppc/app/pktgen.py        | 12 +++++++++---
 tools/sppc/app/spp-nfv.py       | 20 ++++++++------------
 tools/sppc/app/spp-primary.py   | 20 ++++++++------------
 tools/sppc/app/suricata.py      | 12 +++++++++---
 tools/sppc/app/testpmd.py       | 12 +++++++++---
 tools/sppc/build/main.py        |  2 +-
 tools/sppc/conf/env.py          |  8 --------
 tools/sppc/lib/app_helper.py    | 15 +--------------
 tools/sppc/lib/common.py        |  9 ++++++++-
 14 files changed, 98 insertions(+), 72 deletions(-)

diff --git a/tools/sppc/app/helloworld.py b/tools/sppc/app/helloworld.py
index 2d2837b..d155b64 100755
--- a/tools/sppc/app/helloworld.py
+++ b/tools/sppc/app/helloworld.py
@@ -13,8 +13,6 @@ from conf import env
 from lib import app_helper
 from lib import common
 
-target_name = 'dpdk'
-
 
 def parse_args():
     parser = argparse.ArgumentParser(
@@ -32,6 +30,14 @@ def parse_args():
 def main():
     args = parse_args()
 
+    # Container image name such as 'sppc/dpdk-ubuntu:18.04'
+    if args.container_image is not None:
+        container_image = args.container_image
+    else:
+        container_image = common.container_img_name(
+            common.IMG_BASE_NAMES['dpdk'],
+            args.dist_name, args.dist_ver)
+
     # Check for other mandatory opitons.
     if args.dev_ids is None:
         common.error_exit('--dev-ids')
@@ -43,7 +49,7 @@ def main():
     # Setup docker command.
     docker_cmd = ['sudo', 'docker', 'run', '\\']
     docker_opts = app_helper.setup_docker_opts(
-        args, target_name, sock_files)
+        args, container_image, sock_files)
 
     # Setup helloworld run on container.
     cmd_path = '%s/examples/helloworld/%s/helloworld' % (
diff --git a/tools/sppc/app/l2fwd.py b/tools/sppc/app/l2fwd.py
index 90a1270..a658d6c 100755
--- a/tools/sppc/app/l2fwd.py
+++ b/tools/sppc/app/l2fwd.py
@@ -13,8 +13,6 @@ from conf import env
 from lib import app_helper
 from lib import common
 
-target_name = 'dpdk'
-
 
 def parse_args():
     parser = argparse.ArgumentParser(
@@ -36,6 +34,14 @@ def parse_args():
 def main():
     args = parse_args()
 
+    # Container image name such as 'sppc/dpdk-ubuntu:18.04'
+    if args.container_image is not None:
+        container_image = args.container_image
+    else:
+        container_image = common.container_img_name(
+            common.IMG_BASE_NAMES['dpdk'],
+            args.dist_name, args.dist_ver)
+
     # Check for other mandatory opitons.
     if args.port_mask is None:
         common.error_exit('--port-mask')
@@ -49,7 +55,7 @@ def main():
     # Setup docker command.
     docker_cmd = ['sudo', 'docker', 'run', '\\']
     docker_opts = app_helper.setup_docker_opts(
-        args, target_name, sock_files)
+        args, container_image, sock_files)
 
     # Check if the number of ports is even for l2fwd.
     nof_ports = app_helper.count_ports(args.port_mask)
diff --git a/tools/sppc/app/l3fwd-acl.py b/tools/sppc/app/l3fwd-acl.py
index 6a7afff..d1e2178 100755
--- a/tools/sppc/app/l3fwd-acl.py
+++ b/tools/sppc/app/l3fwd-acl.py
@@ -14,8 +14,6 @@ from conf import env
 from lib import app_helper
 from lib import common
 
-target_name = 'dpdk'
-
 
 def parse_args():
     parser = argparse.ArgumentParser(
@@ -140,6 +138,14 @@ def check_jumbo_opt(enable_jumbo, max_pkt_len):
 def main():
     args = parse_args()
 
+    # Container image name such as 'sppc/dpdk-ubuntu:18.04'
+    if args.container_image is not None:
+        container_image = args.container_image
+    else:
+        container_image = common.container_img_name(
+            common.IMG_BASE_NAMES['dpdk'],
+            args.dist_name, args.dist_ver)
+
     # Check for other mandatory opitons.
     if args.port_mask is None:
         common.error_exit('--port-mask')
@@ -153,7 +159,7 @@ def main():
     # Setup docker command.
     docker_cmd = ['sudo', 'docker', 'run', '\\']
     docker_opts = app_helper.setup_docker_opts(
-        args, target_name, sock_files)
+        args, container_image, sock_files)
 
     # Parse vhost device IDs and Check the number of devices is
     # sufficient for port mask.
diff --git a/tools/sppc/app/l3fwd.py b/tools/sppc/app/l3fwd.py
index 1732648..131eb66 100755
--- a/tools/sppc/app/l3fwd.py
+++ b/tools/sppc/app/l3fwd.py
@@ -14,8 +14,6 @@ from conf import env
 from lib import app_helper
 from lib import common
 
-target_name = 'dpdk'
-
 
 def parse_args():
     parser = argparse.ArgumentParser(
@@ -175,6 +173,14 @@ def check_eth_dest(eth_dests):
 def main():
     args = parse_args()
 
+    # Container image name such as 'sppc/dpdk-ubuntu:18.04'
+    if args.container_image is not None:
+        container_image = args.container_image
+    else:
+        container_image = common.container_img_name(
+            common.IMG_BASE_NAMES['dpdk'],
+            args.dist_name, args.dist_ver)
+
     # Check for other mandatory opitons.
     if args.port_mask is None:
         common.error_exit('--port-mask')
@@ -188,7 +194,7 @@ def main():
     # Setup docker command.
     docker_cmd = ['sudo', 'docker', 'run', '\\']
     docker_opts = app_helper.setup_docker_opts(
-        args, target_name, sock_files)
+        args, container_image, sock_files)
 
     # Parse vhost device IDs and Check the number of devices is
     # sufficient for port mask.
diff --git a/tools/sppc/app/load-balancer.py b/tools/sppc/app/load-balancer.py
index 5ec156e..687bfe5 100755
--- a/tools/sppc/app/load-balancer.py
+++ b/tools/sppc/app/load-balancer.py
@@ -13,8 +13,6 @@ from conf import env
 from lib import app_helper
 from lib import common
 
-target_name = 'dpdk'
-
 
 def parse_args():
     parser = argparse.ArgumentParser(
@@ -60,6 +58,14 @@ def parse_args():
 def main():
     args = parse_args()
 
+    # Container image name such as 'sppc/dpdk-ubuntu:18.04'
+    if args.container_image is not None:
+        container_image = args.container_image
+    else:
+        container_image = common.container_img_name(
+            common.IMG_BASE_NAMES['dpdk'],
+            args.dist_name, args.dist_ver)
+
     # Check for other mandatory opitons.
     if args.dev_ids is None:
         common.error_exit('--dev-ids')
@@ -71,7 +77,7 @@ def main():
     # Setup docker command.
     docker_cmd = ['sudo', 'docker', 'run', '\\']
     docker_opts = app_helper.setup_docker_opts(
-        args, target_name, sock_files)
+        args, container_image, sock_files)
 
     app_name = 'load_balancer'
     cmd_path = '%s/examples/%s/%s/%s' % (
diff --git a/tools/sppc/app/pktgen.py b/tools/sppc/app/pktgen.py
index e673b3b..319557c 100755
--- a/tools/sppc/app/pktgen.py
+++ b/tools/sppc/app/pktgen.py
@@ -13,8 +13,6 @@ from conf import env
 from lib import app_helper
 from lib import common
 
-target_name = 'pktgen'
-
 
 def parse_args():
     parser = argparse.ArgumentParser(
@@ -69,6 +67,14 @@ def parse_args():
 def main():
     args = parse_args()
 
+    # Container image name such as 'sppc/dpdk-ubuntu:18.04'
+    if args.container_image is not None:
+        container_image = args.container_image
+    else:
+        container_image = common.container_img_name(
+            common.IMG_BASE_NAMES['pktgen'],
+            args.dist_name, args.dist_ver)
+
     # Setup for vhost devices with given device IDs.
     dev_ids_list = app_helper.dev_ids_to_list(args.dev_ids)
     sock_files = app_helper.sock_files(dev_ids_list)
@@ -80,7 +86,7 @@ def main():
         wd = '/root/pktgen-dpdk'
     docker_cmd = ['sudo', 'docker', 'run', '\\']
     docker_opts = app_helper.setup_docker_opts(
-            args, target_name, sock_files, wd)
+            args, container_image, sock_files, wd)
 
     # Setup pktgen command
     pktgen_cmd = ['pktgen', '\\']
diff --git a/tools/sppc/app/spp-nfv.py b/tools/sppc/app/spp-nfv.py
index 100d20d..34d87c9 100755
--- a/tools/sppc/app/spp-nfv.py
+++ b/tools/sppc/app/spp-nfv.py
@@ -9,12 +9,9 @@ import sys
 
 work_dir = os.path.dirname(__file__)
 sys.path.append(work_dir + '/..')
-from conf import env
 from lib import app_helper
 from lib import common
 
-target_name = 'spp'
-
 
 def parse_args():
     parser = argparse.ArgumentParser(
@@ -49,21 +46,20 @@ def main():
     docker_cmd = ['sudo', 'docker', 'run', '\\']
     docker_opts = []
 
+    # Container image name such as 'sppc/spp-ubuntu:18.04'
+    if args.container_image is not None:
+        container_image = args.container_image
+    else:
+        container_image = common.container_img_name(
+            common.IMG_BASE_NAMES['spp'],
+            args.dist_name, args.dist_ver)
+
     # This container is running in backgroud in defualt.
     if args.foreground is not True:
         docker_opts += ['-d', '\\']
     else:
         docker_opts += ['-it', '\\']
 
-    if args.container_image is not None:
-        container_image = args.container_image
-    else:
-        # Container image name, for exp 'sppc/dpdk-ubuntu:18.04'
-        container_image = common.container_img_name(
-            env.CONTAINER_IMG_NAME[target_name],
-            args.dist_name,
-            args.dist_ver)
-
     docker_opts += [
         '--privileged', '\\',  # should be privileged
         '-v', '/dev/hugepages:/dev/hugepages', '\\',
diff --git a/tools/sppc/app/spp-primary.py b/tools/sppc/app/spp-primary.py
index ac7facd..7ebee68 100755
--- a/tools/sppc/app/spp-primary.py
+++ b/tools/sppc/app/spp-primary.py
@@ -9,12 +9,9 @@ import sys
 
 work_dir = os.path.dirname(__file__)
 sys.path.append(work_dir + '/..')
-from conf import env
 from lib import app_helper
 from lib import common
 
-target_name = 'spp'
-
 
 def parse_args():
     parser = argparse.ArgumentParser(
@@ -62,6 +59,14 @@ def main():
     docker_cmd = ['sudo', 'docker', 'run', '\\']
     docker_opts = []
 
+    # Container image name such as 'sppc/spp-ubuntu:18.04'
+    if args.container_image is not None:
+        container_image = args.container_image
+    else:
+        container_image = common.container_img_name(
+            common.IMG_BASE_NAMES['spp'],
+            args.dist_name, args.dist_ver)
+
     # This container is running in backgroud in defualt.
     if args.foreground is not True:
         docker_opts += ['-d', '\\']
@@ -93,15 +98,6 @@ def main():
     else:
         dev_vhost_ids = []
 
-    if args.container_image is not None:
-        container_image = args.container_image
-    else:
-        # Container image name, for exp 'sppc/dpdk-ubuntu:18.04'
-        container_image = common.container_img_name(
-            env.CONTAINER_IMG_NAME[target_name],
-            args.dist_name,
-            args.dist_ver)
-
     docker_opts += [
         container_image, '\\']
 
diff --git a/tools/sppc/app/suricata.py b/tools/sppc/app/suricata.py
index ad4e053..2ac01c0 100755
--- a/tools/sppc/app/suricata.py
+++ b/tools/sppc/app/suricata.py
@@ -13,8 +13,6 @@ from conf import env
 from lib import app_helper
 from lib import common
 
-target_name = 'suricata'
-
 
 def parse_args():
     parser = argparse.ArgumentParser(
@@ -29,6 +27,14 @@ def parse_args():
 def main():
     args = parse_args()
 
+    # Container image name such as 'sppc/suricata-ubuntu:18.04'
+    if args.container_image is not None:
+        container_image = args.container_image
+    else:
+        container_image = common.container_img_name(
+            common.IMG_BASE_NAMES['suricata'],
+            args.dist_name, args.dist_ver)
+
     # Check for other mandatory opitons.
     if args.dev_ids is None:
         common.error_exit('--dev-ids')
@@ -40,7 +46,7 @@ def main():
     # Setup docker command.
     docker_cmd = ['sudo', 'docker', 'run', '\\']
     docker_opts = app_helper.setup_docker_opts(
-        args, target_name, sock_files)
+        args, container_image, sock_files)
 
     cmd_path = '/bin/bash'
 
diff --git a/tools/sppc/app/testpmd.py b/tools/sppc/app/testpmd.py
index f6197fe..ff84335 100755
--- a/tools/sppc/app/testpmd.py
+++ b/tools/sppc/app/testpmd.py
@@ -14,8 +14,6 @@ from conf import env
 from lib import app_helper
 from lib import common
 
-target_name = 'dpdk'
-
 
 def parse_args():
     parser = argparse.ArgumentParser(
@@ -456,6 +454,14 @@ def not_supported_exit(opt):
 def main():
     args = parse_args()
 
+    # Container image name such as 'sppc/dpdk-ubuntu:18.04'
+    if args.container_image is not None:
+        container_image = args.container_image
+    else:
+        container_image = common.container_img_name(
+            common.IMG_BASE_NAMES['dpdk'],
+            args.dist_name, args.dist_ver)
+
     # Check for other mandatory opitons.
     if args.dev_ids is None:
         common.error_exit('--dev-ids')
@@ -467,7 +473,7 @@ def main():
     # Setup docker command.
     docker_cmd = ['sudo', 'docker', 'run', '\\']
     docker_opts = app_helper.setup_docker_opts(
-        args, target_name, sock_files)
+        args, container_image, sock_files)
 
     cmd_path = 'testpmd'
 
diff --git a/tools/sppc/build/main.py b/tools/sppc/build/main.py
index 578bc42..023ec82 100755
--- a/tools/sppc/build/main.py
+++ b/tools/sppc/build/main.py
@@ -116,7 +116,7 @@ def main():
             work_dir, args.dist_name, args.target)
         # Container image name, for exp 'sppc/dpdk-ubuntu:18.04'
         container_image = common.container_img_name(
-            env.CONTAINER_IMG_NAME[args.target],
+            common.IMG_BASE_NAMES[args.target],
             args.dist_name,
             args.dist_ver)
     else:
diff --git a/tools/sppc/conf/env.py b/tools/sppc/conf/env.py
index 3fb0c2d..dc0fe12 100644
--- a/tools/sppc/conf/env.py
+++ b/tools/sppc/conf/env.py
@@ -1,4 +1,3 @@
-#!/usr/bin/env python
 # SPDX-License-Identifier: BSD-3-Clause
 # Copyright(c) 2018 Nippon Telegraph and Telephone Corporation
 
@@ -6,10 +5,3 @@
 HOMEDIR = '/root'
 RTE_SDK = '/root/dpdk'
 RTE_TARGET = 'x86_64-native-linuxapp-gcc'
-
-CONTAINER_IMG_NAME = {
-    'dpdk': 'sppc/dpdk',
-    'pktgen': 'sppc/pktgen',
-    'spp': 'sppc/spp',
-    'suricata': 'sppc/suricata',
-    }
diff --git a/tools/sppc/lib/app_helper.py b/tools/sppc/lib/app_helper.py
index 85762ea..7ab1982 100644
--- a/tools/sppc/lib/app_helper.py
+++ b/tools/sppc/lib/app_helper.py
@@ -5,10 +5,6 @@ from . import common
 import os
 import sys
 
-work_dir = os.path.dirname(__file__)
-sys.path.append(work_dir + '/..')
-from conf import env
-
 
 def add_eal_args(parser, mem_size=1024, mem_channel=4):
     parser.add_argument(
@@ -143,7 +139,7 @@ def add_sppc_args(parser):
     return parser
 
 
-def setup_docker_opts(args, target_name, sock_files, workdir=None):
+def setup_docker_opts(args, container_image, sock_files, workdir=None):
     docker_opts = []
 
     if args.foreground is True:
@@ -161,15 +157,6 @@ def setup_docker_opts(args, target_name, sock_files, workdir=None):
         docker_opts += [
             '-v', '%s:%s' % (sock['host'], sock['guest']), '\\']
 
-    if args.container_image is not None:
-        container_image = args.container_image
-    else:
-        # Container image name, for exp 'sppc/dpdk-ubuntu:18.04'
-        container_image = common.container_img_name(
-            env.CONTAINER_IMG_NAME[target_name],
-            args.dist_name,
-            args.dist_ver)
-
     docker_opts += [
         '-v', '/dev/hugepages:/dev/hugepages', '\\',
         container_image, '\\']
diff --git a/tools/sppc/lib/common.py b/tools/sppc/lib/common.py
index a4903cd..657f812 100644
--- a/tools/sppc/lib/common.py
+++ b/tools/sppc/lib/common.py
@@ -2,6 +2,14 @@
 # Copyright(c) 2018 Nippon Telegraph and Telephone Corporation
 
 
+IMG_BASE_NAMES = {
+    'dpdk': 'sppc/dpdk',
+    'pktgen': 'sppc/pktgen',
+    'spp': 'sppc/spp',
+    'suricata': 'sppc/suricata',
+    }
+
+
 def print_pretty_commands(cmds):
     """Print given command in pretty format."""
 
@@ -13,7 +21,6 @@ def container_img_name(base, dist_name, dist_ver):
 
     Return the name of container image for '-t' of docker command
     such as 'sppc/dpdk-ubuntu:16.04' or 'sppc/spp-ubuntu:18.04'.
-    'base' is defined as 'env.CONTAINER_IMG_NAME' in lib module.
     """
     return '%s-%s:%s' % (base, dist_name, dist_ver)
 
-- 
2.17.1


  parent reply	other threads:[~2020-02-13 12:10 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-13 12:10 [spp] [PATCH 0/5] Update SPP Container tools Yasufumi Ogawa
2020-02-13 12:10 ` [spp] [PATCH 1/5] tools/sppc: python3 support for sppc apps Yasufumi Ogawa
2020-02-13 12:10 ` [spp] [PATCH 2/5] tools/sppc: check mandatory params for suricata Yasufumi Ogawa
2020-02-13 12:10 ` Yasufumi Ogawa [this message]
2020-02-13 12:10 ` [spp] [PATCH 4/5] tools/sppc: remove duplicated options Yasufumi Ogawa
2020-02-13 12:10 ` [spp] [PATCH 5/5] docs: update list of app container launchers Yasufumi Ogawa

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200213121029.27702-4-yasufum.o@gmail.com \
    --to=yasufum.o@gmail.com \
    --cc=ferruh.yigit@intel.com \
    --cc=spp@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Soft Patch Panel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://inbox.dpdk.org/spp/0 spp/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 spp spp/ https://inbox.dpdk.org/spp \
		spp@dpdk.org
	public-inbox-index spp

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://inbox.dpdk.org/inbox.dpdk.spp


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git