summary |
shortlog |
log |
commit | commitdiff |
review |
tree
raw |
patch |
inline | side by side (from parent 1:
d540d30)
1.send bytes data to the socket
see https://docs.python.org/3/library/socket.html
2.fix a endless loop
Change-Id: I880e713266347d8836cec45ebf9a500bb7c813f4
Signed-off-by: dongwenjuan <dong.wenjuan@zte.com.cn>
class Pinger(Thread):
interval = 0.1 # second
timeout = 0.1 # second
class Pinger(Thread):
interval = 0.1 # second
timeout = 0.1 # second
- ICMP_ECHO_MESSAGE = '\x08\x00\xf7\xff\x00\x00\x00\x00'
+ ICMP_ECHO_MESSAGE = bytes([0x08, 0x00, 0xf7, 0xff, 0x00, 0x00, 0x00, 0x00])
def __init__(self, host_name, host_ip, monitor, log):
Thread.__init__(self)
def __init__(self, host_name, host_ip, monitor, log):
Thread.__init__(self)
self._stopped = False
def run(self):
self._stopped = False
def run(self):
- while True:
- if self._stopped:
- return
- self._run()
- time.sleep(self.interval)
-
- def stop(self):
- self.log.info("Stopping Pinger host_name(%s), host_ip(%s)"
- % (self.hostname, self.ip_addr))
- self._stopped = True
-
- def _run(self):
self.log.info("Starting Pinger host_name(%s), host_ip(%s)"
% (self.hostname, self.ip_addr))
self.log.info("Starting Pinger host_name(%s), host_ip(%s)"
% (self.hostname, self.ip_addr))
socket.IPPROTO_ICMP)
sock.settimeout(self.timeout)
while True:
socket.IPPROTO_ICMP)
sock.settimeout(self.timeout)
while True:
+ if self._stopped:
+ return
- sock.sendto(self.ICMP_ECHO_MESSAGE.encode(), (self.ip_addr, 0))
+ sock.sendto(self.ICMP_ECHO_MESSAGE, (self.ip_addr, 0))
sock.recv(4096)
except socket.timeout:
self.log.info("doctor monitor detected at %s" % time.time())
sock.recv(4096)
except socket.timeout:
self.log.info("doctor monitor detected at %s" % time.time())
self.log.info("ping timeout, quit monitoring...")
self._stopped = True
return
self.log.info("ping timeout, quit monitoring...")
self._stopped = True
return
+ time.sleep(self.interval)
+
+ def stop(self):
+ self.log.info("Stopping Pinger host_name(%s), host_ip(%s)"
+ % (self.hostname, self.ip_addr))
+ self._stopped = True
ret = stdout.channel.recv_exit_status()
output = list()
for line in stdout.read().splitlines():
ret = stdout.channel.recv_exit_status()
output = list()
for line in stdout.read().splitlines():
+ output.append(line.decode('utf-8'))
if ret:
if self.log:
self.log.debug("*** FAILED to run command %s (%s)" % (command, ret))
if ret:
if self.log:
self.log.debug("*** FAILED to run command %s (%s)" % (command, ret))