diff options
| author | Paul Barker <pbarker@konsulko.com> | 2021-04-26 09:16:28 +0100 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2021-04-27 15:12:57 +0100 |
| commit | 10236718236e6a12e2e6528abcd920276d181545 (patch) | |
| tree | 1026bd499be15ab6bfea99971dd73ff5d0b4fd32 | |
| parent | bf348561f332fdeba6b79019852fdd98d031d4a1 (diff) | |
| download | poky-10236718236e6a12e2e6528abcd920276d181545.tar.gz | |
bitbake: hashserv: Use generic ConnectionError
The Python built-in ConnectionError type can be used instead of a custom
HashConnectionError type. This will make code refactoring simpler.
(Bitbake rev: 8a796c3d6d99cfa8ef7aff0ae55bb0f23bbbeae1)
Signed-off-by: Paul Barker <pbarker@konsulko.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
| -rw-r--r-- | bitbake/lib/bb/siggen.py | 6 | ||||
| -rw-r--r-- | bitbake/lib/hashserv/client.py | 20 | ||||
| -rw-r--r-- | bitbake/lib/hashserv/tests.py | 3 |
3 files changed, 12 insertions, 17 deletions
diff --git a/bitbake/lib/bb/siggen.py b/bitbake/lib/bb/siggen.py index 0d88c6ec68..f3fa3000fa 100644 --- a/bitbake/lib/bb/siggen.py +++ b/bitbake/lib/bb/siggen.py | |||
| @@ -542,7 +542,7 @@ class SignatureGeneratorUniHashMixIn(object): | |||
| 542 | hashequiv_logger.debug((1, 2)[unihash == taskhash], 'Found unihash %s in place of %s for %s from %s' % (unihash, taskhash, tid, self.server)) | 542 | hashequiv_logger.debug((1, 2)[unihash == taskhash], 'Found unihash %s in place of %s for %s from %s' % (unihash, taskhash, tid, self.server)) |
| 543 | else: | 543 | else: |
| 544 | hashequiv_logger.debug2('No reported unihash for %s:%s from %s' % (tid, taskhash, self.server)) | 544 | hashequiv_logger.debug2('No reported unihash for %s:%s from %s' % (tid, taskhash, self.server)) |
| 545 | except hashserv.client.HashConnectionError as e: | 545 | except ConnectionError as e: |
| 546 | bb.warn('Error contacting Hash Equivalence Server %s: %s' % (self.server, str(e))) | 546 | bb.warn('Error contacting Hash Equivalence Server %s: %s' % (self.server, str(e))) |
| 547 | 547 | ||
| 548 | self.set_unihash(tid, unihash) | 548 | self.set_unihash(tid, unihash) |
| @@ -621,7 +621,7 @@ class SignatureGeneratorUniHashMixIn(object): | |||
| 621 | d.setVar('BB_UNIHASH', new_unihash) | 621 | d.setVar('BB_UNIHASH', new_unihash) |
| 622 | else: | 622 | else: |
| 623 | hashequiv_logger.debug('Reported task %s as unihash %s to %s' % (taskhash, unihash, self.server)) | 623 | hashequiv_logger.debug('Reported task %s as unihash %s to %s' % (taskhash, unihash, self.server)) |
| 624 | except hashserv.client.HashConnectionError as e: | 624 | except ConnectionError as e: |
| 625 | bb.warn('Error contacting Hash Equivalence Server %s: %s' % (self.server, str(e))) | 625 | bb.warn('Error contacting Hash Equivalence Server %s: %s' % (self.server, str(e))) |
| 626 | finally: | 626 | finally: |
| 627 | if sigfile: | 627 | if sigfile: |
| @@ -661,7 +661,7 @@ class SignatureGeneratorUniHashMixIn(object): | |||
| 661 | # TODO: What to do here? | 661 | # TODO: What to do here? |
| 662 | hashequiv_logger.verbose('Task %s unihash reported as unwanted hash %s' % (tid, finalunihash)) | 662 | hashequiv_logger.verbose('Task %s unihash reported as unwanted hash %s' % (tid, finalunihash)) |
| 663 | 663 | ||
| 664 | except hashserv.client.HashConnectionError as e: | 664 | except ConnectionError as e: |
| 665 | bb.warn('Error contacting Hash Equivalence Server %s: %s' % (self.server, str(e))) | 665 | bb.warn('Error contacting Hash Equivalence Server %s: %s' % (self.server, str(e))) |
| 666 | 666 | ||
| 667 | return False | 667 | return False |
diff --git a/bitbake/lib/hashserv/client.py b/bitbake/lib/hashserv/client.py index e05c1eb568..f370cba63f 100644 --- a/bitbake/lib/hashserv/client.py +++ b/bitbake/lib/hashserv/client.py | |||
| @@ -14,10 +14,6 @@ from . import chunkify, DEFAULT_MAX_CHUNK, create_async_client | |||
| 14 | logger = logging.getLogger("hashserv.client") | 14 | logger = logging.getLogger("hashserv.client") |
| 15 | 15 | ||
| 16 | 16 | ||
| 17 | class HashConnectionError(Exception): | ||
| 18 | pass | ||
| 19 | |||
| 20 | |||
| 21 | class AsyncClient(object): | 17 | class AsyncClient(object): |
| 22 | MODE_NORMAL = 0 | 18 | MODE_NORMAL = 0 |
| 23 | MODE_GET_STREAM = 1 | 19 | MODE_GET_STREAM = 1 |
| @@ -66,14 +62,14 @@ class AsyncClient(object): | |||
| 66 | return await proc() | 62 | return await proc() |
| 67 | except ( | 63 | except ( |
| 68 | OSError, | 64 | OSError, |
| 69 | HashConnectionError, | 65 | ConnectionError, |
| 70 | json.JSONDecodeError, | 66 | json.JSONDecodeError, |
| 71 | UnicodeDecodeError, | 67 | UnicodeDecodeError, |
| 72 | ) as e: | 68 | ) as e: |
| 73 | logger.warning("Error talking to server: %s" % e) | 69 | logger.warning("Error talking to server: %s" % e) |
| 74 | if count >= 3: | 70 | if count >= 3: |
| 75 | if not isinstance(e, HashConnectionError): | 71 | if not isinstance(e, ConnectionError): |
| 76 | raise HashConnectionError(str(e)) | 72 | raise ConnectionError(str(e)) |
| 77 | raise e | 73 | raise e |
| 78 | await self.close() | 74 | await self.close() |
| 79 | count += 1 | 75 | count += 1 |
| @@ -82,12 +78,12 @@ class AsyncClient(object): | |||
| 82 | async def get_line(): | 78 | async def get_line(): |
| 83 | line = await self.reader.readline() | 79 | line = await self.reader.readline() |
| 84 | if not line: | 80 | if not line: |
| 85 | raise HashConnectionError("Connection closed") | 81 | raise ConnectionError("Connection closed") |
| 86 | 82 | ||
| 87 | line = line.decode("utf-8") | 83 | line = line.decode("utf-8") |
| 88 | 84 | ||
| 89 | if not line.endswith("\n"): | 85 | if not line.endswith("\n"): |
| 90 | raise HashConnectionError("Bad message %r" % message) | 86 | raise ConnectionError("Bad message %r" % message) |
| 91 | 87 | ||
| 92 | return line | 88 | return line |
| 93 | 89 | ||
| @@ -119,7 +115,7 @@ class AsyncClient(object): | |||
| 119 | await self.writer.drain() | 115 | await self.writer.drain() |
| 120 | l = await self.reader.readline() | 116 | l = await self.reader.readline() |
| 121 | if not l: | 117 | if not l: |
| 122 | raise HashConnectionError("Connection closed") | 118 | raise ConnectionError("Connection closed") |
| 123 | return l.decode("utf-8").rstrip() | 119 | return l.decode("utf-8").rstrip() |
| 124 | 120 | ||
| 125 | return await self._send_wrapper(proc) | 121 | return await self._send_wrapper(proc) |
| @@ -128,11 +124,11 @@ class AsyncClient(object): | |||
| 128 | if new_mode == self.MODE_NORMAL and self.mode == self.MODE_GET_STREAM: | 124 | if new_mode == self.MODE_NORMAL and self.mode == self.MODE_GET_STREAM: |
| 129 | r = await self.send_stream("END") | 125 | r = await self.send_stream("END") |
| 130 | if r != "ok": | 126 | if r != "ok": |
| 131 | raise HashConnectionError("Bad response from server %r" % r) | 127 | raise ConnectionError("Bad response from server %r" % r) |
| 132 | elif new_mode == self.MODE_GET_STREAM and self.mode == self.MODE_NORMAL: | 128 | elif new_mode == self.MODE_GET_STREAM and self.mode == self.MODE_NORMAL: |
| 133 | r = await self.send_message({"get-stream": None}) | 129 | r = await self.send_message({"get-stream": None}) |
| 134 | if r != "ok": | 130 | if r != "ok": |
| 135 | raise HashConnectionError("Bad response from server %r" % r) | 131 | raise ConnectionError("Bad response from server %r" % r) |
| 136 | elif new_mode != self.mode: | 132 | elif new_mode != self.mode: |
| 137 | raise Exception( | 133 | raise Exception( |
| 138 | "Undefined mode transition %r -> %r" % (self.mode, new_mode) | 134 | "Undefined mode transition %r -> %r" % (self.mode, new_mode) |
diff --git a/bitbake/lib/hashserv/tests.py b/bitbake/lib/hashserv/tests.py index 1a696481e3..e2b762dbf0 100644 --- a/bitbake/lib/hashserv/tests.py +++ b/bitbake/lib/hashserv/tests.py | |||
| @@ -6,7 +6,6 @@ | |||
| 6 | # | 6 | # |
| 7 | 7 | ||
| 8 | from . import create_server, create_client | 8 | from . import create_server, create_client |
| 9 | from .client import HashConnectionError | ||
| 10 | import hashlib | 9 | import hashlib |
| 11 | import logging | 10 | import logging |
| 12 | import multiprocessing | 11 | import multiprocessing |
| @@ -277,7 +276,7 @@ class HashEquivalenceCommonTests(object): | |||
| 277 | outhash2 = '3c979c3db45c569f51ab7626a4651074be3a9d11a84b1db076f5b14f7d39db44' | 276 | outhash2 = '3c979c3db45c569f51ab7626a4651074be3a9d11a84b1db076f5b14f7d39db44' |
| 278 | unihash2 = '90e9bc1d1f094c51824adca7f8ea79a048d68824' | 277 | unihash2 = '90e9bc1d1f094c51824adca7f8ea79a048d68824' |
| 279 | 278 | ||
| 280 | with self.assertRaises(HashConnectionError): | 279 | with self.assertRaises(ConnectionError): |
| 281 | ro_client.report_unihash(taskhash2, self.METHOD, outhash2, unihash2) | 280 | ro_client.report_unihash(taskhash2, self.METHOD, outhash2, unihash2) |
| 282 | 281 | ||
| 283 | # Ensure that the database was not modified | 282 | # Ensure that the database was not modified |
