gamunu/cassandra_snap

View on GitHub
cassandra_snap/snapshotting.py

Summary

Maintainability
D
2 days
Test Coverage

File snapshotting.py has 546 lines of code (exceeds 250 allowed). Consider refactoring.
Open

from __future__ import (absolute_import, print_function)

# From system
import os
import re
Severity: Major
Found in cassandra_snap/snapshotting.py - About 1 day to fix

    Function __init__ has 22 arguments (exceeds 4 allowed). Consider refactoring.
    Open

        def __init__(self, aws_secret_access_key,
    Severity: Major
    Found in cassandra_snap/snapshotting.py - About 2 hrs to fix

      Function node_start_backup has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
      Open

          def node_start_backup(self, snapshot, incremental_backups):
              """Runs snapshot command on a cassandra node"""
      
              def run_cmd(cmd):
                  with hide('running', 'stdout', 'stderr'):
      Severity: Minor
      Found in cassandra_snap/snapshotting.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 upload_node_backups has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

          def upload_node_backups(self, snapshot, incremental_backups):
              prefix = os.path.join(snapshot.base_path,
                                    self.get_current_node_hostname())
      
              manifest_path = '/tmp/backupmanifest'
      Severity: Minor
      Found in cassandra_snap/snapshotting.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 restore has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

          def restore(self, keyspace, table, hosts, target_hosts):
              table_log = "table: %s" % table if table else ''
              snap_name = os.path.basename(self.snapshot.base_path)
              logging.info("Restoring keyspace: %(keyspace)s %(table)s "
                           "from backup %(snap)s" %
      Severity: Minor
      Found in cassandra_snap/snapshotting.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 __init__ has 8 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          def __init__(self, aws_access_key_id, aws_secret_access_key, snapshot,
      Severity: Major
      Found in cassandra_snap/snapshotting.py - About 1 hr to fix

        Function _download_key has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

            def _download_key(self, key):
                r = self.keyspace_table_matcher.search(key.name)
                keyspace = r.group(2)
                table = r.group(3)
                host = key.name.split('/')[2]
        Severity: Minor
        Found in cassandra_snap/snapshotting.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

        Function __init__ has 5 arguments (exceeds 4 allowed). Consider refactoring.
        Open

            def __init__(
        Severity: Minor
        Found in cassandra_snap/snapshotting.py - About 35 mins to fix

          Function __init__ has 5 arguments (exceeds 4 allowed). Consider refactoring.
          Open

              def __init__(self, base_path, s3_bucket, hosts, keyspaces, table):
          Severity: Minor
          Found in cassandra_snap/snapshotting.py - About 35 mins to fix

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

                def _read_s3(self):
                    if self.snapshots:
                        return
            
                    conn = S3Connection(
            Severity: Minor
            Found in cassandra_snap/snapshotting.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 get_snapshot_for has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                def get_snapshot_for(self, hosts, keyspaces, table):
                    """Returns the most recent compatible snapshot"""
                    for snapshot in self:
                        if snapshot.hosts != hosts:
                            continue
            Severity: Minor
            Found in cassandra_snap/snapshotting.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 get_keyspace_schema has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                def get_keyspace_schema(self, keyspace=None):
                    if self.cqlsh_user and self.cqlsh_password:
                        auth = "-u {!s} -p {!s}".format(self.cqlsh_user,
                                                        self.cqlsh_password)
                    else:
            Severity: Minor
            Found in cassandra_snap/snapshotting.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

                def start_cluster_backup(self, snapshot, incremental_backups=False):
                    logging.info("Creating snapshots")
                    with settings(parallel=True, pool_size=self.connection_pool_size):
                        execute(self.node_start_backup, snapshot, incremental_backups)
            Severity: Minor
            Found in cassandra_snap/snapshotting.py and 1 other location - About 50 mins to fix
            cassandra_snap/snapshotting.py on lines 541..544

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

            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 upload_cluster_backups(self, snapshot, incremental_backups):
                    logging.info("Uploading backups")
                    with settings(parallel=True, pool_size=self.connection_pool_size):
                        execute(self.upload_node_backups, snapshot, incremental_backups)
            Severity: Minor
            Found in cassandra_snap/snapshotting.py and 1 other location - About 50 mins to fix
            cassandra_snap/snapshotting.py on lines 481..484

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

            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

            Line too long (80 > 79 characters)
            Open

                    # Remove the root dir from the list since it won't have a manifest file.
            Severity: Minor
            Found in cassandra_snap/snapshotting.py by pep8

            Limit all lines to a maximum of 79 characters.

            There are still many devices around that are limited to 80 character
            lines; plus, limiting windows to 80 characters makes it possible to
            have several windows side-by-side.  The default wrapping on such
            devices looks ugly.  Therefore, please limit all lines to a maximum
            of 79 characters. For flowing long blocks of text (docstrings or
            comments), limiting the length to 72 characters is recommended.
            
            Reports error E501.

            Invalid escape sequence '.'
            Open

                                '\.lzo$', '', key_full_path)
            Severity: Minor
            Found in cassandra_snap/snapshotting.py by pep8

            Invalid escape sequences are deprecated in Python 3.6.

            Okay: regex = r'\.png$'
            W605: regex = '\.png$'

            Line too long (81 > 79 characters)
            Open

                    upload_command = "cassandra-snapshotter-agent %(incremental_backups)s " \
            Severity: Minor
            Found in cassandra_snap/snapshotting.py by pep8

            Limit all lines to a maximum of 79 characters.

            There are still many devices around that are limited to 80 character
            lines; plus, limiting windows to 80 characters makes it possible to
            have several windows side-by-side.  The default wrapping on such
            devices looks ugly.  Therefore, please limit all lines to a maximum
            of 79 characters. For flowing long blocks of text (docstrings or
            comments), limiting the length to 72 characters is recommended.
            
            Reports error E501.

            Line too long (93 > 79 characters)
            Open

                        self.aws_access_key_id, self.aws_secret_access_key, host=self.s3_connection_host)
            Severity: Minor
            Found in cassandra_snap/snapshotting.py by pep8

            Limit all lines to a maximum of 79 characters.

            There are still many devices around that are limited to 80 character
            lines; plus, limiting windows to 80 characters makes it possible to
            have several windows side-by-side.  The default wrapping on such
            devices looks ugly.  Therefore, please limit all lines to a maximum
            of 79 characters. For flowing long blocks of text (docstrings or
            comments), limiting the length to 72 characters is recommended.
            
            Reports error E501.

            Line too long (87 > 79 characters)
            Open

                                    "lzop Out: %s\nError:%s\nExit Code %d: " % (out, err, errcode))
            Severity: Minor
            Found in cassandra_snap/snapshotting.py by pep8

            Limit all lines to a maximum of 79 characters.

            There are still many devices around that are limited to 80 character
            lines; plus, limiting windows to 80 characters makes it possible to
            have several windows side-by-side.  The default wrapping on such
            devices looks ugly.  Therefore, please limit all lines to a maximum
            of 79 characters. For flowing long blocks of text (docstrings or
            comments), limiting the length to 72 characters is recommended.
            
            Reports error E501.

            Line too long (80 > 79 characters)
            Open

                    logging.info("Found %(files_count)d files, with total size of %(size)s."
            Severity: Minor
            Found in cassandra_snap/snapshotting.py by pep8

            Limit all lines to a maximum of 79 characters.

            There are still many devices around that are limited to 80 character
            lines; plus, limiting windows to 80 characters makes it possible to
            have several windows side-by-side.  The default wrapping on such
            devices looks ugly.  Therefore, please limit all lines to a maximum
            of 79 characters. For flowing long blocks of text (docstrings or
            comments), limiting the length to 72 characters is recommended.
            
            Reports error E501.

            Line too long (85 > 79 characters)
            Open

                        incremental_backups=incremental_backups and '--incremental_backups' or ''
            Severity: Minor
            Found in cassandra_snap/snapshotting.py by pep8

            Limit all lines to a maximum of 79 characters.

            There are still many devices around that are limited to 80 character
            lines; plus, limiting windows to 80 characters makes it possible to
            have several windows side-by-side.  The default wrapping on such
            devices looks ugly.  Therefore, please limit all lines to a maximum
            of 79 characters. For flowing long blocks of text (docstrings or
            comments), limiting the length to 72 characters is recommended.
            
            Reports error E501.

            Line too long (89 > 79 characters)
            Open

                def _run_sstableloader(self, keyspace_path, tables, target_hosts, cassandra_bin_dir):
            Severity: Minor
            Found in cassandra_snap/snapshotting.py by pep8

            Limit all lines to a maximum of 79 characters.

            There are still many devices around that are limited to 80 character
            lines; plus, limiting windows to 80 characters makes it possible to
            have several windows side-by-side.  The default wrapping on such
            devices looks ugly.  Therefore, please limit all lines to a maximum
            of 79 characters. For flowing long blocks of text (docstrings or
            comments), limiting the length to 72 characters is recommended.
            
            Reports error E501.

            Line too long (107 > 79 characters)
            Open

                             connection_pool_size=12, reduced_redundancy=False, nodetool_user=None, nodetool_pass=None,
            Severity: Minor
            Found in cassandra_snap/snapshotting.py by pep8

            Limit all lines to a maximum of 79 characters.

            There are still many devices around that are limited to 80 character
            lines; plus, limiting windows to 80 characters makes it possible to
            have several windows side-by-side.  The default wrapping on such
            devices looks ugly.  Therefore, please limit all lines to a maximum
            of 79 characters. For flowing long blocks of text (docstrings or
            comments), limiting the length to 72 characters is recommended.
            
            Reports error E501.

            Line too long (90 > 79 characters)
            Open

                    matcher_string = "(%(hosts)s).*/(%(keyspace)s)/(%(table)s-?[A-Za-z0-9]*)/" % dict(
            Severity: Minor
            Found in cassandra_snap/snapshotting.py by pep8

            Limit all lines to a maximum of 79 characters.

            There are still many devices around that are limited to 80 character
            lines; plus, limiting windows to 80 characters makes it possible to
            have several windows side-by-side.  The default wrapping on such
            devices looks ugly.  Therefore, please limit all lines to a maximum
            of 79 characters. For flowing long blocks of text (docstrings or
            comments), limiting the length to 72 characters is recommended.
            
            Reports error E501.

            Line too long (85 > 79 characters)
            Open

                        incremental_backups=incremental_backups and '--incremental_backups' or ''
            Severity: Minor
            Found in cassandra_snap/snapshotting.py by pep8

            Limit all lines to a maximum of 79 characters.

            There are still many devices around that are limited to 80 character
            lines; plus, limiting windows to 80 characters makes it possible to
            have several windows side-by-side.  The default wrapping on such
            devices looks ugly.  Therefore, please limit all lines to a maximum
            of 79 characters. For flowing long blocks of text (docstrings or
            comments), limiting the length to 72 characters is recommended.
            
            Reports error E501.

            Line too long (82 > 79 characters)
            Open

                                cmd = "{!s} -k {!s} {!s} -e 'DESCRIBE KEYSPACE {!s};'".format(
            Severity: Minor
            Found in cassandra_snap/snapshotting.py by pep8

            Limit all lines to a maximum of 79 characters.

            There are still many devices around that are limited to 80 character
            lines; plus, limiting windows to 80 characters makes it possible to
            have several windows side-by-side.  The default wrapping on such
            devices looks ugly.  Therefore, please limit all lines to a maximum
            of 79 characters. For flowing long blocks of text (docstrings or
            comments), limiting the length to 72 characters is recommended.
            
            Reports error E501.

            Line too long (82 > 79 characters)
            Open

                                     "--s3-bucket-region=%(s3_bucket_region)s %(s3_ssenc)s " \
            Severity: Minor
            Found in cassandra_snap/snapshotting.py by pep8

            Limit all lines to a maximum of 79 characters.

            There are still many devices around that are limited to 80 character
            lines; plus, limiting windows to 80 characters makes it possible to
            have several windows side-by-side.  The default wrapping on such
            devices looks ugly.  Therefore, please limit all lines to a maximum
            of 79 characters. For flowing long blocks of text (docstrings or
            comments), limiting the length to 72 characters is recommended.
            
            Reports error E501.

            Line too long (110 > 79 characters)
            Open

                            %(keyspace_path)s/%(table)s' % dict(sstableloader=sstableloader, hosts=','.join(target_hosts),
            Severity: Minor
            Found in cassandra_snap/snapshotting.py by pep8

            Limit all lines to a maximum of 79 characters.

            There are still many devices around that are limited to 80 character
            lines; plus, limiting windows to 80 characters makes it possible to
            have several windows side-by-side.  The default wrapping on such
            devices looks ugly.  Therefore, please limit all lines to a maximum
            of 79 characters. For flowing long blocks of text (docstrings or
            comments), limiting the length to 72 characters is recommended.
            
            Reports error E501.

            Line too long (93 > 79 characters)
            Open

                                                                keyspace_path=keyspace_path, table=table)
            Severity: Minor
            Found in cassandra_snap/snapshotting.py by pep8

            Limit all lines to a maximum of 79 characters.

            There are still many devices around that are limited to 80 character
            lines; plus, limiting windows to 80 characters makes it possible to
            have several windows side-by-side.  The default wrapping on such
            devices looks ugly.  Therefore, please limit all lines to a maximum
            of 79 characters. For flowing long blocks of text (docstrings or
            comments), limiting the length to 72 characters is recommended.
            
            Reports error E501.

            Line too long (80 > 79 characters)
            Open

                            # Only one keyspace can be specified along with a column family.
            Severity: Minor
            Found in cassandra_snap/snapshotting.py by pep8

            Limit all lines to a maximum of 79 characters.

            There are still many devices around that are limited to 80 character
            lines; plus, limiting windows to 80 characters makes it possible to
            have several windows side-by-side.  The default wrapping on such
            devices looks ugly.  Therefore, please limit all lines to a maximum
            of 79 characters. For flowing long blocks of text (docstrings or
            comments), limiting the length to 72 characters is recommended.
            
            Reports error E501.

            Line too long (80 > 79 characters)
            Open

                                         "to the following host(s) via sstableloader: %s." %
            Severity: Minor
            Found in cassandra_snap/snapshotting.py by pep8

            Limit all lines to a maximum of 79 characters.

            There are still many devices around that are limited to 80 character
            lines; plus, limiting windows to 80 characters makes it possible to
            have several windows side-by-side.  The default wrapping on such
            devices looks ugly.  Therefore, please limit all lines to a maximum
            of 79 characters. For flowing long blocks of text (docstrings or
            comments), limiting the length to 72 characters is recommended.
            
            Reports error E501.

            There are no issues that match your filters.

            Category
            Status