cloudamatic/mu

View on GitHub
modules/mu/deploy.rb

Summary

Maintainability
D
1 day
Test Coverage

Assignment Branch Condition size for run is too high. [274.8/75]
Open

    def run
      Signal.trap("INT") do
        # Don't use MU.log in here, it does a synchronize {} and that ain't
        # legal inside a trap.
        die = true if (Time.now.to_i - @last_sigterm) < 5
Severity: Minor
Found in modules/mu/deploy.rb by rubocop

This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

Assignment Branch Condition size for createResources is too high. [177.8/75]
Open

    def createResources(services, mode="create")
      return if services.nil?

      parent_thread_id = Thread.current.object_id
      services.uniq!
Severity: Minor
Found in modules/mu/deploy.rb by rubocop

This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

Assignment Branch Condition size for initialize is too high. [103.1/75]
Open

    def initialize(environment,
                   verbosity: MU::Logger::NORMAL,
                   color: true,
                   webify_logs: false,
                   nocleanup: false,
Severity: Minor
Found in modules/mu/deploy.rb by rubocop

This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

Method has too many lines. [227/200]
Open

    def run
      Signal.trap("INT") do
        # Don't use MU.log in here, it does a synchronize {} and that ain't
        # legal inside a trap.
        die = true if (Time.now.to_i - @last_sigterm) < 5
Severity: Minor
Found in modules/mu/deploy.rb by rubocop

This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Cyclomatic complexity for run is too high. [52/30]
Open

    def run
      Signal.trap("INT") do
        # Don't use MU.log in here, it does a synchronize {} and that ain't
        # legal inside a trap.
        die = true if (Time.now.to_i - @last_sigterm) < 5
Severity: Minor
Found in modules/mu/deploy.rb by rubocop

This cop checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.

An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one.

Method run has 227 lines of code (exceeds 150 allowed). Consider refactoring.
Open

    def run
      Signal.trap("INT") do
        # Don't use MU.log in here, it does a synchronize {} and that ain't
        # legal inside a trap.
        die = true if (Time.now.to_i - @last_sigterm) < 5
Severity: Major
Found in modules/mu/deploy.rb - About 4 hrs to fix

    Perceived complexity for run is too high. [55/35]
    Open

        def run
          Signal.trap("INT") do
            # Don't use MU.log in here, it does a synchronize {} and that ain't
            # legal inside a trap.
            die = true if (Time.now.to_i - @last_sigterm) < 5
    Severity: Minor
    Found in modules/mu/deploy.rb by rubocop

    This cop tries to produce a complexity score that's a measure of the complexity the reader experiences when looking at a method. For that reason it considers when nodes as something that doesn't add as much complexity as an if or a &&. Except if it's one of those special case/when constructs where there's no expression after case. Then the cop treats it as an if/elsif/elsif... and lets all the when nodes count. In contrast to the CyclomaticComplexity cop, this cop considers else nodes as adding complexity.

    Example:

    def my_method                   # 1
      if cond                       # 1
        case var                    # 2 (0.8 + 4 * 0.2, rounded)
        when 1 then func_one
        when 2 then func_two
        when 3 then func_three
        when 4..10 then func_other
        end
      else                          # 1
        do_something until a && b   # 2
      end                           # ===
    end                             # 7 complexity points

    Method run has a Cognitive Complexity of 94 (exceeds 75 allowed). Consider refactoring.
    Open

        def run
          Signal.trap("INT") do
            # Don't use MU.log in here, it does a synchronize {} and that ain't
            # legal inside a trap.
            die = true if (Time.now.to_i - @last_sigterm) < 5
    Severity: Minor
    Found in modules/mu/deploy.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 createResources has a Cognitive Complexity of 92 (exceeds 75 allowed). Consider refactoring.
    Open

        def createResources(services, mode="create")
          return if services.nil?
    
          parent_thread_id = Thread.current.object_id
          services.uniq!
    Severity: Minor
    Found in modules/mu/deploy.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

    Assignment Branch Condition size for setThreadDependencies is too high. [77.89/75]
    Open

        def setThreadDependencies(services)
          if services.nil? or services.size < 1
    #        MU.log "Got nil service list in setThreadDependencies for called from #{caller_locations(1,1)[0].label}", MU::DEBUG
            return
          end
    Severity: Minor
    Found in modules/mu/deploy.rb by rubocop

    This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

    Cyclomatic complexity for createResources is too high. [31/30]
    Open

        def createResources(services, mode="create")
          return if services.nil?
    
          parent_thread_id = Thread.current.object_id
          services.uniq!
    Severity: Minor
    Found in modules/mu/deploy.rb by rubocop

    This cop checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.

    An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one.

    Block has too many lines. [115/100]
    Open

          services.each do |service|
            begin
              @my_threads << Thread.new(service) { |myservice|
                MU.dupGlobals(parent_thread_id)
                threadname = myservice["#MU_CLOUDCLASS"].cfg_name+"_"+myservice["name"]+"_#{mode}"
    Severity: Minor
    Found in modules/mu/deploy.rb by rubocop

    This cop checks if the length of a block exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable. The cop can be configured to ignore blocks passed to certain methods.

    Block has too many lines. [102/100]
    Open

              @my_threads << Thread.new(service) { |myservice|
                MU.dupGlobals(parent_thread_id)
                threadname = myservice["#MU_CLOUDCLASS"].cfg_name+"_"+myservice["name"]+"_#{mode}"
                Thread.current.thread_variable_set("name", threadname)
                Thread.current.thread_variable_set("owned_by_mu", true)
    Severity: Minor
    Found in modules/mu/deploy.rb by rubocop

    This cop checks if the length of a block exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable. The cop can be configured to ignore blocks passed to certain methods.

    Use each_value instead of values.each.
    Open

          MU::Cloud.resource_types.values.each { |data|
    Severity: Minor
    Found in modules/mu/deploy.rb by rubocop

    This cop checks for uses of each_key and each_value Hash methods.

    Note: If you have an array of two-element arrays, you can put parentheses around the block arguments to indicate that you're not working with a hash, and suppress RuboCop offenses.

    Example:

    # bad
    hash.keys.each { |k| p k }
    hash.values.each { |v| p v }
    hash.each { |k, _v| p k }
    hash.each { |_k, v| p v }
    
    # good
    hash.each_key { |k| p k }
    hash.each_value { |v| p v }

    Use =~ in places where the MatchData returned by #match will not be used.
    Open

                  if e.message.match(/can't add a new key into hash during iteration/)
    Severity: Minor
    Found in modules/mu/deploy.rb by rubocop

    This cop identifies the use of Regexp#match or String#match, which returns #<MatchData>/nil. The return value of =~ is an integral index/nil and is more performant.

    Example:

    # bad
    do_something if str.match(/regex/)
    while regex.match('str')
      do_something
    end
    
    # good
    method(str =~ /regex/)
    return value unless regex =~ 'str'

    Use each_value instead of values.each.
    Open

              MU::Cloud.resource_types.values.each { |data|
    Severity: Minor
    Found in modules/mu/deploy.rb by rubocop

    This cop checks for uses of each_key and each_value Hash methods.

    Note: If you have an array of two-element arrays, you can put parentheses around the block arguments to indicate that you're not working with a hash, and suppress RuboCop offenses.

    Example:

    # bad
    hash.keys.each { |k| p k }
    hash.values.each { |v| p v }
    hash.each { |k, _v| p k }
    hash.each { |_k, v| p v }
    
    # good
    hash.each_key { |k| p k }
    hash.each_value { |v| p v }

    Use each_value instead of values.each.
    Open

              MU::Cloud.resource_types.values.each { |data|
    Severity: Minor
    Found in modules/mu/deploy.rb by rubocop

    This cop checks for uses of each_key and each_value Hash methods.

    Note: If you have an array of two-element arrays, you can put parentheses around the block arguments to indicate that you're not working with a hash, and suppress RuboCop offenses.

    Example:

    # bad
    hash.keys.each { |k| p k }
    hash.values.each { |v| p v }
    hash.each { |k, _v| p k }
    hash.each { |_k, v| p v }
    
    # good
    hash.each_key { |k| p k }
    hash.each_value { |v| p v }

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

            @my_threads << Thread.new {
              MU.dupGlobals(parent_thread_id)
              Thread.current.thread_variable_set("name", "mu_groom_container")
    #          Thread.abort_on_exception = false
              MU::Cloud.resource_types.values.each { |data|
    Severity: Major
    Found in modules/mu/deploy.rb and 1 other location - About 1 hr to fix
    modules/mu/deploy.rb on lines 275..284

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

    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

            @my_threads << Thread.new {
              MU.dupGlobals(parent_thread_id)
              Thread.current.thread_variable_set("name", "mu_create_container")
    #          Thread.abort_on_exception = false
              MU::Cloud.resource_types.values.each { |data|
    Severity: Major
    Found in modules/mu/deploy.rb and 1 other location - About 1 hr to fix
    modules/mu/deploy.rb on lines 289..298

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

    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

                rescue ThreadError => e
                  MU.log "Waiting for threads to complete (#{e.message})", MU::NOTICE
                  @my_threads.each do |thr|
                    next if thr.object_id == Thread.current.object_id
                    thr.join(0.1)
    Severity: Minor
    Found in modules/mu/deploy.rb and 1 other location - About 55 mins to fix
    modules/mu/deploy.rb on lines 750..759

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

    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

            rescue ThreadError => e
              MU.log "Waiting for threads to complete (#{e.message})", MU::NOTICE
              @my_threads.each do |thr|
                next if thr.object_id == Thread.current.object_id
                thr.join(0.1)
    Severity: Minor
    Found in modules/mu/deploy.rb and 1 other location - About 55 mins to fix
    modules/mu/deploy.rb on lines 725..747

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

    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

    Redundant use of Object#to_s in interpolation.
    Open

                        MU.log "Invoking #{run_this_method.to_s} #{myservice['name']} #{myservice['name']}", MU::NOTICE
    Severity: Minor
    Found in modules/mu/deploy.rb by rubocop

    This cop checks for string conversion in string interpolation, which is redundant.

    Example:

    # bad
    
    "result is #{something.to_s}"

    Example:

    # good
    
    "result is #{something}"

    Do not suppress exceptions.
    Open

              rescue MU::Cloud::MuCloudFlagNotImplemented, MU::Cloud::MuCloudResourceNotImplemented, MU::MuError => e
    Severity: Minor
    Found in modules/mu/deploy.rb by rubocop

    This cop checks for rescue blocks with no body.

    Example:

    # bad
    
    def some_method
      do_something
    rescue
      # do nothing
    end

    Example:

    # bad
    
    begin
      do_something
    rescue
      # do nothing
    end

    Example:

    # good
    
    def some_method
      do_something
    rescue
      handle_exception
    end

    Example:

    # good
    
    begin
      do_something
    rescue
      handle_exception
    end

    Use meaningful heredoc delimiters.
    Open

    MESSAGE_END
    Severity: Minor
    Found in modules/mu/deploy.rb by rubocop

    This cop checks that your heredocs are using meaningful delimiters. By default it disallows END and EO*, and can be configured through blacklisting additional delimiters.

    Example:

    # good
    <<-SQL
      SELECT * FROM foo
    SQL
    
    # bad
    <<-END
      SELECT * FROM foo
    END
    
    # bad
    <<-EOS
      SELECT * FROM foo
    EOS

    There are no issues that match your filters.

    Category
    Status