diff options
author | Daniil Baturin <daniil@baturin.org> | 2019-08-21 08:46:14 +0200 |
---|---|---|
committer | Daniil Baturin <daniil@baturin.org> | 2019-08-21 08:46:14 +0200 |
commit | 683835c1f6020172a270aedc7dcea7f09d5eb208 (patch) | |
tree | 85b995d48ab80962dd89dcf4493d20d89a1ff6ef | |
parent | 525438ac4ad1e4fba534c7d1c51283c4c2561d3e (diff) | |
download | vyos-1x-683835c1f6020172a270aedc7dcea7f09d5eb208.tar.gz vyos-1x-683835c1f6020172a270aedc7dcea7f09d5eb208.zip |
T1598: handle the socket timeout exception in vyos.hostsd_client
-rw-r--r-- | python/vyos/hostsd_client.py | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/python/vyos/hostsd_client.py b/python/vyos/hostsd_client.py index e02aefe6f..e2f05071b 100644 --- a/python/vyos/hostsd_client.py +++ b/python/vyos/hostsd_client.py @@ -12,20 +12,26 @@ class VyOSHostsdError(Exception): class Client(object): def __init__(self): - context = zmq.Context() - self.__socket = context.socket(zmq.REQ) - self.__socket.RCVTIMEO = 10000 #ms - self.__socket.setsockopt(zmq.LINGER, 0) - self.__socket.connect(SOCKET_PATH) + try: + context = zmq.Context() + self.__socket = context.socket(zmq.REQ) + self.__socket.RCVTIMEO = 10000 #ms + self.__socket.setsockopt(zmq.LINGER, 0) + self.__socket.connect(SOCKET_PATH) + except zmq.error.Again: + raise VyOSHostsdError("Could not connect to vyos-hostsd") def _communicate(self, msg): - request = json.dumps(msg).encode() - self.__socket.send(request) - - reply_msg = self.__socket.recv().decode() - reply = json.loads(reply_msg) - if 'error' in reply: - raise VyOSHostsdError(reply['error']) + try: + request = json.dumps(msg).encode() + self.__socket.send(request) + + reply_msg = self.__socket.recv().decode() + reply = json.loads(reply_msg) + if 'error' in reply: + raise VyOSHostsdError(reply['error']) + except zmq.error.Again: + raise VyOSHostsdError("Could not connect to vyos-hostsd") def set_host_name(self, host_name, domain_name, search_domains): msg = { |