saltstack/salt

View on GitHub
salt/states/azurearm_dns.py

Summary

Maintainability
F
1 wk
Test Coverage

Function record_set_present has a Cognitive Complexity of 87 (exceeds 5 allowed). Consider refactoring.
Open

def record_set_present(name, zone_name, resource_group, record_type, if_match=None, if_none_match=None,
                       etag=None, metadata=None, ttl=None, arecords=None, aaaa_records=None, mx_records=None,
                       ns_records=None, ptr_records=None, srv_records=None, txt_records=None, cname_record=None,
                       soa_record=None, caa_records=None, connection_auth=None, **kwargs):
    '''
Severity: Minor
Found in salt/states/azurearm_dns.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

File azurearm_dns.py has 554 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# -*- coding: utf-8 -*-
'''
Azure (ARM) DNS State Module

.. versionadded:: Fluorine
Severity: Major
Found in salt/states/azurearm_dns.py - About 1 day to fix

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

    def zone_present(name, resource_group, etag=None, if_match=None, if_none_match=None,
                     registration_virtual_networks=None, resolution_virtual_networks=None,
                     tags=None, zone_type='Public', connection_auth=None, **kwargs):
        '''
        .. versionadded:: Fluorine
    Severity: Minor
    Found in salt/states/azurearm_dns.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

    Cyclomatic complexity is too high in function record_set_present. (27)
    Open

    def record_set_present(name, zone_name, resource_group, record_type, if_match=None, if_none_match=None,
                           etag=None, metadata=None, ttl=None, arecords=None, aaaa_records=None, mx_records=None,
                           ns_records=None, ptr_records=None, srv_records=None, txt_records=None, cname_record=None,
                           soa_record=None, caa_records=None, connection_auth=None, **kwargs):
        '''
    Severity: Minor
    Found in salt/states/azurearm_dns.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

    Cyclomatic complexity is too high in function zone_present. (26)
    Open

    def zone_present(name, resource_group, etag=None, if_match=None, if_none_match=None,
                     registration_virtual_networks=None, resolution_virtual_networks=None,
                     tags=None, zone_type='Public', connection_auth=None, **kwargs):
        '''
        .. versionadded:: Fluorine
    Severity: Minor
    Found in salt/states/azurearm_dns.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

    Avoid deeply nested control flow statements.
    Open

                        if not isinstance(record, dict):
                            ret['comment'] = '{0} record information must be specified as a dictionary!'.format(record_str)
                            return ret
                        for k, v in record.items():
    Severity: Major
    Found in salt/states/azurearm_dns.py - About 45 mins to fix

      Avoid deeply nested control flow statements.
      Open

                          for k, v in record.items():
                              if v != rec_set[record_str].get(k):
                                  ret['changes'] = {'new': {record_str: record}}
                      elif record_str[-1] == 's':
      Severity: Major
      Found in salt/states/azurearm_dns.py - About 45 mins to fix

        Avoid deeply nested control flow statements.
        Open

                            for idx in six_range(0, len(local)):
                                for key in local[idx]:
                                    local_val = local[idx][key]
                                    remote_val = remote[idx].get(key)
                                    if isinstance(local_val, six.string_types):
        Severity: Major
        Found in salt/states/azurearm_dns.py - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                              if not isinstance(record, list):
                                  ret['comment'] = '{0} record information must be specified as a list of dictionaries!'.format(
                                      record_str
                                  )
                                  return ret
          Severity: Major
          Found in salt/states/azurearm_dns.py - About 45 mins to fix

            Avoid too many return statements within this function.
            Open

                return ret
            Severity: Major
            Found in salt/states/azurearm_dns.py - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                          return ret
              Severity: Major
              Found in salt/states/azurearm_dns.py - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                        return ret
                Severity: Major
                Found in salt/states/azurearm_dns.py - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                          return ret
                  Severity: Major
                  Found in salt/states/azurearm_dns.py - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                                return ret
                    Severity: Major
                    Found in salt/states/azurearm_dns.py - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

                              return ret
                      Severity: Major
                      Found in salt/states/azurearm_dns.py - About 30 mins to fix

                        Avoid too many return statements within this function.
                        Open

                            return ret
                        Severity: Major
                        Found in salt/states/azurearm_dns.py - About 30 mins to fix

                          Avoid too many return statements within this function.
                          Open

                              return ret
                          Severity: Major
                          Found in salt/states/azurearm_dns.py - About 30 mins to fix

                            Avoid too many return statements within this function.
                            Open

                                return ret
                            Severity: Major
                            Found in salt/states/azurearm_dns.py - About 30 mins to fix

                              Avoid too many return statements within this function.
                              Open

                                          return ret
                              Severity: Major
                              Found in salt/states/azurearm_dns.py - About 30 mins to fix

                                Avoid too many return statements within this function.
                                Open

                                        return ret
                                Severity: Major
                                Found in salt/states/azurearm_dns.py - About 30 mins to fix

                                  Similar blocks of code found in 9 locations. Consider refactoring.
                                  Open

                                  def zone_absent(name, resource_group, connection_auth=None):
                                      '''
                                      .. versionadded:: Fluorine
                                  
                                      Ensure a DNS zone does not exist in the resource group.
                                  Severity: Major
                                  Found in salt/states/azurearm_dns.py and 8 other locations - About 2 days to fix
                                  salt/states/azurearm_compute.py on lines 266..326
                                  salt/states/azurearm_network.py on lines 261..321
                                  salt/states/azurearm_network.py on lines 674..734
                                  salt/states/azurearm_network.py on lines 1481..1541
                                  salt/states/azurearm_network.py on lines 1730..1790
                                  salt/states/azurearm_network.py on lines 2050..2110
                                  salt/states/azurearm_network.py on lines 2254..2314
                                  salt/states/azurearm_resource.py on lines 756..816

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

                                  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

                                      rec_set = __salt__['azurearm_dns.record_set_create_or_update'](
                                  Severity: Major
                                  Found in salt/states/azurearm_dns.py and 3 other locations - About 2 hrs to fix
                                  salt/states/boto_lambda.py on lines 243..243
                                  salt/states/boto_lc.py on lines 263..263
                                  salt/states/virt.py on lines 454..454

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

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

                                          if not ret['changes']:
                                              ret['result'] = True
                                              ret['comment'] = 'DNS zone {0} is already present.'.format(name)
                                              return ret
                                  Severity: Major
                                  Found in salt/states/azurearm_dns.py and 14 other locations - About 55 mins to fix
                                  salt/states/azurearm_compute.py on lines 215..218
                                  salt/states/azurearm_dns.py on lines 557..560
                                  salt/states/azurearm_network.py on lines 211..214
                                  salt/states/azurearm_network.py on lines 418..421
                                  salt/states/azurearm_network.py on lines 628..631
                                  salt/states/azurearm_network.py on lines 987..990
                                  salt/states/azurearm_network.py on lines 1422..1425
                                  salt/states/azurearm_network.py on lines 1677..1680
                                  salt/states/azurearm_network.py on lines 1989..1992
                                  salt/states/azurearm_network.py on lines 2207..2210
                                  salt/states/azurearm_network.py on lines 2402..2405
                                  salt/states/azurearm_resource.py on lines 160..163
                                  salt/states/azurearm_resource.py on lines 487..490
                                  salt/states/azurearm_resource.py on lines 702..705

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

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

                                          if not ret['changes']:
                                              ret['result'] = True
                                              ret['comment'] = 'Record set {0} is already present.'.format(name)
                                              return ret
                                  Severity: Major
                                  Found in salt/states/azurearm_dns.py and 14 other locations - About 55 mins to fix
                                  salt/states/azurearm_compute.py on lines 215..218
                                  salt/states/azurearm_dns.py on lines 253..256
                                  salt/states/azurearm_network.py on lines 211..214
                                  salt/states/azurearm_network.py on lines 418..421
                                  salt/states/azurearm_network.py on lines 628..631
                                  salt/states/azurearm_network.py on lines 987..990
                                  salt/states/azurearm_network.py on lines 1422..1425
                                  salt/states/azurearm_network.py on lines 1677..1680
                                  salt/states/azurearm_network.py on lines 1989..1992
                                  salt/states/azurearm_network.py on lines 2207..2210
                                  salt/states/azurearm_network.py on lines 2402..2405
                                  salt/states/azurearm_resource.py on lines 160..163
                                  salt/states/azurearm_resource.py on lines 487..490
                                  salt/states/azurearm_resource.py on lines 702..705

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

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

                                      if 'error' not in zone:
                                          ret['result'] = True
                                          ret['comment'] = 'DNS zone {0} has been created.'.format(name)
                                          return ret
                                  Severity: Major
                                  Found in salt/states/azurearm_dns.py and 14 other locations - About 35 mins to fix
                                  salt/modules/gpg.py on lines 904..907
                                  salt/states/azurearm_compute.py on lines 257..260
                                  salt/states/azurearm_dns.py on lines 617..620
                                  salt/states/azurearm_network.py on lines 252..255
                                  salt/states/azurearm_network.py on lines 457..460
                                  salt/states/azurearm_network.py on lines 665..668
                                  salt/states/azurearm_network.py on lines 1046..1049
                                  salt/states/azurearm_network.py on lines 1472..1475
                                  salt/states/azurearm_network.py on lines 1721..1724
                                  salt/states/azurearm_network.py on lines 2041..2044
                                  salt/states/azurearm_network.py on lines 2245..2248
                                  salt/states/azurearm_network.py on lines 2441..2444
                                  salt/states/azurearm_resource.py on lines 538..541
                                  salt/states/azurearm_resource.py on lines 747..750

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

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

                                      if 'error' not in rec_set:
                                          ret['result'] = True
                                          ret['comment'] = 'Record set {0} has been created.'.format(name)
                                          return ret
                                  Severity: Major
                                  Found in salt/states/azurearm_dns.py and 14 other locations - About 35 mins to fix
                                  salt/modules/gpg.py on lines 904..907
                                  salt/states/azurearm_compute.py on lines 257..260
                                  salt/states/azurearm_dns.py on lines 298..301
                                  salt/states/azurearm_network.py on lines 252..255
                                  salt/states/azurearm_network.py on lines 457..460
                                  salt/states/azurearm_network.py on lines 665..668
                                  salt/states/azurearm_network.py on lines 1046..1049
                                  salt/states/azurearm_network.py on lines 1472..1475
                                  salt/states/azurearm_network.py on lines 1721..1724
                                  salt/states/azurearm_network.py on lines 2041..2044
                                  salt/states/azurearm_network.py on lines 2245..2248
                                  salt/states/azurearm_network.py on lines 2441..2444
                                  salt/states/azurearm_resource.py on lines 538..541
                                  salt/states/azurearm_resource.py on lines 747..750

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

                                  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