summaryrefslogtreecommitdiff
path: root/python
Commit message (Collapse)AuthorAgeFilesLines
* Require Python 3 and remove support for Python 2.Ben Pfaff2019-09-271-7/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Python 2 reaches end-of-life on January 1, 2020, which is only a few months away. This means that OVS needs to stop depending on in the next release that should occur roughly that same time. Therefore, this commit removes all support for Python 2. It also makes Python 3 a mandatory build dependency. Some of the interesting consequences: - HAVE_PYTHON, HAVE_PYTHON2, and HAVE_PYTHON3 conditionals have been removed, since we now know that Python3 is available. - $PYTHON and $PYTHON2 are removed, and $PYTHON3 is always available. - Many tests for Python 2 support have been removed, and the ones that depended on Python 3 now run unconditionally. This allowed several macros in the testsuite to be removed, making the code clearer. This does make some of the changes to the testsuite files large due to indentation level changes. - #! lines for Python now use /usr/bin/python3 instead of /usr/bin/python. - Packaging depends on Python 3 packages. Acked-by: Numan Siddique <nusiddiq@redhat.com> Tested-by: Numan Siddique <nusiddiq@redhat.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
* Add a __str__ method to idl.RowTerry Wilson2019-09-251-0/+6
| | | | | | | | | | It's sometimes handy to log an entire Row object, so this just adds a string representation of the object as: Tablename(col1=val1, col2=val2, ..., coln=valn) Signed-off-by: Terry Wilson <twilson@redhat.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
* Shutdown SSL connection before closing socketTerry Wilson2019-07-121-0/+8
| | | | | | | | | | | | | | | Without shutting down the SSL connection, log messages like: stream_ssl|WARN|SSL_read: unexpected SSL connection close jsonrpc|WARN|ssl:127.0.0.1:47052: receive error: Protocol error reconnect|WARN|ssl:127.0.0.1:47052: connection dropped (Protocol error) would occur whenever the socket is closed. This just adds an SSLStream.close() that calls shutdown() and ignores SSL errors, the same way that lib/stream-ssl.c does in ssl_close(). Signed-off-by: Terry Wilson <twilson@redhat.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
* python: Monitor Database table to manage lifecycle of IDL client.Ted Elhourani2019-03-222-15/+207
| | | | | | | | | | | | | | | | | | | | | | | | The Python IDL implementation supports ovsdb cluster connections. This patch is a follow up to commit 31e434fc98, it adds the option of connecting to the leader (the default) in the Raft-based cluster. It mimics the exisiting C IDL support for clusters introduced in commit 1b1d2e6daa. The _Server database schema is first requested, then a monitor of the Database table in the _Server Database. Method __check_server_db verifies the eligibility of the server. If the attempt to obtain a monitor of the _Server database fails and a cluster id was not provided this implementation proceeds to request the data monitor. If a cluster id was provided via the set_cluster_id method then the connection is aborted and a connection to a different node is instead attempted, until a valid cluster node is found. Thus, when supplied, cluster id is interpreted as the intention to only allow connections to a clustered database. If not supplied, connections to standalone nodes, or nodes that do not have the _Server database are allowed. change_seqno is not incremented in the case of Database table updates. Acked-by: Numan Siddique <nusiddiq@redhat.com> Signed-off-by: Ted Elhourani <ted.elhourani@nutanix.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
* python: Fix package requirements with old setuptoolsTimothy Redaelli2019-03-221-2/+2
| | | | | | | | | | | | | | | | | | | | Commit 00fcc832d598 ("Update Python package requirements") added a PEP 508 environment marker to install pywin32 on Windows systems. This requires a new setuptools version (>= 20.5), but (at least) RHEL/CentOS7 and Debian Jessie are using an older version of setuptools and so python extension failed to build. This commit adds "extras_require" instead of the PEP 508 environment markers in order to have the conditional dependency of pywin32, but by remaining compatible with the old setuptools versions. CC: Alin Gabriel Serdean <aserdean@cloudbasesolutions.com> CC: Lucian Petrut <lpetrut@cloudbasesolutions.com> Fixes: 00fcc832d598 ("Update Python package requirements") Signed-off-by: Timothy Redaelli <tredaelli@redhat.com> Acked-by: Alin Gabriel Serdean <aserdean@ovn.org> Signed-off-by: Alin Gabriel Serdean <aserdean@ovn.org>
* vlog: Better handle syslog handler exceptions.Ilya Maximets2019-02-251-11/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 'set_levels_from_string' doesn't check for exceptions that could happen while opening syslog files or connecting to syslog sockets. For example, if rsyslog stopped on a system: $ test-unixctl.py -vFACILITY:daemon --detach Traceback (most recent call last): File "../../../../tests/test-unixctl.py", line 90, in <module> main() File "../../../../tests/test-unixctl.py", line 61, in main ovs.vlog.handle_args(args) File "python/ovs/vlog.py", line 463, in handle_args msg = Vlog.set_levels_from_string(verbose) File "python/ovs/vlog.py", line 345, in set_levels_from_string Vlog.add_syslog_handler(words[1]) File "python/ovs/vlog.py", line 321, in add_syslog_handler facility=syslog_facility) File "/python2.7/logging/handlers.py", line 759, in __init__ self._connect_unixsocket(address) File "/python2.7/logging/handlers.py", line 787, in _connect_unixsocket self.socket.connect(address) File "/python2.7/socket.py", line 224, in meth return getattr(self._sock,name)(*args) socket.error: [Errno 111] Connection refused In this case "/dev/log" file exists, so the check inside 'add_syslog_handler' doesn't help. We need to catch the exceptions in 'set_levels_from_string' same way as it done in 'init' function. Also, we don't really need to check for '/dev/log' existence, because exception will be catched on the upper layer and properly handled by disabling the corresponding logger. Fixes: d69d61c7c175 ("vlog: Ability to override the default log facility.") Signed-off-by: Ilya Maximets <i.maximets@samsung.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
* Update Python package requirementsLucian Petrut2019-02-251-1/+2
| | | | | | | | The Python ovs package relies on pywin32 for Windows support. For this reason, pywin32 should be included in the requirements list. Signed-off-by: Lucian Petrut <lpetrut@cloudbasesolutions.com>
* python: Fix E117 over-indented.Ilya Maximets2019-02-123-3/+3
| | | | | | | | | | | | | | | | New check was added to recent pycodestyle-2.5.0 and flake8 complains while building on Travis: ../utilities/bugtool/ovs-bugtool.in:767:17: E117 over-indented ../utilities/bugtool/ovs-bugtool.in:771:17: E117 over-indented ../utilities/bugtool/ovs-bugtool.in:774:17: E117 over-indented ../utilities/bugtool/ovs-bugtool.in:778:17: E117 over-indented ../python/ovs/db/error.py:33:17: E117 over-indented ../python/ovs/poller.py:118:21: E117 over-indented ../python/ovs/reconnect.py:244:17: E117 over-indented Signed-off-by: Ilya Maximets <i.maximets@samsung.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
* Un-revert Work around Python/C JSON unicode differencesTerry Wilson2019-01-152-6/+13
| | | | | | | | | | | | | | | | | This fix was reverted because it depended on a small bit of code in a patch that was reverted that changed some python/ovs testing and build. The fix is still necessary. The OVS C-based JSON parser operates on bytes, so the parser_feed function returns the number of bytes that are processed. The pure Python JSON parser currently operates on unicode, so it expects that Parser.feed() returns a number of characters. This difference leads to parsing errors when unicode characters are passed to the C JSON parser from Python. Acked-by: Lucas Alvares Gomes <lucasagomes@gmail.com> Signed-off-by: Terry Wilson <twilson@redhat.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
* python: Escape backslashes while formatting logs.Ilya Maximets2019-01-151-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Since python version 3.7 (and some 3.6+ versions) regexp engine changed to treat the wrong escape sequences as errors. Previously, if the replace string had something like '\u0000', '\u' was qualified as a bad escape sequence and treated just as a sequence of characters '\' and 'u'. But know this triggers an error: Traceback (most recent call last): File "/usr/lib/python3.7/sre_parse.py", line 1021, in parse_template this = chr(ESCAPES[this][1]) KeyError: '\\u' From the documentation [1]: Unknown escapes consisting of '\' and an ASCII letter in replacement templates for re.sub() were deprecated in Python 3.5, and will now cause an error. [1] https://docs.python.org/3/whatsnew/3.7.html#api-and-feature-removals We need to escape the backslash by another one to keep regexp engine from errors. In case of '\\u000', '\\' is a valid escape sequence and the 'u' is a simple character. To be 100% safe we need to use 're.escape(replace)', but it escapes too many characters making the logs hard to read. This change fixes Python 3 tests on systems with python 3.7. Should be backward compatible. Reported-by: Ben Pfaff <blp@ovn.org> Signed-off-by: Ilya Maximets <i.maximets@samsung.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
* python: Avoid flake8 warning for unused variables.Ben Pfaff2019-01-112-2/+2
| | | | | | Acked-by: Numan Siddique <nusiddiq@redhat.com> Tested-by: Numan Siddique <nusiddiq@redhat.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
* python: Fix invalid escape sequences.Ben Pfaff2019-01-116-8/+8
| | | | | | | | | | It appears that Python silently treats invalid escape sequences in strings as literals, e.g. "\." is the same as "\\.". Newer versions of checkpatch complain, and it does seem reasonable to me to fix these. Acked-by: Numan Siddique <nusiddiq@redhat.com> Tested-by: Numan Siddique <nusiddiq@redhat.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
* nroff: Fix fonts for h2, h3, h4.Ben Pfaff2019-01-101-5/+5
| | | | | | | | Without this change, the fonts are wrong if a title contains formatting like <code> or <var>. Acked-by: Mark Michelson <mmichels@redhat.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
* nroff: Increase width for .IP used for ordered lists.Ben Pfaff2019-01-101-1/+1
| | | | | | | | | | | | | | | | | | | The ordered lists that a .25in width produced looked OK in PostScript or PDF output, but in text output every list item spanned two lines, like this: 1. First list item. 2. Second list item. With this change, they appear normally: 1. First list item. 2. Second list item. Acked-by: Mark Michelson <mmichels@redhat.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
* stream: Allow timeout configuration for open_block.Ilya Maximets2019-01-101-3/+13
| | | | | | | | | | | | | | | | | | | | On some systems in case where remote is not responding, socket could remain in SYN_SENT state for a really long time without errors waiting for connection. This leads to situations where open_blok() hangs for a few minutes waiting for connection to the DOWN remote. For example, our "multiple remotes" idl tests hangs waiting for connection to the WRONG_PORT on FreeBSD in CirrusCI environment. This leads to test failures because Alarm signal arrives much faster than ETIMEDOUT from the socket. This patch allowes to specify timeout value for 'open_block' function. If the connection takes more time, socket will be closed with ETIMEDOUT error code. Negative value or None in python could be used to wait infinitely. Signed-off-by: Ilya Maximets <i.maximets@samsung.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
* python: jsonrpc: Pick new remote on disconnect.Ilya Maximets2018-12-271-3/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | If attempt to open non-blocking connection results with EINPROGRESS, further polling will trigger DISCONNECT action in case of failures. While handling this action, jsonrpc python library closes the connection but does not change the current remote. This leads to subsequent connection to the same remote. And the story starts from the beginning producing infinite attempts to connect to a single remote regardless of existense of others. Like this: reconnect | DBG | tcp:127.0.0.1:45932: entering BACKOFF reconnect | INFO | tcp:127.0.0.1:45932: connecting... reconnect | DBG | tcp:127.0.0.1:45932: entering CONNECTING poller | DBG | 999-ms timeout reconnect | INFO | tcp:127.0.0.1:45932: connection attempt timed out reconnect | DBG | tcp:127.0.0.1:45932: entering BACKOFF poller | DBG | 0-ms timeout reconnect | INFO | tcp:127.0.0.1:45932: connecting... <...> reconnect | DBG | tcp:127.0.0.1:45932: entering CONNECTING poller | DBG | 1999-ms timeout reconnect | INFO | tcp:127.0.0.1:45932: connection attempt timed out reconnect | INFO | tcp:127.0.0.1:45932: waiting 4 seconds before reconnect reconnect | DBG | tcp:127.0.0.1:45932: entering BACKOFF <...> Fix that by always picking the new remote on disconnect. This mimics the behaviour of jsonrpc C library. Fixes "multiple remotes" tests on FreeBSD. CC: Numan Siddique <nusiddiq@redhat.com> Fixes: 31e434fc985c ("python jsonrpc: Allow jsonrpc_session to have more than one remote.") Signed-off-by: Ilya Maximets <i.maximets@samsung.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
* socket-util: Report POLLHUP as an error while connection completion checking.Ilya Maximets2018-12-241-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Otherwise failed non-blocking connection could be reported as connected. This causes errors in all following operations with the socket. At least this is true on FreeBSD, where POLLHUP could be set without POLLERR. For example, stream_open_block() tests fails with the following error reporting successful connection to the 'WRONG_PORT': ./ovsdb-idl.at:1817: $PYTHON2 $srcdir/test-stream.py tcp:127.0.0.1:$WRONG_PORT stdout: ./ovsdb-idl.at:1817: exit code was 0, expected 1 2399. ovsdb-idl.at:1817: FAILED (ovsdb-idl.at:1817) Also added new tests to track this issue in C library: 'Check Stream open block - C - tcp' 'Check Stream open block - C - tcp6' CC: Numan Siddique <nusiddiq@redhat.com> Fixes: c1aa16d191d2 ("ovs python: ovs.stream.open_block() returns success even if the remote is unreachable") Fixes: d6cedfd9d29d ("socket-util: Avoid using SO_ERROR.") Signed-off-by: Ilya Maximets <i.maximets@samsung.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
* python: Catch setsockopt exceptions for TCP stream.Ilya Maximets2018-12-201-1/+5
| | | | | | | | | | | | | | | | | | | | | | | | | 'sock.setsockopt' could throw exceptions. For example, if non-blocking connection failed before the call: Traceback (most recent call last): File "../.././test-ovsdb.py", line 896, in <module> main(sys.argv) File "../.././test-ovsdb.py", line 891, in main func(*args) File "../.././test-ovsdb.py", line 604, in do_idl ovs.stream.Stream.open(r)) File "/root/git_/ovs/python/ovs/stream.py", line 190, in open error, sock = cls._open(suffix, dscp) File "/root/git_/ovs/python/ovs/stream.py", line 744, in _open sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) File "/usr/local/lib/python2.7/socket.py", line 228, in meth return getattr(self._sock,name)(*args) socket.error: [Errno 54] Connection reset by peer This fixes tests on FreeBSD. Signed-off-by: Ilya Maximets <i.maximets@samsung.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
* python-c-ext: Fix memory leak in Parser_finishEric Lapointe2018-10-311-0/+1
| | | | | | | The memory returned by json_parser_finish needs to be freed by the caller. Signed-off-by: Eric Lapointe <elapointe@corsa.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
* Revert "Test the Python C JSON extension"Ilya Maximets2018-10-153-24/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This reverts commit a7be68a4d77791bbe02c37f7ad8ae60b02e5679e and a subsequent commit 4617d1f6bd24c543f533f6485b42ebca6b0a8371. There are too many issues with these patches. It's better to revert them for now and make a separate fixed versions later if needed. List of issues (maybe not full): 1. 'make clean' removes entire 'python' directory. 2. Fully broken Travis-CI testsuite build: building 'ovs._json' extension creating build/temp.linux-x86_64-2.7 error: could not create 'build/temp.linux-x86_64-2.7': \ Permission denied https://travis-ci.org/openvswitch/ovs/jobs/440693765 3. Broken local testsuite build on Ubuntu 18.04: running build_ext building 'ovs._json' extension creating build/temp.linux-x86_64-3.6 creating build/temp.linux-x86_64-3.6/ovs <...> /usr/bin/ld: .libs/libopenvswitch.a(util.o): \ relocation R_X86_64_TPOFF32 against `var.7749' can not be \ used when making a shared object; recompile with -fPIC <...> collect2: error: ld returned 1 exit status 4. Fedora build failure because of 'setuptools' ('distutils') hard dependency on 'redhat-rpm-config' package: building 'ovs._json' extension <...> gcc: error: <...>/redhat-hardened-cc1: No such file or directory 5. Looks like 'setuptools' also could download and install unwanted python modules during package build. Signed-off-by: Ilya Maximets <i.maximets@samsung.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
* Work around Python/C JSON unicode differencesTerry Wilson2018-10-111-2/+7
| | | | | | | | | | | | | The OVS C-based JSON parser operates on bytes, so the parser_feed function returns the number of bytes that are processed. The pure Python JSON parser currently operates on unicode, so it expects that Parser.feed() returns a number of characters. This difference leads to parsing errors when unicode characters are passed to the C JSON parser from Python. Signed-off-by: Terry Wilson <twilson@redhat.com> Signed-off-by: Ben Pfaff <blp@ovn.org> Acked-by: Lucas Alvares Gomes <lucasagomes@gmail.com>
* Test the Python C JSON extensionTerry Wilson2018-10-112-4/+17
| | | | | | | | | | | | | | | | | | The C JSON parser was added quite a while ago, but unless you configure with --enable-shared and have the Python 2/3 development libraries installed, and the resulting python-ovs module installed, 'make check' won't actually test it. This patch changes Python-based tests to run from the $builddir/python directory and makes the tests configurable to use both JSON backends. There are some unicode failures in the C JSON extension that I left unfixed in this patch to make it easy to show run the new tests on broken code. The next patch in this set works around the issue. Signed-off-by: Terry Wilson <twilson@redhat.com> Signed-off-by: Ben Pfaff <blp@ovn.org> Acked-by: Lucas Alvares Gomes <lucasagomes@gmail.com>
* Python: Make Row's __getattr__ less error proneLucas Alvares Gomes2018-10-051-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Calling getattr() on a Row object after invoking delkey() with a value that does not exist in the object will cause getattr() to fail with a KeyError error. For example: Oct 05 14:59:28 neutron-server[28435]: File "/usr/local/lib/python2.7/dist-packages/ovsdbapp/backend/ovs_idl/connection.py", line 122, in run Oct 05 14:59:28 neutron-server[28435]: txn.results.put(txn.do_commit()) Oct 05 14:59:28 neutron-server[28435]: File "/usr/local/lib/python2.7/dist-packages/ovsdbapp/backend/ovs_idl/transaction.py", line 86, in do_commit Oct 05 14:59:28 neutron-server[28435]: command.run_idl(txn) Oct 05 14:59:28 neutron-server[28435]: File "/usr/local/lib/python2.7/dist-packages/ovsdbapp/backend/ovs_idl/command.py", line 299, in run_idl Oct 05 14:59:28 neutron-server[28435]: if isinstance(getattr(record, self.column), dict): Oct 05 14:59:28 neutron-server[28435]: File "/usr/local/lib/python2.7/dist-packages/ovs/db/idl.py", line 843, in __getattr__ Oct 05 14:59:28 neutron-server[28435]: del dmap[key] Oct 05 14:59:28 neutron-server[28435]: KeyError: 'bogusvalue' This patch is replacing the "del dmap[key]" instruction with a "dmap.pop(key, None)" instruction instead because a pop() (with a default value) will not raise an exception in case the key does not exist in the object in the first place, it will just ignore it. Signed-off-by: Lucas Alvares Gomes <lucasagomes@gmail.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
* tests: Use environment variable for default timeout.Ilya Maximets2018-08-151-1/+7
| | | | | | | | | | | Introduce new 'OVS_CTL_TIMEOUT' environment variable that, if set, will be used as a default timeout for OVS control utilities. Setting it in 'atlocal.in' will cover all the hangs inside the testsuite, even when utils called in a subshell. Signed-off-by: Ilya Maximets <i.maximets@samsung.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
* python jsonrpc: Allow jsonrpc_session to have more than one remote.Numan Siddique2018-08-142-9/+49
| | | | | | | | | | | | | | Python IDL implementation doesn't have the support to connect to the cluster dbs. This patch adds this support. We are still missing the support in python idl class to connect to the cluster master. That support will be added in an upcoming patch. This patch is similar to the commit 8cf6bbb184 which added multiple remote support in the C jsonrpc implementation. Acked-by: Mark Michelson <mmichels@redhat.com> Signed-off-by: Numan Siddique <nusiddiq@redhat.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
* ovs python: ovs.stream.open_block() returns success even if the remote is ↵Numan Siddique2018-08-143-6/+45
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | unreachable The python function ovs.socket_util.check_connection_completion() uses select() (provided by python) to monitor the socket file descriptor. The select() returns 1 when the file descriptor becomes ready. For error cases like - 111 (Connection refused) and 113 (No route to host) (POLLERR), ovs.poller._SelectSelect.poll() expects the exceptfds list to be set by select(). But that is not the case. As per the select() man page, writefds list will be set for POLLERR. Please see "Correspondence between select() and poll() notifications" section of select(2) man page. Because of this behavior, ovs.socket_util.check_connection_completion() returns success even if the remote is unreachable or not listening on the port. This patch fixes this issue by using poll() to check the connection status similar to the C implementation of check_connection_completion(). A new function 'get_system_poll() is added in ovs/poller.py which returns the select.poll() object. If select.poll is monkey patched by eventlet/gevent, it gets the original select.poll() and returns it. The test cases added in this patch fails without the fix. Suggested-by: Ben Pfaff <blp@ovn.org> Signed-off-by: Numan Siddique <nusiddiq@redhat.com> Signed-off-by: Ben Pfaff <blp@ovn.org> Acked-by: Mark Michelson <mmichels@redhat.com>
* Add ovs.compat module to python packageTerry Wilson2018-08-101-1/+2
| | | | | | Signed-off-by: Terry Wilson <twilson@redhat.com> Signed-off-by: Ben Pfaff <blp@ovn.org> Acked-by: Timothy Redaelli <tredaelli@redhat.com>
* tests: Don't log to syslog during tests.Ben Pfaff2018-08-091-3/+5
| | | | | | | | Until now, "make check" generated a huge amount of output to syslog. This commit suppresses it. Acked-by: Ilya Maximets <i.maximets@samsung.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
* json: Use unnamed embedded union.Flavio Leitner2018-08-061-9/+9
| | | | | | | | Otherwise the code does not build. Fixes: fa37affad362 ("Embrace anonymous unions.") Signed-off-by: Flavio Leitner <fbl@sysclose.org> Signed-off-by: Ben Pfaff <blp@ovn.org>
* DNS: Add basic support for asynchronous DNS resolvingYifeng Sun2018-07-061-2/+2
| | | | | | | | | | | | | | | | | | | | | | This patch is a simple implementation for the proposal discussed in https://mail.openvswitch.org/pipermail/ovs-dev/2017-August/337038.html and https://mail.openvswitch.org/pipermail/ovs-dev/2017-October/340013.html. It enables ovs-vswitchd and other utilities to use DNS names when specifying OpenFlow and OVSDB remotes. Below are some of the features and limitations of this patch: - Resolving is asynchornous in daemon context, avoiding blocking main loop; - Resolving is synchronous in general utility context; - Both IPv4 and IPv6 are supported; - The resolving API is thread-safe; - Depends on the unbound library; - When multiple ip addresses are returned, only the first one is used; - /etc/nsswitch.conf isn't respected as unbound library doesn't look at it; - For async-resolving, caller need to retry later; there is no callback. Signed-off-by: Yifeng Sun <pkusunyifeng@gmail.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
* python: Update docstring in ovs.db.idl.Idl class.Toms Atteka2018-06-051-11/+12
| | | | | | | | | Adjusted docstring and variable names according to previous code changes; Fixed grammar "a attribute" > "an attribute". Fixes: bf42f674 (idl: Convert python daemons to utilize SchemaHelper) Signed-off-by: Toms Atteka <cpp.code.lv@gmail.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
* Embrace anonymous unions.Ben Pfaff2018-05-251-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Several OVS structs contain embedded named unions, like this: struct { ... union { ... } u; }; C11 standardized a feature that many compilers already implemented anyway, where an embedded union may be unnamed, like this: struct { ... union { ... }; }; This is more convenient because it allows the programmer to omit "u." in many places. OVS already used this feature in several places. This commit embraces it in several others. Signed-off-by: Ben Pfaff <blp@ovn.org> Acked-by: Justin Pettit <jpettit@ovn.org> Tested-by: Alin Gabriel Serdean <aserdean@ovn.org> Acked-by: Alin Gabriel Serdean <aserdean@ovn.org>
* python: Tighten the check if we need encodingJakub Sitnicki2018-04-191-5/+2
| | | | | | | | | | | Check if we are dealing with a Unicode string that needs encoding for both Python 2 & 3. Also, do the encoding the same way for Python 2 & 3 and avoid using negation to make the code simpler. Signed-off-by: Jakub Sitnicki <jkbs@redhat.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
* python: Fix a double encoding attempt on an Unicode stringJakub Sitnicki2018-04-181-4/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Encoding from 'unicode' to 'str' that has been added to the Stream class in commit 2254074e3067 ("python: fix python3 encode/decode on Windows") conflicts with SSLStream which already contains a quirk for pyopenssl that does the same thing. This results in a double encoding attempt when SSL is used and we crash and burn due to: Traceback (most recent call last): File "../.././test-ovsdb.py", line 874, in <module> main(sys.argv) File "../.././test-ovsdb.py", line 869, in main func(*args) File "../.././test-ovsdb.py", line 655, in do_idl idl_set(idl, command, step) File "../.././test-ovsdb.py", line 526, in idl_set status = txn.commit_block() File "/home/jkbs/src/ovs/python/ovs/db/idl.py", line 1405, in commit_block status = self.commit() File "/home/jkbs/src/ovs/python/ovs/db/idl.py", line 1388, in commit if not self.idl._session.send(msg): File "/home/jkbs/src/ovs/python/ovs/jsonrpc.py", line 540, in send return self.rpc.send(msg) File "/home/jkbs/src/ovs/python/ovs/jsonrpc.py", line 244, in send self.run() File "/home/jkbs/src/ovs/python/ovs/jsonrpc.py", line 203, in run retval = self.stream.send(self.output) File "/home/jkbs/src/ovs/python/ovs/stream.py", line 808, in send return super(SSLStream, self).send(buf) File "/home/jkbs/src/ovs/python/ovs/stream.py", line 391, in send buf = buf.encode('utf-8') UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 83: ordinal not in range(128) Remove the quirk from SSLStream as the base class now does encoding. Reported-by: Marcin Mirecki <mmirecki@redhat.com> Signed-off-by: Jakub Sitnicki <jkbs@redhat.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
* Add multi-column index support for the Python IDLTerry Wilson2018-04-1710-13/+3848
| | | | | | | | | | This adds multi-column index support for the Python IDL that is similar to the feature in the C IDL. Since it adds sortedcontainers as a dependency and some distros don't yet package it, the library is copied in-tree and used if sortedcontainers is not installed. Signed-off-by: Terry Wilson <twilson@redhat.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
* reconnect: Add ability to do a number of retries without backoff.Ben Pfaff2018-03-241-18/+35
| | | | | | | | | | | This is aimed at an upcoming database clustering implementation, where it's desirable to try all of the cluster members quickly before backing off to retry them again in sequence. Signed-off-by: Ben Pfaff <blp@ovn.org> Acked-by: Russell Bryant <russell@ovn.org> Signed-off-by: Ben Pfaff <blp@ovn.org> Acked-by: Justin Pettit <jpettit@ovn.org>
* ovsdb-idl: Use modern form of <monitor-requests>.Ben Pfaff2018-03-141-2/+3
| | | | | | | | | | | Long ago, a <monitor-requests> object in the OVSDB protocol mapped a table name to a single <monitor-request>. Since then, it has mapped a table name to an *array of* <monitor-request> objects, but the OVSDB IDL has never been updated to use the modern form. This commit makes that change. Reported-by: Anil Jangam <anilj.mailing@gmail.com> Signed-off-by: Ben Pfaff <blp@ovn.org> Acked-by: Justin Pettit <jpettit@ovn.org>
* python: KeyError shouldn't be raised from __getattr__Timothy Redaelli2018-03-141-1/+5
| | | | | | | | | | | | On Python 3 hasattr only intercepts AttributeError exception. On Python2, instead, hasattr intercepts all the exceptions. This means __getattr__ shouldn't return KeyError when the attribute doesn't exists, but it should raise AttributeError instead. Fixes: 2d54d8011e14 ("Python-IDL: getattr after mutate fix") Signed-off-by: Timothy Redaelli <tredaelli@redhat.com> Signed-off-by: Russell Bryant <russell@ovn.org>
* python: Fix decoding error when the received data is larger than 4096.Guoshuai Li2018-03-091-2/+3
| | | | | | | | | | It can only receive 4096 bytes of data each time in jsonrpc, when there are similar and Chinese characters occupy multiple bytes, it may receive half a character, this time the decoding will be abnormal. We need to receive the completed character to decode. Signed-off-by: Guoshuai Li <ligs@dtdream.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
* python: avoid useless JSON conversion to enhance performanceDaniel Alvarez2018-02-281-7/+5
| | | | | | | | | | | | | | | | | | | This patch removes a useless conversion to/from JSON in the processing of any 'modify' operations inside the process_update2 method in Python IDL implementation. Previous code will make resources creation take longer as the number of elements in the row grows because of that JSON conversion. This patch eliminates it and now the time remains consant regardless of the database contents improving performance and scaling. Reported-by: Daniel Alvarez <dalvarez@redhat.com> Reported-at: https://mail.openvswitch.org/pipermail/ovs-discuss/2018-February/046263.html Signed-off-by: Daniel Alvarez <dalvarez@redhat.com> Acked-by: Terry Wilson <twilson@redhat.com> Tested-By: Terry Wilson <twilson@redhat.com> Acked-by: Han Zhou <hzhou8@ebay.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
* ovsdb-idlc: Add infrastructure for IDL schema extensions.Ben Pfaff2018-02-161-11/+26
| | | | | | | | | | | An IDL schema is an OVSDB schema with some extra stuff in it. So far, all of the extras have been at the top level. This commit makes it possible for IDL schemas to have extra information at the table and column levels as long as it is in an "extensions" member. No extensions are actually supported yet. Signed-off-by: Ben Pfaff <blp@ovn.org>
* ovsdb-idlc: Add "cDecls" and "hDecls" IDL schema extensions.Ben Pfaff2018-02-161-2/+9
| | | | | | | | | | An IDL schema is an OVSDB schema with some extra stuff in it: an idlPrefix and an idlHeader at the top level to indicate what ovsdb-idlc needs to generate the interface definitions. This commit adds support for two more optional IDL schema extensions that allow extra code to be written to the .c and .h file that ovsdb-idlc generates. Signed-off-by: Ben Pfaff <blp@ovn.org>
* ovsdb: Improve documentation.Ben Pfaff2017-12-141-7/+8
| | | | | Signed-off-by: Ben Pfaff <blp@ovn.org> Acked-by: Justin Pettit <jpettit@ovn.org>
* tests: Convert soexpand build tool from Perl to Python.Ben Pfaff2017-11-262-1/+58
| | | | | | | | Perl is unfashionable and Python is more widely available and understood, so this commit converts one of the OVS uses of Perl into Python. Signed-off-by: Ben Pfaff <blp@ovn.org> Acked-by: Aaron Conole <aconole@redhat.com>
* windows,python: remove dead code in send_waitAlin Balutoiu2017-09-131-2/+0
| | | | | | | | | | Found while looking over the code. Signed-off-by: Alin Balutoiu <abalutoiu@cloudbasesolutions.com> Suggested-by: Alin Gabriel Serdean <aserdean@ovn.org> Acked-by: Alin Gabriel Serdean <aserdean@ovn.org> Acked-by: Anand Kumar <kumaranand@vmware.com> Signed-off-by: Alin Gabriel Serdean <aserdean@ovn.org>
* windows,python: remove unnecessary codeAlin Balutoiu2017-09-131-23/+18
| | | | | | | | | | | | | | | | | At the moment we have WSAEventSelect in each if branch. Since the call to the function is similar, we can move it outside the if branch and create some local variables which will be passed to WSAEventSelect. This patch also remove the keyword argument passed when the event for the connection overlapped structure is created. The argument is not needed since it does not change the value from the default one. Signed-off-by: Alin Balutoiu <abalutoiu@cloudbasesolutions.com> Signed-off-by: Alin Gabriel Serdean <aserdean@ovn.org> Acked-by: Alin Gabriel Serdean <aserdean@ovn.org>
* windows, python: create a different event for socketsAlin Balutoiu2017-09-131-8/+11
| | | | | | | | | | | | | | | | | At the moment the sockets on Windows use the same events that are being created for the pipes. This is not correct because they should be different events. This patch introduces a new event which should be used for sockets. The new event needs to be set on automatic reset with its initial state not signaled. Signed-off-by: Alin Balutoiu <abalutoiu@cloudbasesolutions.com> Co-authored-by: Alin Gabriel Serdean <aserdean@ovn.org> Signed-off-by: Alin Gabriel Serdean <aserdean@ovn.org> Tested-by: Alin Gabriel Serdean <aserdean@ovn.org> Acked-by: Russell Bryant <russell@ovn.org>
* windows,python: Add restrictions to named pipesAlin Balutoiu2017-09-131-0/+59
| | | | | | | | | | Bump the security around named pipes to be more restrictive: disable network access and allow only administrators and above to access the named pipes. Acked-by: Anand Kumar <kumaranand@vmware.com> Acked-by: Alin Gabriel Serdean <aserdean@ovn.org> Signed-off-by: Alin Balutoiu <abalutoiu@cloudbasesolutions.com> Signed-off-by: Alin Gabriel Serdean <aserdean@ovn.org>
* windows, python: Remove code duplication in send/recv functionsAlin Balutoiu2017-08-231-42/+36
| | | | | | | | | | Move the return value at the end of the function regardless of the pending/non-pending operation. Signed-off-by: Alin Balutoiu <abalutoiu@cloudbasesolutions.com> Acked-by: Russell Bryant <russell@ovn.org> Acked-by: Alin Gabriel Serdean <aserdean@ovn.org> Signed-off-by: Alin Gabriel Serdean <aserdean@ovn.org>
* windows, python: Fix event type returned from pollerAlin Balutoiu2017-08-231-1/+8
| | | | | | | | | | | | | | | | | | The function poll from poller should return a list of tuples containing the events and their types. On Windows the event type is not returned at the moment. Instead of returning zero all the time, we check to see the type of event and we set it accordingly before returning the list. This is used only for debugging purposes inside the function "__log_wakeup" later on. Signed-off-by: Alin Balutoiu <abalutoiu@cloudbasesolutions.com> Acked-by: Russell Bryant <russell@ovn.org> Acked-by: Alin Gabriel Serdean <aserdean@ovn.org> Signed-off-by: Alin Gabriel Serdean <aserdean@ovn.org>