From 4949af894e917ac57fb5365c7ea482770bb1c3ba Mon Sep 17 00:00:00 2001 From: Darko Poljak Date: Mon, 20 May 2019 18:50:25 +0200 Subject: [PATCH] Add type deprecation support. --- cdist/config.py | 11 ++++++++ cdist/core/cdist_type.py | 11 ++++++++ cdist/test/cdist_type/__init__.py | 10 ++++++++ .../fixtures/__deprecated/deprecated | 0 docs/changelog | 1 + docs/src/cdist-type.rst | 25 +++++++++++++++++++ 6 files changed, 58 insertions(+) create mode 100644 cdist/test/cdist_type/fixtures/__deprecated/deprecated diff --git a/cdist/config.py b/cdist/config.py index 30117382..1a0ab4d5 100644 --- a/cdist/config.py +++ b/cdist/config.py @@ -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) diff --git a/cdist/core/cdist_type.py b/cdist/core/cdist_type.py index 99e40e70..7cabd72f 100644 --- a/cdist/core/cdist_type.py +++ b/cdist/core/cdist_type.py @@ -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""" diff --git a/cdist/test/cdist_type/__init__.py b/cdist/test/cdist_type/__init__.py index ca961170..ac84d874 100644 --- a/cdist/test/cdist_type/__init__.py +++ b/cdist/test/cdist_type/__init__.py @@ -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') diff --git a/cdist/test/cdist_type/fixtures/__deprecated/deprecated b/cdist/test/cdist_type/fixtures/__deprecated/deprecated new file mode 100644 index 00000000..e69de29b diff --git a/docs/changelog b/docs/changelog index acf462f2..ba092840 100644 --- a/docs/changelog +++ b/docs/changelog @@ -6,6 +6,7 @@ next: * Type __consul: Add version 1.5.0 (Nico Schottelius) * Type __consul_agent: Add alpine support (Nico Schottelius) * New helper script: cdist-new-type (Steven Armstrong, Darko Poljak) + * Core: Add support for deprecated type marker (Darko Poljak) 5.0.2: 2019-05-17 * Type __package_apk: Fix @repo handling in explorer (Nico Schottelius) diff --git a/docs/src/cdist-type.rst b/docs/src/cdist-type.rst index 880df819..dfad6fa0 100644 --- a/docs/src/cdist-type.rst +++ b/docs/src/cdist-type.rst @@ -71,6 +71,31 @@ when using -j option. Example of such a type is __package_dpkg type where dpkg i 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 +then this content is printed as a deprecation messages, e.g.: + +.. code-block:: sh + + $ ls -l deprecated + -rw-r--r-- 1 darko darko 71 May 20 18:30 deprecated + $ cat deprecated + This type is deprecated. It will be removed in the next minor release. + $ echo '__foo foo' | ./bin/cdist config -i - 185.203.112.26 + WARNING: 185.203.112.26: Type __foo is deprecated: This type is deprecated. It will be removed in the next minor release. + +If 'deprecated' marker has no content then general message is printed, e.g.: + +.. code-block:: sh + + $ ls -l deprecated + -rw-r--r-- 1 darko darko 0 May 20 18:36 deprecated + $ echo '__bar foo' | ./bin/cdist config -i - 185.203.112.26 + WARNING: 185.203.112.26: Type __bar is deprecated. + + How to write a new type ----------------------- A type consists of