add ignore class not found regexp from salt-formulas/reclass
diff --git a/reclass/config.py b/reclass/config.py
index f1a8c0c..5eff1a4 100644
--- a/reclass/config.py
+++ b/reclass/config.py
@@ -32,6 +32,9 @@
ret.add_option('-z', '--ignore-class-notfound', dest='ignore_class_notfound',
default=defaults.get('ignore_class_notfound', OPT_IGNORE_CLASS_NOTFOUND),
help='decision for not found classes [%default]')
+ ret.add_option('-x', '--ignore-class-notfound-regexp', dest='ignore_class_notfound_regexp',
+ default=defaults.get('ignore_class_notfound_regexp', OPT_IGNORE_CLASS_NOTFOUND_REGEXP),
+ help='regexp for not found classes [%default]')
return ret
diff --git a/reclass/core.py b/reclass/core.py
index 02c8da6..9da0ddb 100644
--- a/reclass/core.py
+++ b/reclass/core.py
@@ -13,6 +13,7 @@
import fnmatch
import shlex
import string
+import sys
import yaml
from reclass.settings import Settings
from reclass.output.yaml_outputter import ExplicitDumper
@@ -26,6 +27,8 @@
self._class_mappings = class_mappings
self._settings = settings
self._input_data = input_data
+ if self._settings.ignore_class_notfound:
+ self._cnf_r = re.compile('|'.join([x for x in self._settings.ignore_class_notfound_regexp]))
@staticmethod
def _get_timestamp():
@@ -101,7 +104,11 @@
class_entity = self._storage.get_class(klass, environment, self._settings)
except ClassNotFound as e:
if self._settings.ignore_class_notfound:
- continue
+ if self._cnf_r.match(klass):
+ if self._settings.ignore_class_notfound_warning:
+ # TODO, add logging handler
+ print >>sys.stderr, "[WARNING] Reclass class not found: '%s'. Skipped!" % klass
+ continue
e.nodename = nodename
e.uri = entity.uri
raise
diff --git a/reclass/defaults.py b/reclass/defaults.py
index 4c2c903..82f49b2 100644
--- a/reclass/defaults.py
+++ b/reclass/defaults.py
@@ -18,6 +18,8 @@
OPT_NO_REFS = False
OPT_OUTPUT = 'yaml'
OPT_IGNORE_CLASS_NOTFOUND = False
+OPT_IGNORE_CLASS_NOTFOUND_REGEXP = ['.*']
+OPT_IGNORE_CLASS_NOTFOUND_WARNING = True
OPT_ALLOW_SCALAR_OVER_DICT = False
OPT_ALLOW_SCALAR_OVER_LIST = False
diff --git a/reclass/settings.py b/reclass/settings.py
index 5db57da..987e707 100644
--- a/reclass/settings.py
+++ b/reclass/settings.py
@@ -20,6 +20,13 @@
self.reference_sentinels = options.get('reference_sentinels', REFERENCE_SENTINELS)
self.ignore_class_notfound = options.get('ignore_class_notfound', OPT_IGNORE_CLASS_NOTFOUND)
+ self.ignore_class_notfound_regexp = options.get('ignore_class_notfound_regexp', OPT_IGNORE_CLASS_NOTFOUND_REGEXP)
+ if isinstance(self.ignore_class_notfound_regexp, basestring):
+ self.ignore_class_notfound_regexp = [ self.ignore_class_notfound_regexp ]
+
+ self.ignore_class_notfound_warning = options.get('ignore_class_notfound_warning', OPT_IGNORE_CLASS_NOTFOUND_WARNING)
+
+
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)
@@ -38,7 +45,9 @@
and self.inventory_ignore_failed_node == other.inventory_ignore_failed_node \
and self.inventory_ignore_failed_render == other.inventory_ignore_failed_render \
and self.reference_sentinels == other.reference_sentinels \
- and self.ignore_class_notfound == other.ignore_class_notfound
+ and self.ignore_class_notfound == other.ignore_class_notfound \
+ and self.ignore_class_notfound_regexp == other.ignore_class_notfound_regexp \
+ and self.ignore_class_notfound_warning == other.ignore_class_notfound_warning
def __copy__(self):
cls = self.__class__
diff --git a/reclass/tests/test_core.py b/reclass/tests/test_core.py
index eb9a5b4..9225756 100644
--- a/reclass/tests/test_core.py
+++ b/reclass/tests/test_core.py
@@ -39,7 +39,18 @@
node = reclass.nodeinfo('class_notfound')
def test_ignore_class_notfound(self):
- reclass = self._core('01', opts={ 'ignore_class_notfound': True })
+ reclass = self._core('01', opts={ 'ignore_class_notfound': True, 'ignore_class_notfound_warning': False })
+ node = reclass.nodeinfo('class_notfound')
+ params = { 'node_test': 'class not found', '_reclass_': { 'environment': 'base', 'name': {'full': 'class_notfound', 'short': 'class_notfound' } } }
+ self.assertEqual(node['parameters'], params)
+
+ def test_raise_class_notfound_with_regexp(self):
+ reclass = self._core('01', opts={ 'ignore_class_notfound': True, 'ignore_class_notfound_warning': False, 'ignore_class_notfound_regexp': 'notmatched.*' })
+ with self.assertRaises(ClassNotFound):
+ node = reclass.nodeinfo('class_notfound')
+
+ def test_ignore_class_notfound_with_regexp(self):
+ reclass = self._core('01', opts={ 'ignore_class_notfound': True, 'ignore_class_notfound_warning': False, 'ignore_class_notfound_regexp': 'miss.*' })
node = reclass.nodeinfo('class_notfound')
params = { 'node_test': 'class not found', '_reclass_': { 'environment': 'base', 'name': {'full': 'class_notfound', 'short': 'class_notfound' } } }
self.assertEqual(node['parameters'], params)