crowbar/crowbar-core

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

Summary

Maintainability
F
2 wks
Test Coverage

Method apply_role has a Cognitive Complexity of 178 (exceeds 5 allowed). Consider refactoring.
Open

  def apply_role(role, inst, in_queue, bootstrap = false)
    Rails.logger.debug "apply_role(#{role.name}, #{inst}, #{in_queue}, #{bootstrap})"
    Rails.logger.progress("Starting to apply role #{role.name}")

    # Variables used in the global ensure
Severity: Minor
Found in crowbar_framework/app/models/service_object.rb - About 3 days 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 service_object.rb has 1352 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require "pp"
require "chef"
require "json"
require "hash_only_merge"
require "securerandom"
Severity: Major
Found in crowbar_framework/app/models/service_object.rb - About 3 days to fix

Class ServiceObject has 98 methods (exceeds 20 allowed). Consider refactoring.
Open

class ServiceObject
  include CrowbarPacemakerProxy

  FORBIDDEN_PROPOSAL_NAMES=["template","nodes","commit","status"]

Severity: Major
Found in crowbar_framework/app/models/service_object.rb - About 1 day to fix

Method apply_role has 289 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def apply_role(role, inst, in_queue, bootstrap = false)
    Rails.logger.debug "apply_role(#{role.name}, #{inst}, #{in_queue}, #{bootstrap})"
    Rails.logger.progress("Starting to apply role #{role.name}")

    # Variables used in the global ensure
Severity: Major
Found in crowbar_framework/app/models/service_object.rb - About 1 day to fix

Method reset_proposal has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
Open

  def reset_proposal(inst, bc = @bc_name)
    ::Proposal.find_by(
      barclamp: bc,
      name: inst
    ).tap do |proposal|
Severity: Minor
Found in crowbar_framework/app/models/service_object.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

Method validate_proposal_elements has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
Open

  def validate_proposal_elements proposal_elements
    proposal_elements.each do |role_and_elements|
      role, elements = role_and_elements
      uniq_elements  = elements.uniq

Severity: Minor
Found in crowbar_framework/app/models/service_object.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

Method relevant_attributes_changed_if_roles? has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
Open

  def relevant_attributes_changed_if_roles?(node, old_role, new_role, ignore_attr, only_for_roles)
    # if only_for_roles has some sole
    unless only_for_roles.nil? || only_for_roles.empty?
      # get roles for this node
      roles_in_new = new_role.elements.keys.select { |r| new_role.elements[r].include?(node) }
Severity: Minor
Found in crowbar_framework/app/models/service_object.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

Method validate_proposal_constraints has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
Open

  def validate_proposal_constraints(proposal)
    elements = proposal["deployment"][@bc_name]["elements"]
    nodes_is_admin = {}

    role_constraints.keys.each do |role|
Severity: Minor
Found in crowbar_framework/app/models/service_object.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

Method skip_unready_nodes has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
Open

  def skip_unready_nodes(bc, inst, new_elements, old_elements)
    logger.debug("skip_unready_nodes: enter for #{bc}:#{inst}")
    skip_unready_nodes_roles = Rails.application.config.crowbar.fetch(
      "skip_unready_nodes", {}
    ).fetch("roles", [])
Severity: Minor
Found in crowbar_framework/app/models/service_object.rb - 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

Method validate_postponed_nodes has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
Open

  def validate_postponed_nodes(proposal)
    return unless upgrade_postponed?

    skip_unready_nodes_enabled = Rails.application.config.crowbar.fetch(
      "skip_unready_nodes", {}
Severity: Minor
Found in crowbar_framework/app/models/service_object.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 violates_admin_constraint? has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
Open

  def violates_admin_constraint?(elements, role, nodes_is_admin = {})
    if role_constraints[role] && !role_constraints[role]["admin"]
      elements[role].each do |element|
        next if is_cluster?(element) || is_remotes?(element)
        unless nodes_is_admin.key? element
Severity: Minor
Found in crowbar_framework/app/models/service_object.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 lock_nodes has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
Open

  def lock_nodes(nodes, lock_owner, lock_reason)
    locks = []
    errors = {}

    return [locks, errors] if nodes.empty?
Severity: Minor
Found in crowbar_framework/app/models/service_object.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 reset_proposal has 43 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def reset_proposal(inst, bc = @bc_name)
    ::Proposal.find_by(
      barclamp: bc,
      name: inst
    ).tap do |proposal|
Severity: Minor
Found in crowbar_framework/app/models/service_object.rb - About 1 hr to fix

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

  def wait_for_reboot(node)
    nobj = Node.find_by_name(node)
    if nobj[:crowbar_wall][:wait_for_reboot]
      puts "Waiting for reboot of node #{node}"
      if RemoteNode.ready?(node, 1200)
Severity: Minor
Found in crowbar_framework/app/models/service_object.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 add_role_to_instance_and_node has 37 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def add_role_to_instance_and_node(barclamp, instance, name, prop, role, newrole)
    node = Node.find_by_name(name)
    if node.nil?
      Rails.logger.debug("ARTOI: couldn't find node #{name}. bailing")
      return false
Severity: Minor
Found in crowbar_framework/app/models/service_object.rb - About 1 hr to fix

Method lock_nodes has 35 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def lock_nodes(nodes, lock_owner, lock_reason)
    locks = []
    errors = {}

    return [locks, errors] if nodes.empty?
Severity: Minor
Found in crowbar_framework/app/models/service_object.rb - About 1 hr to fix

Method validate_proposal_constraints has 34 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def validate_proposal_constraints(proposal)
    elements = proposal["deployment"][@bc_name]["elements"]
    nodes_is_admin = {}

    role_constraints.keys.each do |role|
Severity: Minor
Found in crowbar_framework/app/models/service_object.rb - About 1 hr to fix

Method proposal_commit has 33 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def proposal_commit(inst, options = {})
    options.reverse_merge!(
      in_queue: false,
      validate: true,
      validate_after_save: true,
Severity: Minor
Found in crowbar_framework/app/models/service_object.rb - About 1 hr to fix

Method wait_for_reboot has 32 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def wait_for_reboot(node)
    nobj = Node.find_by_name(node)
    if nobj[:crowbar_wall][:wait_for_reboot]
      puts "Waiting for reboot of node #{node}"
      if RemoteNode.ready?(node, 1200)
Severity: Minor
Found in crowbar_framework/app/models/service_object.rb - About 1 hr to fix

Method violates_uniqueness_constraint? has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

  def violates_uniqueness_constraint?(elements, role)
    if role_constraints[role] && role_constraints[role]["unique"]
      elements[role].each do |element|
        elements.keys.each do |loop_role|
          next if loop_role == role
Severity: Minor
Found in crowbar_framework/app/models/service_object.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 add_role_to_instance_and_node has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

  def add_role_to_instance_and_node(barclamp, instance, name, prop, role, newrole)
    node = Node.find_by_name(name)
    if node.nil?
      Rails.logger.debug("ARTOI: couldn't find node #{name}. bailing")
      return false
Severity: Minor
Found in crowbar_framework/app/models/service_object.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 violates_exclude_platform_constraint? has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

  def violates_exclude_platform_constraint?(elements, role)
    if role_constraints[role] && role_constraints[role].key?("exclude_platform")
      constraints = role_constraints[role]["exclude_platform"]
      elements[role].each do |element|
        next if is_cluster?(element) || is_remotes?(element)
Severity: Minor
Found in crowbar_framework/app/models/service_object.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 violates_platform_constraint? has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

  def violates_platform_constraint?(elements, role)
    if role_constraints[role] && role_constraints[role].key?("platform")
      constraints = role_constraints[role]["platform"]
      elements[role].each do |element|
        next if is_cluster?(element) || is_remotes?(element)
Severity: Minor
Found in crowbar_framework/app/models/service_object.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 find_dep_proposal has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

  def find_dep_proposal(bc, optional=false)
    begin
      const_service = self.class.get_service(bc)
    rescue
      Rails.logger.info "Barclamp \"#{bc}\" is not available."
Severity: Minor
Found in crowbar_framework/app/models/service_object.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 wait_for_chef_daemons has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

  def wait_for_chef_daemons(node_list)
    return if node_list.empty?

    queue = Queue.new

Severity: Minor
Found in crowbar_framework/app/models/service_object.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 queue_proposal has 6 arguments (exceeds 4 allowed). Consider refactoring.
Open

  def queue_proposal(inst, element_order, elements, deps, bc = @bc_name, pre_cached_nodes = {})
Severity: Minor
Found in crowbar_framework/app/models/service_object.rb - About 45 mins to fix

Method add_role_to_instance_and_node has 6 arguments (exceeds 4 allowed). Consider refactoring.
Open

  def add_role_to_instance_and_node(barclamp, instance, name, prop, role, newrole)
Severity: Minor
Found in crowbar_framework/app/models/service_object.rb - About 45 mins to fix

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

  def relevant_attributes_changed_if_roles?(node, old_role, new_role, ignore_attr, only_for_roles)
Severity: Minor
Found in crowbar_framework/app/models/service_object.rb - About 35 mins to fix

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

  def restore_to_ready(nodes)
    with_lock "BA-LOCK" do
      nodes_to_save = []
      nodes.each do |node_name|
        node = Node.find_by_name(node_name)
Severity: Minor
Found in crowbar_framework/app/models/service_object.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 select_nodes_for_role has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

  def select_nodes_for_role(all_nodes, role, preferred_intended_role = nil)
    # do not modify array given by caller
    valid_nodes = all_nodes.dup

    valid_nodes.delete_if { |n| n.nil? }
Severity: Minor
Found in crowbar_framework/app/models/service_object.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 proposal_create has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

  def proposal_create(params)
    base_id = params["id"]
    params["id"] = "#{@bc_name}-#{params["id"]}"
    if FORBIDDEN_PROPOSAL_NAMES.any?{ |n| n == base_id }
      return [403,I18n.t("model.service.illegal_name", names: FORBIDDEN_PROPOSAL_NAMES.to_sentence)]
Severity: Minor
Found in crowbar_framework/app/models/service_object.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 set_to_applying has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

  def set_to_applying(nodes, inst, pre_cached_nodes)
    with_lock "BA-LOCK" do
      nodes_to_save = []
      nodes.each do |node_name|
        node = pre_cached_nodes[node_name]
Severity: Minor
Found in crowbar_framework/app/models/service_object.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 [405, message]
Severity: Major
Found in crowbar_framework/app/models/service_object.rb - About 30 mins to fix

Avoid too many return statements within this method.
Open

      return [405, message]
Severity: Major
Found in crowbar_framework/app/models/service_object.rb - About 30 mins to fix

Avoid too many return statements within this method.
Open

      return [405, message]
Severity: Major
Found in crowbar_framework/app/models/service_object.rb - About 30 mins to fix

Method save_nodes has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

  def save_nodes(nodes)
    return if nodes.empty?

    queue = Queue.new
    nodes.each { |n| queue.push n }
Severity: Minor
Found in crowbar_framework/app/models/service_object.rb - 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

Method get_log_lines has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

  def get_log_lines(node)
    begin
      line_count = 0
      last_delimiter_line = 0
      f = File.open("/var/log/crowbar/chef-client/#{node}.log")
Severity: Minor
Found in crowbar_framework/app/models/service_object.rb - 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

Method run_remote_chef_client has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

  def run_remote_chef_client(node, command, logfile_name)
    Thread.new do
      # Exec command
      # the -- tells sudo to stop interpreting options

Severity: Minor
Found in crowbar_framework/app/models/service_object.rb - 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

Method release_chef_locks has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

  def release_chef_locks(locks)
    return if locks.empty?

    queue = Queue.new
    locks.each { |l| queue.push l }
Severity: Minor
Found in crowbar_framework/app/models/service_object.rb - 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

    begin
      apply_role_post_chef_call(old_role, role, all_nodes)
    rescue StandardError => e
      Rails.logger.fatal("apply_role: Exception #{e.message} #{e.backtrace.join("\n")}")
      Rails.logger.progress("Failed to apply role #{role.name} after calling chef")
Severity: Minor
Found in crowbar_framework/app/models/service_object.rb and 1 other location - About 55 mins to fix
crowbar_framework/app/models/service_object.rb on lines 1364..1372

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

    begin
      apply_role_pre_chef_call(old_role, role, all_nodes)
    rescue StandardError => e
      Rails.logger.fatal("apply_role: Exception #{e.message} #{e.backtrace.join("\n")}")
      Rails.logger.progress("Failed to apply role #{role.name} before calling chef")
Severity: Minor
Found in crowbar_framework/app/models/service_object.rb and 1 other location - About 55 mins to fix
crowbar_framework/app/models/service_object.rb on lines 1439..1447

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

  def violates_remotes_constraint?(elements, role)
    if role_constraints[role] && !role_constraints[role]["remotes"]
      remotes = elements[role].select { |e| is_remotes? e }
      unless remotes.empty?
        return true
Severity: Minor
Found in crowbar_framework/app/models/service_object.rb and 1 other location - About 25 mins to fix
crowbar_framework/app/models/service_object.rb on lines 789..796

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

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 violates_cluster_constraint?(elements, role)
    if role_constraints[role] && !role_constraints[role]["cluster"]
      clusters = elements[role].select { |e| is_cluster? e }
      unless clusters.empty?
        return true
Severity: Minor
Found in crowbar_framework/app/models/service_object.rb and 1 other location - About 25 mins to fix
crowbar_framework/app/models/service_object.rb on lines 799..806

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

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 violates_platform_constraint?(elements, role)
        platforms = role_constraints[role]["platform"].map { |k, v| [k, v].join(" ") }.join(", ")
        validation_error("Role #{role} can be used only for #{platforms} platform(s).")
Severity: Minor
Found in crowbar_framework/app/models/service_object.rb and 1 other location - About 25 mins to fix
crowbar_framework/app/models/service_object.rb on lines 843..845

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

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 violates_exclude_platform_constraint?(elements, role)
        platforms = role_constraints[role]["exclude_platform"].map { |k, v| [k, v].join(" ") }.join(", ")
        validation_error("Role #{role} can't be used for #{platforms} platform(s).")
Severity: Minor
Found in crowbar_framework/app/models/service_object.rb and 1 other location - About 25 mins to fix
crowbar_framework/app/models/service_object.rb on lines 838..840

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

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