From patchwork Wed Oct 4 07:31:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Karim Ben Houcine X-Patchwork-Id: 31656 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id A4BC1E8FDD7 for ; Wed, 4 Oct 2023 07:31:59 +0000 (UTC) Received: from mail.landisgyr.com (mail.landisgyr.com [213.95.165.69]) by mx.groups.io with SMTP id smtpd.web10.13069.1696404716479604403 for ; Wed, 04 Oct 2023 00:31:56 -0700 Authentication-Results: mx.groups.io; dkim=none (message not signed); spf=pass (domain: landisgyr.com, ip: 213.95.165.69, mailfrom: karim.benhoucine@landisgyr.com) Received: from FRMONPC1175.eu.bm.net (unknown [10.49.130.40]) by mail.landisgyr.com (Postfix) with ESMTP id C564844E3A5; Wed, 4 Oct 2023 09:31:27 +0200 (CEST) From: Karim Ben Houcine To: bitbake-devel@lists.openembedded.org Cc: Karim Ben Houcine Subject: [PATCH v3] hashserv: Fix read-only mode Date: Wed, 4 Oct 2023 09:31:52 +0200 Message-Id: <20231004073152.3454314-1-karim.benhoucine@landisgyr.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 List-Id: X-Webhook-Received: from li982-79.members.linode.com [45.33.32.79] by aws-us-west-2-korg-lkml-1.web.codeaurora.org with HTTPS for ; Wed, 04 Oct 2023 07:31:59 -0000 X-Groupsio-URL: https://lists.openembedded.org/g/bitbake-devel/message/15180 TCP read-only hash equivalence server is not working: the connection is prematurely closed without even notifying the value of the unihash. Expected behaviour is: 1. the client sends a ‘report’ message indicating the 'taskhash', 'method', 'outhash' and a proposed value of 'unihash'. 2.the server sends back the 'taskhash', 'method' and actual value of 'unihash' to use. The problem is that in read-only mode, the server rejects 'report' messages (connexion is closed). hashserv.tests.TestHashEquivalenceUnixServer.test_ro_server test modified accordingly Signed-off-by: Karim Ben Houcine Indeed, using selt.get_unihash() is better, thanks. --- lib/hashserv/server.py | 27 ++++++++++++++++++++++++++- lib/hashserv/tests.py | 5 ++--- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/lib/hashserv/server.py b/lib/hashserv/server.py index d40a2ab8..8d78ba7f 100644 --- a/lib/hashserv/server.py +++ b/lib/hashserv/server.py @@ -180,7 +180,11 @@ class ServerClient(bb.asyncrpc.AsyncServerConnection): 'get-stats': self.handle_get_stats, }) - if not read_only: + if read_only: + self.handlers.update({ + 'report': self.handle_readonly_report, + }) + else: self.handlers.update({ 'report': self.handle_report, 'report-equiv': self.handle_equivreport, @@ -453,6 +457,27 @@ class ServerClient(bb.asyncrpc.AsyncServerConnection): self.write_message(d) + + async def handle_readonly_report(self, data): + with closing(self.db.cursor()) as cursor: + + # Check if outhash is known + unihash_data = await self.get_unihash(cursor, data['method'], data['taskhash']) + if unihash_data is not None: + # outhash is known => retrieve unihash + unihash = unihash_data['unihash'] + else: + # outhash is unknown => nothing to do + unihash = data['taskhash'] + + d = { + 'taskhash': data['taskhash'], + 'method': data['method'], + 'unihash': unihash, + } + + self.write_message(d) + async def handle_equivreport(self, data): with closing(self.db.cursor()) as cursor: insert_data = { diff --git a/lib/hashserv/tests.py b/lib/hashserv/tests.py index f6b85aed..5bf88092 100644 --- a/lib/hashserv/tests.py +++ b/lib/hashserv/tests.py @@ -312,13 +312,12 @@ class HashEquivalenceCommonTests(object): # Check the hash via the read-only server self.assertClientGetHash(ro_client, taskhash, unihash) - # Ensure that reporting via the read-only server fails + # Ensure that reporting via the read-only server doesn't modify the database taskhash2 = 'c665584ee6817aa99edfc77a44dd853828279370' outhash2 = '3c979c3db45c569f51ab7626a4651074be3a9d11a84b1db076f5b14f7d39db44' unihash2 = '90e9bc1d1f094c51824adca7f8ea79a048d68824' - with self.assertRaises(ConnectionError): - ro_client.report_unihash(taskhash2, self.METHOD, outhash2, unihash2) + ro_client.report_unihash(taskhash2, self.METHOD, outhash2, unihash2) # Ensure that the database was not modified self.assertClientGetHash(self.client, taskhash2, None)