Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new deprecation functionality #214

Merged
merged 5 commits into from
Dec 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions saltlint/linter/rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from saltlint.utils import get_rule_skips_from_line, get_file_type
from saltlint.linter.match import Match
from saltlint.utils import LANGUAGE_SLS


class Rule(object):
Expand Down Expand Up @@ -86,3 +87,32 @@ def matchfulltext(self, file, text):
matches.append(Match(line, section, file['path'], self, message))

return matches


class DeprecationRule(Rule):
id = None
state = None
deprecated_since = None

severity = 'HIGH'
languages = [LANGUAGE_SLS]
tags = ['deprecation']

@property
def shortdesc(self):
return "State '{}' is deprecated since SaltStack version '{}'".format(
self.state, self.deprecated_since
)

@property
def description(self):
return self.shortdesc

@property
def regex(self):
return re.compile(
r"^\s{2}" + self.state.replace(".", r"\.") + "(?=:|$)"
)

def match(self, file, line):
return self.regex.search(line)
4 changes: 2 additions & 2 deletions saltlint/rules/CmdWaitRecommendRule.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
# Copyright (c) 2020 Warpnet B.V.

import re
from saltlint.linter.rule import Rule
from saltlint.linter.rule import DeprecationRule
from saltlint.utils import LANGUAGE_SLS


class CmdWaitRecommendRule(Rule):
class CmdWaitRecommendRule(DeprecationRule):
id = '213'
shortdesc = 'SaltStack recommends using cmd.run together with onchanges, rather than cmd.wait'
description = 'SaltStack recommends using cmd.run together with onchanges, rather than cmd.wait'
Expand Down
11 changes: 11 additions & 0 deletions saltlint/rules/StateDeprecationDockerAbsent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2020 Warpnet B.V.

from saltlint.linter.rule import DeprecationRule


class StateDeprecationDockerAbsent(DeprecationRule):
id = '906'
state = 'docker.absent'
deprecated_since = '2017.7.0'
version_added = 'develop'
11 changes: 11 additions & 0 deletions saltlint/rules/StateDeprecationDockerImageAbsent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2020 Warpnet B.V.

from saltlint.linter.rule import DeprecationRule


class StateDeprecationDockerImageAbsent(DeprecationRule):
id = '907'
state = 'docker.image_absent'
deprecated_since = '2017.7.0'
version_added = 'develop'
11 changes: 11 additions & 0 deletions saltlint/rules/StateDeprecationDockerImagePresent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2020 Warpnet B.V.

from saltlint.linter.rule import DeprecationRule


class StateDeprecationDockerImagePresent(DeprecationRule):
id = '908'
state = 'docker.image_present'
deprecated_since = '2017.7.0'
version_added = 'develop'
11 changes: 11 additions & 0 deletions saltlint/rules/StateDeprecationDockerModWatch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2020 Warpnet B.V.

from saltlint.linter.rule import DeprecationRule


class StateDeprecationDockerModWatch(DeprecationRule):
id = '909'
state = 'docker.mod_watch'
deprecated_since = '2017.7.0'
version_added = 'develop'
11 changes: 11 additions & 0 deletions saltlint/rules/StateDeprecationDockerNetworkAbsent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2020 Warpnet B.V.

from saltlint.linter.rule import DeprecationRule


class StateDeprecationDockerNetworkAbsent(DeprecationRule):
id = '910'
state = 'docker.network_absent'
deprecated_since = '2017.7.0'
version_added = 'develop'
11 changes: 11 additions & 0 deletions saltlint/rules/StateDeprecationDockerNetworkPresent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2020 Warpnet B.V.

from saltlint.linter.rule import DeprecationRule


class StateDeprecationDockerNetworkPresent(DeprecationRule):
id = '911'
state = 'docker.network_present'
deprecated_since = '2017.7.0'
version_added = 'develop'
11 changes: 11 additions & 0 deletions saltlint/rules/StateDeprecationDockerRunning.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2020 Warpnet B.V.

from saltlint.linter.rule import DeprecationRule


class StateDeprecationDockerRunning(DeprecationRule):
id = '912'
state = 'docker.running'
deprecated_since = '2017.7.0'
version_added = 'develop'
11 changes: 11 additions & 0 deletions saltlint/rules/StateDeprecationDockerStopped.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2020 Warpnet B.V.

from saltlint.linter.rule import DeprecationRule


class StateDeprecationDockerStopped(DeprecationRule):
id = '913'
state = 'docker.stopped'
deprecated_since = '2017.7.0'
version_added = 'develop'
11 changes: 11 additions & 0 deletions saltlint/rules/StateDeprecationDockerVolumeAbsent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2020 Warpnet B.V.

from saltlint.linter.rule import DeprecationRule


class StateDeprecationDockerVolumeAbsent(DeprecationRule):
id = '914'
state = 'docker.volume_absent'
deprecated_since = '2017.7.0'
version_added = 'develop'
11 changes: 11 additions & 0 deletions saltlint/rules/StateDeprecationDockerVolumePresent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2020 Warpnet B.V.

from saltlint.linter.rule import DeprecationRule


class StateDeprecationDockerVolumePresent(DeprecationRule):
id = '915'
state = 'docker.volume_present'
deprecated_since = '2017.7.0'
version_added = 'develop'
11 changes: 11 additions & 0 deletions saltlint/rules/StateDeprecationElasticsearchIndexRule.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2020 Warpnet B.V.

from saltlint.linter.rule import DeprecationRule


class StateDeprecationElasticsearchIndexRule(DeprecationRule):
id = '902'
state = 'elasticsearch_index.absent'
deprecated_since = '2017.7.0'
version_added = 'develop'
11 changes: 11 additions & 0 deletions saltlint/rules/StateDeprecationVirtRevertedRule.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2020 Warpnet B.V.

from saltlint.linter.rule import DeprecationRule


class StateDeprecationVirtRevertedRule(DeprecationRule):
id = '903'
state = 'virt.reverted'
deprecated_since = '2016.3.0'
version_added = 'develop'
11 changes: 11 additions & 0 deletions saltlint/rules/StateDeprecationVirtSavedRule.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2020 Warpnet B.V.

from saltlint.linter.rule import DeprecationRule


class StateDeprecationVirtSavedRule(DeprecationRule):
id = '904'
state = 'virt.saved'
deprecated_since = '2016.3.0'
version_added = 'develop'
11 changes: 11 additions & 0 deletions saltlint/rules/StateDeprecationVirtUnpoweredRule.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2020 Warpnet B.V.

from saltlint.linter.rule import DeprecationRule


class StateDeprecationVirtUnpoweredRule(DeprecationRule):
id = '905'
state = 'virt.unpowered'
deprecated_since = '2016.3.0'
version_added = 'develop'
43 changes: 43 additions & 0 deletions tests/unit/TestDeprecationRule.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2020 Warpnet B.V.

import unittest

from saltlint.linter.collection import RulesCollection
from saltlint.rules.StateDeprecationDockerAbsent import StateDeprecationDockerAbsent
from tests import RunFromText


GOOD_STATES_LINE = '''
example:
docker_container.absent:
- name: example

example:
docker_container.absent
'''

BAD_STATES_LINE = '''
example:
docker.absent:
- name: example

example:
docker.absent
'''

class TestFileModeLeadingZeroRule(unittest.TestCase):
collection = RulesCollection()

def setUp(self):
self.collection.register(StateDeprecationDockerAbsent())

def test_statement_positive(self):
runner = RunFromText(self.collection)
results = runner.run_state(GOOD_STATES_LINE)
self.assertEqual(0, len(results))

def test_statement_negative(self):
runner = RunFromText(self.collection)
results = runner.run_state(BAD_STATES_LINE)
self.assertEqual(2, len(results))