saltstack/salt

View on GitHub
salt/cloud/clouds/saltify.py

Summary

Maintainability
F
5 days
Test Coverage

File saltify.py has 381 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# -*- coding: utf-8 -*-
'''
.. _saltify-module:

Saltify Module
Severity: Minor
Found in salt/cloud/clouds/saltify.py - About 5 hrs to fix

    Function create has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring.
    Open

    def create(vm_):
        '''
        if configuration parameter ``deploy`` is ``True``,
    
            Provision a single machine, adding its keys to the salt master
    Severity: Minor
    Found in salt/cloud/clouds/saltify.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 destroy has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
    Open

    def destroy(name, call=None):
        ''' Destroy a node.
    
        .. versionadded:: 2018.3.0
    
    
    Severity: Minor
    Found in salt/cloud/clouds/saltify.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 _verify has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
    Open

    def _verify(vm_):
        '''
        Verify credentials for an existing system
        '''
        log.info('Verifying credentials for %s', vm_['name'])
    Severity: Minor
    Found in salt/cloud/clouds/saltify.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 _build_required_items has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
    Open

    def _build_required_items(nodes):
        ret = {}
        for name, grains in nodes.items():
            if grains:
                private_ips = []
    Severity: Minor
    Found in salt/cloud/clouds/saltify.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

    Avoid deeply nested control flow statements.
    Open

                        if ip_.is_private:
                            private_ips.append(adrs)
                        else:
                            public_ips.append(adrs)
    
    
    Severity: Major
    Found in salt/cloud/clouds/saltify.py - About 45 mins to fix

      Avoid deeply nested control flow statements.
      Open

                          if sleep_time > 0.0:
                              log.info('delaying %d seconds for boot', sleep_time)
                              time.sleep(sleep_time)
              log.info('Provisioning existing machine %s', vm_['name'])
      Severity: Major
      Found in salt/cloud/clouds/saltify.py - About 45 mins to fix

        Avoid too many return statements within this function.
        Open

                    return __utils__['cloud.wait_for_passwd'](**kwargs) is True
        Severity: Major
        Found in salt/cloud/clouds/saltify.py - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

                          return False
          Severity: Major
          Found in salt/cloud/clouds/saltify.py - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

                    return True
            Severity: Major
            Found in salt/cloud/clouds/saltify.py - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                              return __utils__['cloud.wait_for_winrm'](**kwargs) is not None
              Severity: Major
              Found in salt/cloud/clouds/saltify.py - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                            return False
                Severity: Major
                Found in salt/cloud/clouds/saltify.py - About 30 mins to fix

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

                  def list_nodes_full(call=None):
                      '''
                      Lists complete information for all nodes.
                  
                      .. code-block:: bash
                  Severity: Minor
                  Found in salt/cloud/clouds/saltify.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

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

                  def _build_required_items(nodes):
                      ret = {}
                      for name, grains in nodes.items():
                          if grains:
                              private_ips = []
                  Severity: Major
                  Found in salt/cloud/clouds/saltify.py and 1 other location - About 1 day to fix
                  salt/cloud/clouds/vagrant.py on lines 98..122

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

                  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 list_nodes_full(call=None):
                      '''
                      Lists complete information for all nodes.
                  
                      .. code-block:: bash
                  Severity: Major
                  Found in salt/cloud/clouds/saltify.py and 1 other location - About 1 day to fix
                  salt/cloud/clouds/vagrant.py on lines 125..148

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

                  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 and ret[name]:
                              confile = ret[name]
                              ret = local.cmd(name, 'file.remove', [confile])
                              if ret and ret[name]:
                                  log.info('removed minion %s configuration file %s',
                  Severity: Major
                  Found in salt/cloud/clouds/saltify.py and 1 other location - About 2 hrs to fix
                  salt/cloud/clouds/saltify.py on lines 460..467

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

                  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 and ret[name]:
                              pki_dir = ret[name]
                              ret = local.cmd(name, 'file.remove', [pki_dir])
                              if ret and ret[name]:
                                  log.info(
                  Severity: Major
                  Found in salt/cloud/clouds/saltify.py and 1 other location - About 2 hrs to fix
                  salt/cloud/clouds/saltify.py on lines 453..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 67.

                  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