Add support for deprecated type parameters
This commit is contained in:
parent
8315677ad1
commit
55ba49efac
7 changed files with 67 additions and 1 deletions
|
@ -767,6 +767,11 @@ class Config(object):
|
|||
deprecated)
|
||||
else:
|
||||
self.log.warning("Type %s is deprecated.", cdist_type.name)
|
||||
for param in cdist_object.parameters:
|
||||
if param in cdist_type.deprecated_parameters:
|
||||
self.log.warning(("%s parameter of type %s is deprecated, "
|
||||
"see man page for details"),
|
||||
param, cdist_type.name)
|
||||
|
||||
def object_prepare(self, cdist_object, transfer_type_explorers=True):
|
||||
"""Prepare object: Run type explorer + manifest"""
|
||||
|
|
|
@ -69,6 +69,7 @@ class CdistType(object):
|
|||
self.__optional_multiple_parameters = None
|
||||
self.__boolean_parameters = None
|
||||
self.__parameter_defaults = None
|
||||
self.__deprecated_parameters = None
|
||||
|
||||
def __hash__(self):
|
||||
return hash(self.name)
|
||||
|
@ -275,3 +276,23 @@ class CdistType(object):
|
|||
finally:
|
||||
self.__parameter_defaults = defaults
|
||||
return self.__parameter_defaults
|
||||
|
||||
@property
|
||||
def deprecated_parameters(self):
|
||||
"""Return a list of deprecated parameters"""
|
||||
if not self.__deprecated_parameters:
|
||||
parameters = []
|
||||
try:
|
||||
with open(os.path.join(self.absolute_path,
|
||||
"parameter",
|
||||
"deprecated")) as fd:
|
||||
for line in fd:
|
||||
line = line.strip()
|
||||
if line:
|
||||
parameters.append(line)
|
||||
except EnvironmentError:
|
||||
# error ignored
|
||||
pass
|
||||
finally:
|
||||
self.__deprecated_parameters = parameters
|
||||
return self.__deprecated_parameters
|
||||
|
|
|
@ -200,3 +200,15 @@ class TypeTestCase(test.CdistTestCase):
|
|||
self.assertEqual(
|
||||
list(sorted(cdist_type.parameter_defaults.keys())),
|
||||
['bar', 'foo'])
|
||||
|
||||
def test_without_deprecated_parameters(self):
|
||||
base_path = fixtures
|
||||
cdist_type = core.CdistType(base_path,
|
||||
'__without_deprecated_parameters')
|
||||
self.assertEqual(cdist_type.deprecated_parameters, [])
|
||||
|
||||
def test_with_deprecated_parameters(self):
|
||||
base_path = fixtures
|
||||
cdist_type = core.CdistType(base_path, '__with_deprecated_parameters')
|
||||
self.assertEqual(cdist_type.deprecated_parameters,
|
||||
['eggs', 'spam'])
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
eggs
|
||||
spam
|
|
@ -0,0 +1,4 @@
|
|||
spam
|
||||
eggs
|
||||
sausage
|
||||
spam
|
|
@ -74,7 +74,7 @@ prevents to be run in more than one instance.
|
|||
Deprecated types
|
||||
-----------------
|
||||
If a type is flagged with 'deprecated' marker then it is considered deprecated.
|
||||
Upon it's usage cdist writes warning line. If 'deprecated' marker has content
|
||||
When it is used cdist writes warning line. If 'deprecated' marker has content
|
||||
then this content is printed as a deprecation messages, e.g.:
|
||||
|
||||
.. code-block:: sh
|
||||
|
@ -186,6 +186,28 @@ Example: (e.g. in cdist/conf/type/__nginx_vhost/manifest)
|
|||
fi
|
||||
|
||||
|
||||
Deprecated parameters
|
||||
---------------------
|
||||
To deprecate type parameters one can declare a newline separated file
|
||||
**parameter/deprecated** where each line contains deprecated parameter.
|
||||
When it is used cdist writes warning line, e.g.:
|
||||
|
||||
.. code-block:: sh
|
||||
|
||||
$ cat parameter/optional_multiple
|
||||
foo
|
||||
spam
|
||||
eggs
|
||||
$ cat parameter/deprecated
|
||||
spam
|
||||
eggs
|
||||
$ echo '__foo foo --foo foo --spam spam' | ./bin/cdist config -i - 185.203.112.26
|
||||
WARNING: 185.203.112.26: spam parameter of type __foo is deprecated, see man page for details
|
||||
$ echo '__foo foo --foo foo --eggs eggs --spam spam' | ./bin/cdist config -i - 185.203.112.26
|
||||
WARNING: 185.203.112.26: spam parameter of type __foo is deprecated, see man page for details
|
||||
WARNING: 185.203.112.26: eggs parameter of type __foo is deprecated, see man page for details
|
||||
|
||||
|
||||
Input from stdin
|
||||
----------------
|
||||
Every type can access what has been written on stdin when it has been called.
|
||||
|
|
Loading…
Reference in a new issue