saltstack/salt

View on GitHub
salt/utils/napalm.py

Summary

Maintainability
D
2 days
Test Coverage

Function proxy_napalm_wrap has a Cognitive Complexity of 40 (exceeds 5 allowed). Consider refactoring.
Open

def proxy_napalm_wrap(func):
    '''
    This decorator is used to make the execution module functions
    available outside a proxy minion, or when running inside a proxy
    minion. If we are running in a proxy, retrieve the connection details
Severity: Minor
Found in salt/utils/napalm.py - About 6 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

File napalm.py has 397 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# -*- coding: utf-8 -*-
'''
Utils for the NAPALM modules and proxy.

.. seealso::
Severity: Minor
Found in salt/utils/napalm.py - About 5 hrs to fix

    Function call has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
    Open

    def call(napalm_device, method, *args, **kwargs):
        '''
        Calls arbitrary methods from the network driver instance.
        Please check the readthedocs_ page for the updated list of getters.
    
    
    Severity: Minor
    Found in salt/utils/napalm.py - About 2 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 loaded_ret has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

    def loaded_ret(ret, loaded, test, debug, compliance_report=False, opts=None):
        '''
        Return the final state output.
        ret
            The initial state output structure.
    Severity: Minor
    Found in salt/utils/napalm.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

    Consider simplifying this complex logical expression.
    Open

            if is_proxy(opts) and always_alive:
                # if it is running in a NAPALM Proxy and it's using the default
                # always alive behaviour, will get the cached copy of the network
                # device object which should preserve the connection.
                if force_reconnect:
    Severity: Major
    Found in salt/utils/napalm.py - About 40 mins to fix

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

      def get_device_opts(opts, salt_obj=None):
          '''
          Returns the options of the napalm device.
          :pram: opts
          :return: the network device opts
      Severity: Minor
      Found in salt/utils/napalm.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

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

      def virtual(opts, virtualname, filename):
          '''
          Returns the __virtual__.
          '''
          if ((HAS_NAPALM and NAPALM_MAJOR >= 2) or HAS_NAPALM_BASE) and (is_proxy(opts) or is_minion(opts)):
      Severity: Minor
      Found in salt/utils/napalm.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_device has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

      def get_device(opts, salt_obj=None):
          '''
          Initialise the connection with the network device through NAPALM.
          :param: opts
          :return: the network device object
      Severity: Minor
      Found in salt/utils/napalm.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 changes.get('diff'):
              ret['comment'] = '{comment_base}\n\nConfiguration diff:\n\n{diff}'.format(comment_base=ret['comment'],
                                                                                        diff=changes['diff'])
      Severity: Minor
      Found in salt/utils/napalm.py and 1 other location - About 50 mins to fix
      salt/utils/napalm.py on lines 525..528

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

      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 changes.get('loaded_config'):
              ret['comment'] = '{comment_base}\n\nLoaded config:\n\n{loaded_cfg}'.format(
                  comment_base=ret['comment'],
                  loaded_cfg=changes['loaded_config'])
      Severity: Minor
      Found in salt/utils/napalm.py and 1 other location - About 50 mins to fix
      salt/utils/napalm.py on lines 522..524

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

      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

              base_err_msg = "Cannot connect to {hostname}{port} as {username}.".format(
                  hostname=network_device.get('HOSTNAME', '[unspecified hostname]'),
                  port=(':{port}'.format(port=network_device.get('OPTIONAL_ARGS', {}).get('port'))
                        if network_device.get('OPTIONAL_ARGS', {}).get('port') else ''),
      Severity: Minor
      Found in salt/utils/napalm.py and 1 other location - About 45 mins to fix
      salt/utils/napalm.py on lines 231..234

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

      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

                  comment = 'Cannot execute "{method}" on {device}{port} as {user}. Reason: {error}!'.format(
                      device=napalm_device.get('HOSTNAME', '[unspecified hostname]'),
                      port=(':{port}'.format(port=napalm_device.get('OPTIONAL_ARGS', {}).get('port'))
                            if napalm_device.get('OPTIONAL_ARGS', {}).get('port') else ''),
      Severity: Minor
      Found in salt/utils/napalm.py and 1 other location - About 45 mins to fix
      salt/utils/napalm.py on lines 344..347

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

      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