Skip to content
This repository has been archived by the owner on Jun 29, 2022. It is now read-only.

Commit

Permalink
Add 30 minute timeout to host discovery phase
Browse files Browse the repository at this point in the history
  • Loading branch information
Noah Lavine committed Dec 15, 2017
1 parent 165af96 commit 694bdf6
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
1 change: 1 addition & 0 deletions requirements.txt
Expand Up @@ -2,6 +2,7 @@ ansible
pexpect
future
sh
stopit
pyxdg

# These requirements are for DEVELOPMENT ONLY!
Expand Down
19 changes: 13 additions & 6 deletions rho/host_discovery.py
Expand Up @@ -14,6 +14,8 @@
import os
import re

import stopit

from rho import ansible_utils
from rho.translation import _
from rho.utilities import (log, str_to_ascii, PING_INVENTORY_PATH,
Expand Down Expand Up @@ -133,12 +135,17 @@ def create_ping_inventory(vault, vault_pass, profile_ranges, profile_port,
# verbosity can break our parsing of Ansible's output. This is
# a temporary fix - a better solution would be less-fragile
# output parsing.
ansible_utils.run_with_vault(cmd_string, vault_pass,
log_path=PING_LOG_PATH,
env=my_env,
log_to_stdout=process_discovery_scan,
log_to_stdout_env=log_env,
ansible_verbosity=0, error_on_failure=False)
with stopit.ThreadingTimeout(30 * 60) as timeout_mgr:
ansible_utils.run_with_vault(
cmd_string, vault_pass,
log_path=PING_LOG_PATH,
env=my_env,
log_to_stdout=process_discovery_scan,
log_to_stdout_env=log_env,
ansible_verbosity=0, error_on_failure=False)

if timeout_mgr.state == timeout_mgr.TIMED_OUT:
log.warning('Host discovery timed out before completion.')

with open(PING_LOG_PATH, 'r') as ping_log:
success_hosts, failed_hosts, unreachable_hosts = \
Expand Down
14 changes: 14 additions & 0 deletions test/test_host_discovery.py
Expand Up @@ -51,3 +51,17 @@ def test_process_ping_output_fail(self):
'192.168.50.12']))
self.assertEqual(failed, set())
self.assertEqual(unreachable, set(['192.168.50.11']))

def test_partial_output(self):
"""Partial lines of output, for instance from a timeout."""
success, failed, unreachable = host_discovery.process_ping_output([
'192.168.50.11 | UNREACH',
'Hello',
'192.168.50.12 | ',
'Hello',
'192.168',
'Hello'])

self.assertEqual(success, set())
self.assertEqual(failed, set())
self.assertEqual(unreachable, set())

0 comments on commit 694bdf6

Please sign in to comment.