From patchwork Fri Mar 20 15:22:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Terry Wilson X-Patchwork-Id: 1258994 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.138; helo=whitealder.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=gDZKYPec; dkim-atps=neutral Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48kSHs3Hy4z9sSK for ; Sat, 21 Mar 2020 02:24:41 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id EED7387D9D; Fri, 20 Mar 2020 15:24:39 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id AcOj7KFcLscQ; Fri, 20 Mar 2020 15:24:38 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by whitealder.osuosl.org (Postfix) with ESMTP id D6EE38766A; Fri, 20 Mar 2020 15:24:38 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id CB8BAC089E; Fri, 20 Mar 2020 15:24:38 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by lists.linuxfoundation.org (Postfix) with ESMTP id 6A29DC07FF for ; Fri, 20 Mar 2020 15:24:37 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 669378869A for ; Fri, 20 Mar 2020 15:24:37 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id im9Vc2PblwS7 for ; Fri, 20 Mar 2020 15:22:50 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from us-smtp-delivery-74.mimecast.com (us-smtp-delivery-74.mimecast.com [216.205.24.74]) by hemlock.osuosl.org (Postfix) with ESMTPS id 0585F87ACB for ; Fri, 20 Mar 2020 15:22:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584717768; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Xuk41NOHPNF66D7Z4Z7C5Qye4DfpBrqMM7+OLSZOjpc=; b=gDZKYPec+l9avPE2GOQeK40+G+0cYZO+FEdMqjK3JAEeMsDm6sShlSIjchqiCsudeCJzq/ iDcHYSWCSkn+StaIqQ3YkqTQr0OMIImYi5lzBRoFgl7xBC650G7U6sM27WJBkCWfo4XJvn IKecJB3Rtlu2rwy+kLUJ+IvF4FQKVes= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-239-7-luhiTXPcGad2fSxzcp8w-1; Fri, 20 Mar 2020 11:22:46 -0400 X-MC-Unique: 7-luhiTXPcGad2fSxzcp8w-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DE8F9A1362 for ; Fri, 20 Mar 2020 15:22:45 +0000 (UTC) Received: from localhost.localdomain (ovpn-119-38.rdu2.redhat.com [10.10.119.38]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5D3365C1B3; Fri, 20 Mar 2020 15:22:45 +0000 (UTC) From: Terry Wilson To: dev@openvswitch.org Date: Fri, 20 Mar 2020 15:22:38 +0000 Message-Id: <20200320152238.395-1-twilson@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [ovs-dev] [PATCH v3] [python] Handle refTable values with setkey() X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" 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 --- python/ovs/db/idl.py | 3 +-- tests/idltest.ovsschema | 15 +++++++++++++++ tests/ovsdb-idl.at | 13 +++++++++++++ tests/test-ovsdb.py | 23 ++++++++++++++++++++++- 4 files changed, 51 insertions(+), 3 deletions(-) diff --git a/python/ovs/db/idl.py b/python/ovs/db/idl.py index 020291d48..5850ac7ab 100644 --- a/python/ovs/db/idl.py +++ b/python/ovs/db/idl.py @@ -1567,10 +1567,9 @@ class Transaction(object): for col, val in row._mutations['_inserts'].items(): column = row._table.columns[col] if column.type.is_map(): - opdat = ["map"] datum = data.Datum.from_python(column.type, val, _row_to_uuid) - opdat.append(datum.as_list()) + opdat = self._substitute_uuids(datum.to_json()) else: opdat = ["set"] inner_opdat = [] diff --git a/tests/idltest.ovsschema b/tests/idltest.ovsschema index bee79fc50..e02b975bc 100644 --- a/tests/idltest.ovsschema +++ b/tests/idltest.ovsschema @@ -171,6 +171,21 @@ }, "isRoot" : false }, + "simple5": { + "columns" : { + "name": {"type": "string"}, + "irefmap": { + "type": { + "key": {"type": "integer"}, + "value": {"type": "uuid", + "refTable": "simple3"}, + "min": 0, + "max": "unlimited" + } + } + }, + "isRoot": true + }, "singleton" : { "columns" : { "name" : { diff --git a/tests/ovsdb-idl.at b/tests/ovsdb-idl.at index cc38d69c1..564ef4c78 100644 --- a/tests/ovsdb-idl.at +++ b/tests/ovsdb-idl.at @@ -955,6 +955,7 @@ AT_CHECK([sort stdout | uuidfilt], [0], # Check that ovsdb-idl figured out that table link2 and column l2 are missing. AT_CHECK([grep ovsdb_idl stderr | sort], [0], [dnl test-ovsdb|ovsdb_idl|idltest database lacks link2 table (database needs upgrade?) +test-ovsdb|ovsdb_idl|idltest database lacks simple5 table (database needs upgrade?) test-ovsdb|ovsdb_idl|idltest database lacks singleton table (database needs upgrade?) test-ovsdb|ovsdb_idl|link1 table in idltest database lacks l2 column (database needs upgrade?) ]) @@ -1288,6 +1289,18 @@ OVSDB_CHECK_IDL_PY([partial-map idl], 009: done ]]) +OVSDB_CHECK_IDL_PY([partial-map update set refmap idl], +[['["idltest", {"op":"insert", "table":"simple3", "row":{"name":"myString1"}}, + {"op":"insert", "table":"simple5", "row":{"name":"myString2"}}]']], +['partialmapmutateirefmap'], +[[000: name=myString1 uset=[] +000: name=myString2 irefmap=[] +001: commit, status=success +002: name=myString1 uset=[] +002: name=myString2 irefmap=[(1 <0>)] +003: done +]]) + m4_define([OVSDB_CHECK_IDL_PARTIAL_UPDATE_SET_COLUMN], [AT_SETUP([$1 - C]) AT_KEYWORDS([ovsdb server idl partial update set column positive $5]) diff --git a/tests/test-ovsdb.py b/tests/test-ovsdb.py index 1b94b79a0..a19680274 100644 --- a/tests/test-ovsdb.py +++ b/tests/test-ovsdb.py @@ -28,6 +28,7 @@ import ovs.util import ovs.vlog from ovs.db import data from ovs.db import error +from ovs.db.idl import _row_to_uuid as row_to_uuid from ovs.fatal_signal import signal_alarm vlog = ovs.vlog.Vlog("test-ovsdb") @@ -159,7 +160,8 @@ def get_simple_printable_row_string(row, columns): is ovs.db.data.Atom): value = getattr(row, column) if isinstance(value, dict): - value = sorted(value.items()) + value = sorted((row_to_uuid(k), row_to_uuid(v)) + for k, v in value.items()) s += "%s=%s " % (column, value) s = s.strip() s = re.sub('""|,|u?\'', "", s) @@ -212,6 +214,14 @@ def print_idl(idl, step): print(s) n += 1 + if "simple5" in idl.tables: + simple5 = idl.tables["simple5"].rows + for row in simple5.values(): + s = "%03d: " % step + s += get_simple_printable_row_string(row, ["name", "irefmap"]) + print(s) + n += 1 + if "link1" in idl.tables: l1 = idl.tables["link1"].rows for row in l1.values(): @@ -303,6 +313,11 @@ def idltest_find_simple3(idl, i): return next(idl.index_equal("simple3", "simple3_by_name", i), None) +def idltest_find(idl, table, col, match): + return next((r for r in idl.tables[table].rows.values() if + getattr(r, col) == match), None) + + def idl_set(idl, commands, step): txn = ovs.db.idl.Transaction(idl) increment = False @@ -524,6 +539,12 @@ def idl_set(idl, commands, step): setattr(new_row3, 'name', 'String3') new_row3.addvalue('uset', new_row41.uuid) assert len(getattr(new_row3, 'uset', [])) == 1 + elif name == 'partialmapmutateirefmap': + row3 = idltest_find_simple3(idl, "myString1") + row5 = idltest_find(idl, "simple5", "name", "myString2") + row5.setkey('irefmap', 1, row3.uuid) + maplen = len(row5.irefmap) + assert maplen == 1, "expected 1, got %d" % maplen else: sys.stderr.write("unknown command %s\n" % name) sys.exit(1)