fixes to facts timeout

also now handle timeout exception correctly everywhere
pull/19535/head
Brian Coca 8 years ago committed by Brian Coca
parent f533f6603c
commit b4bd6c80de

@ -81,16 +81,16 @@ GATHER_TIMEOUT=None
class TimeoutError(Exception):
pass
def timeout(seconds=10, error_message="Timer expired"):
def timeout(seconds=None, error_message="Timer expired"):
if seconds is None:
seconds = globals().get('GATHER_TIMEOUT') or 10
def decorator(func):
def _handle_timeout(signum, frame):
raise TimeoutError(error_message)
def wrapper(*args, **kwargs):
if 'GATHER_TIMEOUT' in globals():
if GATHER_TIMEOUT:
seconds = GATHER_TIMEOUT
signal.signal(signal.SIGALRM, _handle_timeout)
signal.alarm(seconds)
try:
@ -1327,7 +1327,7 @@ class LinuxHardware(Hardware):
mtab_entries.append(fields)
return mtab_entries
@timeout(10)
@timeout()
def get_mount_facts(self):
self.facts['mounts'] = []
@ -1584,7 +1584,7 @@ class SunOSHardware(Hardware):
self.facts['swap_allocated_mb'] = allocated // 1024
self.facts['swap_reserved_mb'] = reserved // 1024
@timeout(10)
@timeout()
def get_mount_facts(self):
self.facts['mounts'] = []
# For a detailed format description see mnttab(4)
@ -1629,11 +1629,14 @@ class OpenBSDHardware(Hardware):
self.get_memory_facts()
self.get_processor_facts()
self.get_device_facts()
self.get_mount_facts()
try:
self.get_mount_facts()
except TimeoutError:
pass
self.get_dmi_facts()
return self.facts
@timeout(10)
@timeout()
def get_mount_facts(self):
self.facts['mounts'] = []
fstab = get_file_content('/etc/fstab')
@ -1776,7 +1779,7 @@ class FreeBSDHardware(Hardware):
self.facts['swaptotal_mb'] = int(data[1]) // 1024
self.facts['swapfree_mb'] = int(data[3]) // 1024
@timeout(10)
@timeout()
def get_mount_facts(self):
self.facts['mounts'] = []
fstab = get_file_content('/etc/fstab')
@ -1907,7 +1910,7 @@ class NetBSDHardware(Hardware):
val = data[1].strip().split(' ')[0]
self.facts["%s_mb" % key.lower()] = int(val) // 1024
@timeout(10)
@timeout()
def get_mount_facts(self):
self.facts['mounts'] = []
fstab = get_file_content('/etc/fstab')
@ -2241,7 +2244,10 @@ class HurdHardware(LinuxHardware):
def populate(self):
self.get_uptime_facts()
self.get_memory_facts()
self.get_mount_facts()
try:
self.get_mount_facts()
except TimeoutError:
pass
return self.facts
class Network(Facts):

Loading…
Cancel
Save