def waiton(self, timeout=90):
"""Wait until switch if fully operational.
Args:
timeout(int): Wait timeout
Raises:
SwitchException: device doesn't response
Returns:
dict: Status dictionary from probe method or raise an exception.
"""
status = None
message = "Waiting until switch %s(%s) is up." % (self.name, self.ipaddr)
self.class_logger.info(message)
stop_flag = False
end_time = time.time() + timeout
while not stop_flag:
if loggers.LOG_STREAM:
sys.stdout.write(".")
sys.stdout.flush()
if time.time() < end_time:
# While time isn't elapsed continue probing switch.
try:
status = self.probe()
except KeyboardInterrupt:
message = "KeyboardInterrupt while checking switch %s(%s)..." % (self.name, self.ipaddr)
self.class_logger.info(message)
self.sanitize()
pytest.exit(message)
if status["isup"] and status["type"] == "switchpp":
stop_flag = True
if status['prop'] == {}:
# If type == switchpp but prop == empty dict then Platform table return incorrect data.
message = "Found running switchpp on %s but Platform data is corrupted." % (self.ipaddr, )
self.class_logger.warning(message)
raise SwitchException(message)
self.class_logger.info("Switch instance on %s(%s) is OK." % (self.name, self.ipaddr))
else:
# Time is elapsed.
if status["isup"] and status["type"] != "switchpp":
message = ("Port %s on host %s is opened but doesn't response queries." +
" %s Check your environment!") % (self.port, self.ipaddr, self.waiton_err_message)
else:
port = self._get_port_for_probe()
message = "Timeout exceeded. IP address %s port %s doesn't respond" % (self.ipaddr, port)
self.class_logger.warning(message)
raise SwitchException(message)
if not stop_flag:
time.sleep(0.75)
return status
评论列表
文章目录