saltstack/salt

View on GitHub
salt/returners/local_cache.py

Summary

Maintainability
F
4 days
Test Coverage

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

def clean_old_jobs():
    '''
    Clean out the old jobs from the job cache
    '''
    if __opts__['keep_jobs'] != 0:
Severity: Minor
Found in salt/returners/local_cache.py - About 6 hrs to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

File local_cache.py has 417 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# -*- coding: utf-8 -*-
'''
Return data to local job cache

'''
Severity: Minor
Found in salt/returners/local_cache.py - About 6 hrs to fix

    Function get_jid has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring.
    Open

    def get_jid(jid):
        '''
        Return the information returned when the specified job id was executed
        '''
        jid_dir = salt.utils.jid.jid_dir(jid, _job_dir(), __opts__['hash_type'])
    Severity: Minor
    Found in salt/returners/local_cache.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 _walk_through has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

    def _walk_through(job_dir):
        '''
        Walk though the jid dir and look for jobs
        '''
        serial = salt.payload.Serial(__opts__)
    Severity: Minor
    Found in salt/returners/local_cache.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 get_load has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

    def get_load(jid):
        '''
        Return the load data that marks a specified jid
        '''
        jid_dir = salt.utils.jid.jid_dir(jid, _job_dir(), __opts__['hash_type'])
    Severity: Minor
    Found in salt/returners/local_cache.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 prep_jid has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

    def prep_jid(nocache=False, passed_jid=None, recurse_count=0):
        '''
        Return a job id and prepare the job id directory.
    
        This is the function responsible for making sure jids don't collide (unless
    Severity: Minor
    Found in salt/returners/local_cache.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 save_minions has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

    def save_minions(jid, minions, syndic_id=None):
        '''
        Save/update the serialized list of minions for a given job
        '''
        # Ensure we have a list for Python 3 compatability
    Severity: Minor
    Found in salt/returners/local_cache.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 save_load has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

    def save_load(jid, clear_load, minions=None, recurse_count=0):
        '''
        Save the load to the specified jid
    
        minions argument is to provide a pre-computed list of matched minions for
    Severity: Minor
    Found in salt/returners/local_cache.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 get_jids_filter has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

    def get_jids_filter(count, filter_find_job=True):
        '''
        Return a list of all jobs information filtered by the given criteria.
        :param int count: show not more than the count of most recent jobs
        :param bool filter_find_jobs: filter out 'saltutil.find_job' jobs
    Severity: Minor
    Found in salt/returners/local_cache.py - About 45 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 hours_difference > __opts__['keep_jobs'] and os.path.exists(t_path):
                            # Remove the entire f_path from the original JID dir
                            try:
                                shutil.rmtree(f_path)
                            except OSError as err:
    Severity: Major
    Found in salt/returners/local_cache.py - About 45 mins to fix

      Avoid deeply nested control flow statements.
      Open

                              with salt.utils.files.fopen(outp, 'rb') as rfh:
                                  ret[fn_]['out'] = serial.load(rfh)
                      except Exception as exc:
      Severity: Major
      Found in salt/returners/local_cache.py - About 45 mins to fix

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

        def returner(load):
            '''
            Return data to the local job cache
            '''
            serial = salt.payload.Serial(__opts__)
        Severity: Minor
        Found in salt/returners/local_cache.py - About 35 mins to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

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

        def save_reg(data):
            '''
            Save the register to msgpack files
            '''
            reg_dir = _reg_dir()
        Severity: Minor
        Found in salt/returners/local_cache.py - About 25 mins to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

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

        def get_jids():
            '''
            Return a dict mapping all job ids to job information
            '''
            ret = {}
        Severity: Minor
        Found in salt/returners/local_cache.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 3 locations. Consider refactoring.
        Open

            try:
                if not os.path.exists(jid_dir):
                    os.makedirs(jid_dir)
            except OSError as exc:
                if exc.errno == errno.EEXIST:
        Severity: Major
        Found in salt/returners/local_cache.py and 2 other locations - About 1 hr to fix
        salt/returners/local_cache.py on lines 206..210
        salt/returners/local_cache.py on lines 513..517

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

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

            try:
                if not os.path.exists(jid_dir):
                    os.makedirs(jid_dir)
            except OSError as exc:
                if exc.errno == errno.EEXIST:
        Severity: Major
        Found in salt/returners/local_cache.py and 2 other locations - About 1 hr to fix
        salt/returners/local_cache.py on lines 258..262
        salt/returners/local_cache.py on lines 513..517

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

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

            try:
                if not os.path.exists(reg_dir):
                    os.makedirs(reg_dir)
            except OSError as exc:
                if exc.errno == errno.EEXIST:
        Severity: Major
        Found in salt/returners/local_cache.py and 2 other locations - About 1 hr to fix
        salt/returners/local_cache.py on lines 206..210
        salt/returners/local_cache.py on lines 258..262

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

        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

                with salt.utils.files.fopen(os.path.join(jid_dir, ENDTIME), 'w') as etfile:
                    etfile.write(salt.utils.stringutils.to_str(time))
        Severity: Minor
        Found in salt/returners/local_cache.py and 1 other location - About 55 mins to fix
        salt/runners/winrepo.py on lines 122..124

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

            if recurse_count >= 5:
                err = ('save_load could not write job cache file after {0} retries.'
                       .format(recurse_count))
                log.error(err)
                raise salt.exceptions.SaltCacheError(err)
        Severity: Minor
        Found in salt/returners/local_cache.py and 1 other location - About 35 mins to fix
        salt/returners/local_cache.py on lines 96..99

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

            except IOError:
                log.warning(
                    'Could not write out jid file for job %s. Retrying.', jid)
                time.sleep(0.1)
                return prep_jid(passed_jid=jid, nocache=nocache,
        Severity: Minor
        Found in salt/returners/local_cache.py and 1 other location - About 35 mins to fix
        salt/returners/local_cache.py on lines 219..225

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

            except IOError as exc:
                log.warning(
                    'Could not write job invocation cache file: %s', exc
                )
                time.sleep(0.1)
        Severity: Minor
        Found in salt/returners/local_cache.py and 1 other location - About 35 mins to fix
        salt/returners/local_cache.py on lines 123..128

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

            if recurse_count >= 5:
                err = 'prep_jid could not store a jid after {0} tries.'.format(recurse_count)
                log.error(err)
                raise salt.exceptions.SaltCacheError(err)
        Severity: Minor
        Found in salt/returners/local_cache.py and 1 other location - About 35 mins to fix
        salt/returners/local_cache.py on lines 195..199

        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