1 From 858b4575513fe72dce95370944b0da237b755204 Mon Sep 17 00:00:00 2001
2 From: Dave Wallace <dwallacelf@gmail.com>
3 Date: Thu, 15 Oct 2020 15:22:22 -0400
4 Subject: [PATCH] backport dpdk usertools support python 3 only
6 Applicable usertools section of DPDK patch:
7 http://git.dpdk.org/dpdk/commit/?id=3f6f83626cf4967a99382a6518a614a1bf3d2c20
9 Required to avoid build failure of 'make install-ext-deps' on CentOS-8 due
10 to brp-mangle-shebangs failing on un-versioned python shebang (e.g.
11 '#! /usr/bin/env python'.
13 Signed-off-by: Dave Wallace <dwallacelf@gmail.com>
15 usertools/cpu_layout.py | 15 ++-------------
16 usertools/dpdk-devbind.py | 22 ++++------------------
17 usertools/dpdk-pmdinfo.py | 7 +------
18 usertools/dpdk-telemetry-client.py | 18 +++---------------
19 usertools/dpdk-telemetry.py | 2 +-
20 5 files changed, 11 insertions(+), 53 deletions(-)
22 diff --git a/usertools/cpu_layout.py b/usertools/cpu_layout.py
23 index 5423c7965..cc3963821 100755
24 --- a/usertools/cpu_layout.py
25 +++ b/usertools/cpu_layout.py
27 -#!/usr/bin/env python
28 +#!/usr/bin/env python3
29 # SPDX-License-Identifier: BSD-3-Clause
30 # Copyright(c) 2010-2014 Intel Corporation
31 # Copyright(c) 2017 Cavium, Inc. All rights reserved.
33 -from __future__ import print_function
38 - xrange = range # Python 3
40 -if sys.version_info.major < 3:
41 - print("WARNING: Python 2 is deprecated for use in DPDK, and will not work in future releases.", file=sys.stderr)
42 - print("Please use Python 3 instead", file=sys.stderr)
48 fd = open("{}/kernel_max".format(base_path))
49 max_cpus = int(fd.read())
51 -for cpu in xrange(max_cpus + 1):
52 +for cpu in range(max_cpus + 1):
54 fd = open("{}/cpu{}/topology/core_id".format(base_path, cpu))
56 diff --git a/usertools/dpdk-devbind.py b/usertools/dpdk-devbind.py
57 index 094c2ffc8..8278a748d 100755
58 --- a/usertools/dpdk-devbind.py
59 +++ b/usertools/dpdk-devbind.py
61 -#! /usr/bin/env python
62 +#!/usr/bin/env python3
63 # SPDX-License-Identifier: BSD-3-Clause
64 # Copyright(c) 2010-2014 Intel Corporation
67 -from __future__ import print_function
72 from os.path import exists, abspath, dirname, basename
73 from os.path import join as path_join
75 -if sys.version_info.major < 3:
76 - print("WARNING: Python 2 is deprecated for use in DPDK, and will not work in future releases.", file=sys.stderr)
77 - print("Please use Python 3 instead", file=sys.stderr)
79 # The PCI base class for all devices
80 network_class = {'Class': '02', 'Vendor': None, 'Device': None,
81 'SVendor': None, 'SDevice': None}
82 @@ -154,14 +149,6 @@ def usage():
84 """ % locals()) # replace items from local variables
87 -# This is roughly compatible with check_output function in subprocess module
88 -# which is only available in python 2.7.
89 -def check_output(args, stderr=None):
90 - '''Run a command and capture its output'''
91 - return subprocess.Popen(args, stdout=subprocess.PIPE,
92 - stderr=stderr).communicate()[0]
94 # check if a specific kernel module is loaded
95 def module_is_loaded(module):
97 @@ -218,8 +205,7 @@ def get_pci_device_details(dev_id, probe_lspci):
101 - extra_info = check_output(["lspci", "-vmmks", dev_id]).splitlines()
103 + extra_info = subprocess.check_output(["lspci", "-vmmks", dev_id]).splitlines()
104 # parse lspci details
105 for line in extra_info:
107 @@ -255,7 +241,7 @@ def get_device_details(devices_type):
108 # first loop through and read details for all devices
109 # request machine readable format, with numeric IDs and String
111 - dev_lines = check_output(["lspci", "-Dvmmnnk"]).splitlines()
112 + dev_lines = subprocess.check_output(["lspci", "-Dvmmnnk"]).splitlines()
113 for dev_line in dev_lines:
114 if len(dev_line) == 0:
115 if device_type_match(dev, devices_type):
116 @@ -283,7 +269,7 @@ def get_device_details(devices_type):
117 # check what is the interface if any for an ssh connection if
118 # any to this host, so we can mark it later.
120 - route = check_output(["ip", "-o", "route"])
121 + route = subprocess.check_output(["ip", "-o", "route"])
122 # filter out all lines for 169.254 routes
123 route = "\n".join(filter(lambda ln: not ln.startswith("169.254"),
124 route.decode().splitlines()))
125 diff --git a/usertools/dpdk-pmdinfo.py b/usertools/dpdk-pmdinfo.py
126 index f9ed75517..166198279 100755
127 --- a/usertools/dpdk-pmdinfo.py
128 +++ b/usertools/dpdk-pmdinfo.py
130 -#!/usr/bin/env python
131 +#!/usr/bin/env python3
132 # SPDX-License-Identifier: BSD-3-Clause
133 # Copyright(c) 2016 Neil Horman <nhorman@tuxdriver.com>
136 # Utility to dump PMD_INFO_STRING support from an object file
138 # -------------------------------------------------------------------------
139 -from __future__ import print_function
140 -from __future__ import unicode_literals
147 # ===========================================
148 -if sys.version_info.major < 3:
149 - print("WARNING: Python 2 is deprecated for use in DPDK, and will not work in future releases.", file=sys.stderr)
150 - print("Please use Python 3 instead", file=sys.stderr)
154 diff --git a/usertools/dpdk-telemetry-client.py b/usertools/dpdk-telemetry-client.py
155 index 98d28fa89..d8e439027 100755
156 --- a/usertools/dpdk-telemetry-client.py
157 +++ b/usertools/dpdk-telemetry-client.py
159 -#! /usr/bin/env python
160 +#! /usr/bin/env python3
161 # SPDX-License-Identifier: BSD-3-Clause
162 # Copyright(c) 2018 Intel Corporation
164 -from __future__ import print_function
165 -from __future__ import unicode_literals
171 GLOBAL_METRICS_REQ = "{\"action\":0,\"command\":\"global_stat_values\",\"data\":null}"
172 DEFAULT_FP = "/var/run/dpdk/default_client"
175 - raw_input # Python 2
177 - raw_input = input # Python 3
179 -if sys.version_info.major < 3:
180 - print("WARNING: Python 2 is deprecated for use in DPDK, and will not work in future releases.", file=sys.stderr)
181 - print("Please use Python 3 instead", file=sys.stderr)
186 @@ -86,7 +74,7 @@ def requestMetrics(self): # Requests metrics for given client
188 def repeatedlyRequestMetrics(self, sleep_time): # Recursively requests metrics for given client
189 print("\nPlease enter the number of times you'd like to continuously request Metrics:")
190 - n_requests = int(raw_input("\n:"))
191 + n_requests = int(input("\n:"))
192 print("\033[F") #Removes the user input from screen, cleans it up
194 for i in range(n_requests):
195 @@ -107,7 +95,7 @@ def interactiveMenu(self, sleep_time): # Creates Interactive menu within the scr
196 print("[4] Unregister client")
199 - self.choice = int(raw_input("\n:"))
200 + self.choice = int(input("\n:"))
201 print("\033[F") #Removes the user input for screen, cleans it up
204 diff --git a/usertools/dpdk-telemetry.py b/usertools/dpdk-telemetry.py
205 index 8e4039d57..181859658 100755
206 --- a/usertools/dpdk-telemetry.py
207 +++ b/usertools/dpdk-telemetry.py
210 +#! /usr/bin/env python3
211 # SPDX-License-Identifier: BSD-3-Clause
212 # Copyright(c) 2020 Intel Corporation