mirror of
https://git.yoctoproject.org/poky
synced 2026-09-19 18:49:32 +02:00
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>
This commit is contained in:
committed by
Richard Purdie
parent
bf348561f3
commit
1023671823
@@ -542,7 +542,7 @@ class SignatureGeneratorUniHashMixIn(object):
|
|||||||
hashequiv_logger.debug((1, 2)[unihash == taskhash], 'Found unihash %s in place of %s for %s from %s' % (unihash, taskhash, tid, self.server))
|
hashequiv_logger.debug((1, 2)[unihash == taskhash], 'Found unihash %s in place of %s for %s from %s' % (unihash, taskhash, tid, self.server))
|
||||||
else:
|
else:
|
||||||
hashequiv_logger.debug2('No reported unihash for %s:%s from %s' % (tid, taskhash, self.server))
|
hashequiv_logger.debug2('No reported unihash for %s:%s from %s' % (tid, taskhash, self.server))
|
||||||
except hashserv.client.HashConnectionError as e:
|
except ConnectionError as e:
|
||||||
bb.warn('Error contacting Hash Equivalence Server %s: %s' % (self.server, str(e)))
|
bb.warn('Error contacting Hash Equivalence Server %s: %s' % (self.server, str(e)))
|
||||||
|
|
||||||
self.set_unihash(tid, unihash)
|
self.set_unihash(tid, unihash)
|
||||||
@@ -621,7 +621,7 @@ class SignatureGeneratorUniHashMixIn(object):
|
|||||||
d.setVar('BB_UNIHASH', new_unihash)
|
d.setVar('BB_UNIHASH', new_unihash)
|
||||||
else:
|
else:
|
||||||
hashequiv_logger.debug('Reported task %s as unihash %s to %s' % (taskhash, unihash, self.server))
|
hashequiv_logger.debug('Reported task %s as unihash %s to %s' % (taskhash, unihash, self.server))
|
||||||
except hashserv.client.HashConnectionError as e:
|
except ConnectionError as e:
|
||||||
bb.warn('Error contacting Hash Equivalence Server %s: %s' % (self.server, str(e)))
|
bb.warn('Error contacting Hash Equivalence Server %s: %s' % (self.server, str(e)))
|
||||||
finally:
|
finally:
|
||||||
if sigfile:
|
if sigfile:
|
||||||
@@ -661,7 +661,7 @@ class SignatureGeneratorUniHashMixIn(object):
|
|||||||
# TODO: What to do here?
|
# TODO: What to do here?
|
||||||
hashequiv_logger.verbose('Task %s unihash reported as unwanted hash %s' % (tid, finalunihash))
|
hashequiv_logger.verbose('Task %s unihash reported as unwanted hash %s' % (tid, finalunihash))
|
||||||
|
|
||||||
except hashserv.client.HashConnectionError as e:
|
except ConnectionError as e:
|
||||||
bb.warn('Error contacting Hash Equivalence Server %s: %s' % (self.server, str(e)))
|
bb.warn('Error contacting Hash Equivalence Server %s: %s' % (self.server, str(e)))
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|||||||
@@ -14,10 +14,6 @@ from . import chunkify, DEFAULT_MAX_CHUNK, create_async_client
|
|||||||
logger = logging.getLogger("hashserv.client")
|
logger = logging.getLogger("hashserv.client")
|
||||||
|
|
||||||
|
|
||||||
class HashConnectionError(Exception):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class AsyncClient(object):
|
class AsyncClient(object):
|
||||||
MODE_NORMAL = 0
|
MODE_NORMAL = 0
|
||||||
MODE_GET_STREAM = 1
|
MODE_GET_STREAM = 1
|
||||||
@@ -66,14 +62,14 @@ class AsyncClient(object):
|
|||||||
return await proc()
|
return await proc()
|
||||||
except (
|
except (
|
||||||
OSError,
|
OSError,
|
||||||
HashConnectionError,
|
ConnectionError,
|
||||||
json.JSONDecodeError,
|
json.JSONDecodeError,
|
||||||
UnicodeDecodeError,
|
UnicodeDecodeError,
|
||||||
) as e:
|
) as e:
|
||||||
logger.warning("Error talking to server: %s" % e)
|
logger.warning("Error talking to server: %s" % e)
|
||||||
if count >= 3:
|
if count >= 3:
|
||||||
if not isinstance(e, HashConnectionError):
|
if not isinstance(e, ConnectionError):
|
||||||
raise HashConnectionError(str(e))
|
raise ConnectionError(str(e))
|
||||||
raise e
|
raise e
|
||||||
await self.close()
|
await self.close()
|
||||||
count += 1
|
count += 1
|
||||||
@@ -82,12 +78,12 @@ class AsyncClient(object):
|
|||||||
async def get_line():
|
async def get_line():
|
||||||
line = await self.reader.readline()
|
line = await self.reader.readline()
|
||||||
if not line:
|
if not line:
|
||||||
raise HashConnectionError("Connection closed")
|
raise ConnectionError("Connection closed")
|
||||||
|
|
||||||
line = line.decode("utf-8")
|
line = line.decode("utf-8")
|
||||||
|
|
||||||
if not line.endswith("\n"):
|
if not line.endswith("\n"):
|
||||||
raise HashConnectionError("Bad message %r" % message)
|
raise ConnectionError("Bad message %r" % message)
|
||||||
|
|
||||||
return line
|
return line
|
||||||
|
|
||||||
@@ -119,7 +115,7 @@ class AsyncClient(object):
|
|||||||
await self.writer.drain()
|
await self.writer.drain()
|
||||||
l = await self.reader.readline()
|
l = await self.reader.readline()
|
||||||
if not l:
|
if not l:
|
||||||
raise HashConnectionError("Connection closed")
|
raise ConnectionError("Connection closed")
|
||||||
return l.decode("utf-8").rstrip()
|
return l.decode("utf-8").rstrip()
|
||||||
|
|
||||||
return await self._send_wrapper(proc)
|
return await self._send_wrapper(proc)
|
||||||
@@ -128,11 +124,11 @@ class AsyncClient(object):
|
|||||||
if new_mode == self.MODE_NORMAL and self.mode == self.MODE_GET_STREAM:
|
if new_mode == self.MODE_NORMAL and self.mode == self.MODE_GET_STREAM:
|
||||||
r = await self.send_stream("END")
|
r = await self.send_stream("END")
|
||||||
if r != "ok":
|
if r != "ok":
|
||||||
raise HashConnectionError("Bad response from server %r" % r)
|
raise ConnectionError("Bad response from server %r" % r)
|
||||||
elif new_mode == self.MODE_GET_STREAM and self.mode == self.MODE_NORMAL:
|
elif new_mode == self.MODE_GET_STREAM and self.mode == self.MODE_NORMAL:
|
||||||
r = await self.send_message({"get-stream": None})
|
r = await self.send_message({"get-stream": None})
|
||||||
if r != "ok":
|
if r != "ok":
|
||||||
raise HashConnectionError("Bad response from server %r" % r)
|
raise ConnectionError("Bad response from server %r" % r)
|
||||||
elif new_mode != self.mode:
|
elif new_mode != self.mode:
|
||||||
raise Exception(
|
raise Exception(
|
||||||
"Undefined mode transition %r -> %r" % (self.mode, new_mode)
|
"Undefined mode transition %r -> %r" % (self.mode, new_mode)
|
||||||
|
|||||||
@@ -6,7 +6,6 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
from . import create_server, create_client
|
from . import create_server, create_client
|
||||||
from .client import HashConnectionError
|
|
||||||
import hashlib
|
import hashlib
|
||||||
import logging
|
import logging
|
||||||
import multiprocessing
|
import multiprocessing
|
||||||
@@ -277,7 +276,7 @@ class HashEquivalenceCommonTests(object):
|
|||||||
outhash2 = '3c979c3db45c569f51ab7626a4651074be3a9d11a84b1db076f5b14f7d39db44'
|
outhash2 = '3c979c3db45c569f51ab7626a4651074be3a9d11a84b1db076f5b14f7d39db44'
|
||||||
unihash2 = '90e9bc1d1f094c51824adca7f8ea79a048d68824'
|
unihash2 = '90e9bc1d1f094c51824adca7f8ea79a048d68824'
|
||||||
|
|
||||||
with self.assertRaises(HashConnectionError):
|
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
|
# Ensure that the database was not modified
|
||||||
|
|||||||
Reference in New Issue
Block a user