Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #28121 - Fix convert_string_to_bool to deal with Array #77

Merged
merged 1 commit into from Oct 29, 2019

Conversation

shiramax
Copy link
Contributor

The PR fixes a bug in the convert_string_to_bool function. ATM the function It doesn't validate the data type of the item in value.map (when it's an array). It caused the same error. It happens when deploying a host to oVirt (from Foreman 1.23):

NoMethodError: undefined method each' for #<Fog::Ovirt::Compute::Interface:0x007f0b76120628> /usr/share/foreman/vendor/ruby/2.3.0/gems/fog-ovirt-1.2.1/lib/fog/ovirt/compute/v4.rb:116:in convert_string_to_bool'
/usr/share/foreman/vendor/ruby/2.3.0/gems/fog-ovirt-1.2.1/lib/fog/ovirt/compute/v4.rb:124:in block (2 levels) in convert_string_to_bool' /usr/share/foreman/vendor/ruby/2.3.0/gems/fog-core-2.1.0/lib/fog/core/collection.rb:18:in map'
/usr/share/foreman/vendor/ruby/2.3.0/gems/fog-core-2.1.0/lib/fog/core/collection.rb:18:in map' /usr/share/foreman/vendor/ruby/2.3.0/gems/fog-ovirt-1.2.1/lib/fog/ovirt/compute/v4.rb:124:in block in convert_string_to_bool'
/usr/share/foreman/vendor/ruby/2.3.0/gems/fog-ovirt-1.2.1/lib/fog/ovirt/compute/v4.rb:116:in each' /usr/share/foreman/vendor/ruby/2.3.0/gems/fog-ovirt-1.2.1/lib/fog/ovirt/compute/v4.rb:116:in convert_string_to_bool'
/usr/share/foreman/vendor/ruby/2.3.0/gems/fog-ovirt-1.2.1/lib/fog/ovirt/requests/compute/v4/update_vm.rb:9:in update_vm' /usr/share/foreman/vendor/ruby/2.3.0/gems/fog-ovirt-1.2.1/lib/fog/ovirt/models/compute/server.rb:177:in save'
/usr/share/foreman/app/models/compute_resources/foreman/model/ovirt.rb:242:in `start_vm'

@shiramax
Copy link
Contributor Author

see issue: #62

@shiramax
Copy link
Contributor Author

@orrabin , @ShimShtein please review :)

Copy link
Collaborator

@orrabin orrabin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, I tested and no longer get the error with this PR.

convert_string_to_bool(value)
elsif value.is_a? Array
value.map { |item| convert_string_to_bool(item) }
if opts.is_a? Hash
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

def convert_string_to_bool(value)
  case value
  when "true"
    return true
  when "false"
      return false
  when Array
    return value.map { |elem| convert_string_to_bool(elem) }
  when Hash
    value.each do |key, elem|
      value[key] = convert_string_to_bool(elem)
    end
    return value
  else
    return value
  end
end

@shiramax
Copy link
Contributor Author

thanks @ShimShtein, can you please review again :) ?

@ShimShtein ShimShtein merged commit fe3ac5e into fog:master Oct 29, 2019
@ShimShtein
Copy link
Collaborator

merged, Thanks @shiramax!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants