Add type deprecation support.

This commit is contained in:
Darko Poljak 2019-05-20 18:50:25 +02:00
commit 4949af894e
6 changed files with 58 additions and 0 deletions

View file

@ -758,8 +758,19 @@ class Config(object):
("The requirements of the following objects could not be "
"resolved:\n%s") % ("\n".join(info_string)))
def _handle_deprecation(self, cdist_object):
cdist_type = cdist_object.cdist_type
deprecated = cdist_type.deprecated
if deprecated is not None:
if deprecated:
self.log.warning("Type %s is deprecated: %s", cdist_type.name,
deprecated)
else:
self.log.warning("Type %s is deprecated.", cdist_type.name)
def object_prepare(self, cdist_object, transfer_type_explorers=True):
"""Prepare object: Run type explorer + manifest"""
self._handle_deprecation(cdist_object)
self.log.verbose("Preparing object {}".format(cdist_object.name))
self.log.verbose(
"Running manifest and explorers for " + cdist_object.name)

View file

@ -133,6 +133,17 @@ class CdistType(object):
cannot run in parallel."""
return os.path.isfile(os.path.join(self.absolute_path, "nonparallel"))
@property
def deprecated(self):
"""Get type deprecation message. If message is None then type
is not deprecated."""
deprecated_path = os.path.join(self.absolute_path, "deprecated")
try:
with open(deprecated_path, 'r') as f:
return f.read()
except FileNotFoundError:
return None
@property
def explorers(self):
"""Return a list of available explorers"""

View file

@ -123,6 +123,16 @@ class TypeTestCase(test.CdistTestCase):
cdist_type = core.CdistType(base_path, '__not_nonparallel')
self.assertFalse(cdist_type.is_nonparallel)
def test_deprecated(self):
base_path = fixtures
cdist_type = core.CdistType(base_path, '__deprecated')
self.assertIsNotNone(cdist_type.deprecated)
def test_not_deprecated(self):
base_path = fixtures
cdist_type = core.CdistType(base_path, '__not_deprecated')
self.assertIsNone(cdist_type.deprecated)
def test_install_is_install(self):
base_path = fixtures
cdist_type = core.CdistType(base_path, '__install')