From f7d97a7939a81018ffc85875b1332110b89366a1 Mon Sep 17 00:00:00 2001 From: Jonathan Creasy Date: Wed, 28 Oct 2020 11:17:30 -0400 Subject: [PATCH] Fixed issue with tests and also allowed procstats to exit gracefully --- collectors/0/procstats.py | 19 +++++++++++-------- tests.py | 3 ++- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/collectors/0/procstats.py b/collectors/0/procstats.py index 0dd8e042..d103d23b 100755 --- a/collectors/0/procstats.py +++ b/collectors/0/procstats.py @@ -142,14 +142,17 @@ def cpus_csets(cpuset_path): def main(): """procstats main loop""" - - f_uptime = open("/proc/uptime", "r") - f_meminfo = open("/proc/meminfo", "r") - f_vmstat = open("/proc/vmstat", "r") - f_stat = open("/proc/stat", "r") - f_loadavg = open("/proc/loadavg", "r") - f_entropy_avail = open("/proc/sys/kernel/random/entropy_avail", "r") - f_interrupts = open("/proc/interrupts", "r") + try: + f_uptime = open("/proc/uptime", "r") + f_meminfo = open("/proc/meminfo", "r") + f_vmstat = open("/proc/vmstat", "r") + f_stat = open("/proc/stat", "r") + f_loadavg = open("/proc/loadavg", "r") + f_entropy_avail = open("/proc/sys/kernel/random/entropy_avail", "r") + f_interrupts = open("/proc/interrupts", "r") + except FileNotFoundError as exc: + utils.err('FileNotFoundError: %s' % (sys.exc_info()[1])) + sys.exit(1) f_scaling = "/sys/devices/system/cpu/cpu%s/cpufreq/%s_freq" f_scaling_min = dict([]) diff --git a/tests.py b/tests.py index b84a7c14..87f323b1 100755 --- a/tests.py +++ b/tests.py @@ -158,7 +158,8 @@ def test_endtoend(self): "a": tcollector.Collector("mycollector", 5, "a.py"), # pylint:disable=no-member "b": tcollector.Collector("second", 3, "b.py"), # pylint:disable=no-member } - server = tcollector.StatusServer("127.0.0.1", 32025, collectors) # pylint:disable=no-member + reader = {} + server = tcollector.StatusServer("127.0.0.1", 32025, collectors, reader) # pylint:disable=no-member # runs in background until test suite exits :( but it works. thread = threading.Thread(target=server.serve_forever) thread.setDaemon(True)