Revert recent py3 changes under ryu/contrib
Revert recent py3 changes under ryu/contrib, namely parts of the following commits: - commite2dfdbf580
("Treatment was not enough") and - commit325c9ae9c3
("Syntax level compatibility with Python 3") Because: - Some of them are broken (stream.py) - Changes like these should go to upstream Signed-off-by: YAMAMOTO Takashi <yamamoto@valinux.co.jp> Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
This commit is contained in:
parent
30777ea1b9
commit
d4e8026aa8
@ -144,30 +144,30 @@ def _make_pidfile():
|
|||||||
global file_handle
|
global file_handle
|
||||||
|
|
||||||
file_handle = open(tmpfile, "w")
|
file_handle = open(tmpfile, "w")
|
||||||
except IOError as e:
|
except IOError, e:
|
||||||
_fatal("%s: create failed (%s)" % (tmpfile, e.strerror))
|
_fatal("%s: create failed (%s)" % (tmpfile, e.strerror))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
s = os.fstat(file_handle.fileno())
|
s = os.fstat(file_handle.fileno())
|
||||||
except IOError as e:
|
except IOError, e:
|
||||||
_fatal("%s: fstat failed (%s)" % (tmpfile, e.strerror))
|
_fatal("%s: fstat failed (%s)" % (tmpfile, e.strerror))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
file_handle.write("%s\n" % pid)
|
file_handle.write("%s\n" % pid)
|
||||||
file_handle.flush()
|
file_handle.flush()
|
||||||
except OSError as e:
|
except OSError, e:
|
||||||
_fatal("%s: write failed: %s" % (tmpfile, e.strerror))
|
_fatal("%s: write failed: %s" % (tmpfile, e.strerror))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
fcntl.lockf(file_handle, fcntl.LOCK_EX | fcntl.LOCK_NB)
|
fcntl.lockf(file_handle, fcntl.LOCK_EX | fcntl.LOCK_NB)
|
||||||
except IOError as e:
|
except IOError, e:
|
||||||
_fatal("%s: fcntl failed: %s" % (tmpfile, e.strerror))
|
_fatal("%s: fcntl failed: %s" % (tmpfile, e.strerror))
|
||||||
|
|
||||||
# Rename or link it to the correct name.
|
# Rename or link it to the correct name.
|
||||||
if _overwrite_pidfile:
|
if _overwrite_pidfile:
|
||||||
try:
|
try:
|
||||||
os.rename(tmpfile, _pidfile)
|
os.rename(tmpfile, _pidfile)
|
||||||
except OSError as e:
|
except OSError, e:
|
||||||
_fatal("failed to rename \"%s\" to \"%s\" (%s)"
|
_fatal("failed to rename \"%s\" to \"%s\" (%s)"
|
||||||
% (tmpfile, _pidfile, e.strerror))
|
% (tmpfile, _pidfile, e.strerror))
|
||||||
else:
|
else:
|
||||||
@ -175,7 +175,7 @@ def _make_pidfile():
|
|||||||
try:
|
try:
|
||||||
os.link(tmpfile, _pidfile)
|
os.link(tmpfile, _pidfile)
|
||||||
error = 0
|
error = 0
|
||||||
except OSError as e:
|
except OSError, e:
|
||||||
error = e.errno
|
error = e.errno
|
||||||
if error == errno.EEXIST:
|
if error == errno.EEXIST:
|
||||||
_check_already_running()
|
_check_already_running()
|
||||||
@ -211,7 +211,7 @@ def _waitpid(pid, options):
|
|||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
return os.waitpid(pid, options)
|
return os.waitpid(pid, options)
|
||||||
except OSError as e:
|
except OSError, e:
|
||||||
if e.errno == errno.EINTR:
|
if e.errno == errno.EINTR:
|
||||||
pass
|
pass
|
||||||
return -e.errno, 0
|
return -e.errno, 0
|
||||||
@ -220,13 +220,13 @@ def _waitpid(pid, options):
|
|||||||
def _fork_and_wait_for_startup():
|
def _fork_and_wait_for_startup():
|
||||||
try:
|
try:
|
||||||
rfd, wfd = os.pipe()
|
rfd, wfd = os.pipe()
|
||||||
except OSError as e:
|
except OSError, e:
|
||||||
sys.stderr.write("pipe failed: %s\n" % os.strerror(e.errno))
|
sys.stderr.write("pipe failed: %s\n" % os.strerror(e.errno))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
pid = os.fork()
|
pid = os.fork()
|
||||||
except OSError as e:
|
except OSError, e:
|
||||||
sys.stderr.write("could not fork: %s\n" % os.strerror(e.errno))
|
sys.stderr.write("could not fork: %s\n" % os.strerror(e.errno))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
@ -238,7 +238,7 @@ def _fork_and_wait_for_startup():
|
|||||||
try:
|
try:
|
||||||
s = os.read(rfd, 1)
|
s = os.read(rfd, 1)
|
||||||
error = 0
|
error = 0
|
||||||
except OSError as e:
|
except OSError, e:
|
||||||
s = ""
|
s = ""
|
||||||
error = e.errno
|
error = e.errno
|
||||||
if error != errno.EINTR:
|
if error != errno.EINTR:
|
||||||
@ -326,7 +326,7 @@ def _monitor_daemon(daemon_pid):
|
|||||||
wakeup = last_restart + 10000
|
wakeup = last_restart + 10000
|
||||||
if now > wakeup:
|
if now > wakeup:
|
||||||
break
|
break
|
||||||
print("sleep %f" % ((wakeup - now) / 1000.0))
|
print "sleep %f" % ((wakeup - now) / 1000.0)
|
||||||
time.sleep((wakeup - now) / 1000.0)
|
time.sleep((wakeup - now) / 1000.0)
|
||||||
last_restart = ovs.timeval.msec()
|
last_restart = ovs.timeval.msec()
|
||||||
|
|
||||||
@ -416,7 +416,7 @@ def __read_pidfile(pidfile, delete_if_stale):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
file_handle = open(pidfile, "r+")
|
file_handle = open(pidfile, "r+")
|
||||||
except IOError as e:
|
except IOError, e:
|
||||||
if e.errno == errno.ENOENT and delete_if_stale:
|
if e.errno == errno.ENOENT and delete_if_stale:
|
||||||
return 0
|
return 0
|
||||||
vlog.warn("%s: open: %s" % (pidfile, e.strerror))
|
vlog.warn("%s: open: %s" % (pidfile, e.strerror))
|
||||||
@ -449,7 +449,7 @@ def __read_pidfile(pidfile, delete_if_stale):
|
|||||||
# We won the right to delete the stale pidfile.
|
# We won the right to delete the stale pidfile.
|
||||||
try:
|
try:
|
||||||
os.unlink(pidfile)
|
os.unlink(pidfile)
|
||||||
except IOError as e:
|
except IOError, e:
|
||||||
vlog.warn("%s: failed to delete stale pidfile (%s)"
|
vlog.warn("%s: failed to delete stale pidfile (%s)"
|
||||||
% (pidfile, e.strerror))
|
% (pidfile, e.strerror))
|
||||||
return -e.errno
|
return -e.errno
|
||||||
@ -457,7 +457,7 @@ def __read_pidfile(pidfile, delete_if_stale):
|
|||||||
vlog.dbg("%s: deleted stale pidfile" % pidfile)
|
vlog.dbg("%s: deleted stale pidfile" % pidfile)
|
||||||
file_handle.close()
|
file_handle.close()
|
||||||
return 0
|
return 0
|
||||||
except IOError as e:
|
except IOError, e:
|
||||||
if e.errno not in [errno.EACCES, errno.EAGAIN]:
|
if e.errno not in [errno.EACCES, errno.EAGAIN]:
|
||||||
vlog.warn("%s: fcntl: %s" % (pidfile, e.strerror))
|
vlog.warn("%s: fcntl: %s" % (pidfile, e.strerror))
|
||||||
return -e.errno
|
return -e.errno
|
||||||
@ -466,7 +466,7 @@ def __read_pidfile(pidfile, delete_if_stale):
|
|||||||
try:
|
try:
|
||||||
try:
|
try:
|
||||||
error = int(file_handle.readline())
|
error = int(file_handle.readline())
|
||||||
except IOError as e:
|
except IOError, e:
|
||||||
vlog.warn("%s: read: %s" % (pidfile, e.strerror))
|
vlog.warn("%s: read: %s" % (pidfile, e.strerror))
|
||||||
error = -e.errno
|
error = -e.errno
|
||||||
except ValueError:
|
except ValueError:
|
||||||
|
@ -186,7 +186,7 @@ class Idl:
|
|||||||
self._monitor_request_id = None
|
self._monitor_request_id = None
|
||||||
self.__clear()
|
self.__clear()
|
||||||
self.__parse_update(msg.result)
|
self.__parse_update(msg.result)
|
||||||
except error.Error as e:
|
except error.Error, e:
|
||||||
vlog.err("%s: parse error in received schema: %s"
|
vlog.err("%s: parse error in received schema: %s"
|
||||||
% (self._session.get_name(), e))
|
% (self._session.get_name(), e))
|
||||||
self.__error()
|
self.__error()
|
||||||
@ -332,7 +332,7 @@ class Idl:
|
|||||||
def __parse_update(self, update):
|
def __parse_update(self, update):
|
||||||
try:
|
try:
|
||||||
self.__do_parse_update(update)
|
self.__do_parse_update(update)
|
||||||
except error.Error as e:
|
except error.Error, e:
|
||||||
vlog.err("%s: error parsing update: %s"
|
vlog.err("%s: error parsing update: %s"
|
||||||
% (self._session.get_name(), e))
|
% (self._session.get_name(), e))
|
||||||
|
|
||||||
@ -424,7 +424,7 @@ class Idl:
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
datum = ovs.db.data.Datum.from_json(column.type, datum_json)
|
datum = ovs.db.data.Datum.from_json(column.type, datum_json)
|
||||||
except error.Error as e:
|
except error.Error, e:
|
||||||
# XXX rate-limit
|
# XXX rate-limit
|
||||||
vlog.warn("error parsing column %s in table %s: %s"
|
vlog.warn("error parsing column %s in table %s: %s"
|
||||||
% (column_name, table.name, e))
|
% (column_name, table.name, e))
|
||||||
@ -563,7 +563,7 @@ class Row(object):
|
|||||||
try:
|
try:
|
||||||
datum = ovs.db.data.Datum.from_python(column.type, value,
|
datum = ovs.db.data.Datum.from_python(column.type, value,
|
||||||
_row_to_uuid)
|
_row_to_uuid)
|
||||||
except error.Error as e:
|
except error.Error, e:
|
||||||
# XXX rate-limit
|
# XXX rate-limit
|
||||||
vlog.err("attempting to write bad value to column %s (%s)"
|
vlog.err("attempting to write bad value to column %s (%s)"
|
||||||
% (column_name, e))
|
% (column_name, e))
|
||||||
|
@ -90,7 +90,7 @@ def _unlink(file_):
|
|||||||
try:
|
try:
|
||||||
os.unlink(file_)
|
os.unlink(file_)
|
||||||
return 0
|
return 0
|
||||||
except OSError as e:
|
except OSError, e:
|
||||||
return e.errno
|
return e.errno
|
||||||
|
|
||||||
|
|
||||||
|
@ -143,7 +143,7 @@ def from_file(name):
|
|||||||
def from_string(s):
|
def from_string(s):
|
||||||
try:
|
try:
|
||||||
s = unicode(s, 'utf-8')
|
s = unicode(s, 'utf-8')
|
||||||
except UnicodeDecodeError as e:
|
except UnicodeDecodeError, e:
|
||||||
seq = ' '.join(["0x%2x" % ord(c)
|
seq = ' '.join(["0x%2x" % ord(c)
|
||||||
for c in e.object[e.start:e.end] if ord(c) >= 0x80])
|
for c in e.object[e.start:e.end] if ord(c) >= 0x80])
|
||||||
return ("not a valid UTF-8 string: invalid UTF-8 sequence %s" % seq)
|
return ("not a valid UTF-8 string: invalid UTF-8 sequence %s" % seq)
|
||||||
|
@ -42,7 +42,7 @@ def from_json(json, symtab=None):
|
|||||||
if not uuidRE.match(s):
|
if not uuidRE.match(s):
|
||||||
raise error.Error("\"%s\" is not a valid UUID" % s, json)
|
raise error.Error("\"%s\" is not a valid UUID" % s, json)
|
||||||
return uuid.UUID(s)
|
return uuid.UUID(s)
|
||||||
except error.Error as e:
|
except error.Error, e:
|
||||||
if not symtab:
|
if not symtab:
|
||||||
raise e
|
raise e
|
||||||
try:
|
try:
|
||||||
|
@ -171,7 +171,7 @@ class Poller(object):
|
|||||||
try:
|
try:
|
||||||
events = self.poll.poll(self.timeout)
|
events = self.poll.poll(self.timeout)
|
||||||
self.__log_wakeup(events)
|
self.__log_wakeup(events)
|
||||||
except select.error as e:
|
except select.error, e:
|
||||||
# XXX rate-limit
|
# XXX rate-limit
|
||||||
error, msg = e
|
error, msg = e
|
||||||
if error != errno.EINTR:
|
if error != errno.EINTR:
|
||||||
|
@ -37,7 +37,7 @@ def make_unix_socket(style, nonblock, bind_path, connect_path):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
sock = socket.socket(socket.AF_UNIX, style)
|
sock = socket.socket(socket.AF_UNIX, style)
|
||||||
except socket.error as e:
|
except socket.error, e:
|
||||||
return get_exception_errno(e), None
|
return get_exception_errno(e), None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -47,7 +47,7 @@ def make_unix_socket(style, nonblock, bind_path, connect_path):
|
|||||||
# Delete bind_path but ignore ENOENT.
|
# Delete bind_path but ignore ENOENT.
|
||||||
try:
|
try:
|
||||||
os.unlink(bind_path)
|
os.unlink(bind_path)
|
||||||
except OSError as e:
|
except OSError, e:
|
||||||
if e.errno != errno.ENOENT:
|
if e.errno != errno.ENOENT:
|
||||||
return e.errno, None
|
return e.errno, None
|
||||||
|
|
||||||
@ -56,19 +56,19 @@ def make_unix_socket(style, nonblock, bind_path, connect_path):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
if sys.hexversion >= 0x02060000:
|
if sys.hexversion >= 0x02060000:
|
||||||
os.fchmod(sock.fileno(), 0o700)
|
os.fchmod(sock.fileno(), 0700)
|
||||||
else:
|
else:
|
||||||
os.chmod("/dev/fd/%d" % sock.fileno(), 0o700)
|
os.chmod("/dev/fd/%d" % sock.fileno(), 0700)
|
||||||
except OSError as e:
|
except OSError, e:
|
||||||
pass
|
pass
|
||||||
if connect_path is not None:
|
if connect_path is not None:
|
||||||
try:
|
try:
|
||||||
sock.connect(connect_path)
|
sock.connect(connect_path)
|
||||||
except socket.error as e:
|
except socket.error, e:
|
||||||
if get_exception_errno(e) != errno.EINPROGRESS:
|
if get_exception_errno(e) != errno.EINPROGRESS:
|
||||||
raise
|
raise
|
||||||
return 0, sock
|
return 0, sock
|
||||||
except socket.error as e:
|
except socket.error, e:
|
||||||
sock.close()
|
sock.close()
|
||||||
if bind_path is not None:
|
if bind_path is not None:
|
||||||
ovs.fatal_signal.unlink_file_now(bind_path)
|
ovs.fatal_signal.unlink_file_now(bind_path)
|
||||||
@ -102,7 +102,7 @@ def inet_open_active(style, target, default_port, dscp):
|
|||||||
address = inet_parse_active(target, default_port)
|
address = inet_parse_active(target, default_port)
|
||||||
try:
|
try:
|
||||||
sock = socket.socket(socket.AF_INET, style, 0)
|
sock = socket.socket(socket.AF_INET, style, 0)
|
||||||
except socket.error as e:
|
except socket.error, e:
|
||||||
return get_exception_errno(e), None
|
return get_exception_errno(e), None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -110,11 +110,11 @@ def inet_open_active(style, target, default_port, dscp):
|
|||||||
set_dscp(sock, dscp)
|
set_dscp(sock, dscp)
|
||||||
try:
|
try:
|
||||||
sock.connect(address)
|
sock.connect(address)
|
||||||
except socket.error as e:
|
except socket.error, e:
|
||||||
if get_exception_errno(e) != errno.EINPROGRESS:
|
if get_exception_errno(e) != errno.EINPROGRESS:
|
||||||
raise
|
raise
|
||||||
return 0, sock
|
return 0, sock
|
||||||
except socket.error as e:
|
except socket.error, e:
|
||||||
sock.close()
|
sock.close()
|
||||||
return get_exception_errno(e), None
|
return get_exception_errno(e), None
|
||||||
|
|
||||||
@ -147,7 +147,7 @@ def get_null_fd():
|
|||||||
if null_fd < 0:
|
if null_fd < 0:
|
||||||
try:
|
try:
|
||||||
null_fd = os.open("/dev/null", os.O_RDWR)
|
null_fd = os.open("/dev/null", os.O_RDWR)
|
||||||
except OSError as e:
|
except OSError, e:
|
||||||
vlog.err("could not open /dev/null: %s" % os.strerror(e.errno))
|
vlog.err("could not open /dev/null: %s" % os.strerror(e.errno))
|
||||||
return -e.errno
|
return -e.errno
|
||||||
return null_fd
|
return null_fd
|
||||||
@ -173,14 +173,14 @@ def write_fully(fd, buf):
|
|||||||
else:
|
else:
|
||||||
bytes_written += retval
|
bytes_written += retval
|
||||||
buf = buf[:retval]
|
buf = buf[:retval]
|
||||||
except OSError as e:
|
except OSError, e:
|
||||||
return e.errno, bytes_written
|
return e.errno, bytes_written
|
||||||
|
|
||||||
|
|
||||||
def set_nonblocking(sock):
|
def set_nonblocking(sock):
|
||||||
try:
|
try:
|
||||||
sock.setblocking(0)
|
sock.setblocking(0)
|
||||||
except socket.error as e:
|
except socket.error, e:
|
||||||
vlog.err("could not set nonblocking mode on socket: %s"
|
vlog.err("could not set nonblocking mode on socket: %s"
|
||||||
% os.strerror(get_socket_error(e)))
|
% os.strerror(get_socket_error(e)))
|
||||||
|
|
||||||
|
@ -119,9 +119,8 @@ class Stream(object):
|
|||||||
raise NotImplementedError("This method must be overrided by subclass")
|
raise NotImplementedError("This method must be overrided by subclass")
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def open_block(args):
|
def open_block((error, stream)):
|
||||||
"""Blocks until a Stream completes its connection attempt, either
|
"""Blocks until a Stream completes its connection attempt, either
|
||||||
(error, stream) = args
|
|
||||||
succeeding or failing. (error, stream) should be the tuple returned by
|
succeeding or failing. (error, stream) should be the tuple returned by
|
||||||
Stream.open(). Returns a tuple of the same form.
|
Stream.open(). Returns a tuple of the same form.
|
||||||
|
|
||||||
@ -197,7 +196,7 @@ class Stream(object):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
return (0, self.socket.recv(n))
|
return (0, self.socket.recv(n))
|
||||||
except socket.error as e:
|
except socket.error, e:
|
||||||
return (ovs.socket_util.get_exception_errno(e), "")
|
return (ovs.socket_util.get_exception_errno(e), "")
|
||||||
|
|
||||||
def send(self, buf):
|
def send(self, buf):
|
||||||
@ -219,7 +218,7 @@ class Stream(object):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
return self.socket.send(buf)
|
return self.socket.send(buf)
|
||||||
except socket.error as e:
|
except socket.error, e:
|
||||||
return -ovs.socket_util.get_exception_errno(e)
|
return -ovs.socket_util.get_exception_errno(e)
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
@ -290,7 +289,7 @@ class PassiveStream(object):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
sock.listen(10)
|
sock.listen(10)
|
||||||
except socket.error as e:
|
except socket.error, e:
|
||||||
vlog.err("%s: listen: %s" % (name, os.strerror(e.error)))
|
vlog.err("%s: listen: %s" % (name, os.strerror(e.error)))
|
||||||
sock.close()
|
sock.close()
|
||||||
return e.error, None
|
return e.error, None
|
||||||
@ -318,7 +317,7 @@ class PassiveStream(object):
|
|||||||
sock, addr = self.socket.accept()
|
sock, addr = self.socket.accept()
|
||||||
ovs.socket_util.set_nonblocking(sock)
|
ovs.socket_util.set_nonblocking(sock)
|
||||||
return 0, Stream(sock, "unix:%s" % addr, 0)
|
return 0, Stream(sock, "unix:%s" % addr, 0)
|
||||||
except socket.error as e:
|
except socket.error, e:
|
||||||
error = ovs.socket_util.get_exception_errno(e)
|
error = ovs.socket_util.get_exception_errno(e)
|
||||||
if error != errno.EAGAIN:
|
if error != errno.EAGAIN:
|
||||||
# XXX rate-limit
|
# XXX rate-limit
|
||||||
|
Loading…
Reference in New Issue
Block a user