openvswitch: backport py3 fixups

While attempting to get ovs to be built and run with py3 (completely
free of py2) host contamination was found (builds on hosts without
python-six installed would fail). It was also determined that pyc
files were still being generated with py2 and not py3. This resulted
in more work being done to achieve the desired results. This work was
sent upstream and subsequently merged. Unfortunately this didn't make
v2.7.1 and may not be available until the next major release, so here
we backport these commits and adjust the recipe to get a clean py3
only build.

Signed-off-by: Mark Asselstine <mark.asselstine@windriver.com>
Signed-off-by: Bruce Ashfield <bruce.ashfield@windriver.com>
This commit is contained in:
Mark Asselstine 2017-07-12 17:02:42 -04:00 committed by Bruce Ashfield
parent 165ffabe89
commit f0f0453984
10 changed files with 1677 additions and 1 deletions

View File

@ -0,0 +1,79 @@
From c98fee41d130cb946aa4e60fefaa6cbf203f6790 Mon Sep 17 00:00:00 2001
From: Jason Wessel <jason.wessel@windriver.com>
Date: Thu, 29 Jun 2017 20:33:23 -0700
Subject: [PATCH 2/8] Python3 compatibility: exception cleanup
Commit 52e4a477f0b3c0a0ece7adeede6e06e07814f8b9 from
https://github.com/openvswitch/ovs.git
The exception syntax which is compatible with python2 and python3 is
to use the "as" form for "except:".
Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
---
build-aux/extract-ofp-fields | 2 +-
ovsdb/ovsdb-doc | 4 ++--
ovsdb/ovsdb-idlc.in | 4 ++--
3 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/build-aux/extract-ofp-fields b/build-aux/extract-ofp-fields
index 425a85f..61e752b 100755
--- a/build-aux/extract-ofp-fields
+++ b/build-aux/extract-ofp-fields
@@ -784,7 +784,7 @@ if __name__ == "__main__":
try:
options, args = getopt.gnu_getopt(sys.argv[1:], 'h',
['help', 'ovs-version='])
- except getopt.GetoptError, geo:
+ except getopt.GetoptError as geo:
sys.stderr.write("%s: %s\n" % (argv0, geo.msg))
sys.exit(1)
diff --git a/ovsdb/ovsdb-doc b/ovsdb/ovsdb-doc
index b34fb11..918e88a 100755
--- a/ovsdb/ovsdb-doc
+++ b/ovsdb/ovsdb-doc
@@ -278,7 +278,7 @@ if __name__ == "__main__":
options, args = getopt.gnu_getopt(sys.argv[1:], 'hV',
['er-diagram=',
'version=', 'help'])
- except getopt.GetoptError, geo:
+ except getopt.GetoptError as geo:
sys.stderr.write("%s: %s\n" % (argv0, geo.msg))
sys.exit(1)
@@ -306,7 +306,7 @@ if __name__ == "__main__":
if len(line):
print(line)
- except error.Error, e:
+ except error.Error as e:
sys.stderr.write("%s: %s\n" % (argv0, e.msg))
sys.exit(1)
diff --git a/ovsdb/ovsdb-idlc.in b/ovsdb/ovsdb-idlc.in
index 1064448..8b85f0d 100755
--- a/ovsdb/ovsdb-idlc.in
+++ b/ovsdb/ovsdb-idlc.in
@@ -1098,7 +1098,7 @@ if __name__ == "__main__":
['directory',
'help',
'version'])
- except getopt.GetoptError, geo:
+ except getopt.GetoptError as geo:
sys.stderr.write("%s: %s\n" % (argv0, geo.msg))
sys.exit(1)
@@ -1136,7 +1136,7 @@ if __name__ == "__main__":
sys.exit(1)
func(*args[1:])
- except ovs.db.error.Error, e:
+ except ovs.db.error.Error as e:
sys.stderr.write("%s: %s\n" % (argv0, e))
sys.exit(1)
--
2.5.0

View File

@ -0,0 +1,33 @@
From 9cbae86be03756df76560c15720756f9ac088144 Mon Sep 17 00:00:00 2001
From: Jason Wessel <jason.wessel@windriver.com>
Date: Thu, 29 Jun 2017 20:33:23 -0700
Subject: [PATCH 3/8] Python3 compatibility: execfile to exec
Commit a4d10a7ca937d73873f6f98619d88682e69f5dbe from
https://github.com/openvswitch/ovs.git
Allow compability with python3 and python2 by changing execfile() to
exec().
Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
---
ovsdb/ovsdb-idlc.in | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/ovsdb/ovsdb-idlc.in b/ovsdb/ovsdb-idlc.in
index 8b85f0d..3fa1a0f 100755
--- a/ovsdb/ovsdb-idlc.in
+++ b/ovsdb/ovsdb-idlc.in
@@ -17,7 +17,7 @@ def parseSchema(filename):
def annotateSchema(schemaFile, annotationFile):
schemaJson = ovs.json.from_file(schemaFile)
- execfile(annotationFile, globals(), {"s": schemaJson})
+ exec(compile(open(annotationFile, "rb").read(), annotationFile, 'exec'), globals(), {"s": schemaJson})
ovs.json.to_stream(schemaJson, sys.stdout)
sys.stdout.write('\n')
--
2.5.0

View File

@ -0,0 +1,102 @@
From 0f318e472d9897d99395adcfb17cbeaff05677ba Mon Sep 17 00:00:00 2001
From: Jason Wessel <jason.wessel@windriver.com>
Date: Thu, 29 Jun 2017 20:33:23 -0700
Subject: [PATCH 4/8] Python3 compatibility: iteritems to items
Commit 4ab665623cbb4c6506e48b82e0c9fe8585f42e13 from
https://github.com/openvswitch/ovs.git
Allow compability with python3 and python2 by changing iteritems() to
items().
Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
---
build-aux/extract-ofp-actions | 2 +-
build-aux/extract-ofp-errors | 2 +-
build-aux/extract-ofp-fields | 2 +-
ovsdb/ovsdb-idlc.in | 8 ++++----
4 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/build-aux/extract-ofp-actions b/build-aux/extract-ofp-actions
index 874e6b4..c11297c 100755
--- a/build-aux/extract-ofp-actions
+++ b/build-aux/extract-ofp-actions
@@ -13,7 +13,7 @@ version_map = {"1.0": 0x01,
"1.3": 0x04,
"1.4": 0x05,
"1.5": 0x06}
-version_reverse_map = dict((v, k) for (k, v) in version_map.iteritems())
+version_reverse_map = dict((v, k) for (k, v) in version_map.items())
# Map from vendor name to the length of the action header.
vendor_map = {"OF": (0x00000000, 4),
diff --git a/build-aux/extract-ofp-errors b/build-aux/extract-ofp-errors
index 336a240..71ae0bd 100755
--- a/build-aux/extract-ofp-errors
+++ b/build-aux/extract-ofp-errors
@@ -14,7 +14,7 @@ version_map = {"1.0": 0x01,
"1.4": 0x05,
"1.5": 0x06,
"1.6": 0x07}
-version_reverse_map = dict((v, k) for (k, v) in version_map.iteritems())
+version_reverse_map = dict((v, k) for (k, v) in version_map.items())
token = None
line = ""
diff --git a/build-aux/extract-ofp-fields b/build-aux/extract-ofp-fields
index 61e752b..ef997dd 100755
--- a/build-aux/extract-ofp-fields
+++ b/build-aux/extract-ofp-fields
@@ -16,7 +16,7 @@ VERSION = {"1.0": 0x01,
"1.3": 0x04,
"1.4": 0x05,
"1.5": 0x06}
-VERSION_REVERSE = dict((v,k) for k, v in VERSION.iteritems())
+VERSION_REVERSE = dict((v,k) for k, v in VERSION.items())
TYPES = {"u8": (1, False),
"be16": (2, False),
diff --git a/ovsdb/ovsdb-idlc.in b/ovsdb/ovsdb-idlc.in
index 3fa1a0f..615548f 100755
--- a/ovsdb/ovsdb-idlc.in
+++ b/ovsdb/ovsdb-idlc.in
@@ -138,7 +138,7 @@ def printCIDLHeader(schemaFile):
#include "smap.h"
#include "uuid.h"''' % {'prefix': prefix.upper()})
- for tableName, table in sorted(schema.tables.iteritems()):
+ for tableName, table in sorted(schema.tables.items()):
structName = "%s%s" % (prefix, tableName.lower())
print(" ")
@@ -300,7 +300,7 @@ def printCIDLSource(schemaFile):
''' % schema.idlHeader)
# Cast functions.
- for tableName, table in sorted(schema.tables.iteritems()):
+ for tableName, table in sorted(schema.tables.items()):
structName = "%s%s" % (prefix, tableName.lower())
print('''
static struct %(s)s *
@@ -311,7 +311,7 @@ static struct %(s)s *
''' % {'s': structName})
- for tableName, table in sorted(schema.tables.iteritems()):
+ for tableName, table in sorted(schema.tables.items()):
structName = "%s%s" % (prefix, tableName.lower())
print(" ")
print("/* %s table. */" % (tableName))
@@ -1025,7 +1025,7 @@ void
# Table classes.
print(" ")
print("struct ovsdb_idl_table_class %stable_classes[%sN_TABLES] = {" % (prefix, prefix.upper()))
- for tableName, table in sorted(schema.tables.iteritems()):
+ for tableName, table in sorted(schema.tables.items()):
structName = "%s%s" % (prefix, tableName.lower())
if table.is_root:
is_root = "true"
--
2.5.0

View File

@ -0,0 +1,51 @@
From bc29f98f0137fa1083a4cacf832d52f740d150a8 Mon Sep 17 00:00:00 2001
From: Jason Wessel <jason.wessel@windriver.com>
Date: Thu, 29 Jun 2017 20:33:23 -0700
Subject: [PATCH 5/8] Python3 compatibility: fix integer problems
Commit fa145f1a53943243f94a32ce98525db8494b0052 from
https://github.com/openvswitch/ovs.git
In python3 maxint is not defined, but maxsize is defined in both
python2 and python3.
The put_text() will not automatically use a value which came in as
float due to a pior math function and python3 will throw an exception.
The simple answer is to convert it with int() and move on.
Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
---
ovsdb/ovsdb-idlc.in | 2 +-
python/build/nroff.py | 2 ++
2 files changed, 3 insertions(+), 1 deletion(-)
diff --git a/ovsdb/ovsdb-idlc.in b/ovsdb/ovsdb-idlc.in
index 615548f..7cbcbf5 100755
--- a/ovsdb/ovsdb-idlc.in
+++ b/ovsdb/ovsdb-idlc.in
@@ -358,7 +358,7 @@ static void
print(" %s" % type.value.initCDefault(valueVar, type.n_min == 0))
print(" }")
else:
- if type.n_max != sys.maxint:
+ if type.n_max != sys.maxsize:
print(" size_t n = MIN(%d, datum->n);" % type.n_max)
nMax = "n"
else:
diff --git a/python/build/nroff.py b/python/build/nroff.py
index c23837f..401f699 100644
--- a/python/build/nroff.py
+++ b/python/build/nroff.py
@@ -148,6 +148,8 @@ def fatal(msg):
def put_text(text, x, y, s):
+ x = int(x)
+ y = int(y)
extend = x + len(s) - len(text[y])
if extend > 0:
text[y] += ' ' * extend
--
2.5.0

View File

@ -0,0 +1,56 @@
From 3a9fcf1c8f60c160c282c9755ee1c7f9f7e113c3 Mon Sep 17 00:00:00 2001
From: Jason Wessel <jason.wessel@windriver.com>
Date: Thu, 29 Jun 2017 20:33:23 -0700
Subject: [PATCH 6/8] Python3 compatibility: math error compatibility
Commit 3fa5aa4294377e0f35267936d0c5caea3e61db48 from
https://github.com/openvswitch/ovs.git
The way math is handled with typing is completely different in python3.
% python2<<EOF
x=10
y=8
print((x + (y - 1)) / y * y)
EOF
16
python3<<EOF
x=10
y=8
print((x + (y - 1)) / y * y)
EOF
17.0
So we need to force an integer for the round function as follows and
maintain compatibility with python2.
python3<<EOF
x=10
y=8
print(int((x + (y - 1)) / y) * y)
EOF
16
Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
---
build-aux/extract-ofp-actions | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/build-aux/extract-ofp-actions b/build-aux/extract-ofp-actions
index c11297c..bd7131f 100755
--- a/build-aux/extract-ofp-actions
+++ b/build-aux/extract-ofp-actions
@@ -35,7 +35,7 @@ line = ""
arg_structs = set()
def round_up(x, y):
- return (x + (y - 1)) / y * y
+ return int((x + (y - 1)) / y) * y
def open_file(fn):
global file_name
--
2.5.0

View File

@ -0,0 +1,51 @@
From 2fe58f87b00d0ec24d6997930d0bcdb130c84396 Mon Sep 17 00:00:00 2001
From: Jason Wessel <jason.wessel@windriver.com>
Date: Thu, 29 Jun 2017 20:33:23 -0700
Subject: [PATCH 7/8] Python3 compatibility: unicode to str
Commit 7430959d4ad17db89b8387c3aef58c8b230cad10 from
https://github.com/openvswitch/ovs.git
When transitioning from python2 to python3 the following type class
changes occured:
python2 -> python3
unicode -> str
str -> bytes
That means we have to check the python version and do the right type
check python3 will throw an error when it tries to use the unicode
type because it doesn't exist.
Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
---
ovsdb/ovsdb-doc | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/ovsdb/ovsdb-doc b/ovsdb/ovsdb-doc
index 918e88a..406c293 100755
--- a/ovsdb/ovsdb-doc
+++ b/ovsdb/ovsdb-doc
@@ -65,9 +65,15 @@ def columnGroupToNroff(table, groupXml, documented_columns):
if node.hasAttribute('type'):
type_string = node.attributes['type'].nodeValue
type_json = ovs.json.from_string(str(type_string))
- if type(type_json) in (str, unicode):
- raise error.Error("%s %s:%s has invalid 'type': %s"
- % (table.name, name, key, type_json))
+ # py2 -> py3 means str -> bytes and unicode -> str
+ try:
+ if type(type_json) in (str, unicode):
+ raise error.Error("%s %s:%s has invalid 'type': %s"
+ % (table.name, name, key, type_json))
+ except:
+ if type(type_json) in (bytes, str):
+ raise error.Error("%s %s:%s has invalid 'type': %s"
+ % (table.name, name, key, type_json))
type_ = ovs.db.types.BaseType.from_json(type_json)
else:
type_ = column.type.value
--
2.5.0

View File

@ -0,0 +1,28 @@
From a3289add8368e0c970ae1c1c84f5df1f817ed43c Mon Sep 17 00:00:00 2001
From: Ben Pfaff <blp@ovn.org>
Date: Thu, 6 Jul 2017 14:01:27 -0700
Subject: [PATCH 8/8] AUTHORS: Add Jason Wessel.
Commit a91c4cfaf863718bc94fb9c88939bd0b0385a6fe from
https://github.com/openvswitch/ovs.git
Signed-off-by: Ben Pfaff <blp@ovn.org>
---
AUTHORS.rst | 1 +
1 file changed, 1 insertion(+)
diff --git a/AUTHORS.rst b/AUTHORS.rst
index 63e6a8d..d0dc70d 100644
--- a/AUTHORS.rst
+++ b/AUTHORS.rst
@@ -156,6 +156,7 @@ Jan Scheurich jan.scheurich@ericsson.com
Jan Vansteenkiste jan@vstone.eu
Jarno Rajahalme jarno@ovn.org
Jason Kölker jason@koelker.net
+Jason Wessel jason.wessel@windriver.com
Jasper Capel jasper@capel.tv
Jean Tourrilhes jt@hpl.hp.com
Jeremy Stribling strib@nicira.com
--
2.5.0

View File

@ -34,7 +34,6 @@ SRC_URI = "\
"
EXTRA_OECONF += "\
PYTHON=python \
PYTHON3=python3 \
PERL=${bindir}/perl \
"

View File

@ -33,6 +33,19 @@ SRC_URI = "file://openvswitch-switch \
file://python-switch-remaining-scripts-to-use-python3.patch \
"
# Temporarily backport patches to better support py3. These have been
# merged upstream but are not part of v2.7.1.
SRC_URI += " \
file://0001-Python3-compatibility-Convert-print-statements.patch \
file://0002-Python3-compatibility-exception-cleanup.patch \
file://0003-Python3-compatibility-execfile-to-exec.patch \
file://0004-Python3-compatibility-iteritems-to-items.patch \
file://0005-Python3-compatibility-fix-integer-problems.patch \
file://0006-Python3-compatibility-math-error-compatibility.patch \
file://0007-Python3-compatibility-unicode-to-str.patch \
file://0008-AUTHORS-Add-Jason-Wessel.patch \
"
LIC_FILES_CHKSUM = "file://COPYING;md5=17b2c9d4c70853a09c0e143137754b35"
PACKAGECONFIG ?= ""