crowbar/crowbar-core

View on GitHub
crowbar_framework/app/models/network_service.rb

Summary

Maintainability
F
5 days
Test Coverage

Method allocate_ip_by_type has a Cognitive Complexity of 52 (exceeds 5 allowed). Consider refactoring.
Open

  def allocate_ip_by_type(bc_instance, network, range, object, type, suggestion = nil)
    Rails.logger.debug("Network allocate ip for #{type}: entering #{object} #{network} #{range}")
    return [404, "No network specified"] if network.nil?
    return [404, "No range specified"] if range.nil?
    return [404, "No object specified"] if object.nil?
Severity: Minor
Found in crowbar_framework/app/models/network_service.rb - 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

Method transition has a Cognitive Complexity of 48 (exceeds 5 allowed). Consider refactoring.
Open

  def transition(inst, name, state)
    Rails.logger.debug("Network transition: entering: #{name} for #{state}")

    # we need one state before "installed" (and after allocation) because we
    # need the node to have the admin network fully defined for
Severity: Minor
Found in crowbar_framework/app/models/network_service.rb - About 7 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

Method deallocate_ip_by_type has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring.
Open

  def deallocate_ip_by_type(bc_instance, network, object, type)
    Rails.logger.debug("Network deallocate ip from #{type}: entering #{object} #{network}")

    return [404, "No network specified"] if network.nil?
    return [404, "No type specified"] if type.nil?
Severity: Minor
Found in crowbar_framework/app/models/network_service.rb - 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

File network_service.rb has 354 lines of code (exceeds 250 allowed). Consider refactoring.
Open

class NetworkService < ServiceObject
  def initialize(thelogger = nil)
    super
    @bc_name = "network"
  end
Severity: Minor
Found in crowbar_framework/app/models/network_service.rb - About 4 hrs to fix

Method allocate_ip_by_type has 94 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def allocate_ip_by_type(bc_instance, network, range, object, type, suggestion = nil)
    Rails.logger.debug("Network allocate ip for #{type}: entering #{object} #{network} #{range}")
    return [404, "No network specified"] if network.nil?
    return [404, "No range specified"] if range.nil?
    return [404, "No object specified"] if object.nil?
Severity: Major
Found in crowbar_framework/app/models/network_service.rb - About 3 hrs to fix

Method deallocate_ip_by_type has 76 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def deallocate_ip_by_type(bc_instance, network, object, type)
    Rails.logger.debug("Network deallocate ip from #{type}: entering #{object} #{network}")

    return [404, "No network specified"] if network.nil?
    return [404, "No type specified"] if type.nil?
Severity: Major
Found in crowbar_framework/app/models/network_service.rb - About 3 hrs to fix

Method transition has 67 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def transition(inst, name, state)
    Rails.logger.debug("Network transition: entering: #{name} for #{state}")

    # we need one state before "installed" (and after allocation) because we
    # need the node to have the admin network fully defined for
Severity: Major
Found in crowbar_framework/app/models/network_service.rb - About 2 hrs to fix

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

  def enable_interface(bc_instance, network, name)
    Rails.logger.debug("Network enable_interface: entering #{name} #{network}")

    return [404, "No network specified"] if network.nil?
    return [404, "No name specified"] if name.nil?
Severity: Minor
Found in crowbar_framework/app/models/network_service.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 allocate_ip_by_type has 6 arguments (exceeds 4 allowed). Consider refactoring.
Open

  def allocate_ip_by_type(bc_instance, network, range, object, type, suggestion = nil)
Severity: Minor
Found in crowbar_framework/app/models/network_service.rb - About 45 mins to fix

Avoid deeply nested control flow statements.
Open

            if result[0] != 200
              Rails.logger.error(
                "Failed to allocate bastion address for: #{node.name}: #{result[0]}"
              )
            else
Severity: Major
Found in crowbar_framework/app/models/network_service.rb - About 45 mins to fix

Avoid deeply nested control flow statements.
Open

            if result[0] != 200
              Rails.logger.error("Failed to allocate bmc_vlan address for: " \
                "#{node.name}: #{result[0]}")
            end
Severity: Major
Found in crowbar_framework/app/models/network_service.rb - About 45 mins to fix

Method allocate_virtual_ip has 5 arguments (exceeds 4 allowed). Consider refactoring.
Open

  def allocate_virtual_ip(bc_instance, network, range, service, suggestion = nil)
Severity: Minor
Found in crowbar_framework/app/models/network_service.rb - About 35 mins to fix

Method allocate_ip has 5 arguments (exceeds 4 allowed). Consider refactoring.
Open

  def allocate_ip(bc_instance, network, range, name, suggestion = nil)
Severity: Minor
Found in crowbar_framework/app/models/network_service.rb - About 35 mins to fix

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

  def apply_role_pre_chef_call(old_role, role, all_nodes)
    Rails.logger.debug("Network apply_role_pre_chef_call: entering #{all_nodes.inspect}")

    role.default_attributes["network"]["networks"].each do |k,net|
      db = Chef::DataBag.load("crowbar/#{k}_network") rescue nil
Severity: Minor
Found in crowbar_framework/app/models/network_service.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

Avoid too many return statements within this method.
Open

      return [404, "No node found"] if node.nil?
Severity: Major
Found in crowbar_framework/app/models/network_service.rb - About 30 mins to fix

Avoid too many return statements within this method.
Open

      return [404, "No network data found"]
Severity: Major
Found in crowbar_framework/app/models/network_service.rb - About 30 mins to fix

Avoid too many return statements within this method.
Open

      return [200, net_info]
Severity: Major
Found in crowbar_framework/app/models/network_service.rb - About 30 mins to fix

Avoid too many return statements within this method.
Open

      return [404, "No Address Available"]
Severity: Major
Found in crowbar_framework/app/models/network_service.rb - About 30 mins to fix

Avoid too many return statements within this method.
Open

      return [404, "No network data found"]
Severity: Major
Found in crowbar_framework/app/models/network_service.rb - About 30 mins to fix

Avoid too many return statements within this method.
Open

        return [404, "Node does not have address in #{network}"]
Severity: Major
Found in crowbar_framework/app/models/network_service.rb - About 30 mins to fix

Avoid too many return statements within this method.
Open

      return [404, "Network deallocate ip from #{type}: network does not exists: #{object} #{network}"]
Severity: Major
Found in crowbar_framework/app/models/network_service.rb - About 30 mins to fix

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

    if role.nil? || !role.default_attributes["network"]["networks"].key?(network)
      Rails.logger.error("Network allocate ip by type: No network data found: #{name} #{network}")
      return [404, "No network data found"]
    end
Severity: Minor
Found in crowbar_framework/app/models/network_service.rb and 1 other location - About 20 mins to fix
crowbar_framework/app/models/network_service.rb on lines 415..418

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

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 role.nil? || !role.default_attributes["network"]["networks"].key?(network)
      Rails.logger.error("Network enable_interface: No network data found: #{name} #{network}")
      return [404, "No network data found"]
    end
Severity: Minor
Found in crowbar_framework/app/models/network_service.rb and 1 other location - About 20 mins to fix
crowbar_framework/app/models/network_service.rb on lines 61..64

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

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