HewlettPackard/oneview-chef

View on GitHub

Showing 65 of 65 total issues

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

    def self.recursive_diff(data, desired_data, str = '', indent = '')
      unless desired_data.class == Hash
        return '' if data == desired_data
        return str << "\n#{indent}#{data.nil? ? 'nil' : data} -> #{desired_data}"
      end
Severity: Minor
Found in libraries/oneview_helper.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

Class ResourceProvider has 21 methods (exceeds 20 allowed). Consider refactoring.
Open

  class ResourceProvider
    attr_accessor \
      :context,       # Ususally a Chef resource's context (self)
      :resource_name, # The Chef resource's type. e.g., oneview_ethernet_network
      :name,          # Name of the Chef resource. e.g., EthNet1
Severity: Minor
Found in libraries/resource_provider.rb - About 2 hrs to fix

    Method modify_resource_scopes_assignments has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

            def modify_resource_scopes_assignments
              return Chef::Log.info('No resource were specified to modify resource scopes. Skipping') if @new_resource.resource.nil?
              add_or_remove = @new_resource.add.any? || @new_resource.remove.any?
              raise "Unspecified properties: 'add' and 'remove'. Please set at least one before attempting this action." unless add_or_remove
              client = OneviewCookbook::Helper.build_client(@new_resource.client)
    Severity: Minor
    Found in libraries/resource_providers/api600/c7000/scope_provider.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

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

    module OneviewCookbook
      module ImageStreamer
        # Module for Image Streamer API 500 Resources
        module API500
          # Get resource class that matches the type given
    Severity: Major
    Found in libraries/resource_providers/image_streamer/api500.rb and 2 other locations - About 1 hr to fix
    libraries/resource_providers/image_streamer/api300.rb on lines 12..28
    libraries/resource_providers/image_streamer/api600.rb on lines 14..30

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

    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 3 locations. Consider refactoring.
    Open

    module OneviewCookbook
      module ImageStreamer
        # Module for Image Streamer API 600 Resources
        module API600
          # Get resource class that matches the type given
    Severity: Major
    Found in libraries/resource_providers/image_streamer/api600.rb and 2 other locations - About 1 hr to fix
    libraries/resource_providers/image_streamer/api300.rb on lines 12..28
    libraries/resource_providers/image_streamer/api500.rb on lines 14..30

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

    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 3 locations. Consider refactoring.
    Open

    module OneviewCookbook
      module ImageStreamer
        # Module for Image Streamer API 300 Resources
        module API300
          # Get resource class that matches the type given
    Severity: Major
    Found in libraries/resource_providers/image_streamer/api300.rb and 2 other locations - About 1 hr to fix
    libraries/resource_providers/image_streamer/api500.rb on lines 14..30
    libraries/resource_providers/image_streamer/api600.rb on lines 14..30

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

    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

    Method build_volume_attachments has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

          def build_volume_attachments
            @new_resource.volume_attachments.each do |options|
              options = convert_keys(options, :to_s)
              volume_name = options['volume']
              volume_data = options['volume_data']
    Severity: Minor
    Found in libraries/resource_providers/api200/server_profile_provider.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 load_resource has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

        def self.load_resource(client, type: nil, id: nil, ret_attribute: nil, api_ver: nil, variant: nil, node: nil, base_module: OneviewSDK)
          raise(ArgumentError, 'Must specify a resource type') unless type
          return unless id
          c = build_client(client)
          api_ver ||= node['oneview']['api_version'] rescue 200
    Severity: Minor
    Found in libraries/oneview_helper.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 parse_namespace has 35 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def parse_namespace
          klass_name = self.class.to_s
          Chef::Log.debug("Resource '#{@resource_name}' received with the '#{klass_name}' class name")
          name_arr = klass_name.split('::')
          @sdk_resource_type = name_arr.pop.gsub(/Provider$/i, '') # e.g., EthernetNetwork
    Severity: Minor
    Found in libraries/resource_provider.rb - About 1 hr to fix

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

          def self.convert_keys(info, conversion_method)
            return nil unless info
            support = {}
            info.each do |k, v|
              if v.class == Hash
      Severity: Minor
      Found in libraries/oneview_helper.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 load_ports has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

            def load_ports(item_to_update)
              port_monitor_attributes = convert_keys(@new_resource.port_monitor, :to_s)
              enable_port_monitor = item_to_update['portMonitor']['enablePortMonitor'] if item_to_update['portMonitor']
              enable_port_monitor ||= port_monitor_attributes['enablePortMonitor']
              if enable_port_monitor

      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_provider_named has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

          def self.get_provider_named(type, api_module, variant = nil)
            api_version = api_module.to_s.split('::').last
            if variant
              raise "#{api_version} variant #{variant} is not supported!" unless api_module::SUPPORTED_VARIANTS.include?(variant.to_s)
              api_module = api_module.const_get(variant.to_s)
      Severity: Minor
      Found in libraries/oneview_helper.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 load_ligs has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

              def load_ligs
                load_lig # Deprecated method
                return unless @new_resource.logical_interconnect_groups
                lig_klass = resource_named(:LogicalInterconnectGroup)
                sas_lig_klass = resource_named(:SASLogicalInterconnectGroup)

      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 load_logical_switch has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

            def load_logical_switch
              lsg_defined = @new_resource.logical_switch_group || @item['LogicalSwitchGroupUri']
              raise "Undefined Property: 'logical_switch_group'. Please set it before attempting this action" unless lsg_defined
              unless @item['LogicalSwitchGroupUri']
                @item.set_logical_switch_group(load_resource(:LogicalSwitchGroup, @new_resource.logical_switch_group))
      Severity: Minor
      Found in libraries/resource_providers/api200/logical_switch_provider.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 change_resource_assignments has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

              def change_resource_assignments
                add_or_remove = @new_resource.add.any? || @new_resource.remove.any?
                raise "Unspecified properties: 'add' and 'remove'. Please set at least one before attempting this action." unless add_or_remove
                @item.retrieve! || raise("#{@resource_name} '#{@name}' not found!")
                values_to_add = build_resource_list
      Severity: Minor
      Found in libraries/resource_providers/api300/c7000/scope_provider.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

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

              def create_csr_request
                @item.retrieve! || raise("#{@resource_name} '#{@name}' not found!")
                @context.converge_by "Creating CSR request #{@new_resource.csr_data} for bay #{@new_resource.bay_number}" do
                  @item.create_csr_request(@new_resource.csr_data, @new_resource.bay_number)
                  csr_cert = @item.get_csr_request(@new_resource.bay_number)
      libraries/resource_providers/api600/c7000/enclosure_provider.rb on lines 19..24

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

      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 create_csr_request
                @item.retrieve! || raise("#{@resource_name} '#{@name}' not found!")
                @context.converge_by "Creating CSR request #{@new_resource.csr_data} for bay #{@new_resource.bay_number}" do
                  @item.create_csr_request(@new_resource.csr_data, @new_resource.bay_number)
                  csr_cert = @item.get_csr_request(@new_resource.bay_number)
      libraries/resource_providers/api600/synergy/enclosure_provider.rb on lines 18..23

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

      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

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

              def backup_from_file
                raise "#{@resource_name} #{@new_resource.file_path} must be specified for this action" unless @new_resource.file_path
                raise "'#{@new_resource.file_path}' file does not exist." unless File.file?(@new_resource.file_path)
                raise 'A deployment_group field is required for this action.' unless @new_resource.deployment_group
                deployment_group = load_resource(:DeploymentGroup, @new_resource.deployment_group)

      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 build_resource_list has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

              def build_resource_list(op = :add)
                retrieved_resources = []
                context = op == :add ? @new_resource.add : @new_resource.remove
                context.each do |resource_name, values|
                  values.each do |value|
      Severity: Minor
      Found in libraries/resource_providers/api300/c7000/scope_provider.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 load_downlink_ports has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

            def load_downlink_ports(monitored_ports, interconnect_name)
              interconnect = load_resource(:Interconnect, interconnect_name)
              monitored_ports.each do |downlink|
                interconnect['ports'].each do |k|
                  next unless k['portName'] == downlink['portName']
      Severity: Minor
      Found in libraries/resource_providers/api200/logical_interconnect_provider.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

      Severity
      Category
      Status
      Source
      Language