saltstack/salt

View on GitHub
salt/modules/rh_service.py

Summary

Maintainability
F
3 days
Test Coverage

File rh_service.py has 463 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# -*- coding: utf-8 -*-
'''
Service support for RHEL-based systems, including support for both upstart and sysvinit

.. important::
Severity: Minor
Found in salt/modules/rh_service.py - About 7 hrs to fix

    Function __virtual__ has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
    Open

    def __virtual__():
        '''
        Only work on select distros which still use Red Hat's /usr/bin/service for
        management of either sysvinit or a hybrid sysvinit/upstart init system.
        '''
    Severity: Minor
    Found in salt/modules/rh_service.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 _chkconfig_is_enabled has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

    def _chkconfig_is_enabled(name, runlevel=None):
        '''
        Return ``True`` if the service is enabled according to chkconfig; otherwise
        return ``False``.  If ``runlevel`` is ``None``, then use the current
        runlevel.
    Severity: Minor
    Found in salt/modules/rh_service.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 status has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

    def status(name, sig=None):
        '''
        Return the status for a service.
        If the name contains globbing, a dict mapping service name to True/False
        values is returned.
    Severity: Minor
    Found in salt/modules/rh_service.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

    Avoid too many return statements within this function.
    Open

                    return (
    Severity: Major
    Found in salt/modules/rh_service.py - About 30 mins to fix

      Avoid too many return statements within this function.
      Open

              return __virtualname__
      Severity: Major
      Found in salt/modules/rh_service.py - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

                    return __virtualname__
        Severity: Major
        Found in salt/modules/rh_service.py - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

              return (False, 'Cannot load rh_service module: OS not in {0}'.format(enable))
          Severity: Major
          Found in salt/modules/rh_service.py - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

                            return (
            Severity: Major
            Found in salt/modules/rh_service.py - About 30 mins to fix

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

              def missing(name, limit=''):
                  '''
                  The inverse of service.available.
                  Return True if the named service is not available.  Use the ``limit`` param to
                  restrict results to services of that type.
              Severity: Minor
              Found in salt/modules/rh_service.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

              def _sysv_disable(name):
                  '''
                  Disable the named sysv service from starting at boot.  The service will be
                  disabled using chkconfig with default run-levels if the service is chkconfig
                  compatible; otherwise, the service will be disabled for the current
              Severity: Major
              Found in salt/modules/rh_service.py and 1 other location - About 2 hrs to fix
              salt/modules/rh_service.py on lines 207..216

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

              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

              def _sysv_enable(name):
                  '''
                  Enable the named sysv service to start at boot.  The service will be enabled
                  using chkconfig with default run-levels if the service is chkconfig
                  compatible.  If chkconfig is not available, then this will fail.
              Severity: Major
              Found in salt/modules/rh_service.py and 1 other location - About 2 hrs to fix
              salt/modules/rh_service.py on lines 219..229

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

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

              def stop(name):
                  '''
                  Stop the specified service
              
                  CLI Example:
              Severity: Major
              Found in salt/modules/rh_service.py and 3 other locations - About 2 hrs to fix
              salt/modules/rh_service.py on lines 410..424
              salt/modules/rh_service.py on lines 444..458
              salt/modules/rh_service.py on lines 461..475

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

              def start(name):
                  '''
                  Start the specified service
              
                  CLI Example:
              Severity: Major
              Found in salt/modules/rh_service.py and 3 other locations - About 2 hrs to fix
              salt/modules/rh_service.py on lines 427..441
              salt/modules/rh_service.py on lines 444..458
              salt/modules/rh_service.py on lines 461..475

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

              def restart(name):
                  '''
                  Restart the named service
              
                  CLI Example:
              Severity: Major
              Found in salt/modules/rh_service.py and 3 other locations - About 2 hrs to fix
              salt/modules/rh_service.py on lines 410..424
              salt/modules/rh_service.py on lines 427..441
              salt/modules/rh_service.py on lines 461..475

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

              def reload_(name):
                  '''
                  Reload the named service
              
                  CLI Example:
              Severity: Major
              Found in salt/modules/rh_service.py and 3 other locations - About 2 hrs to fix
              salt/modules/rh_service.py on lines 410..424
              salt/modules/rh_service.py on lines 427..441
              salt/modules/rh_service.py on lines 444..458

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

              def _runlevel():
                  '''
                  Return the current runlevel
                  '''
                  out = __salt__['cmd.run']('/sbin/runlevel')
              Severity: Major
              Found in salt/modules/rh_service.py and 1 other location - About 1 hr to fix
              salt/modules/debian_service.py on lines 60..73

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

              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