zhmcclient/python-zhmcclient

View on GitHub
zhmcclient/_session.py

Summary

Maintainability
F
1 wk
Test Coverage

File _session.py has 1688 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# Copyright 2016,2021 IBM Corp. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
Severity: Major
Found in zhmcclient/_session.py - About 4 days to fix

    Function post has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring.
    Open

        def post(self, uri, resource=None, body=None, logon_required=True,
                 wait_for_completion=False, operation_timeout=None,
                 renew_session=True):
            """
            Perform the HTTP POST method against the resource identified by a URI,
    Severity: Minor
    Found in zhmcclient/_session.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

    Session has 35 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class Session(object):
        """
        A session to the HMC, optionally in context of an HMC user.
    
        The session supports operations that require to be authenticated, as well
    Severity: Minor
    Found in zhmcclient/_session.py - About 4 hrs to fix

      Function _log_http_response has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
      Open

          def _log_http_response(
                  method, url, resource, status, headers=None, content=None):
              """
              Log the HTTP response of an HMC REST API call, at the debug level.
      
      
      Severity: Minor
      Found in zhmcclient/_session.py - About 3 hrs to fix

      Cognitive Complexity

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

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

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

      Further reading

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

          def _log_http_request(
                  method, url, resource, headers=None, content=None,
                  content_len=None):
              """
              Log the HTTP request of an HMC REST API call, at the debug level.
      Severity: Minor
      Found in zhmcclient/_session.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

      Cyclomatic complexity is too high in method post. (24)
      Open

          @logged_api_call
          def post(self, uri, resource=None, body=None, logon_required=True,
                   wait_for_completion=False, operation_timeout=None,
                   renew_session=True):
              """
      Severity: Minor
      Found in zhmcclient/_session.py by radon

      Cyclomatic Complexity

      Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

      Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

      Construct Effect on CC Reasoning
      if +1 An if statement is a single decision.
      elif +1 The elif statement adds another decision.
      else +0 The else statement does not cause a new decision. The decision is at the if.
      for +1 There is a decision at the start of the loop.
      while +1 There is a decision at the while statement.
      except +1 Each except branch adds a new conditional path of execution.
      finally +0 The finally block is unconditionally executed.
      with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
      assert +1 The assert statement internally roughly equals a conditional statement.
      Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
      Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

      Source: http://radon.readthedocs.org/en/latest/intro.html

      Function _result_object has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
      Open

      def _result_object(result):
          """
          Return the JSON payload in the HTTP response as a Python dict.
      
          Parameters:
      Severity: Minor
      Found in zhmcclient/_session.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 check_for_completion has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

          def check_for_completion(self):
              """
              Check once for completion of the job and return completion status and
              result if it has completed.
      
      
      Severity: Minor
      Found in zhmcclient/_session.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 has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

          def get(self, uri, resource=None, logon_required=True, renew_session=True):
              """
              Perform the HTTP GET method against the resource identified by a URI.
      
              A set of standard HTTP headers is automatically part of the request.
      Severity: Minor
      Found in zhmcclient/_session.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 wait_for_completion has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

          def wait_for_completion(self, operation_timeout=None):
              """
              Wait for completion of the job, then delete the job on the HMC and
              return the result of the original asynchronous HMC operation, if it
              completed successfully.
      Severity: Minor
      Found in zhmcclient/_session.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 delete has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

          def delete(
                  self, uri, resource=None, logon_required=True, renew_session=True):
              """
              Perform the HTTP DELETE method against the resource identified by a
              URI.
      Severity: Minor
      Found in zhmcclient/_session.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 _request_exc_message has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

      def _request_exc_message(exc):
          """
          Return a reasonable exception message from a
          :exc:`request.exceptions.RequestException` exception.
      
      
      Severity: Minor
      Found in zhmcclient/_session.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, host, userid=None, password=None, session_id=None,
      Severity: Major
      Found in zhmcclient/_session.py - About 1 hr to fix

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

            def __init__(self, connect_timeout=None, connect_retries=None,
        Severity: Major
        Found in zhmcclient/_session.py - About 1 hr to fix

          Function post has 7 arguments (exceeds 4 allowed). Consider refactoring.
          Open

              def post(self, uri, resource=None, body=None, logon_required=True,
          Severity: Major
          Found in zhmcclient/_session.py - About 50 mins to fix

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

                def _log_http_response(
            Severity: Minor
            Found in zhmcclient/_session.py - About 35 mins to fix

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

                  def _log_http_request(
              Severity: Minor
              Found in zhmcclient/_session.py - About 35 mins to fix

                Avoid too many return statements within this function.
                Open

                                        return self.post(
                Severity: Major
                Found in zhmcclient/_session.py - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                                  return job
                  Severity: Major
                  Found in zhmcclient/_session.py - About 30 mins to fix

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

                            if resource:
                                names = []
                                res_class = resource.manager.class_name
                                while resource:
                                    # Using resource.name gets into an infinite recursion when
                    Severity: Major
                    Found in zhmcclient/_session.py and 1 other location - About 4 hrs to fix
                    zhmcclient/_session.py on lines 1058..1071

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

                    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

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

                            if resource:
                                names = []
                                res_class = resource.manager.class_name
                                while resource:
                                    # Using resource.name gets into an infinite recursion when
                    Severity: Major
                    Found in zhmcclient/_session.py and 1 other location - About 4 hrs to fix
                    zhmcclient/_session.py on lines 981..994

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

                    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

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

                            if logon_required:
                                self.logon()
                            elif self._base_url is None:
                                self._actual_host = self._determine_actual_host()
                                self._base_url = \
                    Severity: Major
                    Found in zhmcclient/_session.py and 2 other locations - About 1 hr to fix
                    zhmcclient/_session.py on lines 1118..1123
                    zhmcclient/_session.py on lines 1304..1309

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

                    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

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

                            if logon_required:
                                self.logon()
                            elif self._base_url is None:
                                self._actual_host = self._determine_actual_host()
                                self._base_url = \
                    Severity: Major
                    Found in zhmcclient/_session.py and 2 other locations - About 1 hr to fix
                    zhmcclient/_session.py on lines 1118..1123
                    zhmcclient/_session.py on lines 1480..1485

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

                    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

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

                            if logon_required:
                                self.logon()
                            elif self._base_url is None:
                                self._actual_host = self._determine_actual_host()
                                self._base_url = \
                    Severity: Major
                    Found in zhmcclient/_session.py and 2 other locations - About 1 hr to fix
                    zhmcclient/_session.py on lines 1304..1309
                    zhmcclient/_session.py on lines 1480..1485

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

                    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