support python 3 only

Changed scripts to explicitly use Python 3 only, to avoid
maintaining Python 2.
Removed deprecation notices.

Signed-off-by: Louise Kilheeney <louise.kilheeney@intel.com>
Signed-off-by: Kevin Laatz <kevin.laatz@intel.com>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
Acked-by: Robin Jarry <robin.jarry@6wind.com>
Acked-by: Stephen Hemminger <stephen@networkplumber.org>
Acked-by: Ray Kinsella <mdr@ashroe.eu>
This commit is contained in:
Louise Kilheeney 2020-09-30 12:40:14 +01:00 committed by David Marchand
parent 2a8be2ff75
commit 3f6f83626c
19 changed files with 34 additions and 108 deletions

View File

@ -1,9 +1,8 @@
#!/usr/bin/env python
#!/usr/bin/env python3
# SPDX-License-Identifier: BSD-3-Clause
# Copyright(c) 2017 Intel Corporation
from __future__ import print_function
import sys
import os
import argparse
@ -16,10 +15,6 @@ def kill(process):
print("ERROR: Test app timed out")
process.kill()
if sys.version_info.major < 3:
print("WARNING: Python 2 is deprecated for use in DPDK, and will not work in future releases.", file=sys.stderr)
print("Please use Python 3 instead", file=sys.stderr)
dpdk_path = "../.."
dpdk_target = "build"

View File

@ -1,9 +1,8 @@
#!/usr/bin/env python
#!/usr/bin/env python3
# SPDX-License-Identifier: BSD-3-Clause
# Copyright(c) 2010-2014 Intel Corporation
# Script that runs cmdline_test app and feeds keystrokes into it.
from __future__ import print_function
import cmdline_test_data
import os
import pexpect
@ -19,10 +18,6 @@ def runTest(child, test):
return 0
child.expect(test["Result"], 1)
if sys.version_info.major < 3:
print("WARNING: Python 2 is deprecated for use in DPDK, and will not work in future releases.", file=sys.stderr)
print("Please use Python 3 instead", file=sys.stderr)
#
# history test is a special case
#
@ -43,7 +38,7 @@ def runHistoryTest(child):
i = 0
# fill the history with numbers
while i < history_size / 10:
while i < history_size // 10:
# add 1 to prevent from parsing as octals
child.send("1" + str(i).zfill(8) + cmdline_test_data.ENTER)
# the app will simply print out the number

View File

@ -1,3 +1,4 @@
#!/usr/bin/env python3
# SPDX-License-Identifier: BSD-3-Clause
# Copyright(c) 2010-2014 Intel Corporation

View File

@ -1,9 +1,8 @@
#!/usr/bin/env python
#!/usr/bin/env python3
# SPDX-License-Identifier: BSD-3-Clause
# Copyright(c) 2010-2014 Intel Corporation
# Script that uses either test app or qemu controlled by python-pexpect
from __future__ import print_function
import autotest_data
import autotest_runner
import sys
@ -17,10 +16,6 @@ def usage():
usage()
sys.exit(1)
if sys.version_info.major < 3:
print("WARNING: Python 2 is deprecated for use in DPDK, and will not work in future releases.", file=sys.stderr)
print("Please use Python 3 instead", file=sys.stderr)
target = sys.argv[2]
test_whitelist = None

View File

@ -1,3 +1,4 @@
#!/usr/bin/env python3
# SPDX-License-Identifier: BSD-3-Clause
# Copyright(c) 2010-2014 Intel Corporation

View File

@ -1,10 +1,10 @@
#!/usr/bin/env python3
# SPDX-License-Identifier: BSD-3-Clause
# Copyright(c) 2010-2014 Intel Corporation
# The main logic behind running autotests in parallel
from __future__ import print_function
import StringIO
import io
import csv
from multiprocessing import Pool, Queue
import pexpect
@ -50,11 +50,7 @@ def first_cpu_on_node(node_nr):
map(os.path.basename, cpu_path)
)
)
# for compatibility between python 3 and 2 we need to make interable out
# of filter return as it returns list in python 2 and a generator in 3
m = next(iter(cpu_name))
return int(m.group(1))
return int(next(cpu_name).group(1))
pool_child = None # per-process child
@ -78,7 +74,7 @@ def pool_init(queue, result_queue):
cmdline = "%s %s" % (cmdline, prefix_cmdline)
# prepare logging of init
startuplog = StringIO.StringIO()
startuplog = io.StringIO()
# run test app
try:
@ -86,8 +82,7 @@ def pool_init(queue, result_queue):
print("\n%s %s\n" % ("=" * 20, prefix), file=startuplog)
print("\ncmdline=%s" % cmdline, file=startuplog)
pool_child = pexpect.spawn(cmdline, logfile=startuplog)
pool_child = pexpect.spawn(cmdline, logfile=startuplog, encoding='utf-8')
# wait for target to boot
if not wait_prompt(pool_child):
pool_child.close()
@ -138,7 +133,7 @@ def run_test(target, test):
# create log buffer for each test
# in multiprocessing environment, the logging would be
# interleaved and will create a mess, hence the buffering
logfile = StringIO.StringIO()
logfile = io.StringIO()
pool_child.logfile = logfile
# make a note when the test started
@ -210,9 +205,9 @@ def __init__(self, cmdline, target, blacklist, whitelist, n_processes):
# parse the binary for available test commands
binary = cmdline.split()[0]
stripped = 'not stripped' not in \
subprocess.check_output(['file', binary])
subprocess.check_output(['file', binary]).decode()
if not stripped:
symbols = subprocess.check_output(['nm', binary]).decode('utf-8')
symbols = subprocess.check_output(['nm', binary]).decode()
self.avail_cmds = re.findall('test_register_(\w+)', symbols)
else:
self.avail_cmds = None

View File

@ -1,3 +1,4 @@
#!/usr/bin/env python3
# SPDX-License-Identifier: BSD-3-Clause
# Copyright(c) 2010-2014 Intel Corporation

View File

@ -1,8 +1,7 @@
#!/usr/bin/env python
#!/usr/bin/env python3
# SPDX-License-Identifier: BSD-3-Clause
# Copyright(c) 2019 Intel Corporation
from __future__ import print_function
import sys
from os.path import dirname, basename, join, exists

View File

@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/env python3
# SPDX-License-Identifier: BSD-3-Clause
# Copyright(c) 2017 Cavium, Inc

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
# SPDX-License-Identifier: BSD-3-Clause
# Copyright(c) 2019 Intel Corporation
@ -9,7 +9,6 @@
from the devtools/update-abi.sh utility.
"""
from __future__ import print_function
import argparse
import sys
import re
@ -160,10 +159,6 @@ def __generate_internal_abi(f_out, lines):
print("};", file=f_out)
def __main():
if sys.version_info.major < 3:
print("WARNING: Python 2 is deprecated for use in DPDK, and will not work in future releases.", file=sys.stderr)
print("Please use Python 3 instead", file=sys.stderr)
arg_parser = argparse.ArgumentParser(
description='Merge versions in linker version script.')

View File

@ -1,7 +1,7 @@
#!/usr/bin/env python3
# SPDX-License-Identifier: BSD-3-Clause
# Copyright(c) 2010-2015 Intel Corporation
from __future__ import print_function
from docutils import nodes
from distutils.version import LooseVersion
from sphinx import __version__ as sphinx_version
@ -13,12 +13,7 @@
from os.path import dirname
from os.path import join as path_join
try:
# Python 2.
import ConfigParser as configparser
except:
# Python 3.
import configparser
import configparser
try:
import sphinx_rtd_theme

View File

@ -765,7 +765,7 @@ specializations, run the ``app/test`` binary, and use the ``dump_log_types``
Python Code
-----------
All Python code should work with Python 2.7+ and 3.2+ and be compliant with
All Python code should be compliant with
`PEP8 (Style Guide for Python Code) <https://www.python.org/dev/peps/pep-0008/>`_.
The ``pep8`` tool can be used for testing compliance with the guidelines.

View File

@ -233,12 +233,6 @@ Deprecation Notices
In this case the function will return -1 unless the environment is unset first
(using ``rte_power_unset_env``). Other function usage scenarios will not change.
* python: Since the beginning of 2020, Python 2 has officially reached
end-of-support: https://www.python.org/doc/sunset-python-2/.
Python 2 support will be completely removed in 20.11.
In 20.08, explicit deprecation warnings will be displayed when running
scripts with Python 2.
* dpdk-setup.sh: This old script relies on deprecated stuff, and especially
``make``. Given environments are too much variables for such a simple script,
it will be removed in DPDK 20.11.

View File

@ -122,6 +122,8 @@ Removed Items
* vhost: Dequeue zero-copy support has been removed.
* Removed Python 2 support since it was EOL'd in January 2020.
API Changes
-----------

View File

@ -1,19 +1,8 @@
#!/usr/bin/env python
#!/usr/bin/env python3
# SPDX-License-Identifier: BSD-3-Clause
# Copyright(c) 2010-2014 Intel Corporation
# Copyright(c) 2017 Cavium, Inc. All rights reserved.
from __future__ import print_function
import sys
try:
xrange # Python 2
except NameError:
xrange = range # Python 3
if sys.version_info.major < 3:
print("WARNING: Python 2 is deprecated for use in DPDK, and will not work in future releases.", file=sys.stderr)
print("Please use Python 3 instead", file=sys.stderr)
sockets = []
cores = []
core_map = {}
@ -21,7 +10,7 @@
fd = open("{}/kernel_max".format(base_path))
max_cpus = int(fd.read())
fd.close()
for cpu in xrange(max_cpus + 1):
for cpu in range(max_cpus + 1):
try:
fd = open("{}/cpu{}/topology/core_id".format(base_path, cpu))
except IOError:

View File

@ -1,9 +1,8 @@
#! /usr/bin/env python
#!/usr/bin/env python3
# SPDX-License-Identifier: BSD-3-Clause
# Copyright(c) 2010-2014 Intel Corporation
#
from __future__ import print_function
import sys
import os
import getopt
@ -12,10 +11,6 @@
from os.path import exists, abspath, dirname, basename
from os.path import join as path_join
if sys.version_info.major < 3:
print("WARNING: Python 2 is deprecated for use in DPDK, and will not work in future releases.", file=sys.stderr)
print("Please use Python 3 instead", file=sys.stderr)
# The PCI base class for all devices
network_class = {'Class': '02', 'Vendor': None, 'Device': None,
'SVendor': None, 'SDevice': None}
@ -154,14 +149,6 @@ def usage():
""" % locals()) # replace items from local variables
# This is roughly compatible with check_output function in subprocess module
# which is only available in python 2.7.
def check_output(args, stderr=None):
'''Run a command and capture its output'''
return subprocess.Popen(args, stdout=subprocess.PIPE,
stderr=stderr).communicate()[0]
# check if a specific kernel module is loaded
def module_is_loaded(module):
global loaded_modules
@ -218,8 +205,7 @@ def get_pci_device_details(dev_id, probe_lspci):
device = {}
if probe_lspci:
extra_info = check_output(["lspci", "-vmmks", dev_id]).splitlines()
extra_info = subprocess.check_output(["lspci", "-vmmks", dev_id]).splitlines()
# parse lspci details
for line in extra_info:
if len(line) == 0:
@ -255,7 +241,7 @@ def get_device_details(devices_type):
# first loop through and read details for all devices
# request machine readable format, with numeric IDs and String
dev = {}
dev_lines = check_output(["lspci", "-Dvmmnnk"]).splitlines()
dev_lines = subprocess.check_output(["lspci", "-Dvmmnnk"]).splitlines()
for dev_line in dev_lines:
if len(dev_line) == 0:
if device_type_match(dev, devices_type):
@ -283,7 +269,7 @@ def get_device_details(devices_type):
# check what is the interface if any for an ssh connection if
# any to this host, so we can mark it later.
ssh_if = []
route = check_output(["ip", "-o", "route"])
route = subprocess.check_output(["ip", "-o", "route"])
# filter out all lines for 169.254 routes
route = "\n".join(filter(lambda ln: not ln.startswith("169.254"),
route.decode().splitlines()))

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
# SPDX-License-Identifier: BSD-3-Clause
# Copyright(c) 2016 Neil Horman <nhorman@tuxdriver.com>
@ -7,8 +7,6 @@
# Utility to dump PMD_INFO_STRING support from an object file
#
# -------------------------------------------------------------------------
from __future__ import print_function
from __future__ import unicode_literals
import json
import io
import os
@ -28,9 +26,6 @@
pcidb = None
# ===========================================
if sys.version_info.major < 3:
print("WARNING: Python 2 is deprecated for use in DPDK, and will not work in future releases.", file=sys.stderr)
print("Please use Python 3 instead", file=sys.stderr)
class Vendor:
"""

View File

@ -1,10 +1,7 @@
#! /usr/bin/env python
#! /usr/bin/env python3
# SPDX-License-Identifier: BSD-3-Clause
# Copyright(c) 2018 Intel Corporation
from __future__ import print_function
from __future__ import unicode_literals
import socket
import os
import sys
@ -18,15 +15,6 @@
GLOBAL_METRICS_REQ = "{\"action\":0,\"command\":\"global_stat_values\",\"data\":null}"
DEFAULT_FP = "/var/run/dpdk/default_client"
try:
raw_input # Python 2
except NameError:
raw_input = input # Python 3
if sys.version_info.major < 3:
print("WARNING: Python 2 is deprecated for use in DPDK, and will not work in future releases.", file=sys.stderr)
print("Please use Python 3 instead", file=sys.stderr)
class Socket:
def __init__(self):
@ -86,7 +74,7 @@ def requestMetrics(self): # Requests metrics for given client
def repeatedlyRequestMetrics(self, sleep_time): # Recursively requests metrics for given client
print("\nPlease enter the number of times you'd like to continuously request Metrics:")
n_requests = int(raw_input("\n:"))
n_requests = int(input("\n:"))
print("\033[F") #Removes the user input from screen, cleans it up
print("\033[K")
for i in range(n_requests):
@ -107,7 +95,7 @@ def interactiveMenu(self, sleep_time): # Creates Interactive menu within the scr
print("[4] Unregister client")
try:
self.choice = int(raw_input("\n:"))
self.choice = int(input("\n:"))
print("\033[F") #Removes the user input for screen, cleans it up
print("\033[K")
if self.choice == 1:

View File

@ -1,4 +1,4 @@
#! /usr/bin/python3
#! /usr/bin/env python3
# SPDX-License-Identifier: BSD-3-Clause
# Copyright(c) 2020 Intel Corporation