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

get_raw_vmfolder now fails due to blank? method being attempted against strings for type param #177

Open
Ryuzavi opened this issue Nov 26, 2018 · 1 comment
Assignees

Comments

@Ryuzavi
Copy link

Ryuzavi commented Nov 26, 2018

Hey

Found this issue today when trying out fog-vsphere. It appears the recent changes to get_folder has introduced an error whenever get_raw_vmfolder is called from other resources such as clone_vm or list_folders.

The specific problem is get_raw_vmfolder calls get_folder and sets the type param to 'vm':

def get_raw_vmfolder(path, datacenter_name)
get_raw_folder(path, datacenter_name, 'vm')
end

Passing in a string for the type param now fails as a call to the blank? method is performed as an argument check:

raise ArgumentError, "#{type} is unknown" if type.blank?

Problem is string in ruby doesn't have that method available so it fails accordingly:

NoMethodError: undefined method `blank?' for "vm":String

The previous version of get_folder, in 2.4.0, didn't have this issue as it specifically converted the type param to a symbol if it was detected as the string 'vm':

when 'vm', :vm
# if you're a vm then grab the VM.
folder = get_raw_vmfolder(path, datacenter_name)
raise(Fog::Compute::Vsphere::NotFound) unless folder
folder_attributes(folder, datacenter_name)

Cheers,
R.

@Ryuzavi Ryuzavi changed the title get_raw_vmfolder method now fails due to 'blank?' method being attempted against strings for type param get_raw_vmfolder method now fails due to blank? method being attempted against strings for type param Nov 26, 2018
@Ryuzavi Ryuzavi changed the title get_raw_vmfolder method now fails due to blank? method being attempted against strings for type param get_raw_vmfolder now fails due to blank? method being attempted against strings for type param Nov 26, 2018
@Ryuzavi
Copy link
Author

Ryuzavi commented Nov 26, 2018

Just noticed that there's another call to blank? elsewhere that also causes the problem but this time for the Nil class:

unless options.key?('storage_pod')
unless options['volumes'].blank?
relocation_spec[:disk] = relocate_template_volumes_specs(vm_mob_ref, options['volumes'], options['datacenter'])
end
end

Workaround for both issues is to monkey patch the base classes to include a blank method:

class NilClass
  def blank?
    true
  end
end

class String
  def blank?
    self.strip.empty?
  end
end

@chris1984 chris1984 self-assigned this Nov 26, 2018
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

No branches or pull requests

2 participants