add option to ignore missing classes
diff --git a/reclass/core.py b/reclass/core.py
index 9e9b714..fb8ee42 100644
--- a/reclass/core.py
+++ b/reclass/core.py
@@ -100,6 +100,8 @@
try:
class_entity = self._storage.get_class(klass, environment, self._settings)
except ClassNotFound as e:
+ if self._settings.ignore_class_not_found:
+ continue
e.nodename = nodename
e.uri = entity.uri
raise
diff --git a/reclass/settings.py b/reclass/settings.py
index d0332d0..f6168fd 100644
--- a/reclass/settings.py
+++ b/reclass/settings.py
@@ -17,6 +17,7 @@
self.inventory_ignore_failed_node = options.get('inventory_ignore_failed_node', reclass.defaults.INVENTORY_IGNORE_FAILED_NODE)
self.inventory_ignore_failed_render = options.get('inventory_ignore_failed_render', reclass.defaults.INVENTORY_IGNORE_FAILED_RENDER)
self.reference_sentinels = options.get('reference_sentinels', reclass.defaults.REFERENCE_SENTINELS)
+ self.ignore_class_not_found = options.get('ignore_class_not_found', reclass.defaults.IGNORE_CLASS_NOT_FOUND)
self.ref_parser = reclass.values.parser_funcs.get_ref_parser(self.escape_character, self.reference_sentinels, self.export_sentinels)
self.simple_ref_parser = reclass.values.parser_funcs.get_simple_ref_parser(self.escape_character, self.reference_sentinels, self.export_sentinels)
diff --git a/reclass/tests/__init__.py b/reclass/tests/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/reclass/tests/__init__.py
diff --git a/reclass/tests/data/01/classes/standard.yml b/reclass/tests/data/01/classes/standard.yml
new file mode 100644
index 0000000..13bce54
--- /dev/null
+++ b/reclass/tests/data/01/classes/standard.yml
@@ -0,0 +1,4 @@
+parameters:
+ int: 1
+ string: '1'
+ bool: True
diff --git a/reclass/tests/data/01/nodes/class_not_found.yml b/reclass/tests/data/01/nodes/class_not_found.yml
new file mode 100644
index 0000000..616a49b
--- /dev/null
+++ b/reclass/tests/data/01/nodes/class_not_found.yml
@@ -0,0 +1,5 @@
+classes:
+ - missing
+
+parameters:
+ node_test: class not found
diff --git a/reclass/tests/data/01/nodes/data_types.yml b/reclass/tests/data/01/nodes/data_types.yml
new file mode 100644
index 0000000..28ff151
--- /dev/null
+++ b/reclass/tests/data/01/nodes/data_types.yml
@@ -0,0 +1,2 @@
+classes:
+ - standard
diff --git a/reclass/tests/test_core.py b/reclass/tests/test_core.py
new file mode 100644
index 0000000..e0097b7
--- /dev/null
+++ b/reclass/tests/test_core.py
@@ -0,0 +1,49 @@
+#
+# -*- coding: utf-8 -*-
+#
+# This file is part of reclass (http://github.com/madduck/reclass)
+#
+
+import os
+
+from reclass import get_storage, get_path_mangler
+from reclass.core import Core
+from reclass.settings import Settings
+from reclass.errors import ClassNotFound
+
+import unittest
+try:
+ import unittest.mock as mock
+except ImportError:
+ import mock
+
+class TestCore(unittest.TestCase):
+
+ def _core(self, dataset, opts={}):
+ inventory_uri = os.path.dirname(os.path.abspath(__file__)) + '/data/' + dataset
+ path_mangler = get_path_mangler('yaml_fs')
+ nodes_uri, classes_uri = path_mangler(inventory_uri, 'nodes', 'classes')
+ storage = get_storage('yaml_fs', nodes_uri, classes_uri)
+ settings = Settings(opts)
+ return Core(storage, None, settings)
+
+ def test_type_conversion(self):
+ reclass = self._core('01')
+ node = reclass.nodeinfo('data_types')
+ params = { 'int': 1, 'bool': True, 'string': '1', '_reclass_': { 'environment': 'base', 'name': {'full': 'data_types', 'short': 'data_types' } } }
+ self.assertEqual(node['parameters'], params)
+
+ def test_raise_class_not_found(self):
+ reclass = self._core('01')
+ with self.assertRaises(ClassNotFound):
+ node = reclass.nodeinfo('class_not_found')
+
+ def test_ignore_class_not_found(self):
+ reclass = self._core('01', opts={ 'ignore_class_not_found': True })
+ node = reclass.nodeinfo('class_not_found')
+ params = { 'node_test': 'class not found', '_reclass_': { 'environment': 'base', 'name': {'full': 'class_not_found', 'short': 'class_not_found' } } }
+ self.assertEqual(node['parameters'], params)
+
+
+if __name__ == '__main__':
+ unittest.main()