saltstack/salt

View on GitHub
salt/modules/bcache.py

Summary

Maintainability
F
1 wk
Test Coverage

File bcache.py has 697 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# -*- coding: utf-8 -*-
'''
Module for managing BCache sets

BCache is a block-level caching mechanism similar to ZFS L2ARC/ZIL, dm-cache and fscache.
Severity: Major
Found in salt/modules/bcache.py - About 1 day to fix

    Function _sysfs_parse has a Cognitive Complexity of 64 (exceeds 5 allowed). Consider refactoring.
    Open

    def _sysfs_parse(path, base_attr=None, stats=False, config=False, internals=False, options=False):
        '''
        Helper function for parsing BCache's SysFS interface
        '''
        result = {}
    Severity: Minor
    Found in salt/modules/bcache.py - About 1 day 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 device has a Cognitive Complexity of 57 (exceeds 5 allowed). Consider refactoring.
    Open

    def device(dev, stats=False, config=False, internals=False, superblock=False):
        '''
        Check the state of a single bcache device
    
        CLI example:
    Severity: Minor
    Found in salt/modules/bcache.py - About 1 day 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 function _sysfs_parse. (37)
    Open

    def _sysfs_parse(path, base_attr=None, stats=False, config=False, internals=False, options=False):
        '''
        Helper function for parsing BCache's SysFS interface
        '''
        result = {}
    Severity: Minor
    Found in salt/modules/bcache.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 status has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
    Open

    def status(stats=False, config=False, internals=False, superblock=False, alldevs=False):
        '''
        Show the full status of the BCache system and optionally all it's involved devices
    
        CLI example:
    Severity: Minor
    Found in salt/modules/bcache.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 super_ has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
    Open

    def super_(dev):
        '''
        Read out BCache SuperBlock
    
        CLI example:
    Severity: Minor
    Found in salt/modules/bcache.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 cache_make has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
    Open

    def cache_make(dev, reserved=None, force=False, block_size=None, bucket_size=None, attach=True):
        '''
        Create BCache cache on a block device.
        If blkdiscard is available the entire device will be properly cleared in advance.
    
    
    Severity: Minor
    Found in salt/modules/bcache.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

    Cyclomatic complexity is too high in function device. (23)
    Open

    def device(dev, stats=False, config=False, internals=False, superblock=False):
        '''
        Check the state of a single bcache device
    
        CLI example:
    Severity: Minor
    Found in salt/modules/bcache.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 attach_ has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
    Open

    def attach_(dev=None):
        '''
        Attach a backing devices to a cache set
        If no dev is given, all backing devices will be attached.
    
    
    Severity: Minor
    Found in salt/modules/bcache.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

    Cyclomatic complexity is too high in function cache_make. (21)
    Open

    def cache_make(dev, reserved=None, force=False, block_size=None, bucket_size=None, attach=True):
        '''
        Create BCache cache on a block device.
        If blkdiscard is available the entire device will be properly cleared in advance.
    
    
    Severity: Minor
    Found in salt/modules/bcache.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 back_make has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

    def back_make(dev, cache_mode='writeback', force=False, attach=True, bucket_size=None):
        '''
        Create a backing device for attachment to a set.
        Because the block size must be the same, a cache set already needs to exist.
    
    
    Severity: Minor
    Found in salt/modules/bcache.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 config_ has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

    def config_(dev=None, **kwargs):
        '''
        Show or update config of a bcache device.
    
        If no device is given, operate on the cache set itself.
    Severity: Minor
    Found in salt/modules/bcache.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 detach has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

    def detach(dev=None):
        '''
        Detach a backing device(s) from a cache set
        If no dev is given, all backing devices will be attached.
    
    
    Severity: Minor
    Found in salt/modules/bcache.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 stop has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

    def stop(dev=None):
        '''
        Stop a bcache device
        If no device is given, all backing devices will be detached from the cache, which will subsequently be stopped.
    
    
    Severity: Minor
    Found in salt/modules/bcache.py - About 55 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 deeply nested control flow statements.
    Open

                        if mkey not in interres:
                            interres[mkey] = {}
                        interres[mkey][skey] = interres.pop(key)
    Severity: Major
    Found in salt/modules/bcache.py - About 45 mins to fix

      Avoid too many return statements within this function.
      Open

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

        Avoid too many return statements within this function.
        Open

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

          Avoid too many return statements within this function.
          Open

              return _wait(lambda: uuid(dev) == cache,
          Severity: Major
          Found in salt/modules/bcache.py - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

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

              Avoid too many return statements within this function.
              Open

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

                Avoid too many return statements within this function.
                Open

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

                  Avoid too many return statements within this function.
                  Open

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

                    Avoid too many return statements within this function.
                    Open

                            return _wait(lambda: uuid() is False, 'error', 'Cache did not stop', 300)
                    Severity: Major
                    Found in salt/modules/bcache.py - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

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

                        Avoid too many return statements within this function.
                        Open

                                return attach_(dev)
                        Severity: Major
                        Found in salt/modules/bcache.py - About 30 mins to fix

                          Avoid too many return statements within this function.
                          Open

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

                            Avoid too many return statements within this function.
                            Open

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

                              Avoid too many return statements within this function.
                              Open

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

                                Avoid too many return statements within this function.
                                Open

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

                                  Avoid too many return statements within this function.
                                  Open

                                          return _alltrue(attach_())
                                  Severity: Major
                                  Found in salt/modules/bcache.py - About 30 mins to fix

                                    Avoid too many return statements within this function.
                                    Open

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

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

                                      def _wipe(dev):
                                          '''
                                          REALLY DESTRUCTIVE STUFF RIGHT AHEAD
                                          '''
                                          endres = 0
                                      Severity: Minor
                                      Found in salt/modules/bcache.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 dev is None:
                                              res = {}
                                              for dev, data in status(alldevs=True).items():
                                                  if 'cache' in data:
                                                      res[dev] = detach(dev)
                                      Severity: Major
                                      Found in salt/modules/bcache.py and 1 other location - About 2 hrs to fix
                                      salt/modules/bcache.py on lines 102..108

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

                                      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 dev is None:
                                              res = {}
                                              for dev, data in status(alldevs=True).items():
                                                  if 'cache' in data:
                                                      res[dev] = attach_(dev)
                                      Severity: Major
                                      Found in salt/modules/bcache.py and 1 other location - About 2 hrs to fix
                                      salt/modules/bcache.py on lines 144..150

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

                                      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 key.startswith(('btree', 'writeback')):
                                                          mkey, skey = re.split(r'_', key, maxsplit=1)
                                                          if mkey not in interres:
                                                              interres[mkey] = {}
                                                          interres[mkey][skey] = interres.pop(key)
                                      Severity: Major
                                      Found in salt/modules/bcache.py and 1 other location - About 2 hrs to fix
                                      salt/modules/bcache.py on lines 550..554

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

                                      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 key.startswith('writeback'):
                                                      mkey, skey = re.split(r'_', key, maxsplit=1)
                                                      if mkey not in configres:
                                                          configres[mkey] = {}
                                                      configres[mkey][skey] = configres.pop(key)
                                      Severity: Major
                                      Found in salt/modules/bcache.py and 1 other location - About 2 hrs to fix
                                      salt/modules/bcache.py on lines 539..543

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

                                      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