theforeman/foreman_maintain

View on GitHub

Showing 105 of 105 total issues

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

    def ask_to_select(message, steps, run_strategy)
      if assumeyes?
        puts('(assuming first option)')
        return steps.first
      end
Severity: Minor
Found in lib/foreman_maintain/reporter.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 run has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

    def run
      unless @preserve_dir
        puts "Creating backup folder #{@backup_dir}"

        FileUtils.mkdir_p @backup_dir
Severity: Minor
Found in definitions/procedures/backup/prepare_directory.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 2 locations. Consider refactoring.
Open

  class Disable < ForemanMaintain::Procedure
    include ForemanMaintain::Concerns::Hammer
    metadata do
      for_feature :sync_plans
      description 'disable active sync plans'
Severity: Major
Found in definitions/procedures/sync_plans/disable.rb and 1 other location - About 1 hr to fix
definitions/procedures/sync_plans/enable.rb on lines 2..29

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

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

  class Enable < ForemanMaintain::Procedure
    include ForemanMaintain::Concerns::Hammer
    metadata do
      for_feature :sync_plans
      description 're-enable sync plans'
Severity: Major
Found in definitions/procedures/sync_plans/enable.rb and 1 other location - About 1 hr to fix
definitions/procedures/sync_plans/disable.rb on lines 2..29

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

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 tar_command has 32 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def tar_command(options)
    volume_size = options.fetch(:volume_size, nil)
    absolute_names = options.fetch(:absolute_names, nil)
    validate_volume_size(volume_size) unless volume_size.nil?

Severity: Minor
Found in definitions/features/tar.rb - About 1 hr to fix

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

        def compose
          add_steps(
            Checks::Foreman::FactsNames, # if Foreman database present
            Checks::ForemanProxy::CheckTftpStorage, # if Satellite with foreman-proxy+tftp
            Checks::ForemanProxy::VerifyDhcpConfigSyntax, # if foreman-proxy+dhcp-isc
    Severity: Minor
    Found in definitions/scenarios/satellite_upgrade.rb - About 1 hr to fix

      Method compose has 31 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def compose
            backup = ForemanMaintain::Utils::Backup.new(context.get(:backup_dir))
      
            add_step(Checks::RootUser)
            add_steps_with_context(Checks::Restore::ValidateBackup,
      Severity: Minor
      Found in definitions/scenarios/restore.rb - About 1 hr to fix

        Method compose has 31 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def compose
              add_steps(
                Checks::Foreman::FactsNames, # if Foreman database present
                Checks::ForemanProxy::CheckTftpStorage, # if Satellite with foreman-proxy+tftp
                Checks::ForemanProxy::VerifyDhcpConfigSyntax, # if foreman-proxy+dhcp-isc
        Severity: Minor
        Found in definitions/scenarios/foreman_upgrade.rb - About 1 hr to fix

          Method compose has 30 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              def compose
                add_steps(
                  Checks::Foreman::FactsNames, # if Foreman database present
                  Checks::ForemanProxy::CheckTftpStorage, # if Satellite with foreman-proxy+tftp
                  Checks::ForemanProxy::VerifyDhcpConfigSyntax, # if foreman-proxy+dhcp-isc
          Severity: Minor
          Found in definitions/scenarios/update.rb - About 1 hr to fix

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

              module Candlepin
                class DBUp < ForemanMaintain::Check
                  metadata do
                    description 'Make sure Candlepin DB is up'
                    label :candlepin_db_up
            Severity: Major
            Found in definitions/checks/candlepin/db_up.rb and 1 other location - About 1 hr to fix
            definitions/checks/foreman/db_up.rb on lines 2..28

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

            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

              module Foreman
                class DBUp < ForemanMaintain::Check
                  metadata do
                    description 'Make sure Foreman DB is up'
                    label :foreman_db_up
            Severity: Major
            Found in definitions/checks/foreman/db_up.rb and 1 other location - About 1 hr to fix
            definitions/checks/candlepin/db_up.rb on lines 2..28

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

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

                def setup_protector(enabled)
                  config = protector_config
                  config += "\n" unless config[-1] == "\n"
                  enabled_re = /^\s*enabled\s*=.*$/
                  if enabled_re.match(config)
            Severity: Minor
            Found in lib/foreman_maintain/package_manager/dnf.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_http_error_msg has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Open

              def find_http_error_msg(array_output, curl_http_status)
                if curl_http_status == 0
                  'No valid HTTP response (Connection failed)'
                else
                  http_line = ''
            Severity: Minor
            Found in definitions/features/foreman_proxy.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 run_action_on_services has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Open

              def run_action_on_services(action, options, spinner)
                status = 0
                failed_services = []
                filtered_services(options, action).each_value do |group|
                  fork_threads_for_services(action, group, spinner).each do |service, status_and_output|
            Severity: Minor
            Found in definitions/features/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 include_unregistered_services has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Open

              def include_unregistered_services(service_list, services_filter)
                return service_list unless services_filter
                return service_list unless services_filter.any?
            
                services_filter = services_filter.reject do |obj|
            Severity: Minor
            Found in definitions/features/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 status_for_maintenance_mode has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Open

              def status_for_maintenance_mode(mode_on)
                default_storage = ForemanMaintain.storage(:default)
                load_from_storage(default_storage)
                return ['sync plans: empty data', []] if both_empty?
            
            
            Severity: Minor
            Found in definitions/features/sync_plans.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 run has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Open

                def run
                  backup = ForemanMaintain::Utils::Backup.new(@backup_dir)
                  if feature(:instance).postgresql_local?
                    errors = []
                    [:candlepin_dump, :foreman_dump, :pulpcore_dump].each do |dump|
            Severity: Minor
            Found in definitions/checks/restore/validate_postgresql_dump_permissions.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

                    until_valid_decision do
                      actions = (run_strategy == :fail_slow) ? 'n(next)' : 'n(next), q(quit)'
                      answer = ask("#{message}, [#{actions}]")
                      if answer =~ /^\d+$/ && (answer.to_i - 1) < steps.size
                        steps[answer.to_i - 1]
            Severity: Major
            Found in lib/foreman_maintain/reporter/cli_reporter.rb and 1 other location - About 1 hr to fix
            lib/foreman_maintain/reporter.rb on lines 115..128

            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

                  until_valid_decision do
                    actions = (run_strategy == :fail_slow) ? 'n(next)' : 'n(next), q(quit)'
            
                    answer = ask("#{message}, [#{actions}]")
                    if answer =~ /^\d+$/ && (answer.to_i - 1) < steps.size
            Severity: Major
            Found in lib/foreman_maintain/reporter.rb and 1 other location - About 1 hr to fix
            lib/foreman_maintain/reporter/cli_reporter.rb on lines 230..242

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

              def katello_ping
                res = server_connection.get('/katello/api/ping')
                logger.debug('Called /katello/api/ping')
                logger.debug("Response: #{res.code}, #{res.body}")
                response = JSON.parse(res.body)
            Severity: Minor
            Found in definitions/features/instance.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