Return True if host (str) responds to a ping request. Remember that a host may not respond to a ping (ICMP) request even if the host name is valid.
(host, logger)
| 1528 | |
| 1529 | |
| 1530 | def ping_server(host, logger): |
| 1531 | """ |
| 1532 | Return True if host (str) responds to a ping request. |
| 1533 | Remember that a host may not respond to a ping (ICMP) request even if |
| 1534 | the host name is valid. |
| 1535 | """ |
| 1536 | logger.info("Pinging '{}' to check the connectivity...".format(str(host))) |
| 1537 | |
| 1538 | # ping command count option as function of OS |
| 1539 | param = "-n" if system().lower() == "windows" else "-c" |
| 1540 | # building the command. Ex: "ping -c 1 google.com" |
| 1541 | command = " ".join(["ping", param, "1", str(host)]) |
| 1542 | need_sh = False if system().lower() == "windows" else True |
| 1543 | |
| 1544 | # pinging |
| 1545 | ping_attempts = 2 |
| 1546 | connectivity = None |
| 1547 | |
| 1548 | while connectivity is not True and ping_attempts > 0: |
| 1549 | connectivity = call(command, shell=need_sh) == 0 |
| 1550 | |
| 1551 | if connectivity is False: |
| 1552 | logger.warning( |
| 1553 | "Pinging the server again!\t~total attempts left: {}".format( |
| 1554 | ping_attempts |
| 1555 | ) |
| 1556 | ) |
| 1557 | ping_attempts -= 1 |
| 1558 | sleep(5) |
| 1559 | |
| 1560 | if connectivity is False: |
| 1561 | logger.critical("There is no connection to the '{}' server!".format(host)) |
| 1562 | return False |
| 1563 | |
| 1564 | return True |
| 1565 | |
| 1566 | |
| 1567 | def emergency_exit(browser, username, logger): |
no test coverage detected