crowbar/crowbar-hyperv

View on GitHub

Showing 45 of 45 total issues

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

action :enable do
  # use load instead of require to ensure the handler file
  # is reloaded into memory each chef run. fixes COOK-620
  handler = nil
  converge_by("load #{@new_resource.source}") do
Severity: Major
Found in chef/cookbooks/windows/chef_handler/providers/default.rb and 1 other location - About 3 hrs to fix
chef/cookbooks/chef_handler/providers/default.rb on lines 25..49

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

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

action :enable do
  # use load instead of require to ensure the handler file
  # is reloaded into memory each chef run. fixes COOK-620
  handler = nil
  converge_by("load #{@new_resource.source}") do
Severity: Major
Found in chef/cookbooks/chef_handler/providers/default.rb and 1 other location - About 3 hrs to fix
chef/cookbooks/windows/chef_handler/providers/default.rb on lines 25..49

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

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

    def load_user_hive(hive,reg_path,user_hive)
      Chef::Log.debug("Reg Path #{reg_path}")
      # See if the hive is loaded. Logged in users will have a key that is named their SID
      # if the user has specified the a path by SID and the user is logged in, this function
      # should not be executed.
Severity: Minor
Found in chef/cookbooks/windows/libraries/registry_helper.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

File registry_helper.rb has 271 lines of code (exceeds 250 allowed). Consider refactoring.
Open

if RUBY_PLATFORM =~ /mswin|mingw32|windows/
  require "win32/registry"
  require "ruby-wmi"
end

Severity: Minor
Found in chef/cookbooks/windows/libraries/registry_helper.rb - About 2 hrs to fix

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

powershell "register_services" do
  code <<-EOH
    if (-not (Get-Service "#{node[:service][:nova][:name]}" -ErrorAction SilentlyContinue))
    {
      New-Service -name "#{node[:service][:nova][:name]}" -binaryPathName "`"#{node[:openstack][:bin]}\\#{node[:service][:file]}`" nova-compute `"#{node[:openstack][:nova][:binary]}`" --config-file `"#{node[:openstack][:nova][:config]}\\nova.conf`"" -displayName "#{node[:service][:nova][:displayname]}" -description "#{node[:service][:nova][:description]}" -startupType Automatic
Severity: Major
Found in chef/cookbooks/hyperv/recipes/register_services_nova.rb and 2 other locations - About 2 hrs to fix
chef/cookbooks/hyperv/recipes/register_services_ceilometer.rb on lines 3..8
chef/cookbooks/hyperv/recipes/register_services_neutron.rb on lines 3..8

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

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

powershell "register_services" do
  code <<-EOH
    if (-not (Get-Service "#{node[:service][:ceilometer][:name]}" -ErrorAction SilentlyContinue))
    {
      New-Service -name "#{node[:service][:ceilometer][:name]}" -binaryPathName "`"#{node[:openstack][:bin]}\\#{node[:service][:file]}`" ceilometer-agent-compute `"#{node[:openstack][:ceilometer][:binary]}`" --config-file `"#{node[:openstack][:ceilometer][:config]}\\ceilometer.conf`"" -displayName "#{node[:service][:ceilometer][:displayname]}" -description "#{node[:service][:ceilometer][:description]}" -startupType Automatic
chef/cookbooks/hyperv/recipes/register_services_neutron.rb on lines 3..8
chef/cookbooks/hyperv/recipes/register_services_nova.rb on lines 3..8

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

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

powershell "register_services" do
  code <<-EOH
    if (-not (Get-Service "#{node[:service][:neutron][:name]}" -ErrorAction SilentlyContinue))
    {
      New-Service -name "#{node[:service][:neutron][:name]}" -binaryPathName "`"#{node[:openstack][:bin]}\\#{node[:service][:file]}`" neutron-hyperv-agent `"#{node[:openstack][:neutron][:binary]}`" --config-file `"#{node[:openstack][:neutron][:config]}\\neutron_hyperv_agent.conf`"" -displayName "#{node[:service][:neutron][:displayname]}" -description "#{node[:service][:neutron][:description]}" -startupType Automatic
Severity: Major
Found in chef/cookbooks/hyperv/recipes/register_services_neutron.rb and 2 other locations - About 2 hrs to fix
chef/cookbooks/hyperv/recipes/register_services_ceilometer.rb on lines 3..8
chef/cookbooks/hyperv/recipes/register_services_nova.rb on lines 3..8

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

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

def extract_installed_packages_from_key(hkey = ::Win32::Registry::HKEY_LOCAL_MACHINE, desired = ::Win32::Registry::Constants::KEY_READ)
  uninstall_subkey = 'Software\Microsoft\Windows\CurrentVersion\Uninstall'
  packages = {}
  begin
    ::Win32::Registry.open(hkey, uninstall_subkey, desired) do |reg|
Severity: Minor
Found in chef/cookbooks/windows/providers/package.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

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

windows_batch "unzip #{component}" do
  code <<-EOH
  rmdir /S /Q #{node[:openstack][:src]}\\#{component}
  #{node[:sevenzip][:command]} x #{cached_file} -so -y | #{node[:sevenzip][:command]} x -ttar -si -y -o#{node[:openstack][:src]}
  for /D %%f in (#{node[:openstack][:src]}\\#{component}-*) do ren "%%f" #{component}
chef/cookbooks/hyperv/recipes/openstack_install_neutron.rb on lines 25..29
chef/cookbooks/hyperv/recipes/openstack_install_nova.rb on lines 25..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 70.

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

windows_batch "unzip #{component}" do
  code <<-EOH
  rmdir /S /Q #{node[:openstack][:src]}\\#{component}
  #{node[:sevenzip][:command]} x #{cached_file} -so -y | #{node[:sevenzip][:command]} x -ttar -si -y -o#{node[:openstack][:src]}
  for /D %%f in (#{node[:openstack][:src]}\\#{component}-*) do ren "%%f" #{component}
Severity: Major
Found in chef/cookbooks/hyperv/recipes/openstack_install_neutron.rb and 2 other locations - About 1 hr to fix
chef/cookbooks/hyperv/recipes/openstack_install_ceilometer.rb on lines 25..29
chef/cookbooks/hyperv/recipes/openstack_install_nova.rb on lines 25..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 70.

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

windows_batch "unzip #{component}" do
  code <<-EOH
  rmdir /S /Q #{node[:openstack][:src]}\\#{component}
  #{node[:sevenzip][:command]} x #{cached_file} -so -y | #{node[:sevenzip][:command]} x -ttar -si -y -o#{node[:openstack][:src]}
  for /D %%f in (#{node[:openstack][:src]}\\#{component}-*) do ren "%%f" #{component}
Severity: Major
Found in chef/cookbooks/hyperv/recipes/openstack_install_nova.rb and 2 other locations - About 1 hr to fix
chef/cookbooks/hyperv/recipes/openstack_install_ceilometer.rb on lines 25..29
chef/cookbooks/hyperv/recipes/openstack_install_neutron.rb on lines 25..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 70.

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

def installer_type
  @installer_type || begin
    if @new_resource.installer_type
      @new_resource.installer_type
    else
Severity: Minor
Found in chef/cookbooks/windows/providers/package.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 set_value has 37 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def set_value(mode,path,values,type=nil)
      hive, reg_path, hive_name, root_key, hive_loaded = get_reg_path_info(path)
      key_name = reg_path.join("\\")

      Chef::Log.debug("Creating #{path}")
Severity: Minor
Found in chef/cookbooks/windows/libraries/registry_helper.rb - About 1 hr to fix

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

    def set_value(mode,path,values,type=nil)
      hive, reg_path, hive_name, root_key, hive_loaded = get_reg_path_info(path)
      key_name = reg_path.join("\\")

      Chef::Log.debug("Creating #{path}")
Severity: Minor
Found in chef/cookbooks/windows/libraries/registry_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_user_hive has 30 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def load_user_hive(hive,reg_path,user_hive)
      Chef::Log.debug("Reg Path #{reg_path}")
      # See if the hive is loaded. Logged in users will have a key that is named their SID
      # if the user has specified the a path by SID and the user is logged in, this function
      # should not be executed.
Severity: Minor
Found in chef/cookbooks/windows/libraries/registry_helper.rb - About 1 hr to fix

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

action :disable do
  @new_resource.supports.each_key do |type|
    if enabled?(type)
      converge_by("disable #{@new_resource} as a #{type} handler") do
        Chef::Log.info("Disabling #{@new_resource} as a #{type} handler")
Severity: Major
Found in chef/cookbooks/chef_handler/providers/default.rb and 1 other location - About 1 hr to fix
chef/cookbooks/windows/chef_handler/providers/default.rb on lines 55..60

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

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

action :disable do
  @new_resource.supports.each_key do |type|
    if enabled?(type)
      converge_by("disable #{@new_resource} as a #{type} handler") do
        Chef::Log.info("Disabling #{@new_resource} as a #{type} handler")
Severity: Major
Found in chef/cookbooks/windows/chef_handler/providers/default.rb and 1 other location - About 1 hr to fix
chef/cookbooks/chef_handler/providers/default.rb on lines 55..60

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

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

def installer_type
  @installer_type || begin
    if @new_resource.installer_type
      @new_resource.installer_type
    else
Severity: Minor
Found in chef/cookbooks/windows/providers/package.rb - About 1 hr to fix

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

def action_create
  if compare_shortcut
    @link.TargetPath = @new_resource.target if @new_resource.target != nil
    @link.Arguments = @new_resource.arguments if @new_resource.arguments != nil
    @link.Description = @new_resource.description if @new_resource.description != nil
Severity: Minor
Found in chef/cookbooks/windows/providers/shortcut.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

Avoid deeply nested control flow statements.
Open

              if priv.reg_load_key(sid,ntuser_dat)
                Chef::Log.debug("RegLoadKey(#{sid}, #{user_hive}, #{ntuser_dat})")
                reg_path[0] = sid
              else
                Chef::Log.debug("Failed RegLoadKey(#{sid}, #{user_hive}, #{ntuser_dat})")
Severity: Major
Found in chef/cookbooks/windows/libraries/registry_helper.rb - About 45 mins to fix
Severity
Category
Status
Source
Language