theforeman/foreman

View on GitHub
app/models/concerns/orchestration/compute.rb

Summary

Maintainability
D
1 day
Test Coverage

Method setComputeDetails has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
Open

  def setComputeDetails
    if vm
      attrs = compute_resource.provided_attributes

      attrs.each do |foreman_attr, fog_attr|
Severity: Minor
Found in app/models/concerns/orchestration/compute.rb - 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

File compute.rb has 317 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'socket'
require 'timeout'

module Orchestration::Compute
  extend ActiveSupport::Concern
Severity: Minor
Found in app/models/concerns/orchestration/compute.rb - About 3 hrs to fix

    Method find_address has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

      def find_address(type)
        vm_addresses = filter_ip_addresses(vm.ip_addresses, type)
    
        # We can exit early if the host already has any kind of ip and the vm does not
        # provide one for this kind to speed up things
    Severity: Minor
    Found in app/models/concerns/orchestration/compute.rb - 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

    Method validate_compute_provisioning has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

      def validate_compute_provisioning
        return true if compute_attributes.nil?
        if image_build?
          return true if (compute_attributes[:image_id] || compute_attributes[:image_ref]).blank?
          img = find_image
    Severity: Minor
    Found in app/models/concerns/orchestration/compute.rb - About 55 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

    Method setComputeIP has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

      def setComputeIP
        attrs = compute_resource.provided_attributes
        if attrs.key?(:ip) || attrs.key?(:ip6)
          logger.info "Waiting for #{name} to become ready"
          compute_resource.vm_ready vm
    Severity: Minor
    Found in app/models/concerns/orchestration/compute.rb - 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

    Method queue_compute_create has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

      def queue_compute_create
        if find_image.try(:user_data)
          queue.create(:name   => _("Render user data template for %s") % self, :priority => 2,
                       :action => [self, :setUserData])
        end
    Severity: Minor
    Found in app/models/concerns/orchestration/compute.rb - 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

    Consider simplifying this complex logical expression.
    Open

        if attrs.key?(:ip) || attrs.key?(:ip6)
          logger.info "Waiting for #{name} to become ready"
          compute_resource.vm_ready vm
          logger.info "waiting for instance to acquire ip address"
          vm.wait_for do
    Severity: Major
    Found in app/models/concerns/orchestration/compute.rb - About 40 mins to fix

      Method match_macs_to_nics has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

        def match_macs_to_nics(fog_attr)
          # mac/ip are properties of the NIC, and there may be more than one,
          # so we need to loop. First store the nics returned from Fog in a local
          # array so we can delete from it safely
          fog_nics = vm.interfaces.dup
      Severity: Minor
      Found in app/models/concerns/orchestration/compute.rb - 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

      Method queue_compute has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

        def queue_compute
          return log_orchestration_errors unless compute? && errors.empty?
          # Create a new VM if it doesn't already exist or update an existing vm
      
          update_or_create = vm_exists?
      Severity: Minor
      Found in app/models/concerns/orchestration/compute.rb - 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

      There are no issues that match your filters.

      Category
      Status