summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/hashserv/client.py
diff options
context:
space:
mode:
Diffstat (limited to 'bitbake/lib/hashserv/client.py')
-rw-r--r--bitbake/lib/hashserv/client.py44
1 files changed, 34 insertions, 10 deletions
diff --git a/bitbake/lib/hashserv/client.py b/bitbake/lib/hashserv/client.py
index e6dc417912..daf1e12842 100644
--- a/bitbake/lib/hashserv/client.py
+++ b/bitbake/lib/hashserv/client.py
@@ -16,6 +16,7 @@ logger = logging.getLogger("hashserv.client")
16class AsyncClient(bb.asyncrpc.AsyncClient): 16class AsyncClient(bb.asyncrpc.AsyncClient):
17 MODE_NORMAL = 0 17 MODE_NORMAL = 0
18 MODE_GET_STREAM = 1 18 MODE_GET_STREAM = 1
19 MODE_EXIST_STREAM = 2
19 20
20 def __init__(self, username=None, password=None): 21 def __init__(self, username=None, password=None):
21 super().__init__("OEHASHEQUIV", "1.1", logger) 22 super().__init__("OEHASHEQUIV", "1.1", logger)
@@ -49,19 +50,36 @@ class AsyncClient(bb.asyncrpc.AsyncClient):
49 await self.socket.send("END") 50 await self.socket.send("END")
50 return await self.socket.recv() 51 return await self.socket.recv()
51 52
52 if new_mode == self.MODE_NORMAL and self.mode == self.MODE_GET_STREAM: 53 async def normal_to_stream(command):
54 r = await self.invoke({command: None})
55 if r != "ok":
56 raise ConnectionError(
57 f"Unable to transition to stream mode: Bad response from server {r!r}"
58 )
59
60 self.logger.debug("Mode is now %s", command)
61
62 if new_mode == self.mode:
63 return
64
65 self.logger.debug("Transitioning mode %s -> %s", self.mode, new_mode)
66
67 # Always transition to normal mode before switching to any other mode
68 if self.mode != self.MODE_NORMAL:
53 r = await self._send_wrapper(stream_to_normal) 69 r = await self._send_wrapper(stream_to_normal)
54 if r != "ok": 70 if r != "ok":
55 self.check_invoke_error(r) 71 self.check_invoke_error(r)
56 raise ConnectionError("Unable to transition to normal mode: Bad response from server %r" % r) 72 raise ConnectionError(
57 elif new_mode == self.MODE_GET_STREAM and self.mode == self.MODE_NORMAL: 73 f"Unable to transition to normal mode: Bad response from server {r!r}"
58 r = await self.invoke({"get-stream": None}) 74 )
59 if r != "ok": 75 self.logger.debug("Mode is now normal")
60 raise ConnectionError("Unable to transition to stream mode: Bad response from server %r" % r) 76
61 elif new_mode != self.mode: 77 if new_mode == self.MODE_GET_STREAM:
62 raise Exception( 78 await normal_to_stream("get-stream")
63 "Undefined mode transition %r -> %r" % (self.mode, new_mode) 79 elif new_mode == self.MODE_EXIST_STREAM:
64 ) 80 await normal_to_stream("exists-stream")
81 elif new_mode != self.MODE_NORMAL:
82 raise Exception("Undefined mode transition {self.mode!r} -> {new_mode!r}")
65 83
66 self.mode = new_mode 84 self.mode = new_mode
67 85
@@ -95,6 +113,11 @@ class AsyncClient(bb.asyncrpc.AsyncClient):
95 {"get": {"taskhash": taskhash, "method": method, "all": all_properties}} 113 {"get": {"taskhash": taskhash, "method": method, "all": all_properties}}
96 ) 114 )
97 115
116 async def unihash_exists(self, unihash):
117 await self._set_mode(self.MODE_EXIST_STREAM)
118 r = await self.send_stream(unihash)
119 return r == "true"
120
98 async def get_outhash(self, method, outhash, taskhash, with_unihash=True): 121 async def get_outhash(self, method, outhash, taskhash, with_unihash=True):
99 await self._set_mode(self.MODE_NORMAL) 122 await self._set_mode(self.MODE_NORMAL)
100 return await self.invoke( 123 return await self.invoke(
@@ -236,6 +259,7 @@ class Client(bb.asyncrpc.Client):
236 "report_unihash", 259 "report_unihash",
237 "report_unihash_equiv", 260 "report_unihash_equiv",
238 "get_taskhash", 261 "get_taskhash",
262 "unihash_exists",
239 "get_outhash", 263 "get_outhash",
240 "get_stats", 264 "get_stats",
241 "reset_stats", 265 "reset_stats",