Disallow overlapping of nodes and classes URIs
Signed-off-by: martin f. krafft <madduck@madduck.net>
diff --git a/doc/source/changelog.rst b/doc/source/changelog.rst
index 4604c6a..3553051 100644
--- a/doc/source/changelog.rst
+++ b/doc/source/changelog.rst
@@ -5,6 +5,7 @@
========= ========== ========================================================
Version Date Changes
========= ========== ========================================================
+ * Classes and nodes URI must not overlap anymore
* Class names must not contain spaces
1.1 2013-08-28 Salt adapter: fix interface to include minion_id, filter
output accordingly; fixes master_tops
diff --git a/doc/source/operations.rst b/doc/source/operations.rst
index 75da3f1..c3439c5 100644
--- a/doc/source/operations.rst
+++ b/doc/source/operations.rst
@@ -10,8 +10,8 @@
(as suggested by the ``_fs`` postfix).
``yaml_fs`` works with two directories, one for node definitions, and another
-for class definitions. It is possible to use a single directory for both, but
-that could get messy and is therefore not recommended.
+for class definitions. The two directories must not be the same, nor can one
+be a parent of the other.
Files in those directories are YAML-files, specifying key-value pairs. The
following three keys are read by |reclass|:
diff --git a/reclass/config.py b/reclass/config.py
index 9243a46..e9aa9ba 100644
--- a/reclass/config.py
+++ b/reclass/config.py
@@ -185,6 +185,11 @@
ret = os.path.expanduser(ret)
return os.path.abspath(ret)
- return map(_path_mangler_inner, (nodes_uri, classes_uri))
+ n, c = map(_path_mangler_inner, (nodes_uri, classes_uri))
+ if n == c:
+ raise errors.DuplicateUriError(n, c)
+ common = os.path.commonprefix((n, c))
+ if common == n or common == c:
+ raise errors.UriOverlapError(n, c)
- return nodes_uri, classes_uri
+ return n, c
diff --git a/reclass/errors.py b/reclass/errors.py
index dbd6a78..8f097c6 100644
--- a/reclass/errors.py
+++ b/reclass/errors.py
@@ -39,6 +39,29 @@
super(InvocationError, self).__init__(msg, rc)
+class ConfigError(ReclassException):
+
+ def __init__(self, msg, rc=posix.EX_CONFIG):
+ super(ConfigError, self).__init__(msg, rc)
+
+
+class DuplicateUriError(ConfigError):
+
+ def __init__(self, nodes_uri, classes_uri):
+ msg = "The inventory URIs must not be the same for nodes and classes: "
+ msg += nodes_uri
+ super(DuplicateUriError, self).__init__(msg)
+
+
+class UriOverlapError(ConfigError):
+
+ def __init__(self, nodes_uri, classes_uri):
+ msg = "The URIs for the nodes and classes inventories must not " \
+ "overlap, but {0} and {1} do."
+ msg = msg.format(nodes_uri, classes_uri)
+ super(UriOverlapError, self).__init__(msg)
+
+
class NotFoundError(ReclassException):
def __init__(self, msg, rc=posix.EX_IOERR):