build: fix typo in dpdk-20.08 patch #0003
[vpp.git] / build / external / patches / dpdk_20.08 / 0003-backport-dpdk-usertools-support-python-3-only.patch
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
5
6 Applicable usertools section of DPDK patch:
7 http://git.dpdk.org/dpdk/commit/?id=3f6f83626cf4967a99382a6518a614a1bf3d2c20
8
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'.
12
13 Signed-off-by: Dave Wallace <dwallacelf@gmail.com>
14 ---
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(-)
21
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
26 @@ -1,19 +1,8 @@
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.
32
33 -from __future__ import print_function
34 -import sys
35 -try:
36 -    xrange # Python 2
37 -except NameError:
38 -    xrange = range # Python 3
39 -
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)
43 -
44  sockets = []
45  cores = []
46  core_map = {}
47 @@ -21,7 +10,7 @@
48  fd = open("{}/kernel_max".format(base_path))
49  max_cpus = int(fd.read())
50  fd.close()
51 -for cpu in xrange(max_cpus + 1):
52 +for cpu in range(max_cpus + 1):
53      try:
54          fd = open("{}/cpu{}/topology/core_id".format(base_path, cpu))
55      except IOError:
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
60 @@ -1,4 +1,4 @@
61 -#! /usr/bin/env python
62 +#! /usr/bin/env python3
63  # SPDX-License-Identifier: BSD-3-Clause
64  # Copyright(c) 2010-2014 Intel Corporation
65  #
66
67 -from __future__ import print_function
68  import sys
69  import os
70  import getopt
71 @@ -12,10 +11,6 @@
72  from os.path import exists, abspath, dirname, basename
73  from os.path import join as path_join
74
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)
78 -
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():
83
84      """ % locals())  # replace items from local variables
85
86 -
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]
93 -
94  # check if a specific kernel module is loaded
95  def module_is_loaded(module):
96      global loaded_modules
97 @@ -218,8 +205,7 @@ def get_pci_device_details(dev_id, probe_lspci):
98      device = {}
99
100      if probe_lspci:
101 -        extra_info = check_output(["lspci", "-vmmks", dev_id]).splitlines()
102 -
103 +        extra_info = subprocess.check_output(["lspci", "-vmmks", dev_id]).splitlines()
104          # parse lspci details
105          for line in extra_info:
106              if len(line) == 0:
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
110      dev = {}
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.
119          ssh_if = []
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
129 @@ -1,4 +1,4 @@
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>
134
135 @@ -7,8 +7,6 @@
136  # Utility to dump PMD_INFO_STRING support from an object file
137  #
138  # -------------------------------------------------------------------------
139 -from __future__ import print_function
140 -from __future__ import unicode_literals
141  import json
142  import io
143  import os
144 @@ -28,9 +26,6 @@
145  pcidb = None
146
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)
151
152  class Vendor:
153      """
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
158 @@ -1,10 +1,7 @@
159 -#! /usr/bin/env python
160 +#! /usr/bin/env python3
161  # SPDX-License-Identifier: BSD-3-Clause
162  # Copyright(c) 2018 Intel Corporation
163
164 -from __future__ import print_function
165 -from __future__ import unicode_literals
166 -
167  import socket
168  import os
169  import sys
170 @@ -18,15 +15,6 @@
171  GLOBAL_METRICS_REQ = "{\"action\":0,\"command\":\"global_stat_values\",\"data\":null}"
172  DEFAULT_FP = "/var/run/dpdk/default_client"
173
174 -try:
175 -    raw_input  # Python 2
176 -except NameError:
177 -    raw_input = input  # Python 3
178 -
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)
182 -
183  class Socket:
184
185      def __init__(self):
186 @@ -86,7 +74,7 @@ def requestMetrics(self): # Requests metrics for given client
187
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
193          print("\033[K")
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")
197
198              try:
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
202                  print("\033[K")
203                  if self.choice == 1:
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
208 @@ -1,4 +1,4 @@
209 -#! /usr/bin/python3
210 +#! /usr/bin/env python3
211  # SPDX-License-Identifier: BSD-3-Clause
212  # Copyright(c) 2020 Intel Corporation