aboutsummaryrefslogtreecommitdiffstats
path: root/extras
diff options
context:
space:
mode:
authorPaul Vinciguerra <pvinci@vinciconsulting.com>2018-12-19 02:05:25 -0800
committerDave Barach <openvpp@barachs.net>2019-01-10 21:26:08 +0000
commit339bc6b51dd1ea7d783b211c485881ccb495fd0d (patch)
treed910b6bf0dcc49b675ac406cffd3e576e9090061 /extras
parent6ad7231c00287b7c1241c6e1dbbfda86f15798b4 (diff)
vpp_config: Rework for Python2/3 compatibility.
On ubuntu: $cd <basedir>/extras/vpp_config $./scripts/clean.sh $./scripts/cp-data.sh $sudo apt-get install python3-pip python3-setuptools $python3 -m pip install . $vpp-config Changes: * Convert to print() function. * raw_input changes. * floor division changes. * replace vpp-config.py with a setuptools 'vpp-config' entry_point. * replace netaddr with ipaddress from the standard library and backport. * .decode() subprocess.Popen's stdout because in python3 they are bytes. Change-Id: Id98894ee54e0c31a0ba0304134b159caef415705 Signed-off-by: Paul Vinciguerra <pvinci@vinciconsulting.com>
Diffstat (limited to 'extras')
-rw-r--r--extras/vpp_config/README.rst15
-rwxr-xr-xextras/vpp_config/scripts/dpdk-devbind.py3
-rwxr-xr-xextras/vpp_config/scripts/vpp-config22
-rw-r--r--extras/vpp_config/setup.py30
-rwxr-xr-xextras/vpp_config/vpp_config.py156
-rw-r--r--extras/vpp_config/vpplib/AutoConfig.py522
-rw-r--r--extras/vpp_config/vpplib/CpuUtils.py18
-rw-r--r--extras/vpp_config/vpplib/QemuUtils.py59
-rw-r--r--extras/vpp_config/vpplib/VPPUtil.py94
-rw-r--r--extras/vpp_config/vpplib/VppGrubUtil.py3
-rw-r--r--extras/vpp_config/vpplib/VppHugePageUtil.py22
-rw-r--r--extras/vpp_config/vpplib/VppPCIUtil.py16
12 files changed, 554 insertions, 406 deletions
diff --git a/extras/vpp_config/README.rst b/extras/vpp_config/README.rst
index ec9c8e46cf4..8995edfce9f 100644
--- a/extras/vpp_config/README.rst
+++ b/extras/vpp_config/README.rst
@@ -11,7 +11,7 @@ Use:
The installation and executing of the VPP configuration utility is simple. First
install the python pip module. Using pip install, then pip install vpp-config.
-Then simply type Òvpp-configÓ and answer the questions. If you are not sure what
+Then simply type �vpp-config� and answer the questions. If you are not sure what
to answer choose the default. For yes or no questions the capital letter
designates the default. For example, for a question that shows [Y/n] Y is the
default. For numbers the default is within the brackets for example for a
@@ -36,14 +36,15 @@ environment so you can start from scratch. These are the steps to run the utilit
in this environment. The scripts are meant to be run from the root directory.
./scripts/clean.sh
- ./scripts/cp-data.sh
- ./vpp_config.py
+ ./scripts/cp-data.sh
+ ./vpp-config
When the utility is installed with pip the wrapper scripts/vpp-config is written to
/usr/local/bin. However, the starting point when debugging this script locally is
-./vpp_config.py. Run the utility by executing ./vpp_config.py from the root directory.
+vpp-config. Run the utility by executing vpp-config.
-The start point in the code is in vpp_config.py. However, most of the work is done in
+The start point in the code is in vpp_config.py. However, most of the work is
+done in
the files in ./vpplib
Uploading to PyPi:
@@ -51,7 +52,7 @@ Uploading to PyPi:
To upload this utility to PpPi simple do the following. Currently, I have my own account
when we want everyone to contribute we will need to change that.
- sudo ÐH bash
+ sudo �H bash
cd vpp_config
python setup.py sdist bdist_wheel
twine upload dist/*
@@ -137,7 +138,7 @@ There are no VPP packages on node localhost.
Do you want to install VPP [Y/n]?
INFO:root: Local Command: ls /etc/apt/sources.list.d/99fd.io.list.orig
INFO:root: /etc/apt/sources.list.d/99fd.io.list.orig
-ÉÉ..
+��..
What would you like to do?
diff --git a/extras/vpp_config/scripts/dpdk-devbind.py b/extras/vpp_config/scripts/dpdk-devbind.py
index f1d374d6b08..b65677dab0c 100755
--- a/extras/vpp_config/scripts/dpdk-devbind.py
+++ b/extras/vpp_config/scripts/dpdk-devbind.py
@@ -1,4 +1,4 @@
-#! /usr/bin/python
+#! /usr/bin/env python
#
# BSD LICENSE
#
@@ -647,5 +647,6 @@ def main():
get_crypto_details()
do_arg_actions()
+
if __name__ == "__main__":
main()
diff --git a/extras/vpp_config/scripts/vpp-config b/extras/vpp_config/scripts/vpp-config
deleted file mode 100755
index 7cb27fc20e8..00000000000
--- a/extras/vpp_config/scripts/vpp-config
+++ /dev/null
@@ -1,22 +0,0 @@
-#!/usr/bin/python
-
-# Copyright (c) 2016 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:
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-"""VPP Configuration Utility Wrapper"""
-
-import os
-import sys
-import vpp_config as vpp
-
-vpp.config_main()
diff --git a/extras/vpp_config/setup.py b/extras/vpp_config/setup.py
index d3d0e51dc96..fca08f66f82 100644
--- a/extras/vpp_config/setup.py
+++ b/extras/vpp_config/setup.py
@@ -1,25 +1,33 @@
from setuptools import setup
setup(name="vpp_config",
- version="18.10.4",
+ version="19.01.1",
author="John DeNisco",
author_email="jdenisco@cisco.com",
description="VPP Configuration Utility",
- license = 'Apache-2.0',
+ license='Apache-2.0',
keywords="vppconfig",
- url = 'https://wiki.fd.io/view/VPP',
+ url='https://wiki.fd.io/view/VPP',
py_modules=['vpp_config'],
- install_requires=['pyyaml','netaddr', 'requests'],
+ install_requires=['pyyaml', 'requests'],
+ extra_requires=["ipaddress; python_version < '3.3'"],
packages=['vpplib'],
- scripts=['scripts/vpp-config'],
+ entry_points={
+ 'console_scripts': ['vpp-config=vpp_config:config_main'],
+ },
data_files=[('vpp/vpp-config/scripts', ['scripts/dpdk-devbind.py']),
('vpp/vpp-config/configs', ['data/auto-config.yaml']),
('vpp/vpp-config/configs', ['data/cloud-config.iso']),
- ('vpp/vpp-config/configs', ['data/iperf-centos.xml.template']),
- ('vpp/vpp-config/configs', ['data/iperf-ubuntu.xml.template']),
- ('vpp/vpp-config/dryrun/sysctl.d', ['data/80-vpp.conf.template']),
+ ('vpp/vpp-config/configs',
+ ['data/iperf-centos.xml.template']),
+ ('vpp/vpp-config/configs',
+ ['data/iperf-ubuntu.xml.template']),
+ ('vpp/vpp-config/dryrun/sysctl.d',
+ ['data/80-vpp.conf.template']),
('vpp/vpp-config/dryrun/default', ['data/grub.template']),
- ('vpp/vpp-config/dryrun/vpp', ['data/startup.conf.template']),
- ],
- long_description="The VPP configuration utility can be used to easily configure VPP.",
+ ('vpp/vpp-config/dryrun/vpp',
+ ['data/startup.conf.template']),
+ ],
+ long_description="The VPP configuration utility can be used to "
+ "easily configure VPP.",
)
diff --git a/extras/vpp_config/vpp_config.py b/extras/vpp_config/vpp_config.py
index 145bf4ea03c..1f792014074 100755
--- a/extras/vpp_config/vpp_config.py
+++ b/extras/vpp_config/vpp_config.py
@@ -1,6 +1,7 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# Copyright (c) 2016 Cisco and/or its affiliates.
+# Copyright (c) 2018 Vinci Consulting Corp. All rights reserved.
# 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:
@@ -14,6 +15,7 @@
# limitations under the License.
"""VPP Configuration Main Entry"""
+from __future__ import absolute_import, division, print_function
import re
import os
@@ -24,6 +26,12 @@ import argparse
from vpplib.AutoConfig import AutoConfig
from vpplib.VPPUtil import VPPUtil
+# Python2/3 compatible
+try:
+ input = raw_input # noqa
+except NameError:
+ pass
+
VPP_DRYRUNDIR = '/vpp/vpp-config/dryrun'
VPP_AUTO_CONFIGURATION_FILE = '/vpp/vpp-config/configs/auto-config.yaml'
VPP_HUGE_PAGE_FILE = '/vpp/vpp-config/dryrun/sysctl.d/80-vpp.conf'
@@ -51,14 +59,14 @@ def autoconfig_yn(question, default):
default = default.lower()
answer = ''
while not input_valid:
- answer = raw_input(question)
+ answer = input(question)
if len(answer) == 0:
answer = default
if re.findall(r'[YyNn]', answer):
input_valid = True
answer = answer[0].lower()
else:
- print "Please answer Y, N or Return."
+ print ("Please answer Y, N or Return.")
return answer
@@ -153,9 +161,9 @@ def autoconfig_hugepage_apply(node, ask_questions=True):
diffs = autoconfig_diff(node, VPP_REAL_HUGE_PAGE_FILE, rootdir + VPP_HUGE_PAGE_FILE)
if diffs != '':
- print "These are the changes we will apply to"
- print "the huge page file ({}).\n".format(VPP_REAL_HUGE_PAGE_FILE)
- print diffs
+ print ("These are the changes we will apply to")
+ print ("the huge page file ({}).\n".format(VPP_REAL_HUGE_PAGE_FILE))
+ print (diffs)
if ask_questions:
answer = autoconfig_yn("\nAre you sure you want to apply these changes [Y/n]? ", 'y')
if answer == 'n':
@@ -169,7 +177,7 @@ def autoconfig_hugepage_apply(node, ask_questions=True):
raise RuntimeError('{} failed on node {} {} {}'.
format(cmd, node['host'], stdout, stderr))
else:
- print '\nThere are no changes to the huge page configuration.'
+ print ('\nThere are no changes to the huge page configuration.')
return 0
@@ -189,9 +197,9 @@ def autoconfig_vpp_apply(node, ask_questions=True):
diffs = autoconfig_diff(node, VPP_REAL_STARTUP_FILE, rootdir + VPP_STARTUP_FILE)
if diffs != '':
- print "These are the changes we will apply to"
- print "the VPP startup file ({}).\n".format(VPP_REAL_STARTUP_FILE)
- print diffs
+ print ("These are the changes we will apply to")
+ print ("the VPP startup file ({}).\n".format(VPP_REAL_STARTUP_FILE))
+ print (diffs)
if ask_questions:
answer = autoconfig_yn("\nAre you sure you want to apply these changes [Y/n]? ", 'y')
if answer == 'n':
@@ -200,7 +208,7 @@ def autoconfig_vpp_apply(node, ask_questions=True):
# Copy the VPP startup
autoconfig_cp(node, rootdir + VPP_STARTUP_FILE, VPP_REAL_STARTUP_FILE)
else:
- print '\nThere are no changes to VPP startup.'
+ print ('\nThere are no changes to VPP startup.')
return 0
@@ -218,12 +226,12 @@ def autoconfig_grub_apply(node, ask_questions=True):
"""
- print "\nThe configured grub cmdline looks like this:"
+ print ("\nThe configured grub cmdline looks like this:")
configured_cmdline = node['grub']['default_cmdline']
current_cmdline = node['grub']['current_cmdline']
- print configured_cmdline
- print "\nThe current boot cmdline looks like this:"
- print current_cmdline
+ print (configured_cmdline)
+ print ("\nThe current boot cmdline looks like this:")
+ print (current_cmdline)
if ask_questions:
question = "\nDo you want to keep the current boot cmdline [Y/n]? "
answer = autoconfig_yn(question, 'y')
@@ -235,9 +243,9 @@ def autoconfig_grub_apply(node, ask_questions=True):
# Diff the file
diffs = autoconfig_diff(node, VPP_REAL_GRUB_FILE, rootdir + VPP_GRUB_FILE)
if diffs != '':
- print "These are the changes we will apply to"
- print "the GRUB file ({}).\n".format(VPP_REAL_GRUB_FILE)
- print diffs
+ print ("These are the changes we will apply to")
+ print ("the GRUB file ({}).\n".format(VPP_REAL_GRUB_FILE))
+ print (diffs)
if ask_questions:
answer = autoconfig_yn("\nAre you sure you want to apply these changes [y/N]? ", 'n')
if answer == 'n':
@@ -256,11 +264,11 @@ def autoconfig_grub_apply(node, ask_questions=True):
raise RuntimeError('{} failed on node {} {} {}'.
format(cmd, node['host'], stdout, stderr))
- print "There have been changes to the GRUB config a",
- print "reboot will be required."
+ print ("There have been changes to the GRUB config a", end=' ')
+ print ("reboot will be required.")
return -1
else:
- print '\nThere are no changes to the GRUB config.'
+ print ('\nThere are no changes to the GRUB config.')
return 0
@@ -281,13 +289,13 @@ def autoconfig_apply(ask_questions=True):
vutil = VPPUtil()
pkgs = vutil.get_installed_vpp_pkgs()
if len(pkgs) == 0:
- print "\nVPP is not installed, Install VPP with option 4."
+ print ("\nVPP is not installed, Install VPP with option 4.")
return
acfg = AutoConfig(rootdir, VPP_AUTO_CONFIGURATION_FILE)
if ask_questions:
- print "\nWe are now going to configure your system(s).\n"
+ print ("\nWe are now going to configure your system(s).\n")
answer = autoconfig_yn("Are you sure you want to do this [Y/n]? ", 'y')
if answer == 'n':
return
@@ -336,7 +344,7 @@ def autoconfig_dryrun(ask_questions=True):
vutil = VPPUtil()
pkgs = vutil.get_installed_vpp_pkgs()
if len(pkgs) == 0:
- print "\nVPP is not installed, please install VPP."
+ print ("\nVPP is not installed, please install VPP.")
return
acfg = AutoConfig(rootdir, VPP_AUTO_CONFIGURATION_FILE, clean=True)
@@ -405,15 +413,15 @@ def autoconfig_install():
pkgs = vutil.get_installed_vpp_pkgs()
if len(pkgs) > 0:
- print "\nThese packages are installed on node {}" \
- .format(node['host'])
- print "{:25} {}".format("Name", "Version")
+ print ("\nThese packages are installed on node {}"
+ .format(node['host']))
+ print ("{:25} {}".format("Name", "Version"))
for pkg in pkgs:
- if 'version' in pkg:
- print "{:25} {}".format(
- pkg['name'], pkg['version'])
- else:
- print "{}".format(pkg['name'])
+ try:
+ print ("{:25} {}".format(
+ pkg['name'], pkg['version']))
+ except KeyError:
+ print ("{}".format(pkg['name']))
question = "\nDo you want to uninstall these "
question += "packages [y/N]? "
@@ -422,8 +430,8 @@ def autoconfig_install():
logger.setLevel(logging.INFO)
vutil.uninstall_vpp(node)
else:
- print "\nThere are no VPP packages on node {}." \
- .format(node['host'])
+ print ("\nThere are no VPP packages on node {}."
+ .format(node['host']))
question = "Do you want to install VPP [Y/n]? "
answer = autoconfig_yn(question, 'y')
if answer == 'y':
@@ -488,7 +496,7 @@ def autoconfig_not_implemented():
"""
- print "\nThis Feature is not implemented yet...."
+ print ("\nThis Feature is not implemented yet....")
def autoconfig_basic_test_menu():
@@ -502,20 +510,20 @@ def autoconfig_basic_test_menu():
2) Create an iperf VM and Connect to VPP an interface\n\
9 or q) Back to main menu.'
- print "{}".format(basic_menu_text)
+ print ("{}".format(basic_menu_text))
input_valid = False
answer = ''
while not input_valid:
- answer = raw_input("\nCommand: ")
+ answer = input("\nCommand: ")
if len(answer) > 1:
- print "Please enter only 1 character."
+ print ("Please enter only 1 character.")
continue
if re.findall(r'[Qq1-29]', answer):
input_valid = True
answer = answer[0].lower()
else:
- print "Please enter a character between 1 and 2 or 9."
+ print ("Please enter a character between 1 and 2 or 9.")
if answer == '9':
answer = 'q'
@@ -531,7 +539,7 @@ def autoconfig_basic_test():
vutil = VPPUtil()
pkgs = vutil.get_installed_vpp_pkgs()
if len(pkgs) == 0:
- print "\nVPP is not installed, install VPP with option 4."
+ print ("\nVPP is not installed, install VPP with option 4.")
return
answer = ''
@@ -563,20 +571,20 @@ q) Quit'.format(rootdir, rootdir)
# 5) Dry Run from {}/vpp/vpp-config/auto-config.yaml (will not ask questions).\n\
# 6) Install QEMU patch (Needed when running openstack).\n\
- print "{}".format(main_menu_text)
+ print ("{}".format(main_menu_text))
input_valid = False
answer = ''
while not input_valid:
- answer = raw_input("\nCommand: ")
+ answer = input("\nCommand: ")
if len(answer) > 1:
- print "Please enter only 1 character."
+ print ("Please enter only 1 character.")
continue
if re.findall(r'[Qq1-4]', answer):
input_valid = True
answer = answer[0].lower()
else:
- print "Please enter a character between 1 and 4 or q."
+ print ("Please enter a character between 1 and 4 or q.")
return answer
@@ -632,15 +640,19 @@ def autoconfig_setup(ask_questions=True):
format(filename))
if ask_questions:
- print "\nWelcome to the VPP system configuration utility"
+ print ("\nWelcome to the VPP system configuration utility")
- print "\nThese are the files we will modify:"
- print " /etc/vpp/startup.conf"
- print " /etc/sysctl.d/80-vpp.conf"
- print " /etc/default/grub"
+ print ("\nThese are the files we will modify:")
+ print (" /etc/vpp/startup.conf")
+ print (" /etc/sysctl.d/80-vpp.conf")
+ print (" /etc/default/grub")
- print "\nBefore we change them, we'll create working copies in {}".format(rootdir + VPP_DRYRUNDIR)
- print "Please inspect them carefully before applying the actual configuration (option 3)!"
+ print (
+ "\nBefore we change them, we'll create working copies in "
+ "{}".format(rootdir + VPP_DRYRUNDIR))
+ print (
+ "Please inspect them carefully before applying the actual "
+ "configuration (option 3)!")
nodes = acfg.get_nodes()
for i in nodes.items():
@@ -696,31 +708,43 @@ def config_main():
if not os.geteuid() == 0:
sys.exit('\nPlease run the VPP Configuration Utility as root.')
- if len(sys.argv) > 1 and ((sys.argv[1] == '-d') or (sys.argv[1] == '--debug')):
+ if len(sys.argv) > 1 and ((sys.argv[1] == '-d') or (
+ sys.argv[1] == '--debug')):
logging.basicConfig(level=logging.DEBUG)
else:
logging.basicConfig(level=logging.ERROR)
- # If no arguments were entered, ask the user questions to get the main parameters
+ # If no arguments were entered, ask the user questions to
+ # get the main parameters
if len(sys.argv) == 1:
autoconfig_main()
return
- elif len(sys.argv) == 2 and (sys.argv[1] == '-d' or sys.argv[1] == '--debug'):
+ elif len(sys.argv) == 2 and ((sys.argv[1] == '-d') or (
+ sys.argv[1] == '--debug')):
autoconfig_main()
return
- # There were arguments specified, so execute the utility using command line arguments
- description = 'The VPP configuration utility allows the user to configure VPP in a simple and safe manner. \
-The utility takes input from the user or the speficfied .yaml file. The user should then examine these files \
-to be sure they are correct and then actually apply the configuration. When run without arguments the utility run \
-in an interactive mode'
-
- main_parser = argparse.ArgumentParser(prog='arg-test', description=description,
- epilog='See "%(prog)s help COMMAND" for help on a specific command.')
- main_parser.add_argument('--apply', '-a', action='store_true', help='Apply the cofiguration.')
- main_parser.add_argument('--dry-run', '-dr', action='store_true', help='Create the dryrun configuration files.')
- main_parser.add_argument('--show', '-s', action='store_true', help='Shows basic system information')
- main_parser.add_argument('--debug', '-d', action='count', help='Print debug output (multiple levels)')
+ # There were arguments specified, so execute the utility using
+ # command line arguments
+ description = 'The VPP configuration utility allows the user to '
+ 'configure VPP in a simple and safe manner. The utility takes input '
+ 'from the user or the specified .yaml file. The user should then '
+ 'examine these files to be sure they are correct and then actually '
+ 'apply the configuration. When run without arguments the utility run '
+ 'in an interactive mode'
+
+ main_parser = argparse.ArgumentParser(
+ prog='arg-test',
+ description=description,
+ epilog='See "%(prog)s help COMMAND" for help on a specific command.')
+ main_parser.add_argument('--apply', '-a', action='store_true',
+ help='Apply the cofiguration.')
+ main_parser.add_argument('--dry-run', '-dr', action='store_true',
+ help='Create the dryrun configuration files.')
+ main_parser.add_argument('--show', '-s', action='store_true',
+ help='Shows basic system information')
+ main_parser.add_argument('--debug', '-d', action='count',
+ help='Print debug output (multiple levels)')
args = main_parser.parse_args()
diff --git a/extras/vpp_config/vpplib/AutoConfig.py b/extras/vpp_config/vpplib/AutoConfig.py
index 2664a6aa7c4..da00b2878eb 100644
--- a/extras/vpp_config/vpplib/AutoConfig.py
+++ b/extras/vpp_config/vpplib/AutoConfig.py
@@ -12,12 +12,14 @@
# limitations under the License.
"""Library that supports Auto Configuration."""
+from __future__ import absolute_import, division, print_function
import logging
import os
import re
+from ipaddress import ip_address
+
import yaml
-from netaddr import IPAddress
from vpplib.VPPUtil import VPPUtil
from vpplib.VppPCIUtil import VppPCIUtil
@@ -26,6 +28,12 @@ from vpplib.CpuUtils import CpuUtils
from vpplib.VppGrubUtil import VppGrubUtil
from vpplib.QemuUtils import QemuUtils
+# Python2/3 compatible
+try:
+ input = raw_input # noqa
+except NameError:
+ pass
+
__all__ = ["AutoConfig"]
# Constants
@@ -104,18 +112,18 @@ class AutoConfig(object):
"""
while True:
- answer = raw_input("Please enter the IPv4 Address [n.n.n.n/n]: ")
+ answer = input("Please enter the IPv4 Address [n.n.n.n/n]: ")
try:
ipinput = answer.split('/')
- ipaddr = IPAddress(ipinput[0])
+ ipaddr = ip_address(ipinput[0])
if len(ipinput) > 1:
plen = answer.split('/')[1]
else:
- answer = raw_input("Please enter the netmask [n.n.n.n]: ")
- plen = IPAddress(answer).netmask_bits()
+ answer = input("Please enter the netmask [n.n.n.n]: ")
+ plen = ip_address(answer).netmask_bits()
return '{}/{}'.format(ipaddr, plen)
except None:
- print "Please enter a valid IPv4 address."
+ print("Please enter a valid IPv4 address.")
@staticmethod
def _ask_user_range(question, first, last, default):
@@ -136,7 +144,7 @@ class AutoConfig(object):
"""
while True:
- answer = raw_input(question)
+ answer = input(question)
if answer == '':
answer = default
break
@@ -144,11 +152,11 @@ class AutoConfig(object):
if int(answer) in range(first, last + 1):
break
else:
- print "Please a value between {} and {} or Return.". \
- format(first, last)
+ print("Please a value between {} and {} or Return.".
+ format(first, last))
else:
- print "Please a number between {} and {} or Return.". \
- format(first, last)
+ print("Please a number between {} and {} or Return.".
+ format(first, last))
return int(answer)
@@ -169,14 +177,14 @@ class AutoConfig(object):
default = default.lower()
answer = ''
while not input_valid:
- answer = raw_input(question)
+ answer = input(question)
if answer == '':
answer = default
if re.findall(r'[YyNn]', answer):
input_valid = True
answer = answer[0].lower()
else:
- print "Please answer Y, N or Return."
+ print("Please answer Y, N or Return.")
return answer
@@ -194,7 +202,9 @@ class AutoConfig(object):
if 'metadata' in topo:
self._metadata = topo['metadata']
except yaml.YAMLError as exc:
- raise RuntimeError("Couldn't read the Auto config file {}.".format(self._autoconfig_filename, exc))
+ raise RuntimeError(
+ "Couldn't read the Auto config file {}.".format(
+ self._autoconfig_filename, exc))
systemfile = self._rootdir + self._metadata['system_config_file']
if self._clean is False and os.path.isfile(systemfile):
@@ -204,7 +214,9 @@ class AutoConfig(object):
if 'nodes' in systopo:
self._nodes = systopo['nodes']
except yaml.YAMLError as sysexc:
- raise RuntimeError("Couldn't read the System config file {}.".format(systemfile, sysexc))
+ raise RuntimeError(
+ "Couldn't read the System config file {}.".format(
+ systemfile, sysexc))
else:
# Get the nodes from Auto Config
if 'nodes' in topo:
@@ -246,7 +258,7 @@ class AutoConfig(object):
if 'nodes' in ydata:
nodes = ydata['nodes']
except yaml.YAMLError as exc:
- print exc
+ print(exc)
return
for i in nodes.items():
@@ -413,7 +425,8 @@ class AutoConfig(object):
return devices
@staticmethod
- def _calc_vpp_workers(node, vpp_workers, numa_node, other_cpus_end, total_vpp_workers,
+ def _calc_vpp_workers(node, vpp_workers, numa_node, other_cpus_end,
+ total_vpp_workers,
reserve_vpp_main_core):
"""
Calculate the VPP worker information
@@ -542,7 +555,8 @@ class AutoConfig(object):
# Get the number of cpus to skip, we never use the first cpu
other_cpus_start = 1
- other_cpus_end = other_cpus_start + node['cpu']['total_other_cpus'] - 1
+ other_cpus_end = other_cpus_start + \
+ node['cpu']['total_other_cpus'] - 1
other_workers = None
if other_cpus_end is not 0:
other_workers = (other_cpus_start, other_cpus_end)
@@ -569,14 +583,16 @@ class AutoConfig(object):
value = item[1]
# Get the number of descriptors and queues
- mbufs = self._calc_desc_and_queues(len(ports_per_numa),
- len(value['interfaces']), total_rx_queues, value)
+ mbufs = self._calc_desc_and_queues(
+ len(ports_per_numa),
+ len(value['interfaces']), total_rx_queues, value)
total_mbufs += mbufs
# Get the VPP workers
- reserve_vpp_main_core = self._calc_vpp_workers(node, vpp_workers, numa_node,
- other_cpus_end, total_workers_node,
- reserve_vpp_main_core)
+ reserve_vpp_main_core = self._calc_vpp_workers(
+ node, vpp_workers, numa_node,
+ other_cpus_end, total_workers_node,
+ reserve_vpp_main_core)
total_mbufs *= 2.5
total_mbufs = int(total_mbufs)
@@ -607,36 +623,43 @@ class AutoConfig(object):
# Generate the api-segment gid vpp sheit in any case
if (aos + pos) == 0:
- tcp = "api-segment {\n"
- tcp = tcp + " gid vpp\n"
- tcp = tcp + "}\n"
+ tcp = '\n'.join([
+ "api-segment {",
+ " gid vpp",
+ "}"
+ ])
return tcp.rstrip('\n')
- tcp = "# TCP stack-related configuration parameters\n"
- tcp = tcp + "# expecting {:d} client sessions, {:d} server sessions\n\n".format(aos, pos)
- tcp = tcp + "heapsize 4g\n\n"
- tcp = tcp + "api-segment {\n"
- tcp = tcp + " global-size 2000M\n"
- tcp = tcp + " api-size 1G\n"
- tcp = tcp + "}\n\n"
-
- tcp = tcp + "session {\n"
- tcp = tcp + " event-queue-length " + "{:d}".format(aos + pos) + "\n"
- tcp = tcp + " preallocated-sessions " + "{:d}".format(aos + pos) + "\n"
- tcp = tcp + " v4-session-table-buckets " + "{:d}".format((aos + pos) / 4) + "\n"
- tcp = tcp + " v4-session-table-memory 3g\n"
+ tcp = '\n'.join([
+ "# TCP stack-related configuration parameters",
+ "# expecting {:d} client sessions, {:d} server sessions\n".format(
+ aos, pos),
+ "heapsize 4g\n",
+ "api-segment {",
+ " global-size 2000M",
+ " api-size 1G",
+ "}\n",
+
+ "session {",
+ " event-queue-length {:d}".format(aos + pos),
+ " preallocated-sessions {:d}".format(aos + pos),
+ " v4-session-table-buckets {:d}".format((aos + pos) // 4),
+ " v4-session-table-memory 3g\n"
+ ])
if aos > 0:
- tcp = tcp + " v4-halfopen-table-buckets " + \
- "{:d}".format((aos + pos) / 4) + "\n"
+ tcp = tcp + " v4-halfopen-table-buckets {:d}".format(
+ (aos + pos) // 4) + "\n"
tcp = tcp + " v4-halfopen-table-memory 3g\n"
- tcp = tcp + " local-endpoints-table-buckets " + "{:d}".format((aos + pos) / 4) + "\n"
+ tcp = tcp + " local-endpoints-table-buckets {:d}".format(
+ (aos + pos) // 4) + "\n"
tcp = tcp + " local-endpoints-table-memory 3g\n"
tcp = tcp + "}\n\n"
tcp = tcp + "tcp {\n"
- tcp = tcp + " preallocated-connections " + "{:d}".format(aos + pos) + "\n"
+ tcp = tcp + " preallocated-connections {:d}".format(aos + pos) + "\n"
if aos > 0:
- tcp = tcp + " preallocated-half-open-connections " + "{:d}".format(aos) + "\n"
+ tcp = tcp + " preallocated-half-open-connections {:d}".format(
+ aos) + "\n"
tcp = tcp + "}\n\n"
return tcp.rstrip('\n')
@@ -923,22 +946,27 @@ class AutoConfig(object):
:type numa_nodes: list
"""
- print "\nYour system has {} core(s) and {} Numa Nodes.". \
- format(total_cpus, len(numa_nodes))
- print "To begin, we suggest not reserving any cores for VPP or other processes."
- print "Then to improve performance start reserving cores and adding queues as needed. "
+ print("\nYour system has {} core(s) and {} Numa Nodes.".
+ format(total_cpus, len(numa_nodes)))
+ print("To begin, we suggest not reserving any cores for "
+ "VPP or other processes.")
+ print("Then to improve performance start reserving cores and "
+ "adding queues as needed.")
max_vpp_cpus = 4
total_vpp_cpus = 0
if max_vpp_cpus > 0:
- question = "\nHow many core(s) shall we reserve for VPP [0-{}][0]? ".format(max_vpp_cpus)
+ question = "\nHow many core(s) shall we reserve for " \
+ "VPP [0-{}][0]? ".format(max_vpp_cpus)
total_vpp_cpus = self._ask_user_range(question, 0, max_vpp_cpus, 0)
node['cpu']['total_vpp_cpus'] = total_vpp_cpus
max_other_cores = (total_cpus - total_vpp_cpus) / 2
- question = 'How many core(s) do you want to reserve for processes other than VPP? [0-{}][0]? '. \
+ question = 'How many core(s) do you want to reserve for ' \
+ 'processes other than VPP? [0-{}][0]? '. \
format(str(max_other_cores))
- total_other_cpus = self._ask_user_range(question, 0, max_other_cores, 0)
+ total_other_cpus = self._ask_user_range(
+ question, 0, max_other_cores, 0)
node['cpu']['total_other_cpus'] = total_other_cpus
max_main_cpus = max_vpp_cpus + 1 - total_vpp_cpus
@@ -952,8 +980,8 @@ class AutoConfig(object):
node['cpu']['reserve_vpp_main_core'] = reserve_vpp_main_core
node['cpu']['vpp_main_core'] = 0
- question = "How many RX queues per port shall we use for VPP [1-4][1]? ". \
- format(max_vpp_cpus)
+ question = "How many RX queues per port shall we use for " \
+ "VPP [1-4][1]? ".format(max_vpp_cpus)
total_rx_queues = self._ask_user_range(question, 1, 4, 1)
node['cpu']['total_rx_queues'] = total_rx_queues
@@ -1030,8 +1058,8 @@ class AutoConfig(object):
odevices_len = len(other_devices)
if odevices_len > 0:
- print "\nThese device(s) are currently NOT being used",
- print "by VPP or the OS.\n"
+ print("\nThese device(s) are currently NOT being used "
+ "by VPP or the OS.\n")
VppPCIUtil.show_vpp_devices(other_devices, show_interfaces=False)
question = "\nWould you like to give any of these devices"
question += " back to the OS [Y/n]? "
@@ -1046,11 +1074,15 @@ class AutoConfig(object):
question += " the OS [y/N]? "
answer = self._ask_user_yn(question, 'n')
if answer == 'y':
- if 'unused' in device and len(device['unused']) != 0 and device['unused'][0] != '':
+ if 'unused' in device and len(
+ device['unused']) != 0 and \
+ device['unused'][0] != '':
driver = device['unused'][0]
- ret = VppPCIUtil.bind_vpp_device(node, driver, dvid)
+ ret = VppPCIUtil.bind_vpp_device(
+ node, driver, dvid)
if ret:
- logging.debug('Could not bind device {}'.format(dvid))
+ logging.debug(
+ 'Could not bind device {}'.format(dvid))
else:
vppd[dvid] = device
for dit in vppd.items():
@@ -1061,8 +1093,8 @@ class AutoConfig(object):
odevices_len = len(other_devices)
if odevices_len > 0:
- print "\nThese device(s) are still NOT being used ",
- print "by VPP or the OS.\n"
+ print("\nThese device(s) are still NOT being used "
+ "by VPP or the OS.\n")
VppPCIUtil.show_vpp_devices(other_devices, show_interfaces=False)
question = "\nWould you like use any of these for VPP [y/N]? "
answer = self._ask_user_yn(question, 'N')
@@ -1079,12 +1111,16 @@ class AutoConfig(object):
for dit in vppd.items():
dvid = dit[0]
device = dit[1]
- if 'unused' in device and len(device['unused']) != 0 and device['unused'][0] != '':
+ if 'unused' in device and len(device['unused']) != 0 and \
+ device['unused'][0] != '':
driver = device['unused'][0]
- logging.debug('Binding device {} to driver {}'.format(dvid, driver))
+ logging.debug(
+ 'Binding device {} to driver {}'.format(dvid,
+ driver))
ret = VppPCIUtil.bind_vpp_device(node, driver, dvid)
if ret:
- logging.debug('Could not bind device {}'.format(dvid))
+ logging.debug(
+ 'Could not bind device {}'.format(dvid))
else:
dpdk_devices[dvid] = device
del other_devices[dvid]
@@ -1141,19 +1177,17 @@ class AutoConfig(object):
klen = len(kernel_devices)
if klen > 0:
- print "\nThese devices have kernel interfaces, but",
- print "appear to be safe to use with VPP.\n"
+ print("\nThese devices are safe to be used with VPP.\n")
VppPCIUtil.show_vpp_devices(kernel_devices)
- question = "\nWould you like to use any of these "
- question += "device(s) for VPP [y/N]? "
+ question = "\nWould you like to use any of these " \
+ "device(s) for VPP [y/N]? "
answer = self._ask_user_yn(question, 'n')
if answer == 'y':
vppd = {}
for dit in kernel_devices.items():
dvid = dit[0]
device = dit[1]
- question = "Would you like to use device {} ". \
- format(dvid)
+ question = "Would you like to use device {} ".format(dvid)
question += "for VPP [y/N]? "
answer = self._ask_user_yn(question, 'n')
if answer == 'y':
@@ -1161,25 +1195,30 @@ class AutoConfig(object):
for dit in vppd.items():
dvid = dit[0]
device = dit[1]
- if 'unused' in device and len(device['unused']) != 0 and device['unused'][0] != '':
+ if 'unused' in device and len(
+ device['unused']) != 0 and device['unused'][
+ 0] != '':
driver = device['unused'][0]
- logging.debug('Binding device {} to driver {}'.format(dvid, driver))
- ret = VppPCIUtil.bind_vpp_device(node, driver, dvid)
- if ret:
- logging.debug('Could not bind device {}'.format(dvid))
- else:
- dpdk_devices[dvid] = device
- del kernel_devices[dvid]
+ question = "Would you like to bind the driver {} for {} [y/N]? ".format(driver, dvid)
+ answer = self._ask_user_yn(question, 'n')
+ if answer == 'y':
+ logging.debug('Binding device {} to driver {}'.format(dvid, driver))
+ ret = VppPCIUtil.bind_vpp_device(node, driver, dvid)
+ if ret:
+ logging.debug('Could not bind device {}'.format(dvid))
+ dpdk_devices[dvid] = device
+ del kernel_devices[dvid]
dlen = len(dpdk_devices)
if dlen > 0:
- print "\nThese device(s) will be used by VPP.\n"
- VppPCIUtil.show_vpp_devices(dpdk_devices, show_interfaces=False)
+ print("\nThese device(s) are already using DPDK.\n")
+ VppPCIUtil.show_vpp_devices(dpdk_devices,
+ show_interfaces=False)
question = "\nWould you like to remove any of "
question += "these device(s) [y/N]? "
answer = self._ask_user_yn(question, 'n')
if answer == 'y':
- vppd = {}
+ vppdl = {}
for dit in dpdk_devices.items():
dvid = dit[0]
device = dit[1]
@@ -1187,16 +1226,22 @@ class AutoConfig(object):
format(dvid)
answer = self._ask_user_yn(question, 'n')
if answer == 'y':
- vppd[dvid] = device
- for dit in vppd.items():
+ vppdl[dvid] = device
+ for dit in vppdl.items():
dvid = dit[0]
device = dit[1]
- if 'unused' in device and len(device['unused']) != 0 and device['unused'][0] != '':
+ if 'unused' in device and len(
+ device['unused']) != 0 and device['unused'][
+ 0] != '':
driver = device['unused'][0]
- logging.debug('Binding device {} to driver {}'.format(dvid, driver))
- ret = VppPCIUtil.bind_vpp_device(node, driver, dvid)
+ logging.debug(
+ 'Binding device {} to driver {}'.format(
+ dvid, driver))
+ ret = VppPCIUtil.bind_vpp_device(node, driver,
+ dvid)
if ret:
- logging.debug('Could not bind device {}'.format(dvid))
+ logging.debug(
+ 'Could not bind device {}'.format(dvid))
else:
kernel_devices[dvid] = device
del dpdk_devices[dvid]
@@ -1208,10 +1253,6 @@ class AutoConfig(object):
VppPCIUtil.vpp_create_interface(interfaces, dvid, device)
node['interfaces'] = interfaces
- print "\nThese device(s) will be used by VPP, please",
- print "rerun this option if this is incorrect.\n"
- VppPCIUtil.show_vpp_devices(dpdk_devices, show_interfaces=False)
-
self._update_auto_config()
self.updateconfig()
@@ -1231,18 +1272,19 @@ class AutoConfig(object):
hugesize = int(size.split(' ')[0])
# The max number of huge pages should be no more than
# 70% of total free memory
- maxpages = (int(memfree) * MAX_PERCENT_FOR_HUGE_PAGES / 100) / hugesize
- print "\nThere currently {} {} huge pages free.". \
- format(free, size)
- question = "Do you want to reconfigure the number of "
- question += "huge pages [y/N]? "
+ maxpages = (int(memfree) * MAX_PERCENT_FOR_HUGE_PAGES // 100) // \
+ hugesize
+ print("\nThere currently {} {} huge pages free.".format(
+ free, size))
+ question = "Do you want to reconfigure the number of " \
+ "huge pages [y/N]? "
answer = self._ask_user_yn(question, 'n')
if answer == 'n':
node['hugepages']['total'] = total
continue
- print "\nThere currently a total of {} huge pages.". \
- format(total)
+ print("\nThere currently a total of {} huge pages.".
+ format(total))
question = "How many huge pages do you want [{} - {}][{}]? ". \
format(MIN_TOTAL_HUGE_PAGES, maxpages, MIN_TOTAL_HUGE_PAGES)
answer = self._ask_user_range(question, 1024, maxpages, 1024)
@@ -1271,16 +1313,16 @@ class AutoConfig(object):
for i in self._nodes.items():
node = i[1]
- question = "\nHow many active-open / tcp client sessions are expected "
- question = question + "[0-10000000][0]? "
+ question = "\nHow many active-open / tcp client sessions are " \
+ "expected [0-10000000][0]? "
answer = self._ask_user_range(question, 0, 10000000, 0)
# Less than 10K is equivalent to 0
if int(answer) < 10000:
answer = 0
node['tcp']['active_open_sessions'] = answer
- question = "How many passive-open / tcp server sessions are expected "
- question = question + "[0-10000000][0]? "
+ question = "How many passive-open / tcp server sessions are " \
+ "expected [0-10000000][0]? "
answer = self._ask_user_range(question, 0, 10000000, 0)
# Less than 10K is equivalent to 0
if int(answer) < 10000:
@@ -1302,7 +1344,7 @@ class AutoConfig(object):
:type node: dict
"""
- print '\nWe are patching the node "{}":\n'.format(node['host'])
+ print('\nWe are patching the node "{}":\n'.format(node['host']))
QemuUtils.build_qemu(node, force_install=True, apply_patch=True)
@staticmethod
@@ -1316,44 +1358,44 @@ class AutoConfig(object):
item = 'Model name'
if item in cpu:
- print "{:>20}: {}".format(item, cpu[item])
+ print("{:>20}: {}".format(item, cpu[item]))
item = 'CPU(s)'
if item in cpu:
- print "{:>20}: {}".format(item, cpu[item])
+ print("{:>20}: {}".format(item, cpu[item]))
item = 'Thread(s) per core'
if item in cpu:
- print "{:>20}: {}".format(item, cpu[item])
+ print("{:>20}: {}".format(item, cpu[item]))
item = 'Core(s) per socket'
if item in cpu:
- print "{:>20}: {}".format(item, cpu[item])
+ print("{:>20}: {}".format(item, cpu[item]))
item = 'Socket(s)'
if item in cpu:
- print "{:>20}: {}".format(item, cpu[item])
+ print("{:>20}: {}".format(item, cpu[item]))
item = 'NUMA node(s)'
numa_nodes = 0
if item in cpu:
numa_nodes = int(cpu[item])
- for i in xrange(0, numa_nodes):
+ for i in range(0, numa_nodes):
item = "NUMA node{} CPU(s)".format(i)
- print "{:>20}: {}".format(item, cpu[item])
+ print("{:>20}: {}".format(item, cpu[item]))
item = 'CPU max MHz'
if item in cpu:
- print "{:>20}: {}".format(item, cpu[item])
+ print("{:>20}: {}".format(item, cpu[item]))
item = 'CPU min MHz'
if item in cpu:
- print "{:>20}: {}".format(item, cpu[item])
+ print("{:>20}: {}".format(item, cpu[item]))
if node['cpu']['smt_enabled']:
smt = 'Enabled'
else:
smt = 'Disabled'
- print "{:>20}: {}".format('SMT', smt)
+ print("{:>20}: {}".format('SMT', smt))
# VPP Threads
- print "\nVPP Threads: (Name: Cpu Number)"
+ print("\nVPP Threads: (Name: Cpu Number)")
vpp_processes = cpu['vpp_processes']
for i in vpp_processes.items():
- print " {:10}: {:4}".format(i[0], i[1])
+ print(" {:10}: {:4}".format(i[0], i[1]))
@staticmethod
def device_info(node):
@@ -1365,53 +1407,53 @@ class AutoConfig(object):
if 'cpu' in node and 'total_mbufs' in node['cpu']:
total_mbufs = node['cpu']['total_mbufs']
if total_mbufs is not 0:
- print "Total Number of Buffers: {}".format(total_mbufs)
+ print("Total Number of Buffers: {}".format(total_mbufs))
vpp = VppPCIUtil(node)
vpp.get_all_devices()
linkup_devs = vpp.get_link_up_devices()
if len(linkup_devs):
- print ("\nDevices with link up (can not be used with VPP):")
+ print("\nDevices with link up (can not be used with VPP):")
vpp.show_vpp_devices(linkup_devs, show_header=False)
# for dev in linkup_devs:
# print (" " + dev)
kernel_devs = vpp.get_kernel_devices()
if len(kernel_devs):
- print ("\nDevices bound to kernel drivers:")
+ print("\nDevices bound to kernel drivers:")
vpp.show_vpp_devices(kernel_devs, show_header=False)
else:
- print ("\nNo devices bound to kernel drivers")
+ print("\nNo devices bound to kernel drivers")
dpdk_devs = vpp.get_dpdk_devices()
if len(dpdk_devs):
- print ("\nDevices bound to DPDK drivers:")
+ print("\nDevices bound to DPDK drivers:")
vpp.show_vpp_devices(dpdk_devs, show_interfaces=True,
show_header=False)
else:
- print ("\nNo devices bound to DPDK drivers")
+ print("\nNo devices bound to DPDK drivers")
other_devs = vpp.get_other_devices()
if len(other_devs):
- print ("\nDevices not bound to Kernel or DPDK drivers:")
+ print("\nDevices not bound to Kernel or DPDK drivers:")
vpp.show_vpp_devices(other_devs, show_interfaces=True,
show_header=False)
else:
- print ("\nNo devices not bound to Kernel or DPDK drivers")
+ print("\nNo devices not bound to Kernel or DPDK drivers")
vpputl = VPPUtil()
interfaces = vpputl.get_hardware(node)
if interfaces == {}:
return
- print ("\nDevices in use by VPP:")
+ print("\nDevices in use by VPP:")
if len(interfaces.items()) < 2:
- print ("None")
+ print("None")
return
- print "{:30} {:4} {:4} {:7} {:4} {:7}". \
- format('Name', 'Numa', 'RXQs',
- 'RXDescs', 'TXQs', 'TXDescs')
+ print("{:30} {:4} {:4} {:7} {:4} {:7}".
+ format('Name', 'Numa', 'RXQs',
+ 'RXDescs', 'TXQs', 'TXDescs'))
for intf in sorted(interfaces.items()):
name = intf[0]
value = intf[1]
@@ -1429,8 +1471,8 @@ class AutoConfig(object):
if 'tx descs' in value:
tx_ds = int(value['tx descs'])
- print ("{:30} {:>4} {:>4} {:>7} {:>4} {:>7}".
- format(name, numa, rx_qs, rx_ds, tx_qs, tx_ds))
+ print("{:30} {:>4} {:>4} {:>7} {:>4} {:>7}".
+ format(name, numa, rx_qs, rx_ds, tx_qs, tx_ds))
@staticmethod
def hugepage_info(node):
@@ -1458,8 +1500,8 @@ class AutoConfig(object):
if 'layout' in node['cpu']:
total_cpus = len(node['cpu']['layout'])
if total_cpus < 2:
- print "\nThere is only {} CPU(s) available on this system.".format(total_cpus)
- print "This is not enough to run VPP."
+ print("\nThere is only {} CPU(s) available on this system. "
+ "This is not enough to run VPP.".format(total_cpus))
min_sys_res = False
# System Memory
@@ -1474,8 +1516,12 @@ class AutoConfig(object):
percentmemhugepages = (memhugepages / memfree) * 100
if free is '0' and \
percentmemhugepages > MAX_PERCENT_FOR_HUGE_PAGES:
- print "\nThe System has only {} of free memory.".format(int(memfree))
- print "You will not be able to allocate enough Huge Pages for VPP."
+ print(
+ "\nThe System has only {} of free memory. You will not "
+ "be able to allocate enough Huge Pages for VPP.".format(
+ int(
+ memfree))
+ )
min_sys_res = False
return min_sys_res
@@ -1487,45 +1533,43 @@ class AutoConfig(object):
"""
for i in self._nodes.items():
- print "\n=============================="
+ print("\n==============================")
name = i[0]
node = i[1]
- print "NODE: {}\n".format(name)
+ print("NODE: {}\n".format(name))
# CPU
- print "CPU:"
+ print("CPU:")
self.cpu_info(node)
# Grub
- print "\nGrub Command Line:"
+ print("\nGrub Command Line:")
if 'grub' in node:
- print \
- " Current: {}".format(
- node['grub']['current_cmdline'])
- print \
- " Configured: {}".format(
- node['grub']['default_cmdline'])
+ print(" Current: {}".format(
+ node['grub']['current_cmdline']))
+ print(" Configured: {}".format(
+ node['grub']['default_cmdline']))
# Huge Pages
- print "\nHuge Pages:"
+ print("\nHuge Pages:")
self.hugepage_info(node)
# Devices
- print "\nDevices:"
+ print("\nDevices:")
self.device_info(node)
# Status
- print "\nVPP Service Status:"
+ print("\nVPP Service Status:")
state, errors = VPPUtil.status(node)
- print " {}".format(state)
+ print(" {}".format(state))
for e in errors:
- print " {}".format(e)
+ print(" {}".format(e))
# Minimum system resources
self.min_system_resources(node)
- print "\n=============================="
+ print("\n==============================")
def _ipv4_interface_setup_questions(self, node):
"""
@@ -1549,7 +1593,8 @@ class AutoConfig(object):
if name == 'local0':
continue
- question = "Would you like add address to interface {} [Y/n]? ".format(name)
+ question = "Would you like add address to " \
+ "interface {} [Y/n]? ".format(name)
answer = self._ask_user_yn(question, 'y')
if answer == 'y':
address = {}
@@ -1573,7 +1618,7 @@ class AutoConfig(object):
# Show the current interfaces with IP addresses
current_ints = VPPUtil.get_int_ip(node)
if current_ints is not {}:
- print ("\nThese are the current interfaces with IP addresses:")
+ print("\nThese are the current interfaces with IP addresses:")
for items in sorted(current_ints.items()):
name = items[0]
value = items[1]
@@ -1581,13 +1626,16 @@ class AutoConfig(object):
address = 'Not Set'
else:
address = value['address']
- print ("{:30} {:20} {:10}".format(name, address, value['state']))
- question = "\nWould you like to keep this configuration [Y/n]? "
+ print("{:30} {:20} {:10}".format(name, address,
+ value['state']))
+ question = "\nWould you like to keep this configuration " \
+ "[Y/n]? "
answer = self._ask_user_yn(question, 'y')
if answer == 'y':
continue
else:
- print ("\nThere are currently no interfaces with IP addresses.")
+ print("\nThere are currently no interfaces with IP "
+ "addresses.")
# Create a script that add the ip addresses to the interfaces
# and brings the interfaces up
@@ -1653,24 +1701,32 @@ class AutoConfig(object):
if name == 'local0':
continue
- question = "Would you like connect this interface {} to the VM [Y/n]? ".format(name)
+ question = "Would you like connect this interface {} to " \
+ "the VM [Y/n]? ".format(name)
answer = self._ask_user_yn(question, 'y')
if answer == 'y':
- sockfilename = '/var/run/vpp/{}.sock'.format(name.replace('/', '_'))
+ sockfilename = '/var/run/vpp/{}.sock'.format(
+ name.replace('/', '_'))
if os.path.exists(sockfilename):
os.remove(sockfilename)
- cmd = 'vppctl create vhost-user socket {} server'.format(sockfilename)
+ cmd = 'vppctl create vhost-user socket {} server'.format(
+ sockfilename)
(ret, stdout, stderr) = vpputl.exec_command(cmd)
if ret != 0:
- raise RuntimeError("Couldn't execute the command {}, {}.".format(cmd, stderr))
+ raise RuntimeError(
+ "Couldn't execute the command {}, {}.".format(cmd,
+ stderr))
vintname = stdout.rstrip('\r\n')
cmd = 'chmod 777 {}'.format(sockfilename)
(ret, stdout, stderr) = vpputl.exec_command(cmd)
if ret != 0:
- raise RuntimeError("Couldn't execute the command {}, {}.".format(cmd, stderr))
+ raise RuntimeError(
+ "Couldn't execute the command {}, {}.".format(cmd,
+ stderr))
- interface = {'name': name, 'virtualinterface': '{}'.format(vintname),
+ interface = {'name': name,
+ 'virtualinterface': '{}'.format(vintname),
'bridge': '{}'.format(inum)}
inum += 1
interfaces_with_virtual_interfaces.append(interface)
@@ -1679,8 +1735,8 @@ class AutoConfig(object):
def create_and_bridge_virtual_interfaces(self):
"""
- After asking the user some questions, create a VM and connect the interfaces
- to VPP interfaces
+ After asking the user some questions, create a VM and connect
+ the interfaces to VPP interfaces
"""
@@ -1688,39 +1744,49 @@ class AutoConfig(object):
node = i[1]
# Show the current bridge and interface configuration
- print "\nThis the current bridge configuration:"
+ print("\nThis the current bridge configuration:")
VPPUtil.show_bridge(node)
question = "\nWould you like to keep this configuration [Y/n]? "
answer = self._ask_user_yn(question, 'y')
if answer == 'y':
continue
- # Create a script that builds a bridge configuration with physical interfaces
- # and virtual interfaces
+ # Create a script that builds a bridge configuration with
+ # physical interfaces and virtual interfaces
ints_with_vints = self._create_vints_questions(node)
content = ''
for intf in ints_with_vints:
- vhoststr = 'comment { The following command creates the socket }\n'
- vhoststr += 'comment { and returns a virtual interface }\n'
- vhoststr += 'comment {{ create vhost-user socket /var/run/vpp/sock{}.sock server }}\n'. \
- format(intf['bridge'])
-
- setintdnstr = 'set interface state {} down\n'.format(intf['name'])
-
- setintbrstr = 'set interface l2 bridge {} {}\n'.format(intf['name'], intf['bridge'])
- setvintbrstr = 'set interface l2 bridge {} {}\n'.format(intf['virtualinterface'], intf['bridge'])
+ vhoststr = '\n'.join([
+ 'comment { The following command creates the socket }',
+ 'comment { and returns a virtual interface }',
+ 'comment {{ create vhost-user socket '
+ '/var/run/vpp/sock{}.sock server }}\n'.format(
+ intf['bridge'])
+ ])
+
+ setintdnstr = 'set interface state {} down\n'.format(
+ intf['name'])
+
+ setintbrstr = 'set interface l2 bridge {} {}\n'.format(
+ intf['name'], intf['bridge'])
+ setvintbrstr = 'set interface l2 bridge {} {}\n'.format(
+ intf['virtualinterface'], intf['bridge'])
# set interface state VirtualEthernet/0/0/0 up
- setintvststr = 'set interface state {} up\n'.format(intf['virtualinterface'])
+ setintvststr = 'set interface state {} up\n'.format(
+ intf['virtualinterface'])
# set interface state VirtualEthernet/0/0/0 down
- setintupstr = 'set interface state {} up\n'.format(intf['name'])
+ setintupstr = 'set interface state {} up\n'.format(
+ intf['name'])
- content += vhoststr + setintdnstr + setintbrstr + setvintbrstr + setintvststr + setintupstr
+ content += vhoststr + setintdnstr + setintbrstr + \
+ setvintbrstr + setintvststr + setintupstr
# Write the content to the script
rootdir = node['rootdir']
- filename = rootdir + '/vpp/vpp-config/scripts/create_vms_and_connect_to_vpp'
+ filename = rootdir + \
+ '/vpp/vpp-config/scripts/create_vms_and_connect_to_vpp'
with open(filename, 'w+') as sfile:
sfile.write(content)
@@ -1768,30 +1834,38 @@ class AutoConfig(object):
inum = 1
while True:
- print '\nPlease pick one interface to connect to the iperf VM.'
+ print('\nPlease pick one interface to connect to the iperf VM.')
for intf in sorted(interfaces.items()):
name = intf[0]
if name == 'local0':
continue
- question = "Would you like connect this interface {} to the VM [y/N]? ".format(name)
+ question = "Would you like connect this interface {} to " \
+ "the VM [y/N]? ".format(name)
answer = self._ask_user_yn(question, 'n')
if answer == 'y':
- self._sockfilename = '/var/run/vpp/{}.sock'.format(name.replace('/', '_'))
+ self._sockfilename = '/var/run/vpp/{}.sock'.format(
+ name.replace('/', '_'))
if os.path.exists(self._sockfilename):
os.remove(self._sockfilename)
- cmd = 'vppctl create vhost-user socket {} server'.format(self._sockfilename)
+ cmd = 'vppctl create vhost-user socket {} server'.format(
+ self._sockfilename)
(ret, stdout, stderr) = vpputl.exec_command(cmd)
if ret != 0:
- raise RuntimeError("Couldn't execute the command {}, {}.".format(cmd, stderr))
+ raise RuntimeError(
+ "Couldn't execute the command {}, {}.".format(
+ cmd, stderr))
vintname = stdout.rstrip('\r\n')
cmd = 'chmod 777 {}'.format(self._sockfilename)
(ret, stdout, stderr) = vpputl.exec_command(cmd)
if ret != 0:
- raise RuntimeError("Couldn't execute the command {}, {}.".format(cmd, stderr))
+ raise RuntimeError(
+ "Couldn't execute the command {}, {}.".format(
+ cmd, stderr))
- interface = {'name': name, 'virtualinterface': '{}'.format(vintname),
+ interface = {'name': name,
+ 'virtualinterface': '{}'.format(vintname),
'bridge': '{}'.format(inum)}
inum += 1
interfaces_with_virtual_interfaces.append(interface)
@@ -1799,8 +1873,8 @@ class AutoConfig(object):
def create_and_bridge_iperf_virtual_interface(self):
"""
- After asking the user some questions, and create and bridge a virtual interface
- to be used with iperf VM
+ After asking the user some questions, and create and bridge a
+ virtual interface to be used with iperf VM
"""
@@ -1808,37 +1882,47 @@ class AutoConfig(object):
node = i[1]
# Show the current bridge and interface configuration
- print "\nThis the current bridge configuration:"
+ print("\nThis the current bridge configuration:")
ifaces = VPPUtil.show_bridge(node)
question = "\nWould you like to keep this configuration [Y/n]? "
answer = self._ask_user_yn(question, 'y')
if answer == 'y':
- self._sockfilename = '/var/run/vpp/{}.sock'.format(ifaces[0]['name'].replace('/', '_'))
+ self._sockfilename = '/var/run/vpp/{}.sock'.format(
+ ifaces[0]['name'].replace('/', '_'))
if os.path.exists(self._sockfilename):
continue
- # Create a script that builds a bridge configuration with physical interfaces
- # and virtual interfaces
+ # Create a script that builds a bridge configuration with
+ # physical interfaces and virtual interfaces
ints_with_vints = self._iperf_vm_questions(node)
content = ''
for intf in ints_with_vints:
- vhoststr = 'comment { The following command creates the socket }\n'
- vhoststr += 'comment { and returns a virtual interface }\n'
- vhoststr += 'comment {{ create vhost-user socket /var/run/vpp/sock{}.sock server }}\n'. \
- format(intf['bridge'])
-
- setintdnstr = 'set interface state {} down\n'.format(intf['name'])
-
- setintbrstr = 'set interface l2 bridge {} {}\n'.format(intf['name'], intf['bridge'])
- setvintbrstr = 'set interface l2 bridge {} {}\n'.format(intf['virtualinterface'], intf['bridge'])
+ vhoststr = '\n'.join([
+ 'comment { The following command creates the socket }',
+ 'comment { and returns a virtual interface }',
+ 'comment {{ create vhost-user socket '
+ '/var/run/vpp/sock{}.sock server }}\n'.format(
+ intf['bridge'])
+ ])
+
+ setintdnstr = 'set interface state {} down\n'.format(
+ intf['name'])
+
+ setintbrstr = 'set interface l2 bridge {} {}\n'.format(
+ intf['name'], intf['bridge'])
+ setvintbrstr = 'set interface l2 bridge {} {}\n'.format(
+ intf['virtualinterface'], intf['bridge'])
# set interface state VirtualEthernet/0/0/0 up
- setintvststr = 'set interface state {} up\n'.format(intf['virtualinterface'])
+ setintvststr = 'set interface state {} up\n'.format(
+ intf['virtualinterface'])
# set interface state VirtualEthernet/0/0/0 down
- setintupstr = 'set interface state {} up\n'.format(intf['name'])
+ setintupstr = 'set interface state {} up\n'.format(
+ intf['name'])
- content += vhoststr + setintdnstr + setintbrstr + setvintbrstr + setintvststr + setintupstr
+ content += vhoststr + setintdnstr + setintbrstr + \
+ setvintbrstr + setintvststr + setintupstr
# Write the content to the script
rootdir = node['rootdir']
@@ -1859,8 +1943,8 @@ class AutoConfig(object):
@staticmethod
def destroy_iperf_vm(name):
"""
- After asking the user some questions, create a VM and connect the interfaces
- to VPP interfaces
+ After asking the user some questions, create a VM and connect
+ the interfaces to VPP interfaces
:param name: The name of the VM to be be destroyed
:type name: str
@@ -1870,37 +1954,46 @@ class AutoConfig(object):
(ret, stdout, stderr) = VPPUtil.exec_command(cmd)
if ret != 0:
logging.debug(stderr)
- raise RuntimeError("Couldn't execute the command {} : {}".format(cmd, stderr))
+ raise RuntimeError(
+ "Couldn't execute the command {} : {}".format(cmd, stderr))
if re.findall(name, stdout):
cmd = 'virsh destroy {}'.format(name)
(ret, stdout, stderr) = VPPUtil.exec_command(cmd)
if ret != 0:
logging.debug(stderr)
- raise RuntimeError("Couldn't execute the command {} : {}".format(cmd, stderr))
+ raise RuntimeError(
+ "Couldn't execute the command {} : {}".format(
+ cmd, stderr))
def create_iperf_vm(self, vmname):
"""
- After asking the user some questions, create a VM and connect the interfaces
- to VPP interfaces
+ After asking the user some questions, create a VM and connect
+ the interfaces to VPP interfaces
"""
# Read the iperf VM template file
distro = VPPUtil.get_linux_distro()
if distro[0] == 'Ubuntu':
- tfilename = '{}/vpp/vpp-config/configs/iperf-ubuntu.xml.template'.format(self._rootdir)
+ tfilename = \
+ '{}/vpp/vpp-config/configs/iperf-ubuntu.xml.template'.format(
+ self._rootdir)
else:
- tfilename = '{}/vpp/vpp-config/configs/iperf-centos.xml.template'.format(self._rootdir)
+ tfilename = \
+ '{}/vpp/vpp-config/configs/iperf-centos.xml.template'.format(
+ self._rootdir)
with open(tfilename, 'r') as tfile:
tcontents = tfile.read()
tfile.close()
# Add the variables
- imagename = '{}/vpp/vpp-config/{}'.format(self._rootdir, IPERFVM_IMAGE)
+ imagename = '{}/vpp/vpp-config/{}'.format(
+ self._rootdir, IPERFVM_IMAGE)
isoname = '{}/vpp/vpp-config/{}'.format(self._rootdir, IPERFVM_ISO)
- tcontents = tcontents.format(vmname=vmname, imagename=imagename, isoname=isoname,
+ tcontents = tcontents.format(vmname=vmname, imagename=imagename,
+ isoname=isoname,
vhostsocketname=self._sockfilename)
# Write the xml
@@ -1913,4 +2006,5 @@ class AutoConfig(object):
(ret, stdout, stderr) = VPPUtil.exec_command(cmd)
if ret != 0:
logging.debug(stderr)
- raise RuntimeError("Couldn't execute the command {} : {}".format(cmd, stderr))
+ raise RuntimeError(
+ "Couldn't execute the command {} : {}".format(cmd, stderr))
diff --git a/extras/vpp_config/vpplib/CpuUtils.py b/extras/vpp_config/vpplib/CpuUtils.py
index f5c23bc141a..23f418d33be 100644
--- a/extras/vpp_config/vpplib/CpuUtils.py
+++ b/extras/vpp_config/vpplib/CpuUtils.py
@@ -12,7 +12,7 @@
# limitations under the License.
"""CPU utilities library."""
-
+from __future__ import absolute_import, division
import re
from vpplib.VPPUtil import VPPUtil
@@ -43,8 +43,8 @@ class CpuUtils(object):
@staticmethod
def is_smt_enabled(cpu_info):
"""Uses CPU mapping to find out if SMT is enabled or not. If SMT is
- enabled, the L1d,L1i,L2,L3 setting is the same for two processors. These
- two processors are two threads of one core.
+ enabled, the L1d,L1i,L2,L3 setting is the same for two processors.
+ These two processors are two threads of one core.
:param cpu_info: CPU info, the output of "lscpu -p".
:type cpu_info: list
@@ -53,7 +53,7 @@ class CpuUtils(object):
"""
cpu_mems = [item[-4:] for item in cpu_info]
- cpu_mems_len = len(cpu_mems) / CpuUtils.NR_OF_THREADS
+ cpu_mems_len = len(cpu_mems) // CpuUtils.NR_OF_THREADS
count = 0
for cpu_mem in cpu_mems[:cpu_mems_len]:
if cpu_mem in cpu_mems[cpu_mems_len:]:
@@ -137,7 +137,7 @@ class CpuUtils(object):
if smt_enabled and not smt_used:
cpu_list_len = len(cpu_list)
- cpu_list = cpu_list[:cpu_list_len / CpuUtils.NR_OF_THREADS]
+ cpu_list = cpu_list[:cpu_list_len // CpuUtils.NR_OF_THREADS]
return cpu_list
@@ -171,8 +171,8 @@ class CpuUtils(object):
cpu_cnt = cpu_list_len - skip_cnt
if smt_used:
- cpu_list_0 = cpu_list[:cpu_list_len / CpuUtils.NR_OF_THREADS]
- cpu_list_1 = cpu_list[cpu_list_len / CpuUtils.NR_OF_THREADS:]
+ cpu_list_0 = cpu_list[:cpu_list_len // CpuUtils.NR_OF_THREADS]
+ cpu_list_1 = cpu_list[cpu_list_len // CpuUtils.NR_OF_THREADS:]
cpu_list = [cpu for cpu in cpu_list_0[skip_cnt:skip_cnt + cpu_cnt]]
cpu_list_ex = [cpu for cpu in
cpu_list_1[skip_cnt:skip_cnt + cpu_cnt]]
@@ -236,8 +236,8 @@ class CpuUtils(object):
smt_used=smt_used)
if smt_used:
cpu_list_len = len(cpu_list)
- cpu_list_0 = cpu_list[:cpu_list_len / CpuUtils.NR_OF_THREADS]
- cpu_list_1 = cpu_list[cpu_list_len / CpuUtils.NR_OF_THREADS:]
+ cpu_list_0 = cpu_list[:cpu_list_len // CpuUtils.NR_OF_THREADS]
+ cpu_list_1 = cpu_list[cpu_list_len // CpuUtils.NR_OF_THREADS:]
cpu_range = "{}{}{},{}{}{}".format(cpu_list_0[0], sep,
cpu_list_0[-1],
cpu_list_1[0], sep,
diff --git a/extras/vpp_config/vpplib/QemuUtils.py b/extras/vpp_config/vpplib/QemuUtils.py
index a76b873121f..0b7e08b12d8 100644
--- a/extras/vpp_config/vpplib/QemuUtils.py
+++ b/extras/vpp_config/vpplib/QemuUtils.py
@@ -12,6 +12,7 @@
# limitations under the License.
"""QEMU utilities library."""
+from __future__ import absolute_import, division
from time import time, sleep
import json
@@ -100,8 +101,9 @@ class QemuUtils(object):
:type threads: int
:type sockets: int
"""
- self._qemu_opt['smp'] = '-smp {},cores={},threads={},sockets={}'.format(
- cpus, cores, threads, sockets)
+ self._qemu_opt['smp'] = \
+ '-smp {},cores={},threads={},sockets={}'.format(
+ cpus, cores, threads, sockets)
def qemu_set_ssh_fwd_port(self, fwd_port):
"""Set host port for guest SSH forwarding.
@@ -256,7 +258,8 @@ class QemuUtils(object):
if int(ret_code) != 0:
logging.debug('QMP execute failed {0}'.format(stderr))
raise RuntimeError('QMP execute "{0}"'
- ' failed on {1}'.format(cmd, self._node['host']))
+ ' failed on {1}'.format(
+ cmd, self._node['host']))
logging.debug(stdout)
# Skip capabilities negotiation messages.
out_list = stdout.splitlines()
@@ -268,7 +271,8 @@ class QemuUtils(object):
def _qemu_qga_flush(self):
"""Flush the QGA parser state
"""
- qga_cmd = '(printf "\xFF"; sleep 1) | sudo -S socat - UNIX-CONNECT:' + \
+ qga_cmd = '(printf "\xFF"; sleep 1) | ' \
+ 'sudo -S socat - UNIX-CONNECT:' + \
self._qga_sock
# TODO: probably need something else
(ret_code, stdout, stderr) = self._ssh.exec_command(qga_cmd)
@@ -298,7 +302,8 @@ class QemuUtils(object):
if int(ret_code) != 0:
logging.debug('QGA execute failed {0}'.format(stderr))
raise RuntimeError('QGA execute "{0}"'
- ' failed on {1}'.format(cmd, self._node['host']))
+ ' failed on {1}'.format(
+ cmd, self._node['host']))
logging.debug(stdout)
if not stdout:
return {}
@@ -322,7 +327,8 @@ class QemuUtils(object):
self._qemu_qga_flush()
out = self._qemu_qga_exec('guest-ping')
except ValueError:
- logging.debug('QGA guest-ping unexpected output {}'.format(out))
+ logging.debug(
+ 'QGA guest-ping unexpected output {}'.format(out))
# Empty output - VM not booted yet
if not out:
sleep(5)
@@ -335,10 +341,12 @@ class QemuUtils(object):
else:
# If there is an unexpected output from QGA guest-info, try
# again until timeout.
- logging.debug('QGA guest-ping unexpected output {}'.format(out))
+ logging.debug(
+ 'QGA guest-ping unexpected output {}'.format(out))
- logging.debug('VM {0} booted on {1}'.format(self._qemu_opt['disk_image'],
- self._node['host']))
+ logging.debug(
+ 'VM {0} booted on {1}'.format(self._qemu_opt['disk_image'],
+ self._node['host']))
def _update_vm_interfaces(self):
"""Update interface names in VM node dict."""
@@ -349,8 +357,9 @@ class QemuUtils(object):
interfaces = out.get('return')
mac_name = {}
if not interfaces:
- raise RuntimeError('Get VM {0} interface list failed on {1}'.format(
- self._qemu_opt['disk_image'], self._node['host']))
+ raise RuntimeError(
+ 'Get VM {0} interface list failed on {1}'.format(
+ self._qemu_opt['disk_image'], self._node['host']))
# Create MAC-name dict
for interface in interfaces:
if 'hardware-address' not in interface:
@@ -361,7 +370,8 @@ class QemuUtils(object):
mac = interface.get('mac_address')
if_name = mac_name.get(mac)
if if_name is None:
- logging.debug('Interface name for MAC {} not found'.format(mac))
+ logging.debug(
+ 'Interface name for MAC {} not found'.format(mac))
else:
interface['name'] = if_name
@@ -380,20 +390,25 @@ class QemuUtils(object):
# If we want to allocate hugepage dynamically
if allocate:
mem_needed = abs((huge_free * huge_size) - (mem_size * 1024))
- huge_to_allocate = ((mem_needed / huge_size) * 2) + huge_total
+ huge_to_allocate = ((mem_needed // huge_size) * 2) + huge_total
max_map_count = huge_to_allocate*4
- # Increase maximum number of memory map areas a process may have
- cmd = 'echo "{0}" | sudo tee /proc/sys/vm/max_map_count'.format(
+ # Increase maximum number of memory map areas a
+ # process may have
+ cmd = \
+ 'echo "{0}" | sudo tee /proc/sys/vm/max_map_count'.format(
max_map_count)
(ret_code, _, stderr) = self._ssh.exec_command_sudo(cmd)
# Increase hugepage count
- cmd = 'echo "{0}" | sudo tee /proc/sys/vm/nr_hugepages'.format(
+ cmd = \
+ 'echo "{0}" | sudo tee /proc/sys/vm/nr_hugepages'.format(
huge_to_allocate)
(ret_code, _, stderr) = self._ssh.exec_command_sudo(cmd)
if int(ret_code) != 0:
- logging.debug('Mount huge pages failed {0}'.format(stderr))
- raise RuntimeError('Mount huge pages failed on {0}'.format(
- self._node['host']))
+ logging.debug(
+ 'Mount huge pages failed {0}'.format(stderr))
+ raise RuntimeError(
+ 'Mount huge pages failed on {0}'.format(
+ self._node['host']))
# If we do not want to allocate dynamicaly end with error
else:
raise RuntimeError(
@@ -467,7 +482,8 @@ class QemuUtils(object):
try:
huge_free = int(out)
except ValueError:
- logging.debug('Reading free huge pages information failed')
+ logging.debug(
+ 'Reading free huge pages information failed')
else:
break
else:
@@ -493,7 +509,8 @@ class QemuUtils(object):
try:
huge_total = int(out)
except ValueError:
- logging.debug('Reading total huge pages information failed')
+ logging.debug(
+ 'Reading total huge pages information failed')
else:
break
else:
diff --git a/extras/vpp_config/vpplib/VPPUtil.py b/extras/vpp_config/vpplib/VPPUtil.py
index a1c64a3e15d..365c4c95f79 100644
--- a/extras/vpp_config/vpplib/VPPUtil.py
+++ b/extras/vpp_config/vpplib/VPPUtil.py
@@ -11,6 +11,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+from __future__ import print_function
+
"""VPP util library"""
import logging
import re
@@ -45,12 +47,18 @@ class VPPUtil(object):
stderr=subprocess.PIPE)
with prc.stdout:
- for line in iter(prc.stdout.readline, b''):
+ lines = prc.stdout.readlines()
+ for line in lines:
+ if type(line) != str:
+ line = line.decode()
logging.info(" {}".format(line.strip('\n')))
out += line
with prc.stderr:
- for line in iter(prc.stderr.readline, b''):
+ lines = prc.stderr.readlines()
+ for line in lines:
+ if type(line) != str:
+ line = line.decode()
logging.warn(" {}".format(line.strip('\n')))
err += line
@@ -135,8 +143,10 @@ class VPPUtil(object):
sfd.close()
# Add the key
- key = requests.get('https://packagecloud.io/fdio/{}/gpgkey'.format(branch))
- cmd = 'echo "{}" | apt-key add -'.format(key.content)
+
+ key = requests.get(
+ 'https://packagecloud.io/fdio/{}/gpgkey'.format(branch))
+ cmd = 'echo "{}" | apt-key add -'.format(key.content.decode(key.encoding))
(ret, stdout, stderr) = self.exec_command(cmd)
if ret != 0:
raise RuntimeError('{} failed on node {} {}'.format(
@@ -205,28 +215,31 @@ class VPPUtil(object):
stderr))
# Get the file contents
- reps = '[fdio_{}]\n'.format(branch)
- reps += 'name=fdio_{}\n'.format(branch)
- reps += 'baseurl=https://packagecloud.io/fdio/{}/el/7/$basearch\n'.format(branch)
- reps += 'repo_gpgcheck=1\n'
- reps += 'gpgcheck=0\n'
- reps += 'enabled=1\n'
- reps += 'gpgkey=https://packagecloud.io/fdio/{}/gpgkey\n'.format(branch)
- reps += 'sslverify=1\n'
- reps += 'sslcacert=/etc/pki/tls/certs/ca-bundle.crt\n'
- reps += 'metadata_expire=300\n'
- reps += '\n'
- reps += '[fdio_{}-source]\n'.format(branch)
- reps += 'name=fdio_{}-source\n'.format(branch)
- reps += 'baseurl=https://packagecloud.io/fdio/{}/el/7/SRPMS\n'.format(branch)
- reps += 'repo_gpgcheck=1\n'
- reps += 'gpgcheck=0\n'
- reps += 'enabled=1\n'
- reps += 'gpgkey=https://packagecloud.io/fdio/{}/gpgkey\n'.format(branch)
- reps += 'sslverify =1\n'
- reps += 'sslcacert=/etc/pki/tls/certs/ca-bundle.crt\n'
- reps += 'metadata_expire=300\n'
+ reps = '\n'.join([
+ '[fdio_{}]'.format(branch),
+ 'name=fdio_{}'.format(branch),
+ 'baseurl=https://packagecloud.io/fdio/{}/el/7/$basearch'.format(
+ branch),
+ 'repo_gpgcheck=1',
+ 'gpgcheck=0',
+ 'enabled=1',
+ 'gpgkey=https://packagecloud.io/fdio/{}/gpgkey'.format(branch),
+ 'sslverify=1',
+ 'sslcacert=/etc/pki/tls/certs/ca-bundle.crt',
+ 'metadata_expire=300\n',
+ '[fdio_{}-source]'.format(branch),
+ 'name=fdio_release-{}'.format(branch),
+ 'baseurl=https://packagecloud.io/fdio/{}/el/7/SRPMS'.format(
+ branch),
+ 'repo_gpgcheck=1',
+ 'gpgcheck=0',
+ 'enabled=1',
+ 'gpgkey=https://packagecloud.io/fdio/{}/gpgkey'.format(branch),
+ 'sslverify =1',
+ 'sslcacert=/etc/pki/tls/certs/ca-bundle.crt',
+ 'metadata_expire=300\n'
+ ])
with open(sfile, 'w') as sfd:
sfd.write(reps)
sfd.close()
@@ -240,7 +253,8 @@ class VPPUtil(object):
node['host'],
stderr))
- cmd = "yum -q makecache -y --disablerepo='*' --enablerepo='fdio_{}'".format(branch)
+ cmd = "yum -q makecache -y --disablerepo='*' " \
+ "--enablerepo='fdio_{}'".format(branch)
(ret, stdout, stderr) = self.exec_command(cmd)
if ret != 0:
logging.debug('{} failed on node {} {}'.format(
@@ -425,14 +439,15 @@ class VPPUtil(object):
:param node: VPP node.
:type node: dict
- :returns: Dictionary containing a list of VMs and the interfaces that are connected to VPP
+ :returns: Dictionary containing a list of VMs and the interfaces
+ that are connected to VPP
:rtype: dictionary
"""
vmdict = {}
- print "Need to implement get vms"
-
+ print ("Need to implement get vms")
+
return vmdict
@staticmethod
@@ -627,8 +642,10 @@ class VPPUtil(object):
def get_interfaces_numa_node(node, *iface_keys):
"""Get numa node on which are located most of the interfaces.
- Return numa node with highest count of interfaces provided as arguments.
- Return 0 if the interface does not have numa_node information available.
+ Return numa node with highest count of interfaces provided as
+ arguments.
+ Return 0 if the interface does not have numa_node information
+ available.
If all interfaces have unknown location (-1), then return 0.
If most of interfaces have unknown location (-1), but there are
some interfaces with known location, then return the second most
@@ -702,7 +719,9 @@ class VPPUtil(object):
cmd = 'service vpp stop'
(ret, stdout, stderr) = VPPUtil.exec_command(cmd)
if ret != 0:
- logging.debug('{} failed on node {} {} {}'.format(cmd, node['host'], stdout, stderr))
+ logging.debug('{} failed on node {} {} {}'.
+ format(cmd, node['host'],
+ stdout, stderr))
# noinspection RegExpRedundantEscape
@staticmethod
@@ -754,11 +773,12 @@ class VPPUtil(object):
distro = platform.linux_distribution()
if distro[0] == 'Ubuntu' or \
- distro[0] == 'CentOS Linux' or \
- distro[:7] == 'Red Hat':
+ distro[0] == 'CentOS Linux' or \
+ distro[:7] == 'Red Hat':
return distro
else:
- raise RuntimeError('Linux Distribution {} is not supported'.format(distro[0]))
+ raise RuntimeError(
+ 'Linux Distribution {} is not supported'.format(distro[0]))
@staticmethod
def version():
@@ -810,7 +830,7 @@ class VPPUtil(object):
bridges = []
for line in lines:
if line == 'no bridge-domains in use':
- print line
+ print (line)
return ifaces
if len(line) == 0:
continue
@@ -834,5 +854,5 @@ class VPPUtil(object):
ifcidx = {'name': iface[0], 'index': line.split()[1]}
ifaces.append(ifcidx)
- print stdout
+ print (stdout)
return ifaces
diff --git a/extras/vpp_config/vpplib/VppGrubUtil.py b/extras/vpp_config/vpplib/VppGrubUtil.py
index 1723170649e..d199f1eb053 100644
--- a/extras/vpp_config/vpplib/VppGrubUtil.py
+++ b/extras/vpp_config/vpplib/VppGrubUtil.py
@@ -101,7 +101,8 @@ class VppGrubUtil(object):
value = cmdline.split('{}='.format(grubcmdline))[1]
value = value.rstrip('"').lstrip('"')
- # jadfix intel_pstate=disable sometimes cause networks to hang on reboot
+ # jadfix intel_pstate=disable sometimes cause networks to
+ # hang on reboot
# iommu = re.findall(r'iommu=\w+', value)
# pstate = re.findall(r'intel_pstate=\w+', value)
# If there is already some iommu commands set, leave them,
diff --git a/extras/vpp_config/vpplib/VppHugePageUtil.py b/extras/vpp_config/vpplib/VppHugePageUtil.py
index 43df72a455a..3a632828883 100644
--- a/extras/vpp_config/vpplib/VppHugePageUtil.py
+++ b/extras/vpp_config/vpplib/VppHugePageUtil.py
@@ -11,6 +11,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+from __future__ import print_function
+
"""VPP Huge Page Utilities"""
import re
@@ -95,16 +97,16 @@ class VppHugePageUtil(object):
node = self._node
hugepages = node['hugepages']
- print " {:30}: {}".format("Total System Memory",
- hugepages['memtotal'])
- print " {:30}: {}".format("Total Free Memory",
- hugepages['memfree'])
- print " {:30}: {}".format("Actual Huge Page Total",
- hugepages['actual_total'])
- print " {:30}: {}".format("Configured Huge Page Total",
- hugepages['total'])
- print " {:30}: {}".format("Huge Pages Free", hugepages['free'])
- print " {:30}: {}".format("Huge Page Size", hugepages['size'])
+ print (" {:30}: {}".format("Total System Memory",
+ hugepages['memtotal']))
+ print (" {:30}: {}".format("Total Free Memory",
+ hugepages['memfree']))
+ print (" {:30}: {}".format("Actual Huge Page Total",
+ hugepages['actual_total']))
+ print (" {:30}: {}".format("Configured Huge Page Total",
+ hugepages['total']))
+ print (" {:30}: {}".format("Huge Pages Free", hugepages['free']))
+ print (" {:30}: {}".format("Huge Page Size", hugepages['size']))
def get_huge_page_config(self):
"""
diff --git a/extras/vpp_config/vpplib/VppPCIUtil.py b/extras/vpp_config/vpplib/VppPCIUtil.py
index fe64c9d4b14..ceda46f97b9 100644
--- a/extras/vpp_config/vpplib/VppPCIUtil.py
+++ b/extras/vpp_config/vpplib/VppPCIUtil.py
@@ -11,6 +11,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+from __future__ import print_function
+
"""VPP PCI Utility libraries"""
import re
@@ -44,7 +46,7 @@ class VppPCIUtil(object):
ids = re.findall(PCI_DEV_ID_REGEX, device_string)
descriptions = re.findall(r'\'([\s\S]*?)\'', device_string)
- unused = re.findall(r'unused=[\w,]+', device_string)
+ unused = re.findall(r'unused=\w+|unused=', device_string)
for i, j in enumerate(ids):
device = {'description': descriptions[i]}
@@ -268,8 +270,8 @@ class VppPCIUtil(object):
dashseparator = ("-" * (len(header) - 2))
if show_header is True:
- print header
- print dashseparator
+ print (header)
+ print (dashseparator)
for dit in devices.items():
dvid = dit[0]
device = dit[1]
@@ -282,11 +284,11 @@ class VppPCIUtil(object):
else:
interface = interfaces[i]
- print "{:15} {:25} {:50}".format(
- dvid, interface, device['description'])
+ print ("{:15} {:25} {:50}".format(
+ dvid, interface, device['description']))
else:
- print "{:15} {:50}".format(
- dvid, device['description'])
+ print ("{:15} {:50}".format(
+ dvid, device['description']))
@staticmethod
def unbind_vpp_device(node, device_id):