diff options
author | Daniil Baturin <daniil@baturin.org> | 2019-08-21 08:46:14 +0200 |
---|---|---|
committer | Daniil Baturin <daniil@baturin.org> | 2019-08-27 08:14:51 +0200 |
commit | 5824029b4b4aa32048bda3b012eeee1ab6940c63 (patch) | |
tree | ba2142dd61ddead71ed500e8bfeadeaa16f104d6 /python/vyos | |
parent | 4ec3b643adb25cba6039bafde137eda7fced56e3 (diff) | |
download | vyos-1x-5824029b4b4aa32048bda3b012eeee1ab6940c63.tar.gz vyos-1x-5824029b4b4aa32048bda3b012eeee1ab6940c63.zip |
T1598: handle the socket timeout exception in vyos.hostsd_client
Diffstat (limited to 'python/vyos')
-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 = { |