summaryrefslogtreecommitdiffstats
path: root/extras/vpp_config/vpplib/VPPUtil.py
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/vpp_config/vpplib/VPPUtil.py
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/vpp_config/vpplib/VPPUtil.py')
-rw-r--r--extras/vpp_config/vpplib/VPPUtil.py94
1 files changed, 57 insertions, 37 deletions
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