Module: check_mk
Branch: master
Commit: c74df2583367dd4fd9dcb271c1459a701f9b03df
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=c74df2583367dd…
Author: Andreas Boesl <ab(a)mathias-kettner.de>
Date: Thu Dec 14 14:23:19 2017 +0100
5255 FIX Autodiscovery with Automatic Activate changes: fixed race condition when trying
to delete state file
Change-Id: I644c630b8f30489cab242d9628583c6accfa106c
---
.werks/5255 | 10 ++++++++++
cmk_base/discovery.py | 15 ++++++++++++---
2 files changed, 22 insertions(+), 3 deletions(-)
diff --git a/.werks/5255 b/.werks/5255
new file mode 100644
index 0000000..613de91
--- /dev/null
+++ b/.werks/5255
@@ -0,0 +1,10 @@
+Title: Autodiscovery with Automatic Activate changes: fixed race condition when trying to
delete state file
+Level: 1
+Component: checks
+Compatible: compat
+Edition: cre
+Version: 1.5.0i2
+Date: 1513257721
+Class: fix
+
+
diff --git a/cmk_base/discovery.py b/cmk_base/discovery.py
index 85c04b3..239a2f2 100644
--- a/cmk_base/discovery.py
+++ b/cmk_base/discovery.py
@@ -476,7 +476,10 @@ def _set_rediscovery_flag(hostname, need_rediscovery):
touch(discovery_filename)
else:
if os.path.exists(discovery_filename):
- os.remove(discovery_filename)
+ try:
+ os.remove(discovery_filename)
+ except OSError:
+ pass
def discover_marked_hosts():
@@ -540,7 +543,10 @@ def discover_marked_hosts():
host_flag_path = autodiscovery_dir + "/" + hostname
if hostname not in config.all_configured_hosts():
- os.remove(host_flag_path)
+ try:
+ os.remove(host_flag_path)
+ except OSError:
+ pass
console.verbose(" Skipped. Host does not exist in configuration.
Removing mark.\n")
continue
@@ -590,7 +596,10 @@ def discover_marked_hosts():
# delete the file even in error case, otherwise we might be causing the same
error
# every time the cron job runs
- os.remove(host_flag_path)
+ try:
+ os.remove(host_flag_path)
+ except OSError:
+ pass
else:
console.verbose(" skipped: %s\n" % why_not)