saltstack/salt

View on GitHub
salt/utils/master.py

Summary

Maintainability
F
5 days
Test Coverage

File master.py has 648 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# -*- coding: utf-8 -*-
'''
    salt.utils.master
    -----------------

Severity: Major
Found in salt/utils/master.py - About 1 day to fix

    Function run has a Cognitive Complexity of 38 (exceeds 5 allowed). Consider refactoring.
    Open

        def run(self):
            '''
            Main loop of the ConCache, starts updates in intervals and
            answers requests from the MWorkers
            '''
    Severity: Minor
    Found in salt/utils/master.py - About 5 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function clear_cached_minion_data has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring.
    Open

        def clear_cached_minion_data(self,
                                     clear_pillar=False,
                                     clear_grains=False,
                                     clear_mine=False,
                                     clear_mine_func=None):
    Severity: Minor
    Found in salt/utils/master.py - About 4 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Cyclomatic complexity is too high in method clear_cached_minion_data. (25)
    Open

        def clear_cached_minion_data(self,
                                     clear_pillar=False,
                                     clear_grains=False,
                                     clear_mine=False,
                                     clear_mine_func=None):
    Severity: Minor
    Found in salt/utils/master.py by radon

    Cyclomatic Complexity

    Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

    Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

    Construct Effect on CC Reasoning
    if +1 An if statement is a single decision.
    elif +1 The elif statement adds another decision.
    else +0 The else statement does not cause a new decision. The decision is at the if.
    for +1 There is a decision at the start of the loop.
    while +1 There is a decision at the while statement.
    except +1 Each except branch adds a new conditional path of execution.
    finally +0 The finally block is unconditionally executed.
    with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
    assert +1 The assert statement internally roughly equals a conditional statement.
    Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
    Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

    Source: http://radon.readthedocs.org/en/latest/intro.html

    Consider simplifying this complex logical expression.
    Open

                    if ((clear_pillar and clear_grains) or
                        (clear_pillar and not minion_grains) or
                        (clear_grains and not minion_pillar)):
                        # Not saving pillar or grains, so just delete the cache file
                        self.cache.flush(bank, 'data')
    Severity: Critical
    Found in salt/utils/master.py - About 1 hr to fix

      Function _get_cached_minion_data has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

          def _get_cached_minion_data(self, *minion_ids):
              # Return two separate dicts of cached grains and pillar data of the
              # minions
              grains = dict([(minion_id, {}) for minion_id in minion_ids])
              pillars = grains.copy()
      Severity: Minor
      Found in salt/utils/master.py - About 1 hr to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Function run has 27 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def run(self):
              '''
              Main loop of the ConCache, starts updates in intervals and
              answers requests from the MWorkers
              '''
      Severity: Minor
      Found in salt/utils/master.py - About 1 hr to fix

        Function _get_cached_mine_data has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

            def _get_cached_mine_data(self, *minion_ids):
                # Return one dict with the cached mine data of the targeted minions
                mine_data = dict([(minion_id, {}) for minion_id in minion_ids])
                if (not self.opts.get('minion_data_cache', False)
                        and not self.opts.get('enforce_mine_cache', False)):
        Severity: Minor
        Found in salt/utils/master.py - About 45 mins to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Function is_pid_healthy has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

        def is_pid_healthy(pid):
            '''
            This is a health check that will confirm the PID is running
            and executed by salt.
        
        
        Severity: Minor
        Found in salt/utils/master.py - About 35 mins to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Avoid too many return statements within this function.
        Open

                return False
        Severity: Major
        Found in salt/utils/master.py - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

                      return b'salt' in fp_.read()
          Severity: Major
          Found in salt/utils/master.py - About 30 mins to fix

            Function _get_minion_grains has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                def _get_minion_grains(self, *minion_ids, **kwargs):
                    # Get the minion grains either from cache or from a direct query
                    # on the minion. By default try to use cached grains first, then
                    # fall back to querying the minion directly.
                    ret = {}
            Severity: Minor
            Found in salt/utils/master.py - About 25 mins to fix

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            Function get_running_jobs has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

            def get_running_jobs(opts):
                '''
                Return the running jobs on the master
                '''
            
            
            Severity: Minor
            Found in salt/utils/master.py - About 25 mins to fix

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            Function get_master_key has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

            def get_master_key(key_user, opts, skip_perm_errors=False):
                if key_user == 'root':
                    if opts.get('user', 'root') != 'root':
                        key_user = opts.get('user', 'root')
                if key_user.startswith('sudo_'):
            Severity: Minor
            Found in salt/utils/master.py - About 25 mins to fix

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            Function _get_minion_pillar has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                def _get_minion_pillar(self, *minion_ids, **kwargs):
                    # Get the minion pillar either from cache or from a direct query
                    # on the minion. By default try use the cached pillar first, then
                    # fall back to rendering pillar on demand with the supplied grains.
                    ret = {}
            Severity: Minor
            Found in salt/utils/master.py - About 25 mins to fix

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            Identical blocks of code found in 4 locations. Consider refactoring.
            Open

                        ret = {key: value for key, value in [(minion_id, {}) for minion_id in minion_ids] + list(six.iteritems(cret)) + list(six.iteritems(lret))}
            Severity: Major
            Found in salt/utils/master.py and 3 other locations - About 2 hrs to fix
            salt/utils/master.py on lines 285..285
            salt/utils/master.py on lines 310..310
            salt/utils/master.py on lines 317..317

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 61.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Identical blocks of code found in 4 locations. Consider refactoring.
            Open

                        ret = {key: value for key, value in [(minion_id, {}) for minion_id in minion_ids] + list(six.iteritems(cret)) + list(six.iteritems(lret))}
            Severity: Major
            Found in salt/utils/master.py and 3 other locations - About 2 hrs to fix
            salt/utils/master.py on lines 292..292
            salt/utils/master.py on lines 310..310
            salt/utils/master.py on lines 317..317

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 61.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Identical blocks of code found in 4 locations. Consider refactoring.
            Open

                        ret = {key: value for key, value in [(minion_id, {}) for minion_id in minion_ids] + list(six.iteritems(cret)) + list(six.iteritems(lret))}
            Severity: Major
            Found in salt/utils/master.py and 3 other locations - About 2 hrs to fix
            salt/utils/master.py on lines 285..285
            salt/utils/master.py on lines 292..292
            salt/utils/master.py on lines 317..317

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 61.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Identical blocks of code found in 4 locations. Consider refactoring.
            Open

                        ret = {key: value for key, value in [(minion_id, {}) for minion_id in minion_ids] + list(six.iteritems(cret)) + list(six.iteritems(lret))}
            Severity: Major
            Found in salt/utils/master.py and 3 other locations - About 2 hrs to fix
            salt/utils/master.py on lines 285..285
            salt/utils/master.py on lines 292..292
            salt/utils/master.py on lines 310..310

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 61.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 6 locations. Consider refactoring.
            Open

                def __setstate__(self, state):
                    self._is_child = True
                    self.__init__(
                        state['opts'],
                        log_queue=state['log_queue'],
            Severity: Major
            Found in salt/utils/master.py and 5 other locations - About 1 hr to fix
            salt/master.py on lines 164..169
            salt/master.py on lines 802..807
            salt/utils/event.py on lines 1099..1104
            salt/utils/event.py on lines 1230..1235
            salt/utils/master.py on lines 592..597

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 48.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 6 locations. Consider refactoring.
            Open

                def __setstate__(self, state):
                    self._is_child = True
                    self.__init__(
                        state['opts'],
                        log_queue=state['log_queue'],
            Severity: Major
            Found in salt/utils/master.py and 5 other locations - About 1 hr to fix
            salt/master.py on lines 164..169
            salt/master.py on lines 802..807
            salt/utils/event.py on lines 1099..1104
            salt/utils/event.py on lines 1230..1235
            salt/utils/master.py on lines 529..534

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 48.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

                        if self.grains_fallback and missed_minions:
                            cret = dict([(minion_id, mcache) for (minion_id, mcache) in six.iteritems(cached_grains) if mcache])
            Severity: Minor
            Found in salt/utils/master.py and 1 other location - About 40 mins to fix
            salt/utils/master.py on lines 315..316

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 42.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

                        if self.pillar_fallback and missed_minions:
                            cret = dict([(minion_id, mcache) for (minion_id, mcache) in six.iteritems(cached_pillar) if mcache])
            Severity: Minor
            Found in salt/utils/master.py and 1 other location - About 40 mins to fix
            salt/utils/master.py on lines 290..291

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 42.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            There are no issues that match your filters.

            Category
            Status