saltstack/salt

View on GitHub
salt/states/grains.py

Summary

Maintainability
F
5 days
Test Coverage

File grains.py has 395 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# -*- coding: utf-8 -*-
'''
Manage grains on the minion
===========================

Severity: Minor
Found in salt/states/grains.py - About 5 hrs to fix

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

    def list_present(name, value, delimiter=DEFAULT_TARGET_DELIM):
        '''
        .. versionadded:: 2014.1.0
    
        Ensure the value is present in the list-type grain. Note: If the grain that is
    Severity: Minor
    Found in salt/states/grains.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

    Function list_absent has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
    Open

    def list_absent(name, value, delimiter=DEFAULT_TARGET_DELIM):
        '''
        Delete a value from a grain formed as a list.
    
        .. versionadded:: 2014.1.0
    Severity: Minor
    Found in salt/states/grains.py - About 3 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 absent has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
    Open

    def absent(name,
               destructive=False,
               delimiter=DEFAULT_TARGET_DELIM,
               force=False):
        '''
    Severity: Minor
    Found in salt/states/grains.py - About 3 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 append has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
    Open

    def append(name, value, convert=False,
               delimiter=DEFAULT_TARGET_DELIM):
        '''
        .. versionadded:: 2014.7.0
    
    
    Severity: Minor
    Found in salt/states/grains.py - About 3 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

    Avoid deeply nested control flow statements.
    Open

                        if 'deleted' not in ret['changes'].keys():
                            ret['changes'] = {'deleted': []}
                        ret['changes']['deleted'].append(val)
    Severity: Major
    Found in salt/states/grains.py - About 45 mins to fix

      Avoid deeply nested control flow statements.
      Open

                          if 'deleted' not in ret['changes'].keys():
                              ret['changes'] = {'deleted': []}
                          ret['changes']['deleted'].append(val)
      Severity: Major
      Found in salt/states/grains.py - About 45 mins to fix

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

        def present(name, value, delimiter=DEFAULT_TARGET_DELIM, force=False):
            '''
            Ensure that a grain is set
        
            .. versionchanged:: v2015.8.2
        Severity: Minor
        Found in salt/states/grains.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 ret
        Severity: Major
        Found in salt/states/grains.py - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

                  return ret
          Severity: Major
          Found in salt/states/grains.py - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

                        return ret
            Severity: Major
            Found in salt/states/grains.py - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                          return ret
              Severity: Major
              Found in salt/states/grains.py - About 30 mins to fix

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

                def make_hashable(list_grain, result=None):
                    '''
                    Ensure that a list grain is hashable.
                
                    list_grain
                Severity: Minor
                Found in salt/states/grains.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

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

                            if destructive is True:
                                ret['comment'] = 'Grain {0} is set to be deleted'.format(name)
                                ret['changes'] = {'deleted': name}
                            else:
                                ret['comment'] = 'Value for grain {0} is set to be ' \
                Severity: Major
                Found in salt/states/grains.py and 1 other location - About 3 hrs to fix
                salt/states/grains.py on lines 400..406

                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 77.

                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 ret['result']:
                            if destructive is True:
                                ret['comment'] = 'Grain {0} was deleted'.format(name)
                                ret['changes'] = {'deleted': name}
                            else:
                Severity: Major
                Found in salt/states/grains.py and 1 other location - About 3 hrs to fix
                salt/states/grains.py on lines 388..394

                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 77.

                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 3 locations. Consider refactoring.
                Open

                            if __opts__['test']:
                                ret['result'] = None
                                ret['comment'] = 'Value {1} in grain {0} is set to ' \
                                                 'be added'.format(name, value)
                                ret['changes'] = {'added': value}
                Severity: Major
                Found in salt/states/grains.py and 2 other locations - About 1 hr to fix
                salt/states/grains.py on lines 219..223
                salt/states/grains.py on lines 470..476

                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 57.

                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 3 locations. Consider refactoring.
                Open

                        if __opts__['test']:
                            ret['result'] = None
                            ret['comment'] = 'Value {1} is set to be appended to grain {0}'.format(name, value)
                            ret['changes'] = {'new': grain}
                            return ret
                Severity: Major
                Found in salt/states/grains.py and 2 other locations - About 1 hr to fix
                salt/states/grains.py on lines 459..464
                salt/states/grains.py on lines 470..476

                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 57.

                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 3 locations. Consider refactoring.
                Open

                                if __opts__['test']:
                                    ret['result'] = None
                                    ret['comment'] = 'Grain {0} is set to be converted ' \
                                                     'to list and value {1} will be ' \
                                                     'added'.format(name, value)
                Severity: Major
                Found in salt/states/grains.py and 2 other locations - About 1 hr to fix
                salt/states/grains.py on lines 219..223
                salt/states/grains.py on lines 459..464

                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 57.

                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 __opts__['test']:
                        ret['result'] = None
                        ret['comment'] = 'Grain {0} is set to be added'.format(name)
                        ret['changes'] = {'new': grain}
                        return ret
                Severity: Major
                Found in salt/states/grains.py and 1 other location - About 1 hr to fix
                salt/states/file.py on lines 1869..1873

                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 56.

                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 destructive is True:
                                ret['comment'] = 'Grain {0} is set to be deleted'.format(name)
                                ret['changes'] = {'deleted': name}
                Severity: Minor
                Found in salt/states/grains.py and 1 other location - About 40 mins to fix
                salt/states/grains.py on lines 380..383

                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 ret['result']:
                            if destructive is True:
                                ret['comment'] = 'Grain {0} was deleted'.format(name)
                                ret['changes'] = {'deleted': name}
                Severity: Minor
                Found in salt/states/grains.py and 1 other location - About 40 mins to fix
                salt/states/grains.py on lines 372..374

                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