crowbar/crowbar-openstack

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

Summary

Maintainability
F
4 days
Test Coverage

Method validate_proposal_after_save has a Cognitive Complexity of 59 (exceeds 5 allowed). Consider refactoring.
Open

  def validate_proposal_after_save(proposal)
    validate_one_for_role proposal, "nova-controller"

    elements = proposal["deployment"]["nova"]["elements"]
    nodes = Hash.new(0)
Severity: Minor
Found in crowbar_framework/app/models/nova_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

File nova_service.rb has 441 lines of code (exceeds 250 allowed). Consider refactoring.
Open

class NovaService < OpenstackServiceObject
  def initialize(thelogger = nil)
    super(thelogger)
    @bc_name = "nova"
  end
Severity: Minor
Found in crowbar_framework/app/models/nova_service.rb - About 6 hrs to fix

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

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

    unless hyperv_available?
      role.override_attributes["nova"]["elements"]["nova-compute-hyperv"] = []
Severity: Minor
Found in crowbar_framework/app/models/nova_service.rb - About 5 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_after_save has 99 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def validate_proposal_after_save(proposal)
    validate_one_for_role proposal, "nova-controller"

    elements = proposal["deployment"]["nova"]["elements"]
    nodes = Hash.new(0)
Severity: Major
Found in crowbar_framework/app/models/nova_service.rb - About 3 hrs to fix

Method apply_role_pre_chef_call has 88 lines of code (exceeds 25 allowed). Consider refactoring.
Open

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

    unless hyperv_available?
      role.override_attributes["nova"]["elements"]["nova-compute-hyperv"] = []
Severity: Major
Found in crowbar_framework/app/models/nova_service.rb - About 3 hrs to fix

Method role_constraints has 77 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def role_constraints
      {
        "nova-controller" => {
          "unique" => false,
          "count" => 1,
Severity: Major
Found in crowbar_framework/app/models/nova_service.rb - About 3 hrs to fix

Method create_proposal has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
Open

  def create_proposal
    @logger.debug("Nova create_proposal: entering")
    base = super
    @logger.debug("Nova create_proposal: done with base")

Severity: Minor
Found in crowbar_framework/app/models/nova_service.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 create_proposal has 52 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def create_proposal
    @logger.debug("Nova create_proposal: entering")
    base = super
    @logger.debug("Nova create_proposal: done with base")

Severity: Major
Found in crowbar_framework/app/models/nova_service.rb - About 2 hrs to fix

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

  def active_update(proposal, inst, in_queue, bootstrap = false)
    deployment = proposal["deployment"]["nova"]
    elements = deployment["elements"]

    # always reset elements of nova-ha-compute in case the user tried to
Severity: Minor
Found in crowbar_framework/app/models/nova_service.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 node_is_remote_ha? has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

  def node_is_remote_ha?(node, new_role)
    new_role.override_attributes[@bc_name]["elements"].each do |role_name, elements|
      next unless role_name =~ /^nova-compute-/
      elements.each do |element|
        if is_remotes?(element)
Severity: Minor
Found in crowbar_framework/app/models/nova_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

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

  def skip_unchanged_node?(node, old_role, new_role)
    # if old_role is nil, then we are applying the barclamp for the first time, so no skip
    return false if old_role.nil?

    # if the node changed roles, then we need to apply, so no skip
Severity: Minor
Found in crowbar_framework/app/models/nova_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 false if node_changed_ha?(node, old_role, new_role)
Severity: Major
Found in crowbar_framework/app/models/nova_service.rb - About 30 mins to fix

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

      unless network_present? proposal["attributes"][@bc_name]["migration"]["network"]
        validation_error I18n.t(
          "barclamp.#{@bc_name}.validation.invalid_migration_network",
          network: proposal["attributes"][@bc_name]["migration"]["network"]
        )
Severity: Minor
Found in crowbar_framework/app/models/nova_service.rb and 1 other location - About 25 mins to fix
crowbar_framework/app/models/nova_service.rb on lines 415..419

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

      unless network_present? proposal["attributes"][@bc_name]["zvm"]["zvm_xcat_network"]
        validation_error I18n.t(
          "barclamp.#{@bc_name}.validation.invalid_zvm_xcat_network",
          network: proposal["attributes"][@bc_name]["zvm"]["zvm_xcat_network"]
        )
Severity: Minor
Found in crowbar_framework/app/models/nova_service.rb and 1 other location - About 25 mins to fix
crowbar_framework/app/models/nova_service.rb on lines 493..497

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

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

  def network_present?(network_name)
    net_svc = NetworkService.new @logger
    network_proposal = Proposal.find_by(barclamp: net_svc.bc_name, name: "default")
    !network_proposal["attributes"]["network"]["networks"][network_name].nil?
Severity: Minor
Found in crowbar_framework/app/models/nova_service.rb and 1 other location - About 15 mins to fix
crowbar_framework/app/models/monasca_service.rb on lines 195..198

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

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