From patchwork Tue Mar 5 06:21:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ales Musil X-Patchwork-Id: 1908023 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.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=VlPA7qLu; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::133; helo=smtp2.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=patchwork.ozlabs.org) Received: from smtp2.osuosl.org (smtp2.osuosl.org [IPv6:2605:bc80:3010::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Tplnh4Tq0z23hX for ; Tue, 5 Mar 2024 17:21:26 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 3B985400CE; Tue, 5 Mar 2024 06:21:24 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id LcktzvkUYecb; Tue, 5 Mar 2024 06:21:23 +0000 (UTC) X-Comment: SPF check N/A for local connections - client-ip=140.211.9.56; helo=lists.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver= DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org 2FE3940607 Authentication-Results: smtp2.osuosl.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=VlPA7qLu Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp2.osuosl.org (Postfix) with ESMTPS id 2FE3940607; Tue, 5 Mar 2024 06:21:22 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id CA27AC0072; Tue, 5 Mar 2024 06:21:22 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp4.osuosl.org (smtp4.osuosl.org [IPv6:2605:bc80:3010::137]) by lists.linuxfoundation.org (Postfix) with ESMTP id BC878C0037 for ; Tue, 5 Mar 2024 06:21:21 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id AA64D410B6 for ; Tue, 5 Mar 2024 06:21:21 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id YjRJT2UlSKGH for ; Tue, 5 Mar 2024 06:21:20 +0000 (UTC) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=170.10.129.124; helo=us-smtp-delivery-124.mimecast.com; envelope-from=amusil@redhat.com; receiver= DMARC-Filter: OpenDMARC Filter v1.4.2 smtp4.osuosl.org 50CB74109E Authentication-Results: smtp4.osuosl.org; dmarc=pass (p=none dis=none) header.from=redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org 50CB74109E Authentication-Results: smtp4.osuosl.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=VlPA7qLu Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by smtp4.osuosl.org (Postfix) with ESMTPS id 50CB74109E for ; Tue, 5 Mar 2024 06:21:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709619678; 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; bh=fyZU7YkTQKIFXHnmyiB55zgBtvb0NYEbud4888jwQWk=; b=VlPA7qLuWaWO8s4kkyjMUEywcY+cG3Gyeklk+W0BNs9si3mTl5V8+0WQmxaPZSnPjfkzwp 6PJauSmtu8j9Yrja81UUXmADBKo/tOEmURwBFvJst/mvcHSRS18K97zOEKRRLBII2wnevm vbQzdfbs+siq81aHufGujJjTlII84sU= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-187-6zB3vhSOPGaxJU9xpx2ZFg-1; Tue, 05 Mar 2024 01:21:14 -0500 X-MC-Unique: 6zB3vhSOPGaxJU9xpx2ZFg-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 83E8680F7E3 for ; Tue, 5 Mar 2024 06:21:14 +0000 (UTC) Received: from amusil.brq.redhat.com (unknown [10.43.17.32]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0B4DCC01851; Tue, 5 Mar 2024 06:21:13 +0000 (UTC) From: Ales Musil To: dev@openvswitch.org Date: Tue, 5 Mar 2024 07:21:13 +0100 Message-ID: <20240305062113.337617-1-amusil@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [ovs-dev] [PATCH ovn] utilities: Make database connection optional for ovn-detrace. 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" The ovn-detrace required both connections (SB and NB) to provide some output. However, it is a valid scenario to have only one database available, usually the SB. With that in mind make the connection optional and print warning into stderr that the output will not contain information from DB that is not available. Reported-at: https://issues.redhat.com/browse/FDP-68 Signed-off-by: Ales Musil Acked-by: Mark Michelson --- utilities/ovn_detrace.py.in | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/utilities/ovn_detrace.py.in b/utilities/ovn_detrace.py.in index 364f11a71..12df6e52a 100755 --- a/utilities/ovn_detrace.py.in +++ b/utilities/ovn_detrace.py.in @@ -37,6 +37,9 @@ except Exception: argv0 = sys.argv[0] version = "@VERSION@" +DB_CONNECTION_ERR = ('The connection to {0} DB is not available,' + ' {0} information will be missing from the detrace.') + def usage(): print("""\ @@ -77,6 +80,11 @@ def chassis_str(chassis): ch = chassis[0] return 'chassis-name "%s", chassis-str "%s"' % (ch.name, ch.hostname) + +class ConnectionException(Exception): + pass + + class OVSDB(object): STREAM_TIMEOUT_MS = 1000 @@ -111,7 +119,7 @@ class OVSDB(object): os.strerror(error))) strm = None if not strm: - raise Exception('Unable to connect to %s' % self.remote) + raise ConnectionException() rpc = jsonrpc.Connection(strm) req = jsonrpc.Message.create_request('get_schema', [schema_name]) @@ -167,6 +175,8 @@ class CookieHandlerByUUUID(CookieHandler): super(CookieHandlerByUUUID, self).__init__(db, table, printer) def get_records(self, cookie): + if not self._db: + return [] # Adjust cookie to include leading zeroes if needed. cookie = cookie.zfill(8) return self._db.find_rows_by_partial_uuid(self._table, cookie) @@ -488,8 +498,19 @@ def main(): if ovs and not ovs_db: ovs_db = 'unix:%s/db.sock' % ovs_rundir - ovsdb_ovnsb = OVSDB(ovnsb_db, 'OVN_Southbound', leader_only=leader_only) - ovsdb_ovnnb = OVSDB(ovnnb_db, 'OVN_Northbound', leader_only=leader_only) + try: + ovsdb_ovnsb = OVSDB(ovnsb_db, 'OVN_Southbound', + leader_only=leader_only) + except ConnectionException: + print(DB_CONNECTION_ERR.format('SB'), file=sys.stderr) + ovsdb_ovnsb = None + + try: + ovsdb_ovnnb = OVSDB(ovnnb_db, 'OVN_Northbound', + leader_only=leader_only) + except ConnectionException: + print(DB_CONNECTION_ERR.format('NB'), file=sys.stderr) + ovsdb_ovnnb = None printer = Printer() cookie_handlers = get_cookie_handlers(ovsdb_ovnnb, ovsdb_ovnsb, printer)