summaryrefslogtreecommitdiff
path: root/python
Commit message (Collapse)AuthorAgeFilesLines
* ovsdb-idlc: Eliminate <prefix>_init() function from generated code.Ben Pfaff2016-10-193-71/+82
| | | | | Signed-off-by: Ben Pfaff <blp@ovn.org> Acked-by: Andy Zhou <azhou@ovn.org>
* Python-IDL: getattr after mutate fixAmitabha Biswas2016-10-141-14/+24
| | | | | | | | | | | This commit returns the updated column value when getattr is done after a mutate operation is performed (but before the commit). Signed-off-by: Amitabha Biswas <azbiswas@gmail.com> Reported-by: Richard Theis <rtheis@us.ibm.com> Reported-at: http://openvswitch.org/pipermail/dev/2016-September/080120.html Fixes: a59912a0ee8e ("python: Add support for partial map and set updates") Signed-off-by: Russell Bryant <russell@ovn.org>
* python: Add SSL support to the python ovs client libraryNuman Siddique2016-10-052-3/+96
| | | | | | | | | SSL support is added to the ovs/stream.py. pyOpenSSL library is used to support SSL. If this library is not present, then the SSL stream is not registered with the Stream class. Signed-off-by: Numan Siddique <nusiddiq@redhat.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
* ovsdb-idlc: Make set and map update operations take const arguments.Ben Pfaff2016-08-311-1/+13
| | | | | | | | | | In a call like "ovsrec_bridge_update_ports_delvalue(bridge, port)", there's no reason for the port argument to be nonconst, because the call doesn't do anything to the port at all--it only searches the list of ports in the bridge for that particular port and, if it finds it, removes it. Signed-off-by: Ben Pfaff <blp@ovn.org> Acked-by: Russell Bryant <russell@ovn.org>
* ovsdb: Fix mutation of newly inserted rows from Python IDL.Amitabha Biswas2016-08-301-1/+7
| | | | | | | | | | | | | | | This patch fixes the scenario, where the mutate operation on a row is sent in the same transaction as row insert operation. It was obvserved that this mutate operation was not getting committed to the OVSDB. To get around the above problem the "where" condition in an mutate operation is modified to use the named-uuid to identify a row created in the current transaction. Signed-off-by: Amitabha Biswas <abiswas@us.ibm.com> Suggested-by: Richard Theis <rtheis@us.ibm.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
* ovsdb: Fix reference to table's row on condition_add|remove_clauseLiran Schour2016-08-261-3/+10
| | | | | | | | Use struct uuid * on [add|remove]_clause on columns which are references to tables. That prevents use-after-free errors. Signed-off-by: Liran Schour <lirans@il.ibm.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
* ovsdb-idl: Fix bugs in Python IDL partial set and map.Amitabha Biswas2016-08-151-61/+57
| | | | | | | | | | | | | | | | | | This patch fixes a couple of bugs in commit a59912a0 (python: add support for partial map and partial set updates) and reverses a simplication added in commit 884d9bad (Simplify partial map Py3 IDL test) to make the Python3 test cases passes. The following changes have been made: 1. Allow multiple map updates on the same column in a transaction. 2. Partial map Py3 IDL test can now support multiple elements. 3. SetAttr overrides pre-existing insert and remove updates. 4. addvalue/delvalue contains unique elements Signed-off-by: Amitabha Biswas <abiswas@us.ibm.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
* python: Add support for partial map and partial set updatesRyan Moats2016-08-141-11/+185
| | | | | | | | | | | | | | Allow the python IDL to use mutate operations more freely by mimicing the partial map and partial set operations now available in the C IDL. Unit tests for both of these types of operations are included. They are not carbon copies of the C tests, because testing idempotency is a bit difficult for the current python IDL test harness. Signed-off-by: Ryan Moats <rmoats@us.ibm.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
* python tests: Fixed abs_file_name function for WindowsPaul Boca2016-08-031-2/+4
| | | | | | | | On windows a path containint ':' is considered an absolute path. Signed-off-by: Paul-Daniel Boca <pboca@cloudbasesolutions.com> Acked-by: Alin Gabriel Serdean <aserdean@cloudbasesolutions.com> Signed-off-by: Gurucharan Shetty <guru@ovn.org>
* python tests: Fixed OSError not iterable on WindowsPaul Boca2016-08-031-0/+6
| | | | | | | | | On Windows if this exception is triggered then it will raise an exception while in the exception handler. Signed-off-by: Paul-Daniel Boca <pboca@cloudbasesolutions.com> Acked-by: Alin Gabriel Serdean <aserdean@cloudbasesolutions.com> Signed-off-by: Gurucharan Shetty <guru@ovn.org>
* python tests: Added fcntl module for WindowsPaul Boca2016-08-032-0/+43
| | | | | | | | | | This is needed for lockf function used to lock the PID file on Windows. ioctl and fcntl functions are not implemented at this time because they are not used by any script. Signed-off-by: Paul-Daniel Boca <pboca@cloudbasesolutions.com> Acked-by: Alin Gabriel Serdean <aserdean@cloudbasesolutions.com> Signed-off-by: Gurucharan Shetty <guru@ovn.org>
* python tests: Fixed ctl file name for WindowsPaul Boca2016-08-032-4/+15
| | | | | | | | On Windows the CTL filename doesn't contain the pid of the process. Signed-off-by: Paul-Daniel Boca <pboca@cloudbasesolutions.com> Acked-by: Alin Gabriel Serdean <aserdean@cloudbasesolutions.com> Signed-off-by: Gurucharan Shetty <guru@ovn.org>
* python tests: Register signal handlers only on supported types on WindowsPaul Boca2016-08-031-2/+6
| | | | | | | | SIGHUP and SIGALRM are not available on Windows. Signed-off-by: Paul-Daniel Boca <pboca@cloudbasesolutions.com> Acked-by: Alin Gabriel Serdean <aserdean@cloudbasesolutions.com> Signed-off-by: Gurucharan Shetty <guru@ovn.org>
* python tests: Implemented signal.alarm for WindowsPaul Boca2016-08-031-0/+23
| | | | | | | | | | signal.alarm is not available in Windows and would trigger an exception when called. Implemented this to mentain compatibility between Windows and Linux for python tests. Signed-off-by: Paul-Daniel Boca <pboca@cloudbasesolutions.com> Acked-by: Alin Gabriel Serdean <aserdean@cloudbasesolutions.com> Signed-off-by: Gurucharan Shetty <guru@ovn.org>
* python: Send old values of the updated cols in notify for update2Numan Siddique2016-07-271-6/+13
| | | | | | | | | | | | | When python IDL calls the "notify" function after processing the "update2" message from ovsdb-server, it is suppose to send the old values of the updated columns as the last parameter. But the recent commit "897c8064" sends the updated values. This breaks the behaviour. This patch fixes this issue. It also updates the description of the 'updates' param of the notify function to make it more clear. Fixes: 897c8064 ("python: move Python idl to work with monitor_cond") Signed-off-by: Numan Siddique <nusiddiq@redhat.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
* python: Serial JSON via Python's json lib.Terry Wilson2016-07-261-96/+10
| | | | | | | | | | | | There is no particularly good reason to use our own Python JSON serialization implementation when serialization can be done faster with Python's built-in JSON library. A few tests were changed due to Python's default JSON library returning slightly more precise floating point numbers. Signed-off-by: Terry Wilson <twilson@redhat.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
* python: add set type for ovs.idl.data.Datum.from_pythonZong Kai LI2016-07-251-1/+1
| | | | | | | | | | | | | ovs.db.idl.Datum.from_python fails to handle set type value, while set type is also a common iterable sequence, just like list and tuple. No reason IDL caller must to turn set type parameters to list or tuple type. Otherwise, they will fail to insert data, but get no exception. Reported-at: https://bugs.launchpad.net/networking-ovn/+bug/1605573 Signed-off-by: Zong Kai LI <zealokii@gmail.com> Acked-by: Richard Theis <rtheis@us.ibm.com> Tested-by: Richard Theis <rtheis@us.ibm.com> Signed-off-by: Russell Bryant <russell@ovn.org>
* json: Move from lib to include/openvswitch.Terry Wilson2016-07-221-1/+1
| | | | | | | | | | | | | | | To easily allow both in- and out-of-tree building of the Python wrapper for the OVS JSON parser (e.g. w/ pip), move json.h to include/openvswitch. This also requires moving lib/{hmap,shash}.h. Both hmap.h and shash.h were #include-ing "util.h" even though the headers themselves did not use anything from there, but rather from include/openvswitch/util.h. Fixing that required including util.h in several C files mostly due to OVS_NOT_REACHED and things like xmalloc. Signed-off-by: Terry Wilson <twilson@redhat.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
* lib: add monitor_cond_change API to C IDL libLiran Schour2016-07-181-6/+24
| | | | | | | | | | Add to IDL API that allows the user to add and remove clauses on a table's condition iteratively. IDL maintain tables condition and send monitor_cond_change to the server upon condition change. Add tests for conditional monitoring to IDL. Signed-off-by: Liran Schour <lirans@il.ibm.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
* python: move Python idl to work with monitor_condLiran Schour2016-07-182-20/+168
| | | | | | | | Python idl works now with "monitor_cond" method. Add test for backward compatibility with old "monitor" method. Signed-off-by: Liran Schour <lirans@il.ibm.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
* vlog.py: Remove redundant setLevel() if "/dev/log" doesn't exist.Daniele Di Proietto2016-07-061-3/+2
| | | | | | | Also update a comment. Signed-off-by: Daniele Di Proietto <diproiettod@vmware.com> Acked-by: Gurucharan Shetty <guru@ovn.org>
* vlog test: Disable default syslog loggerPaul Boca2016-07-061-0/+1
| | | | | | | | | Disable the syslog logger in case on Windows, '/dev/log' doesn't exist. Seems like on Python34 a default handler is added to the logger and it prints even if no handler is set by us. Signed-off-by: Paul-Daniel Boca <pboca@cloudbasesolutions.com> Acked-by: Daniele Di Proietto <diproiettod@vmware.com>
* Add optional C extension wrapper for Python JSON parsingTerry Wilson2016-06-084-2/+331
| | | | | | | | | | | | | | | | | | | | The pure Python in-tree JSON parser is *much* slower than the in-tree C JSON parser. A local test parsing a 100Mb JSON file showed the Python version taking 270 seconds. With the C wrapper, it took under 4 seconds. The C extension will be used automatically if it can be built. If the extension fails to build, a warning is displayed and the build is restarted without the extension. The Serializer class is replaced with Python's built-in JSON library since the ability to process chunked data is not needed in that case. The extension should work with both Python 2.7 and Python 3.3+. Signed-off-by: Terry Wilson <twilson@redhat.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
* Ensure significand remains an integer in Python3 json parserTerry Wilson2016-06-081-1/+1
| | | | | | | | | | | | | | | | The / operation in Python 2 is "floor division" for int/long types while in Python 3 is "true division". This means that the significand can become a float with the existing code in Python 3. This, in turn, can result in a parse of something like [1.10e1] returning 11 in Python 2 and 11.0 in Python 3. Switching to the // operator resolves this difference. The JSON tests do not catch this difference because the built-in serializer prints floats with the %.15g format which will convert floats with no fractional part to an integer representation. Signed-off-by: Terry Wilson <twilson@redhat.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
* python: Add TCP passive-mode to IDL.Ofer Ben-Yacov2016-05-202-11/+24
| | | | | | | | | Requested-by: "D M, Vikas" <vikas.d-m@hpe.com> Requested-by: "Kamat, Maruti Haridas" <maruti.kamat@hpe.com> Requested-by: "Sukhdev Kapur" <sukhdev@arista.com> Requested-by: "Migliaccio, Armando" <armando.migliaccio@hpe.com> Signed-off-by: "Ofer Ben-Yacov" <ofer.benyacov@gmail.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
* python: Update Python version checks.Russell Bryant2016-04-152-9/+3
| | | | | | | | | | | | Instead of checking the raw version, use the six.PY2 and six.PY3 helpers to determine if Python 2 or Python 3 are in use. In one case, the check was to determine if the Python version was >= 2.6. We now only support >= 2.7, so this check would always be true. Signed-off-by: Russell Bryant <russell@ovn.org> Acked-by: Ben Pfaff <blp@ovn.org> Acked-by: Miguel Angel Ajo <majopela@redhat.com>
* ovsdb: Force columns that contain weak references to be immutable.Ben Pfaff2016-04-111-1/+7
| | | | | | | | | | An immutable weak reference is a hole in the constraint system: if referenced rows are deleted, then the weak reference needs to change. Therefore, force columsn that contain weak references to be mutable. Reported-by: "Elluru, Krishna Mohan" <elluru.kri.mohan@hpe.com> Signed-off-by: Ben Pfaff <blp@ovn.org> Acked-by: Ryan Moats <rmoats@us.ibm.com>
* NEWS: Claim support for Python 3.Russell Bryant2016-02-221-1/+5
| | | | | | | | Also update the Python ovs package info to note that both Python 2 and 3 are supported. Signed-off-by: Russell Bryant <russell@ovn.org> Acked-by: Ben Pfaff <blp@ovn.org>
* vlog: Add vlog/close command.Ben Pfaff2016-02-101-1/+10
| | | | | | | Requested-by: P R Dinesh Requested-at: https://github.com/openvswitch/ovs/pull/94 Signed-off-by: Ben Pfaff <blp@ovn.org> Acked-by: Russell Bryant <russell@ovn.org>
* python: Deal with str and byte differences.Russell Bryant2016-02-023-0/+18
| | | | | | | | | | Python 3 has separate types for strings and bytes. Python 2 used the same type for both. We need to convert strings to bytes before writing them out to a socket. We also need to convert data read from the socket to a string. Signed-off-by: Russell Bryant <russell@ovn.org> Acked-by: Ben Pfaff <blp@ovn.org>
* python: Fix object comparisons in Python 3.Russell Bryant2016-02-022-0/+38
| | | | | | | | | | | | | Python 3 no longer supports __cmp__. Instead, we have to implement the "rich comparison" operators. We implement __eq__ and __lt__ and use functools.total_ordering to implement the rest. In one case, no __cmp__ method was provided and instead relied on the default behavior provided in Python 2. We have to implement the comparisons explicitly for Python 3. Signed-off-by: Russell Bryant <russell@ovn.org> Acked-by: Ben Pfaff <blp@ovn.org>
* python: Don't compare None and int.Russell Bryant2016-02-021-1/+1
| | | | | | | Comparing None to an integer worked in Python 2, but fails in Python 3. Signed-off-by: Russell Bryant <russell@ovn.org> Acked-by: Ben Pfaff <blp@ovn.org>
* python: Remove reamining direct type comparisons.Russell Bryant2016-02-027-26/+26
| | | | | | | | | | | I've hit several bugs in this Python 3 work where the fix was some code needed to be converted to use isinstance(). This has been primarily around deadling with the changes to unicode handling. Go ahead and convert the rest of the direct type comparisons to use isinstance(), as it could avoid a bug I haven't hit yet and it's more Pythonic, anyway. Signed-off-by: Russell Bryant <russell@ovn.org> Acked-by: Ben Pfaff <blp@ovn.org>
* python: Use six.unichr().Russell Bryant2016-02-021-1/+1
| | | | | | | | six.unichr() is equivalent to unichr() in Python 2 and chr() in Python 3. Signed-off-by: Russell Bryant <russell@ovn.org> Acked-by: Ben Pfaff <blp@ovn.org>
* python: Drop use of sys.maxint.Russell Bryant2016-02-024-18/+18
| | | | | | | | | | | | | | | | | | | | | | | | | sys.maxint does not exist in Python 3, as an int does not have a max value anymore (except as limited by implementation details and system resources). sys.maxsize works as a reasonable substitute as it's the same as sys.maxint. The Python 3.0 release notes have this to say: The sys.maxint constant was removed, since there is no longer a limit to the value of integers. However, sys.maxsize can be used as an integer larger than any practical list or string index. It conforms to the implementation’s “natural” integer size and is typically the same as sys.maxint in previous releases on the same platform (assuming the same build options). sys.maxsize is documented as: An integer giving the maximum value a variable of type Py_ssize_t can take. It’s usually 2**31 - 1 on a 32-bit platform and 2**63 - 1 on a 64-bit platform. Signed-off-by: Russell Bryant <russell@ovn.org> Acked-by: Ben Pfaff <blp@ovn.org>
* python: Don't use StringIO directly.Russell Bryant2016-02-021-2/+1
| | | | | | | | StringIO.StringIO in Python 2 became io.StringIO in Python 3. Use six.StringIO which is an alias for the two cases. Signed-off-by: Russell Bryant <russell@ovn.org> Acked-by: Ben Pfaff <blp@ovn.org>
* python: Drop use of types.FunctionType.Russell Bryant2016-02-021-3/+1
| | | | | | | | | | This code asserted that the callback argument was of type types.FunctionType. It's more pythonic to just check that the argument is callable, and not specifically that it's a function. There are other ways to implement a callback than types.FunctionType. Signed-off-by: Russell Bryant <russell@ovn.org> Acked-by: Ben Pfaff <blp@ovn.org>
* python: Drop use of types.StringTypes.Russell Bryant2016-02-023-5/+7
| | | | | | | | types.StringTypes does not exist in Python 3. We can use six.string_types, instead. Signed-off-by: Russell Bryant <russell@ovn.org> Acked-by: Ben Pfaff <blp@ovn.org>
* python: Drop unicode type.Russell Bryant2016-02-028-38/+60
| | | | | | | | | | Python 2 had str and unicode. Python 3 only has str, which is always a unicode string. Drop use of unicode with the help of six.text_type (unicode in py2 and str in py3) and six.string_types ([str, unicode] in py2 and [str] in py3). Signed-off-by: Russell Bryant <russell@ovn.org> Acked-by: Ben Pfaff <blp@ovn.org>
* python: Drop usage of long type.Russell Bryant2016-02-027-34/+52
| | | | | | | | | | | | | | | | | | | | | Python 2 has both long and int types. Python 3 only has int, which behaves like long. In the case of needing a set of integer types, we can use six.integer_types which includes int and long for Python 2 and just int for Python 3. We can convert all cases of long(value) to int(value), because as of Python 2.4, when the result of an operation would be too big for an int, the type is automatically converted to a long. There were several places in this patch doing type comparisons. The preferred way to do this is using the isinstance() or issubclass() built-in functions, so I converted the similar checks nearby while I was at it. Signed-off-by: Russell Bryant <russell@ovn.org> Acked-by: Ben Pfaff <blp@ovn.org>
* python: Convert dict iterators.Russell Bryant2016-01-218-40/+50
| | | | | | | | | | | | | | | | In Python 2, dict.items(), dict.keys(), and dict.values() returned a list. dict.iteritems(), dict.iterkeys(), and dict.itervalues() returned an iterator. As of Python 3, dict.iteritems(), dict.itervalues(), and dict.iterkeys() are gone. items(), keys(), and values() now return an iterator. In the case where we want an iterator, we now use the six.iter*() helpers. If we want a list, we explicitly create a list from the iterator. Signed-off-by: Russell Bryant <russell@ovn.org> Acked-by: Ben Pfaff <blp@ovn.org>
* python: Stop using xrange().Russell Bryant2016-01-206-1/+12
| | | | | | | | | | | | Python 2 had range() and xrange(). xrange() is more efficient, but behaves differently so range() was retained for compatibility. Python 3 only has range() and it behaves like Python 2's xrange(). Remove explicit use of xrange() and use six.moves.range() to make sure we're using xrange() from Python 2 or range() from Python 3. Signed-off-by: Russell Bryant <russell@ovn.org> Acked-by: Ben Pfaff <blp@ovn.org>
* python: Fix xmlrpclib imports.Russell Bryant2016-01-202-4/+7
| | | | | | | | | | | | | | Fix imports of xmlrpclib to be compatible with Python 3. Python 2 had xmlrpclib (client) and SimpleXMLRPCServer (server). In Python 3, these have been renamed to xmlrpc.client and xmlrpc.server. The solution implemented here is to use the six library. It may seem excessive for this particular issue, but the six library provides helpers for Python 2 and 3 compatibility for many different issues. This is just the first of many uses of the six library. Signed-off-by: Russell Bryant <russell@ovn.org> Acked-by: Ben Pfaff <blp@ovn.org>
* python: Fix print function compatibility.Russell Bryant2016-01-122-17/+21
| | | | | | | | | | | | | | | The print statement from Python 2 is a function in Python 3. Enable print function support for Python 2 and convert print statements to function calls. Enable the H233 flake8 warning. If the hacking plugin is installed, this will generate warnings for print statement usage not compatible with Python 3. H233 Python 3.x incompatible use of print operator Signed-off-by: Russell Bryant <russell@ovn.org> Acked-by: Ben Pfaff <blp@ovn.org>
* python: Stop use of tuple parameter unpackingRussell Bryant2016-01-121-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | Python 3 removed support for tuple parameter unpacking. https://www.python.org/dev/peps/pep-3113/ Instead of: def foo((a, b)): print(a) print(b) you should do: def foo(a_b): a, b = a_b print(a) print(b) but in both uses here, the values were never used so the fix is even simpler. Signed-off-by: Russell Bryant <russell@ovn.org> Acked-by: Ben Pfaff <blp@ovn.org>
* python: Start fixing some Python 3 issues.Terry Wilson2016-01-129-46/+49
| | | | | | | | | | | | | This patch fixes just the Python 3 problems found by running: python3 setup.py install There are still many other issues to be fixed, but this is a start. Signed-off-by: Terry Wilson <twilson@redhat.com> [russell@ovn.org resolved conflicts with current master] Signed-off-by: Russell Bryant <russell@ovn.org> Acked-by: Ben Pfaff <blp@ovn.org>
* python: Fix the TypeError exception seen when idl.Idl parses lock replyNuman Siddique2016-01-081-1/+1
| | | | | | | | | | File "/usr/lib/python2.7/site-packages/ovs/db/idl.py", line 334, in __parse_lock_notify self.__update_has_lock(self, new_has_lock) TypeError: __update_has_lock() takes exactly 2 arguments (3 given) Signed-off-by: Numan Siddique <nusiddiq@redhat.com> Signed-off-by: Russell Bryant <russell@ovn.org>
* python: Restrict line length to 79 chars.Russell Bryant2016-01-053-12/+23
| | | | | | | | | Resolve pep8 error: E501 line too long (80 > 79 characters) Signed-off-by: Russell Bryant <russell@ovn.org> Acked-by: Ben Pfaff <blp@ovn.org>
* python: Resolve some indentation warnings.Russell Bryant2016-01-053-15/+24
| | | | | | | | | | | | | | This patch resolves the following warnings from flake8: E111 indentation is not a multiple of four E112 expected an indented block E113 unexpected indentation It's critical to have correct indentation in Python code, so it seemed worth enabling these warnings. Signed-off-by: Russell Bryant <russell@ovn.org> Acked-by: Ben Pfaff <blp@ovn.org>
* python: Add missing Apache License headers.Russell Bryant2016-01-053-0/+36
| | | | | Signed-off-by: Russell Bryant <russell@ovn.org> Acked-by: Ben Pfaff <blp@ovn.org>