Module: check_mk
Branch: master
Commit: 5409e4b3931e5606aceaeaefdbcd5841783d7dde
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=5409e4b3931e56…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Sun Feb 7 21:55:03 2016 +0100
#3170 FIX Fix spurious exception while creating the inventory directory for the first
time
---
.bugs/2410 | 7 +++++--
.werks/3170 | 9 +++++++++
ChangeLog | 1 +
modules/check_mk_base.py | 13 +++++++++++++
modules/inventory.py | 7 ++-----
5 files changed, 30 insertions(+), 7 deletions(-)
diff --git a/.bugs/2410 b/.bugs/2410
index e7306d3..196d580 100644
--- a/.bugs/2410
+++ b/.bugs/2410
@@ -1,9 +1,12 @@
Title: Check_MK HW/SW Inventory fails because var/check_mk/inventory exists
Component: inv
-State: open
+Class: bug
+State: done
Date: 2015-11-12 14:40:55
Targetversion: 1.2.8
-Class: bug
Goes away by itself. Reason seems: race condition. Several checks at the same
time create the directory.
+
+2016-02-07 21:54:28: changed state open -> done
+New atomar function ensure_directory() does this now.
diff --git a/.werks/3170 b/.werks/3170
new file mode 100644
index 0000000..3952326
--- /dev/null
+++ b/.werks/3170
@@ -0,0 +1,9 @@
+Title: Fix spurious exception while creating the inventory directory for the first time
+Level: 1
+Component: inv
+Compatible: compat
+Version: 1.2.7i4
+Date: 1454878471
+Class: fix
+
+
diff --git a/ChangeLog b/ChangeLog
index 233859b..ea88bf5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -397,6 +397,7 @@
* 2827 FIX: win_disks, win_video: now able to detect multiple instances
* 2828 FIX: win_disks: now able to handle disks with missing size or media type
information
* 2906 FIX: Fixed crash in views containing special chars in HW/SW-Inventory based
columns
+ * 3170 FIX: Fix spurious exception while creating the inventory directory for the
first time
1.2.7i3:
diff --git a/modules/check_mk_base.py b/modules/check_mk_base.py
index 4327f22..1964d75 100644
--- a/modules/check_mk_base.py
+++ b/modules/check_mk_base.py
@@ -2030,6 +2030,19 @@ def set_use_cachefile(state=True):
opt_use_cachefile = state
+# Creates the directory at path if it does not exist. If that path does exist
+# it is assumed that it is a directory. the file type is not being checked.
+# This function is atomar so that no exception can arise if two processes
+# at the same time try to create the directory. Only fails if the directory
+# is not present for any reason after this function call.
+def ensure_directory(path):
+ try:
+ os.makedirs(path)
+ except Exception, e:
+ if os.path.exists(path):
+ return
+ raise
+
#.
# .--Check helpers-------------------------------------------------------.
# | ____ _ _ _ _ |
diff --git a/modules/inventory.py b/modules/inventory.py
index d6ded22..33e5a95 100644
--- a/modules/inventory.py
+++ b/modules/inventory.py
@@ -148,11 +148,8 @@ def inv_cleanup_tree(tree):
def do_inv(hostnames):
-
- if not os.path.exists(inventory_output_dir):
- os.makedirs(inventory_output_dir)
- if not os.path.exists(inventory_archive_dir):
- os.makedirs(inventory_archive_dir)
+ ensure_directory(inventory_output_dir)
+ ensure_directory(inventory_archive_dir)
# No hosts specified: do all hosts and force caching
if hostnames == None: