summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorCarlos Goncalves <mail@cgoncalves.pt>2017-08-17 09:23:05 +0000
committerGerrit Code Review <gerrit@opnfv.org>2017-08-17 09:23:05 +0000
commitd2b6574994e065de13c2d31f9a6d7f27142c0a41 (patch)
treec99b6362f9e3e5640201c7ddd152871b6b03bd91 /tests
parent38c45126cb9c993571246b307ff644b1343712c9 (diff)
parent906056bb4e594e3c0a46cf11657b3561583699b4 (diff)
Merge "fix some bugs in monitor"
Diffstat (limited to 'tests')
-rw-r--r--tests/monitor/sample.py24
-rw-r--r--tests/utils.py2
2 files changed, 11 insertions, 15 deletions
diff --git a/tests/monitor/sample.py b/tests/monitor/sample.py
index 4f1ce490..1333a2ec 100644
--- a/tests/monitor/sample.py
+++ b/tests/monitor/sample.py
@@ -78,7 +78,7 @@ class SampleMonitor(BaseMonitor):
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)
@@ -89,18 +89,6 @@ class Pinger(Thread):
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))
@@ -108,8 +96,10 @@ class Pinger(Thread):
socket.IPPROTO_ICMP)
sock.settimeout(self.timeout)
while True:
+ if self._stopped:
+ return
try:
- 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())
@@ -117,3 +107,9 @@ class Pinger(Thread):
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
diff --git a/tests/utils.py b/tests/utils.py
index f57cd266..41e22353 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -56,7 +56,7 @@ class SSHClient(object):
ret = stdout.channel.recv_exit_status()
output = list()
for line in stdout.read().splitlines():
- output.append(line)
+ output.append(line.decode('utf-8'))
if ret:
if self.log:
self.log.debug("*** FAILED to run command %s (%s)" % (command, ret))