summaryrefslogtreecommitdiff
path: root/tests/test-ovsdb.py
Commit message (Collapse)AuthorAgeFilesLines
* ovsdb-cs: Consider default conditions implicitly acked.Dumitru Ceara2022-12-131-8/+29
| | | | | | | | | | | | | | | | | When initializing a monitor table the default monitor condition is [True] which matches the behavior of the server (to send all rows of that table). There's no need to include this default condition in the initial monitor request so we can consider it implicitly acked by the server. This fixes the incorrect (one too large) expected condition sequence number reported by ovsdb_idl_set_condition() when application is trying to set a [True] condition for a new table. Reported-by: Numan Siddique <numans@ovn.org> Suggested-by: Ilya Maximets <i.maximets@ovn.org> Signed-off-by: Dumitru Ceara <dceara@redhat.com> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
* ovsdb-idl: Add the support to specify the uuid for row insert.Numan Siddique2022-11-301-2/+18
| | | | | | | | | | | | | | | | | | | | | | | | ovsdb-server allows the OVSDB clients to specify the uuid for the row inserts [1]. Both the C IDL client library and Python IDL are missing this feature. This patch adds this support. In C IDL, for each schema table, a new function is generated - <schema_table>insert_persistent_uuid(txn, uuid) which can be used the clients to persist the uuid. ovs-vsctl and other derivatives of ctl now supports the same in the generic 'create' command with the option "--id=<UUID>". In Python IDL, the uuid to persist can be specified in the Transaction.insert() function. [1] - a529e3cd1f("ovsdb-server: Allow OVSDB clients to specify the UUID for inserted rows.:) Acked-by: Adrian Moreno <amorenoz@redhat.com> Acked-by: Han Zhou <hzhou@ovn.org> Acked-by: Terry Wilson <twilson@redhat.com> Signed-off-by: Numan Siddique <numans@ovn.org> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
* python: Fix E275 missing whitespace after keyword.Ilya Maximets2022-08-041-1/+1
| | | | | | | | | | | | | | | | | | | | With just released flake8 5.0 we're getting a bunch of E275 errors: utilities/bugtool/ovs-bugtool.in:959:23: E275 missing whitespace after keyword tests/test-ovsdb.py:623:11: E275 missing whitespace after keyword python/setup.py:105:8: E275 missing whitespace after keyword python/setup.py:106:8: E275 missing whitespace after keyword python/ovs/db/idl.py:145:15: E275 missing whitespace after keyword python/ovs/db/idl.py:167:15: E275 missing whitespace after keyword make[2]: *** [flake8-check] Error 1 This breaks CI on branches below 2.16. We don't see a problem right now on newer branches because we're installing extra dependencies that backtrack flake8 down to 4.1 or even 3.9. Acked-by: Mike Pattrick <mkp@redhat.com> Acked-by: Dumitru Ceara <dceara@redhat.com> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
* ovsdb-cs: Clear last_id on reconnect if condition changes in-flight.Dumitru Ceara2022-01-311-14/+32
| | | | | | | | | | | | | | | | | | | | | | | | | | | When reconnecting, if there are condition changes already sent to the server but not yet acked, reset the db's 'last-id', esentially clearing the local cache after reconnect. This is needed because the client cannot easily differentiate between the following cases: a. either the server already processed the requested monitor condition change but the FSM was restarted before the client was notified. In this case the client should clear its local cache because it's out of sync with the monitor view on the server side. b. OR the server hasn't processed the requested monitor condition change yet. Conditions changing at the same time with a reconnection happening are rare so the performance impact of this patch should be minimal. Also, the tests are updated to cover the fact that we cannot control which of the two scenarios ("a" and "b" above) are hit during the test. Reported-by: Maxime Coquelin <maxime.coquelin@redhat.com> Signed-off-by: Dumitru Ceara <dceara@redhat.com> Acked-by: Han Zhou <hzhou@ovn.org> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
* python: idl: Allow retry even when using a single remote.Ilya Maximets2021-06-111-1/+1
| | | | | | | | | | | | As described in commit [1], it's possible that remote IP is backed by a load-balancer and re-connection to this same IP will lead to connection to a different server. This case is supported for C version of IDL and should be supported in a same way for python implementation. [1] ca367fa5f8bb ("ovsdb-idl.c: Allows retry even when using a single remote.") Signed-off-by: Ilya Maximets <i.maximets@ovn.org> Acked-by: Dumitru Ceara <dceara@redhat.com>
* ovsdb-idl: Preserve references for deleted rows.Dumitru Ceara2021-04-011-1/+27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Considering two DB rows, 'a' from table A and 'b' from table B (with column 'ref_a' a reference to table A): a = {A._uuid=<U1>} b = {B._uuid=<U2>, B.ref_a=<U1>} Assuming both records are present in the IDL client's in-memory view of the database, depending whether row 'b' is also deleted in the same transaction or not, deletion of row 'a' should generate the following tracked changes: 1. only row 'a' is deleted: - for table A: - deleted records: a = {A._uuid=<U1>} - for table B: - updated records: b = {B._uuid=<U2>, B.ref_a=[]} 2. row 'a' and row 'b' are deleted in the same update: - for table A: - deleted records: a = {A._uuid=<U1>} - for table B: - deleted records: b = {B._uuid=<U2>, B.ref_a=<U1>} To ensure this, we now delay reparsing row backrefs for deleted rows until all updates in the current run have been processed. Without this change, in scenario 2 above, the tracked changes for table B would be: - deleted records: b = {B._uuid=<U2>, B.ref_a=[]} In particular, for strong references, row 'a' can never be deleted in a transaction that happens strictly before row 'b' is deleted. In some cases [0] both rows are deleted in the same transaction and having B.ref_a=[] would violate the integrity of the database from client perspective. This would force the client to always validate that strong reference fields are non-NULL. This is not really an option because the information in the original reference is required for incrementally processing the record deletion. [0] with ovn-monitor-all=true, the following command triggers a crash in ovn-controller because a strong reference field becomes NULL: $ ovn-nbctl --wait=hv -- lr-add r -- lrp-add r rp 00:00:00:00:00:01 1.0.0.1/24 $ ovn-nbctl lr-del r Reported-at: https://bugzilla.redhat.com/1932642 Fixes: 72aeb243a52a ("ovsdb-idl: Tracking - preserve data for deleted rows.") Signed-off-by: Dumitru Ceara <dceara@redhat.com> Acked-by: Han Zhou <hzhou@ovn.org> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
* ovsdb-idl.at: Make test outputs more predictable.Dumitru Ceara2021-04-011-39/+52
| | | | | | | | | | | | | | | | | | | | | IDL tests need predictable output from test-ovsdb. This used to be done by first sorting the output of test-ovsdb and then applying uuidfilt to predictably translate UUIDs. This was not reliable enough in case test-ovsdb processes two or more insert/delete operations in the same iteration because the order of lines in the output depends on the automatically generated UUID values. To fix this we change the way test-ovsdb and test-ovsdb.py generate outputs and prepend the table name and tracking information before printing the contents of a row. All existing ovsdb-idl.at and ovsdb-cluster.at tests are updated to expect the new output format. Signed-off-by: Dumitru Ceara <dceara@redhat.com> Acked-by: Han Zhou <hzhou@ovn.org> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
* python: Send notifications after the transaction ends.Terry Wilson2021-03-151-2/+6
| | | | | | | | | | | | | | | | | | | | | | | | | The Python IDL notification mechanism was sending a notification for each processed update in a transaction as it was processed. This causes issues with multi-row changes that contain references to each other. For example, if a Logical_Router_Port is created along with a Gateway_Chassis, and the LRP.gateway_chassis set to that GC, then when the notify() passes the CREATE event for the LRP, the GC will not yet have been processed, so __getattr__ when _uuid_to_row fails to find the GC, will return the default value for LRP.gateway_chassis which is []. This patch has the process_update methods return the notifications that would be produced when a row changes, so they can be queued and sent after all rows have been processed. Fixes: d7d417fcddf9 ("Allow subclasses of Idl to define a notification hook") Signed-off-by: Terry Wilson <twilson@redhat.com> Acked-by: Brian Haley <haleyb.dev@gmail.com> Acked-by: Dumitru Ceara <dceara@redhat.com> Tested-by: Flavio Fernandes <flavio@flaviof.com> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
* Handle refTable values with setkey()Terry Wilson2020-03-201-1/+22
| | | | | | | | | | | | For columns like QoS.queues where we have a map containing refTable values, assigning w/ __setattr__ e.g. qos.queues={1: $queue_row} works, but using using qos.setkey('queues', 1, $queue_row) results in an Exception. The opdat argument can essentially just be the JSON representation of the map column instead of trying to build it. Signed-off-by: Terry Wilson <twilson@redhat.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
* Remove dependency on python3-sixTimothy Redaelli2019-12-201-24/+17
| | | | | | | | | | | Since Python 2 support was removed in 1ca0323e7c29 ("Require Python 3 and remove support for Python 2."), python3-six is not needed anymore. Moreover python3-six is not available on RHEL/CentOS7 without using EPEL and so this patch is needed in order to release OVS 2.13 on RHEL7. Signed-off-by: Timothy Redaelli <tredaelli@redhat.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
* python: Monitor Database table to manage lifecycle of IDL client.Ted Elhourani2019-03-221-1/+66
| | | | | | | | | | | | | | | | | | | | | | | | 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 invalid escape sequences.Ben Pfaff2019-01-111-1/+1
| | | | | | | | | | 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>
* stream: Allow timeout configuration for open_block.Ilya Maximets2019-01-101-1/+1
| | | | | | | | | | | | | | | | | | | | 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>
* tests: Enable logging for ovsdb test.Ilya Maximets2018-12-251-0/+5
| | | | | | | | It's useful to see the connection attempts and the transactions in case of test failures. Signed-off-by: Ilya Maximets <i.maximets@samsung.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
* test-ovsdb.py: Add line breaks to the error messages.Ilya Maximets2018-12-201-4/+4
| | | | | | | 'sys.stderr.write' does not add them. Signed-off-by: Ilya Maximets <i.maximets@samsung.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
* Revert "Test the Python C JSON extension"Ilya Maximets2018-10-151-20/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* Test the Python C JSON extensionTerry Wilson2018-10-111-2/+20
| | | | | | | | | | | | | | | | | | 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>
* tests: Use environment variable for default timeout.Ilya Maximets2018-08-151-1/+3
| | | | | | | | | | | 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-141-3/+10
| | | | | | | | | | | | | | 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>
* ovsdb-idl: Correct singleton insert logicMark Michelson2018-06-151-0/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | When inserting data into a "singleton" table (one that has maxRows == 1), there is a check that ensures that the table is currently empty before inserting the row. The intention is to prevent races where multiple clients might attempt to insert rows at the same time. The problem is that this singleton check can cause legitimate transactions to fail. Specifically, a transaction that attempts to delete the current content of the table and insert new data will cause the singleton check to fail since the table currently has data. This patch corrects the issue by keeping a count of the rows being deleted and added to singleton tables. If the total is larger than zero, then the net operation is attempting to insert rows. If the total is less than zero, then the net operation is attempting to remove rows. If the total is zero, then the operation is inserting and deleting an equal number of rows (or is just updating rows). We only add the singleton check if the total is larger than zero. This patch also includes a new test for singleton tables that ensures that the maxRows constraint works as expected. Signed-off-by: Mark Michelson <mmichels@redhat.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
* tests: Complain if key and certs not provided for SSL connectionJakub Sitnicki2018-04-181-0/+5
| | | | | | | | | Add an argument check to test-ovsdb.py to ensure that the user has provided the private key, the certificate, and the peer CA certificate needed to set up an SSL connection. Signed-off-by: Jakub Sitnicki <jkbs@redhat.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
* python: Fix reporting that test-ovsdb.py command needs more argsJakub Sitnicki2018-04-181-1/+1
| | | | | | | | | | | | | | | | | In Python OVSDB tester, we are not unpacking a value from n_args tuple that holds the accepted range of arguments. This causes an error: $ python tests/test-ovsdb.py idl tests/idltest.schema Traceback (most recent call last): File "./tests/test-ovsdb.py", line 869, in <module> main(sys.argv) File "./tests/test-ovsdb.py", line 852, in main n_args, len(args))) TypeError: %d format: a number is required, not tuple Signed-off-by: Jakub Sitnicki <jkbs@redhat.com> Signed-off-by: Ben Pfaff <blp@ovn.org> Acked-by: Mark Michelson <mmichels@redhat.com>
* Add multi-column index support for the Python IDLTerry Wilson2018-04-171-4/+3
| | | | | | | | | | 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>
* python: Force file system encoding on cmdline argsAlin Balutoiu2017-08-181-1/+2
| | | | | | | | | | | | | | On Windows, the default file system encoding is 'mbcs' resulting in a bad conversion. To make it cross-platform tolerant use 'sys.getfilesystemencoding()' instead of 'utf-8'. Co-authored-by: Alin Serdean <aserdean@cloudbasesolutions.com> Signed-off-by: Alin Balutoiu <abalutoiu@cloudbasesolutions.com> Signed-off-by: Alin Serdean <aserdean@cloudbasesolutions.com> Acked-by: Lance Richardson <lrichard@redhat.com> Signed-off-by: Russell Bryant <russell@ovn.org>
* python: make python idl unicode-tolerantLance Richardson2017-08-091-1/+5
| | | | | | | | | | | | Ensure that JSON is utf-8 encoded and that bytes sent/received on the stream sockets are in utf-8 form. Add a test case to verify that unicode data can be sent/received successfully using Python IDL module. Co-authored-by: Terry Wilson <twilson@redhat.com> Signed-off-by: Terry Wilson <twilson@redhat.com> Signed-off-by: Lance Richardson <lrichard@redhat.com> Signed-off-by: Russell Bryant <russell@ovn.org>
* Adapt to flake8-import-orderxurong000379972017-03-081-3/+4
| | | | | | | | | | https://review.openstack.org/#/c/432906/ flake8-import-order adds 3 new flake8 warnings: I100: Your import statements are in the wrong order. I101: The names in your from import are in the wrong order. I201: Missing newline between sections or imports. Signed-off-by: Ben Pfaff <blp@ovn.org>
* ovsdb-idl: Change interface to conditional monitoring.Ben Pfaff2016-12-191-12/+4
| | | | | | | | | | | | | | | | | | | | | | | | Most users of OVSDB react to whatever is currently in their view of the database, as opposed to keeping track of changes and reacting to those changes individually. The interface to conditional monitoring was different, in that it expected the client to say what to add or remove from monitoring instead of what to monitor. This seemed reasonable at the time, but in practice it turns out that the usual approach actually works better, because the condition is generally a function of the data visible in the database. This commit changes the approach. This commit also changes the meaning of an empty condition for a table. Previously, an empty condition meant to replicate every row. Now, an empty condition means to replicate no rows. This is more convenient for code that gradually constructs conditions, because it does not need special cases for replicating nothing. This commit also changes the internal implementation of conditions from linked lists to arrays. I just couldn't see an advantage to using linked lists. Signed-off-by: Ben Pfaff <blp@ovn.org> Acked-by: Liran Schour <lirans@il.ibm.com>
* Python-IDL: getattr after mutate fixAmitabha Biswas2016-10-141-0/+36
| | | | | | | | | | | 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-051-0/+7
| | | | | | | | | 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: Fix mutation of newly inserted rows from Python IDL.Amitabha Biswas2016-08-301-0/+6
| | | | | | | | | | | | | | | 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-idl: Fix bugs in Python IDL partial set and map.Amitabha Biswas2016-08-151-31/+32
| | | | | | | | | | | | | | | | | | 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>
* Simplify partial map Py3 IDL test added by commit a59912a0Ryan Moats2016-08-141-1/+1
| | | | | | | | | | | | | | | Commit a59912a0 ("python: Add support for partial map and partial set updates") added unit tests for the partial map function for the python IDL. However, because Python3 doesn't order dictionaries consistently, this test is a crap shoot for systems that support Python3. As a short term fix, do not use a dictionary with multiple elements for the partial map test case. Change-Id: Ibdec10ebd895051321b9bff7d9fe8a7e0bd9eb88 Signed-off-by: Ryan Moats <rmoats@us.ibm.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
* python: Add support for partial map and partial set updatesRyan Moats2016-08-141-0/+88
| | | | | | | | | | | | | | 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: Implemented signal.alarm for WindowsPaul Boca2016-08-031-2/+2
| | | | | | | | | | 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-12/+41
| | | | | | | | | | | | | 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>
* lib: add monitor_cond_change API to C IDL libLiran Schour2016-07-181-0/+35
| | | | | | | | | | 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: Add TCP passive-mode to IDL.Ofer Ben-Yacov2016-05-201-1/+47
| | | | | | | | | 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>
* tests: Deal with Python output differences.Russell Bryant2016-02-221-1/+1
| | | | | | | | | | | | This test checks the output based on Python's string representation of an array of two unicode strings. These strings have a "u" prefix in Python 2, but not Python 3. In Python 3, all strings are unicode. Use sed on the output to strip the "u" from Python 2 output when checking for the expected result. Signed-off-by: Russell Bryant <russell@ovn.org> Acked-by: Ben Pfaff <blp@ovn.org>
* python: Drop unicode type.Russell Bryant2016-02-021-3/+4
| | | | | | | | | | 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: Convert dict iterators.Russell Bryant2016-01-211-7/+8
| | | | | | | | | | | | | | | | 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: Fix print function compatibility.Russell Bryant2016-01-121-14/+16
| | | | | | | | | | | | | | | 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: Fix exception handler compatibility.Russell Bryant2016-01-121-3/+3
| | | | | | | | | | | | | | | | | Python 3 dropped exception handlers of the deprecated form: except Exception, e: You must use the newer syntax of: except Exception as e: This patch also enables a flake8 warning for this. H231 Python 3.x incompatible 'except x,y:' construct Signed-off-by: Russell Bryant <russell@ovn.org> Acked-by: Ben Pfaff <blp@ovn.org>
* python: Resolve a deprecation warning.Russell Bryant2016-01-051-1/+1
| | | | | | | | | | | | | | | Resolve the following deprecation warning. This deprecation warning advises to use an alternative syntax which is also compatible with Python 3, where has_key() was removed. W601 .has_key() is deprecated, use 'in' Also fix this related error: E713 test for membership should be 'not in' Signed-off-by: Russell Bryant <russell@ovn.org> Acked-by: Ben Pfaff <blp@ovn.org>
* python: Resolve pep8 comparison errors.Russell Bryant2016-01-051-15/+16
| | | | | | | | | | | | | | | | | | | | | Resolve pep8 errors: E711 comparison to None should be 'if cond is None:' The reason comparing against None with "is None" is preferred over "== None" is because a class can define its own equality operator and produce bizarre unexpected behavior. Using "is None" has a very explicit meaning that can not be overridden. E721 do not compare types, use 'isinstance()' This one is actually a mistake by the tool in most cases. 'from ovs.db import types' looks just like types from the Python stdlib. In those cases, use the full ovs.db.types name. Fix one case where it actually was types from the stdlib. Signed-off-by: Russell Bryant <russell@ovn.org> Acked-by: Ben Pfaff <blp@ovn.org>
* python: Remove unused imports and variables.Russell Bryant2016-01-051-1/+0
| | | | | | | | | | This resolves the following flake8 error types: F841 local variable 'e' is assigned to but never used F401 'exceptions' imported but unused Signed-off-by: Russell Bryant <russell@ovn.org> Acked-by: Ben Pfaff <blp@ovn.org>
* ovsdb-idl: Support for readonly columns that are fetched on-demandShad Ansari2015-11-231-39/+75
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | There is currently no mechanism in IDL to fetch specific column values on-demand without having to register them for monitoring. In the case where the column represent a frequently changing entity (e.g. counter), and the reads are relatively infrequent (e.g. CLI client), there is a significant overhead in replication. This patch adds support in the Python IDL to register a subset of the columns of a table as "readonly". Readonly columns are not replicated. Users may "fetch" the readonly columns of a row on-demand. Once fetched, the columns are not updated until the next fetch by the user. Writes by the user to readonly columns does not change the value (both locally or on the server). The two main user visible changes in this patch are: - The SchemaHelper.register_columns() method now takes an optionaly argument to specify the subset of readonly column(s) - A new Row.fetch(columns) method to fetch values of readonly columns(s) Usage: ------ # Schema file includes all columns, including readonly schema_helper = ovs.db.idl.SchemaHelper(schema_file) # Register interest in columns with 'r' and 's' as readonly schema_helper.register_columns("simple", [i, r, s], [r, s]) # Create Idl and jsonrpc, and wait for update, as usual ... # Fetch value of column 'r' for a specific row row.fetch('r') txn.commit_block() print row.r print getattr(row, 'r') # Writing to readonly column has no effect (locally or on server) row.r = 3 print row.r # prints fetched value not 3 Signed-off-by: Shad Ansari <shad.ansari@hp.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
* ovsdb-idl: Test script for Python register_columns functionShad Ansari2015-10-131-2/+21
| | | | | | | | | | | | | | | | | | | | Add test scripts to exercise the register_columns() function of the Python IDL. Add ability to specify columns in the "idl" command of test-ovsdb.py. All columns of all tables are monitored by default. The new "?" option can be used to monitor specific Table:Column(s). The table and their columns are listed as a string of the form starting with "?": ?<table-name>:<column-name>,<column-name>,... e.g.: ?simple:b - Monitor column "b" in table "simple" Entries for multiple tables are seperated by "?": ?<table-name>:<column-name>,...?<table-name>:<column-name>,... e.g.: ?simple:b?link1:i,k - Monitor column "b" in table "simple", and column "i", "k" in table "link1" Signed-off-by: Shad Ansari <shad.ansari@hp.com> Signed-off-by: Ben Pfaff <blp@nicira.com>
* test-ovsdb: Fix conditional statement.Alex Wang2015-04-291-1/+4
| | | | | | | | | | | | Old version of python does not support the following conditional statement syntax in one assignment: var = value1 if cond else value2 This commit fixes it by convert it back to use two assignments. Signed-off-by: Alex Wang <alexw@nicira.com> Acked-by: Russell Bryant <rbryant@redhat.com>
* Allow subclasses of Idl to define a notification hookTerry Wilson2015-04-271-0/+17
| | | | | | | | | | | | | | | It is useful to make the notification events that Idl processes accessible to users of the library. This will make it possible to keep external systems in sync, but does not impose any particular notification pattern. The Row.from_json() call is added to be able to convert the 'old' JSON response on an update to a Row object to make it easy for users of notify() to see what changed, though this usage of Row is quite different than Idl's typical use. Signed-off-by: Terry Wilson <twilson@redhat.com> Signed-off-by: Ben Pfaff <blp@nicira.com>
* test-ovsdb: Workaround unicode bug in Python 2.4.x.Gurucharan Shetty2014-06-261-1/+1
| | | | | | | | | | | | | | | | | Run the following command on Xenserver: PYTHONPATH=`pwd`/python/compat::`pwd`/python python ./tests/test-ovsdb.py \ parse-atoms '{"type": "string", "minLength": 2}' \ '[""]' '["a"]' '["ab"]' '["abc"]' '["\ud834\udd1e"]' And we get the following error: UnicodeEncodeError: 'ascii' codec can't encode character u'\U0001d11e' in position 23: ordinal not in range(128). It looks like we are hitting the following bug: http://bugs.python.org/issue2517 Signed-off-by: Gurucharan Shetty <gshetty@nicira.com> Acked-By: Ben Pfaff <blp@nicira.com>