saltstack/salt

View on GitHub
salt/netapi/rest_tornado/saltnado.py

Summary

Maintainability
F
6 days
Test Coverage

File saltnado.py has 1277 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# encoding: utf-8
'''
A non-blocking REST API for Salt
================================

Severity: Major
Found in salt/netapi/rest_tornado/saltnado.py - About 3 days to fix

    Function _disbatch_local has a Cognitive Complexity of 48 (exceeds 5 allowed). Consider refactoring.
    Open

        def _disbatch_local(self, chunk):
            '''
            Dispatch local client commands
            '''
            # Generate jid and find all minions before triggering a job to subscribe all returns from minions
    Severity: Minor
    Found in salt/netapi/rest_tornado/saltnado.py - About 7 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 _disbatch_local. (23)
    Wontfix

        @tornado.gen.coroutine
        def _disbatch_local(self, chunk):
            '''
            Dispatch local client commands
            '''
    Severity: Minor
    Found in salt/netapi/rest_tornado/saltnado.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

    Function job_not_running has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
    Open

        def job_not_running(self, jid, tgt, tgt_type, minions, is_finished):
            '''
            Return a future which will complete once jid (passed in) is no longer
            running on tgt
            '''
    Severity: Minor
    Found in salt/netapi/rest_tornado/saltnado.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 disbatch has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

        def disbatch(self):
            '''
            Disbatch all lowstates to the appropriate clients
            '''
            ret = []
    Severity: Minor
    Found in salt/netapi/rest_tornado/saltnado.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 _handle_event_socket_recv has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

        def _handle_event_socket_recv(self, raw):
            '''
            Callback for events on the event sub socket
            '''
            mtag, data = self.event.unpack(raw, self.event.serial)
    Severity: Minor
    Found in salt/netapi/rest_tornado/saltnado.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 post has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

        def post(self):
            '''
            :ref:`Authenticate <rest_tornado-auth>` against Salt's eauth system
    
            .. http:post:: /login
    Severity: Minor
    Found in salt/netapi/rest_tornado/saltnado.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 prepare has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

        def prepare(self):
            '''
            Run before get/posts etc. Pre-flight checks:
                - verify that we can speak back to them (compatible accept header)
            '''
    Severity: Minor
    Found in salt/netapi/rest_tornado/saltnado.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

    Avoid too many return statements within this function.
    Open

                return
    Severity: Major
    Found in salt/netapi/rest_tornado/saltnado.py - About 30 mins to fix

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

          def post(self, tag_suffix=None):  # pylint: disable=W0221
              '''
              Fire an event in Salt with a custom event tag and data
      
              .. http:post:: /hook
      Severity: Minor
      Found in salt/netapi/rest_tornado/saltnado.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 post has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          def post(self):
              '''
              Start an execution command and immediately return the job id
      
              .. http:post:: /minions
      Severity: Minor
      Found in salt/netapi/rest_tornado/saltnado.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 'groups' in token and token['groups']:
                      user_groups = set(token['groups'])
                      eauth_groups = set([i.rstrip('%') for i in eauth.keys() if i.endswith('%')])
      
                      for group in user_groups & eauth_groups:
      Severity: Major
      Found in salt/netapi/rest_tornado/saltnado.py and 1 other location - About 5 hrs to fix
      salt/netapi/rest_cherrypy/app.py on lines 1908..1913

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

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

                  if future in self.timeout_map:
                      tornado.ioloop.IOLoop.current().remove_timeout(self.timeout_map[future])
                      del self.timeout_map[future]
      Severity: Major
      Found in salt/netapi/rest_tornado/saltnado.py and 1 other location - About 1 hr to fix
      salt/netapi/rest_tornado/saltnado.py on lines 396..398

      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

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

                      if future in self.timeout_map:
                          tornado.ioloop.IOLoop.current().remove_timeout(self.timeout_map[future])
                          del self.timeout_map[future]
      Severity: Major
      Found in salt/netapi/rest_tornado/saltnado.py and 1 other location - About 1 hr to fix
      salt/netapi/rest_tornado/saltnado.py on lines 312..314

      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 not (('token' in low)
                          or ('username' in low and 'password' in low and 'eauth' in low)):
      Severity: Minor
      Found in salt/netapi/rest_tornado/saltnado.py and 1 other location - About 30 mins to fix
      salt/client/api.py on lines 131..132

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

      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