[spp] [PATCH 15/29] tools/sppc: setup with docker opts in SPP pri
Yasufumi Ogawa
yasufum.o at gmail.com
Tue Feb 25 11:34:32 CET 2020
spp_primary launcher only does not use setup_docker_opts() because some
options are different from others, but almost similar actually. This
update is to merge primary's setup process into the method.
As a refactoring, name of container image is excluded from the result of
the method because it is not a option, but a mandatory param.
Signed-off-by: Yasufumi Ogawa <yasufum.o at gmail.com>
---
tools/sppc/app/spp-primary.py | 37 ++++++++++++-----------------------
tools/sppc/lib/app_helper.py | 33 +++++++++++++++++++++----------
2 files changed, 35 insertions(+), 35 deletions(-)
diff --git a/tools/sppc/app/spp-primary.py b/tools/sppc/app/spp-primary.py
index 3e5b2ba..25f94ef 100755
--- a/tools/sppc/app/spp-primary.py
+++ b/tools/sppc/app/spp-primary.py
@@ -18,17 +18,9 @@ def parse_args():
description="Launcher for spp-primary application container")
parser = app_helper.add_eal_args(parser)
- parser = app_helper.add_sppc_args(parser)
+ parser = app_helper.add_appc_args(parser)
# Application specific arguments
- parser.add_argument(
- '-d', '--dev-uids',
- type=str,
- help='Virtual devices of SPP in resource UID format')
- parser.add_argument(
- '-v', '--volume',
- nargs='*', type=str,
- help='Bind mount a volume (for docker)')
parser.add_argument(
'-n', '--nof-ring',
type=int,
@@ -48,6 +40,7 @@ def parse_args():
default=5555,
help="Port for primary of spp-ctl")
+ parser = app_helper.add_sppc_args(parser)
return parser.parse_args()
@@ -58,7 +51,6 @@ def main():
# Setup docker command.
docker_cmd = ['sudo', 'docker', 'run', '\\']
- docker_opts = []
# Container image name such as 'sppc/spp-ubuntu:18.04'
if args.container_image is not None:
@@ -68,18 +60,6 @@ def main():
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', '\\']
-
- docker_opts += [
- '--privileged', '\\', # must be privileged
- '-v', '/dev/hugepages:/dev/hugepages', '\\',
- '-v', '/var/run/:/var/run/', '\\',
- '-v', '/tmp:/tmp', '\\']
-
# Setup devices with given device UIDs.
dev_uids_list = None
sock_files = []
@@ -91,8 +71,13 @@ def main():
dev_uids_list = args.dev_uids.split(',')
sock_files = app_helper.sock_files(dev_uids_list, is_spp_pri=True)
- docker_opts += [
- container_image, '\\']
+ app_opts = [
+ '-v', '/var/run/:/var/run/', '\\',
+ '-v', '/tmp:/tmp', '\\',
+ '--net', 'host', '\\']
+
+ docker_opts = app_helper.setup_docker_opts(
+ args, None, app_opts)
# Setup spp primary command.
spp_cmd = [app_name, '\\']
@@ -118,7 +103,9 @@ def main():
else:
spp_opts += ['-s', '{}:{}'.format(ctl_ip, args.ctl_port), '\\']
- cmds = docker_cmd + docker_opts + spp_cmd + eal_opts + spp_opts
+ cmds = docker_cmd + docker_opts + [container_image] + spp_cmd + \
+ eal_opts + spp_opts
+
if cmds[-1] == '\\':
cmds.pop()
common.print_pretty_commands(cmds)
diff --git a/tools/sppc/lib/app_helper.py b/tools/sppc/lib/app_helper.py
index 411b3f5..f5c65f8 100644
--- a/tools/sppc/lib/app_helper.py
+++ b/tools/sppc/lib/app_helper.py
@@ -231,7 +231,18 @@ def setup_eal_opts(args, file_prefix, proc_type='auto', is_spp_pri=False,
return eal_opts
-def setup_docker_opts(args, container_image, socks, workdir=None):
+def setup_docker_opts(args, socks=None, app_opts=None, workdir=None):
+ """Return docker options as a list.
+
+ socks must be None if process behaves as master role, such as
+ spp_primary, or failed to initialize the process.
+
+ :param args: Parsed args with argparse
+ :param socks: Socket files, it must be None in spp-primary
+ :param app_opts: Application specific option
+ :returns: A list of docker options
+ """
+
docker_opts = []
if args.foreground is True:
@@ -239,24 +250,26 @@ def setup_docker_opts(args, container_image, socks, workdir=None):
else:
docker_opts = ['-d', '\\']
- if workdir is not None:
- docker_opts += ['--workdir', workdir, '\\']
+ if args.no_privileged is not True:
+ docker_opts += ['--privileged', '\\']
+
+ docker_opts += [
+ '-v', '/dev/hugepages:/dev/hugepages', '\\']
+
+ if app_opts is not None:
+ docker_opts += app_opts
+
+ if args.workdir is not None:
+ docker_opts += ['--workdir', args.workdir, '\\']
if args.name is not None:
docker_opts += ['--name', args.name, '\\']
- if args.no_privileged is not True:
- docker_opts += ['--privileged', '\\']
-
if socks is not None:
for sock in socks:
docker_opts += [
'-v', '%s:%s' % (sock['host'], sock['guest']), '\\']
- docker_opts += [
- '-v', '/dev/hugepages:/dev/hugepages', '\\',
- container_image, '\\']
-
return docker_opts
--
2.17.1
More information about the spp
mailing list