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

vSphere usability improvements #592

Merged
merged 4 commits into from Nov 8, 2011
Merged

vSphere usability improvements #592

merged 4 commits into from Nov 8, 2011

Conversation

kelseyhightower
Copy link

commit b53416a
Author: Carl Caum carl@carlcaum.com
Date: Fri Oct 28 09:03:02 2011 -0400

(#10055) Search vmFolder inventory vs children

This patch changes how the `list_all_virtual_machine_mobs` method
searches for virtual machines. Previously the search was based on
children of the `dc.vmFolder` object. This makes the false assumption
that all children are virtual machines.

Now the search is based on the entire inventory of the `dc.vmFolder`
object, which gives us more control over what we consider a virtual
machine.

This patch also adds a new `find_all_in_inventory` method; a generic
method that can be used to search an inventory for any VMware object
exposed by RbVmomi. Using `find_all_in_inventory` we are able to
traverse VMware folders and pickout specific VMware object, in this case
`RbVmomi::VIM::VirtualMachine`

commit 762aa62
Author: Carl Caum carl@carlcaum.com
Date: Fri Oct 28 10:10:37 2011 -0400

Adding a path attribute to the vm_mob_ref hash

This patch adds a new `path` attribute to the vm_mob_ref hash returned
by the `convert_vm_mob_ref_to_attr_hash` method. In order to support the
new `path` attribute, this patch also adds a new `get_folder_path` method
to the `list_virtual_machines` vsphere module.

commit bc74e06
Author: Kelsey Hightower kelsey@puppetlabs.com
Date: Mon Nov 7 07:08:54 2011 -0500

(#10570) Use nil in-place of missing attributes

Without this patch, `Fog::Compute::Vsphere#convert_vm_mob_ref_to_attr_hash`
method produces unhandled exceptions during VMware cloning and listing
operations. The root cause of these exceptions are based on the fact
that some VMware virtual machine attributes: hypervisor name, and
macaddress, are not available until the cloning process has finished.

These exceptions can be triggered when external events take place within
the VMware infrastructure such as end-users cloning machines via some
other VMware management tool.

This patch solves the problem by catching any exceptions that occur
during attribute lookups for both the hypervisor name and the virtual
machine macaddress, and setting them to nil.

This patch also removes the host attribute from the hash generated by
the `Fog::Compute::Vsphere#convert_vm_mob_ref_to_attr_hash` method. The
hypervisor attribute is added instead, which is an alias to host.

This patch changes the behaviour of the
`Fog::Compute::Vsphere#convert_vm_mob_ref_to_attr_hash` method by
catching exceptions for missing attributes, and setting them to nil.

commit a65db7f
Author: Kelsey Hightower kelsey@puppetlabs.com
Date: Tue Nov 8 00:47:27 2011 -0500

(#10570) Update `Fog::Compute::Vsphere` tests

Update `Fog::Compute::Vsphere` tests to reflect the way the
`Fog::Compute::Vsphere#convert_vm_mob_ref_to_attr_hash` method currently
converts a `RbVmomi::VIM::ManagedObject` object to a hash.

Without this patch, tests related to converting an instance of
`RbVmomi::VIM::ManagedObject` to a hash will raise an exception:
NoMethodError: undefined method `collect!' for Hash; causing the test to
fail.

This patch solves the problem by mocking `RbVmomi::VIM::ManagedObject`
with a new `MockManagedObject` class, which provides a `collect!`
method, and the `_ref` and `parent` attributes.

This patch renames fake_vm to fake_vm_mob_ref in order to provide a
more descriptive name for what's actually being tested.

The `Fog::Compute::Vshpere::Mock` class has been updated to require the
rbvmomi library, which prevents an `NameError` exception from being raised
due to the `Fog::Compute::Vsphere::Shared::RbVmomi` constant not being
initialized.

The `Fog::Compute::Vshpere::Mock` class has been updated with a
`get_folder_path` method, which prevents a `NoMethodError` exception
from being raised due to the `get_folder_path` method being undefined.

ccaum and others added 3 commits November 7, 2011 13:42
This patch changes how the `list_all_virtual_machine_mobs` method
searches for virtual machines. Previously the search was based on
children of the `dc.vmFolder` object. This makes the false assumption
that all children are virtual machines.

Now the search is based on the entire inventory of the `dc.vmFolder`
object, which gives us more control over what we consider a virtual
machine.

This patch also adds a new `find_all_in_inventory` method; a generic
method that can be used to search an inventory for any VMware object
exposed by RbVmomi. Using `find_all_in_inventory` we are able to
traverse VMware folders and pickout specific VMware object, in this case
`RbVmomi::VIM::VirtualMachine`
This patch adds a new `path` attribute to the vm_mob_ref hash returned
by the `convert_vm_mob_ref_to_attr_hash` method. In order to support the
new `path` attribute, this patch also adds a new `get_folder_path` method
to the `list_virtual_machines` vsphere module.
Without this patch, `Fog::Compute::Vsphere#convert_vm_mob_ref_to_attr_hash`
method produces unhandled exceptions during VMware cloning and listing
operations. The root cause of these exceptions are based on the fact
that some VMware virtual machine attributes: hypervisor name, and
macaddress, are not available until the cloning process has finished.

These exceptions can be triggered when external events take place within
the VMware infrastructure such as end-users cloning machines via some
other VMware management tool.

This patch solves the problem by catching any exceptions that occur
during attribute lookups for both the hypervisor name and the virtual
machine macaddress, and setting them to nil.

This patch also removes the host attribute from the hash generated by
the `Fog::Compute::Vsphere#convert_vm_mob_ref_to_attr_hash` method. The
hypervisor attribute is added instead, which is an alias to host.

This patch changes the behaviour of the
`Fog::Compute::Vsphere#convert_vm_mob_ref_to_attr_hash` method by
catching exceptions for missing attributes, and setting them to nil.
@jeffmccune
Copy link

@kelseyhightower

I'd merge this, but the spec tests need to be updated to pass after this change in behavior. Here's what I'm getting now:

% shindont tests/vsphere/compute_tests.rb

  Skipping tests for bluebox due to lacking credentials (add some to '~/.fog' to run them)
  Skipping tests for brightbox due to lacking credentials (add some to '~/.fog' to run them)
  Skipping tests for dnsimple due to lacking credentials (add some to '~/.fog' to run them)
  Skipping tests for dnsmadeeasy due to lacking credentials (add some to '~/.fog' to run them)
  Skipping tests for dynect due to lacking credentials (add some to '~/.fog' to run them)
  Skipping tests for ecloud due to lacking credentials (add some to '~/.fog' to run them)
  Skipping tests for glesys due to lacking credentials (add some to '~/.fog' to run them)
  Skipping tests for gogrid due to lacking credentials (add some to '~/.fog' to run them)
  Skipping tests for google due to lacking credentials (add some to '~/.fog' to run them)
  Skipping tests for linode due to lacking credentials (add some to '~/.fog' to run them)
  Skipping tests for local due to lacking credentials (add some to '~/.fog' to run them)
  Skipping tests for ninefold due to lacking credentials (add some to '~/.fog' to run them)
  Skipping tests for newservers due to lacking credentials (add some to '~/.fog' to run them)
  Skipping tests for openstack due to lacking credentials (add some to '~/.fog' to run them)
  Skipping tests for rackspace due to lacking credentials (add some to '~/.fog' to run them)
  Skipping tests for slicehost due to lacking credentials (add some to '~/.fog' to run them)
  Skipping tests for stormondemand due to lacking credentials (add some to '~/.fog' to run them)
  Skipping tests for voxel due to lacking credentials (add some to '~/.fog' to run them)
  Skipping tests for zerigo due to lacking credentials (add some to '~/.fog' to run them)

  Fog::Compute[:vsphere] (vsphere)         
        /Users/jeff/vms/puppet/src/fog/tests/vsphere/compute_tests.rb
          When converting an incomplete vm object
          | convert_vm_mob_ref_to_attr_hash
          Fog::Compute[:vsphere] (vsphere)
        - it should return a Hash

        /Users/jeff/vms/puppet/src/fog/tests/vsphere/compute_tests.rb
        undefined method `collect!' for #<OpenStruct _ref="vm-123", runtime=#<OpenStruct>, summary=#<OpenStruct guest=#<OpenStruct>>, name="fakevm"> (NoMethodError)
          /Users/jeff/vms/puppet/src/fog/lib/fog/vsphere/compute.rb:55:in `convert_vm_mob_ref_to_attr_hash'
          /Users/jeff/vms/puppet/src/fog/tests/vsphere/compute_tests.rb:17
          /Users/jeff/.rvm/gems/ruby-1.8.7-p334@ckcp/gems/shindo-0.3.4/bin/../lib/shindo/../shindo.rb:139:in `instance_eval'
          /Users/jeff/.rvm/gems/ruby-1.8.7-p334@ckcp/gems/shindo-0.3.4/bin/../lib/shindo/../shindo.rb:139:in `assert'
          /Users/jeff/.rvm/gems/ruby-1.8.7-p334@ckcp/gems/shindo-0.3.4/bin/../lib/shindo/../shindo.rb:115:in `test'
          /Users/jeff/vms/puppet/src/fog/tests/vsphere/compute_tests.rb:16
          /Users/jeff/.rvm/gems/ruby-1.8.7-p334@ckcp/gems/shindo-0.3.4/bin/../lib/shindo/../shindo.rb:79:in `instance_eval'
          /Users/jeff/.rvm/gems/ruby-1.8.7-p334@ckcp/gems/shindo-0.3.4/bin/../lib/shindo/../shindo.rb:79:in `tests'
          /Users/jeff/vms/puppet/src/fog/tests/vsphere/compute_tests.rb:15
          /Users/jeff/.rvm/gems/ruby-1.8.7-p334@ckcp/gems/shindo-0.3.4/bin/../lib/shindo/../shindo.rb:79:in `instance_eval'
          /Users/jeff/.rvm/gems/ruby-1.8.7-p334@ckcp/gems/shindo-0.3.4/bin/../lib/shindo/../shindo.rb:79:in `tests'
          /Users/jeff/vms/puppet/src/fog/tests/vsphere/compute_tests.rb:5
          /Users/jeff/.rvm/gems/ruby-1.8.7-p334@ckcp/gems/shindo-0.3.4/bin/../lib/shindo/../shindo.rb:79:in `instance_eval'
          /Users/jeff/.rvm/gems/ruby-1.8.7-p334@ckcp/gems/shindo-0.3.4/bin/../lib/shindo/../shindo.rb:79:in `tests'
          /Users/jeff/.rvm/gems/ruby-1.8.7-p334@ckcp/gems/shindo-0.3.4/bin/../lib/shindo/../shindo.rb:38:in `initialize'
          /Users/jeff/.rvm/gems/ruby-1.8.7-p334@ckcp/gems/shindo-0.3.4/bin/../lib/shindo/../shindo.rb:14:in `new'
          /Users/jeff/.rvm/gems/ruby-1.8.7-p334@ckcp/gems/shindo-0.3.4/bin/../lib/shindo/../shindo.rb:14:in `tests'
          /Users/jeff/vms/puppet/src/fog/tests/vsphere/compute_tests.rb:1
          /Users/jeff/.rvm/gems/ruby-1.8.7-p334@ckcp/gems/shindo-0.3.4/bin/../lib/shindo/bin.rb:61:in `load'
          /Users/jeff/.rvm/gems/ruby-1.8.7-p334@ckcp/gems/shindo-0.3.4/bin/../lib/shindo/bin.rb:61:in `run_in_thread'
          /Users/jeff/.rvm/gems/ruby-1.8.7-p334@ckcp/gems/shindo-0.3.4/bin/../lib/shindo/bin.rb:58:in `each'
          /Users/jeff/.rvm/gems/ruby-1.8.7-p334@ckcp/gems/shindo-0.3.4/bin/../lib/shindo/bin.rb:58:in `run_in_thread'
          /Users/jeff/.rvm/gems/ruby-1.8.7-p334@ckcp/gems/shindo-0.3.4/bin/../lib/shindo/bin.rb:49:in `initialize'
          /Users/jeff/.rvm/gems/ruby-1.8.7-p334@ckcp/gems/shindo-0.3.4/bin/../lib/shindo/bin.rb:49:in `new'
          /Users/jeff/.rvm/gems/ruby-1.8.7-p334@ckcp/gems/shindo-0.3.4/bin/../lib/shindo/bin.rb:49:in `run_in_thread'
          /Users/jeff/.rvm/gems/ruby-1.8.7-p334@ckcp/gems/shindo-0.3.4/bin/../lib/shindo/bin.rb:72
          /Users/jeff/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require'
          /Users/jeff/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `require'
          /Users/jeff/.rvm/gems/ruby-1.8.7-p334@ckcp/gems/shindo-0.3.4/bin/shindont:4
          /Users/jeff/.rvm/gems/ruby-1.8.7-p334@ckcp/bin/shindont:19:in `load'
          /Users/jeff/.rvm/gems/ruby-1.8.7-p334@ckcp/bin/shindont:19

          /Users/jeff/vms/puppet/src/fog/tests/vsphere/compute_tests.rb
            The converted Hash should
          undefined method `collect!' for #<OpenStruct _ref="vm-123", runtime=#<OpenStruct>, summary=#<OpenStruct guest=#<OpenStruct>>, name="fakevm"> (NoMethodError)
            /Users/jeff/vms/puppet/src/fog/lib/fog/vsphere/compute.rb:55:in `convert_vm_mob_ref_to_attr_hash'
            /Users/jeff/vms/puppet/src/fog/tests/vsphere/compute_tests.rb:20
            /Users/jeff/.rvm/gems/ruby-1.8.7-p334@ckcp/gems/shindo-0.3.4/bin/../lib/shindo/../shindo.rb:79:in `instance_eval'
            /Users/jeff/.rvm/gems/ruby-1.8.7-p334@ckcp/gems/shindo-0.3.4/bin/../lib/shindo/../shindo.rb:79:in `tests'
            /Users/jeff/vms/puppet/src/fog/tests/vsphere/compute_tests.rb:19
            /Users/jeff/.rvm/gems/ruby-1.8.7-p334@ckcp/gems/shindo-0.3.4/bin/../lib/shindo/../shindo.rb:79:in `instance_eval'
            /Users/jeff/.rvm/gems/ruby-1.8.7-p334@ckcp/gems/shindo-0.3.4/bin/../lib/shindo/../shindo.rb:79:in `tests'
            /Users/jeff/vms/puppet/src/fog/tests/vsphere/compute_tests.rb:15
            /Users/jeff/.rvm/gems/ruby-1.8.7-p334@ckcp/gems/shindo-0.3.4/bin/../lib/shindo/../shindo.rb:79:in `instance_eval'
            /Users/jeff/.rvm/gems/ruby-1.8.7-p334@ckcp/gems/shindo-0.3.4/bin/../lib/shindo/../shindo.rb:79:in `tests'
            /Users/jeff/vms/puppet/src/fog/tests/vsphere/compute_tests.rb:5
            /Users/jeff/.rvm/gems/ruby-1.8.7-p334@ckcp/gems/shindo-0.3.4/bin/../lib/shindo/../shindo.rb:79:in `instance_eval'
            /Users/jeff/.rvm/gems/ruby-1.8.7-p334@ckcp/gems/shindo-0.3.4/bin/../lib/shindo/../shindo.rb:79:in `tests'
            /Users/jeff/.rvm/gems/ruby-1.8.7-p334@ckcp/gems/shindo-0.3.4/bin/../lib/shindo/../shindo.rb:38:in `initialize'
            /Users/jeff/.rvm/gems/ruby-1.8.7-p334@ckcp/gems/shindo-0.3.4/bin/../lib/shindo/../shindo.rb:14:in `new'
            /Users/jeff/.rvm/gems/ruby-1.8.7-p334@ckcp/gems/shindo-0.3.4/bin/../lib/shindo/../shindo.rb:14:in `tests'
            /Users/jeff/vms/puppet/src/fog/tests/vsphere/compute_tests.rb:1
            /Users/jeff/.rvm/gems/ruby-1.8.7-p334@ckcp/gems/shindo-0.3.4/bin/../lib/shindo/bin.rb:61:in `load'
            /Users/jeff/.rvm/gems/ruby-1.8.7-p334@ckcp/gems/shindo-0.3.4/bin/../lib/shindo/bin.rb:61:in `run_in_thread'
            /Users/jeff/.rvm/gems/ruby-1.8.7-p334@ckcp/gems/shindo-0.3.4/bin/../lib/shindo/bin.rb:58:in `each'
            /Users/jeff/.rvm/gems/ruby-1.8.7-p334@ckcp/gems/shindo-0.3.4/bin/../lib/shindo/bin.rb:58:in `run_in_thread'
            /Users/jeff/.rvm/gems/ruby-1.8.7-p334@ckcp/gems/shindo-0.3.4/bin/../lib/shindo/bin.rb:49:in `initialize'
            /Users/jeff/.rvm/gems/ruby-1.8.7-p334@ckcp/gems/shindo-0.3.4/bin/../lib/shindo/bin.rb:49:in `new'
            /Users/jeff/.rvm/gems/ruby-1.8.7-p334@ckcp/gems/shindo-0.3.4/bin/../lib/shindo/bin.rb:49:in `run_in_thread'
            /Users/jeff/.rvm/gems/ruby-1.8.7-p334@ckcp/gems/shindo-0.3.4/bin/../lib/shindo/bin.rb:72
            /Users/jeff/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require'
            /Users/jeff/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `require'
            /Users/jeff/.rvm/gems/ruby-1.8.7-p334@ckcp/gems/shindo-0.3.4/bin/shindont:4
            /Users/jeff/.rvm/gems/ruby-1.8.7-p334@ckcp/bin/shindont:19:in `load'
            /Users/jeff/.rvm/gems/ruby-1.8.7-p334@ckcp/bin/shindont:19
++++++  
  1 failed, 6 succeeded in 0.505181 seconds

@kelseyhightower
Copy link
Author

Let me take a look that, fix it, and add the additional commit to this pull request.

@jeffmccune
Copy link

@kelseyhightower Here's the full run of vsphere tests with FOG_MOCK turned on.

% FOG_MOCK=true shindont tests/vsphere/**/*_tests.rb


  Fog::Compute[:vsphere] (vsphere)         
        /Users/jeff/vms/puppet/src/fog/tests/vsphere/compute_tests.rb
          When converting an incomplete vm object
          | convert_vm_mob_ref_to_attr_hash
          Fog::Compute[:vsphere] (vsphere)
        - it should return a Hash

        /Users/jeff/vms/puppet/src/fog/tests/vsphere/compute_tests.rb
        undefined method `collect!' for #<OpenStruct _ref="vm-123", runtime=#<OpenStruct>, summary=#<OpenStruct guest=#<OpenStruct>>, name="fakevm"> (NoMethodError)
          /Users/jeff/vms/puppet/src/fog/lib/fog/vsphere/compute.rb:55:in `convert_vm_mob_ref_to_attr_hash'
          /Users/jeff/vms/puppet/src/fog/tests/vsphere/compute_tests.rb:17
          /Users/jeff/.rvm/gems/ruby-1.8.7-p334@ckcp/gems/shindo-0.3.4/bin/../lib/shindo/../shindo.rb:139:in `instance_eval'
          /Users/jeff/.rvm/gems/ruby-1.8.7-p334@ckcp/gems/shindo-0.3.4/bin/../lib/shindo/../shindo.rb:139:in `assert'
          /Users/jeff/.rvm/gems/ruby-1.8.7-p334@ckcp/gems/shindo-0.3.4/bin/../lib/shindo/../shindo.rb:115:in `test'
          /Users/jeff/vms/puppet/src/fog/tests/vsphere/compute_tests.rb:16
          /Users/jeff/.rvm/gems/ruby-1.8.7-p334@ckcp/gems/shindo-0.3.4/bin/../lib/shindo/../shindo.rb:79:in `instance_eval'
          /Users/jeff/.rvm/gems/ruby-1.8.7-p334@ckcp/gems/shindo-0.3.4/bin/../lib/shindo/../shindo.rb:79:in `tests'
          /Users/jeff/vms/puppet/src/fog/tests/vsphere/compute_tests.rb:15
          /Users/jeff/.rvm/gems/ruby-1.8.7-p334@ckcp/gems/shindo-0.3.4/bin/../lib/shindo/../shindo.rb:79:in `instance_eval'
          /Users/jeff/.rvm/gems/ruby-1.8.7-p334@ckcp/gems/shindo-0.3.4/bin/../lib/shindo/../shindo.rb:79:in `tests'
          /Users/jeff/vms/puppet/src/fog/tests/vsphere/compute_tests.rb:5
          /Users/jeff/.rvm/gems/ruby-1.8.7-p334@ckcp/gems/shindo-0.3.4/bin/../lib/shindo/../shindo.rb:79:in `instance_eval'
          /Users/jeff/.rvm/gems/ruby-1.8.7-p334@ckcp/gems/shindo-0.3.4/bin/../lib/shindo/../shindo.rb:79:in `tests'
          /Users/jeff/.rvm/gems/ruby-1.8.7-p334@ckcp/gems/shindo-0.3.4/bin/../lib/shindo/../shindo.rb:38:in `initialize'
          /Users/jeff/.rvm/gems/ruby-1.8.7-p334@ckcp/gems/shindo-0.3.4/bin/../lib/shindo/../shindo.rb:14:in `new'
          /Users/jeff/.rvm/gems/ruby-1.8.7-p334@ckcp/gems/shindo-0.3.4/bin/../lib/shindo/../shindo.rb:14:in `tests'
          /Users/jeff/vms/puppet/src/fog/tests/vsphere/compute_tests.rb:1
          /Users/jeff/.rvm/gems/ruby-1.8.7-p334@ckcp/gems/shindo-0.3.4/bin/../lib/shindo/bin.rb:61:in `load'
          /Users/jeff/.rvm/gems/ruby-1.8.7-p334@ckcp/gems/shindo-0.3.4/bin/../lib/shindo/bin.rb:61:in `run_in_thread'
          /Users/jeff/.rvm/gems/ruby-1.8.7-p334@ckcp/gems/shindo-0.3.4/bin/../lib/shindo/bin.rb:58:in `each'
          /Users/jeff/.rvm/gems/ruby-1.8.7-p334@ckcp/gems/shindo-0.3.4/bin/../lib/shindo/bin.rb:58:in `run_in_thread'
          /Users/jeff/.rvm/gems/ruby-1.8.7-p334@ckcp/gems/shindo-0.3.4/bin/../lib/shindo/bin.rb:49:in `initialize'
          /Users/jeff/.rvm/gems/ruby-1.8.7-p334@ckcp/gems/shindo-0.3.4/bin/../lib/shindo/bin.rb:49:in `new'
          /Users/jeff/.rvm/gems/ruby-1.8.7-p334@ckcp/gems/shindo-0.3.4/bin/../lib/shindo/bin.rb:49:in `run_in_thread'
          /Users/jeff/.rvm/gems/ruby-1.8.7-p334@ckcp/gems/shindo-0.3.4/bin/../lib/shindo/bin.rb:72
          /Users/jeff/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require'
          /Users/jeff/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `require'
          /Users/jeff/.rvm/gems/ruby-1.8.7-p334@ckcp/gems/shindo-0.3.4/bin/shindont:4
          /Users/jeff/.rvm/gems/ruby-1.8.7-p334@ckcp/bin/shindont:19:in `load'
          /Users/jeff/.rvm/gems/ruby-1.8.7-p334@ckcp/bin/shindont:19

          /Users/jeff/vms/puppet/src/fog/tests/vsphere/compute_tests.rb
            The converted Hash should
          undefined method `collect!' for #<OpenStruct _ref="vm-123", runtime=#<OpenStruct>, summary=#<OpenStruct guest=#<OpenStruct>>, name="fakevm"> (NoMethodError)
            /Users/jeff/vms/puppet/src/fog/lib/fog/vsphere/compute.rb:55:in `convert_vm_mob_ref_to_attr_hash'
            /Users/jeff/vms/puppet/src/fog/tests/vsphere/compute_tests.rb:20
            /Users/jeff/.rvm/gems/ruby-1.8.7-p334@ckcp/gems/shindo-0.3.4/bin/../lib/shindo/../shindo.rb:79:in `instance_eval'
            /Users/jeff/.rvm/gems/ruby-1.8.7-p334@ckcp/gems/shindo-0.3.4/bin/../lib/shindo/../shindo.rb:79:in `tests'
            /Users/jeff/vms/puppet/src/fog/tests/vsphere/compute_tests.rb:19
            /Users/jeff/.rvm/gems/ruby-1.8.7-p334@ckcp/gems/shindo-0.3.4/bin/../lib/shindo/../shindo.rb:79:in `instance_eval'
            /Users/jeff/.rvm/gems/ruby-1.8.7-p334@ckcp/gems/shindo-0.3.4/bin/../lib/shindo/../shindo.rb:79:in `tests'
            /Users/jeff/vms/puppet/src/fog/tests/vsphere/compute_tests.rb:15
            /Users/jeff/.rvm/gems/ruby-1.8.7-p334@ckcp/gems/shindo-0.3.4/bin/../lib/shindo/../shindo.rb:79:in `instance_eval'
            /Users/jeff/.rvm/gems/ruby-1.8.7-p334@ckcp/gems/shindo-0.3.4/bin/../lib/shindo/../shindo.rb:79:in `tests'
            /Users/jeff/vms/puppet/src/fog/tests/vsphere/compute_tests.rb:5
            /Users/jeff/.rvm/gems/ruby-1.8.7-p334@ckcp/gems/shindo-0.3.4/bin/../lib/shindo/../shindo.rb:79:in `instance_eval'
            /Users/jeff/.rvm/gems/ruby-1.8.7-p334@ckcp/gems/shindo-0.3.4/bin/../lib/shindo/../shindo.rb:79:in `tests'
            /Users/jeff/.rvm/gems/ruby-1.8.7-p334@ckcp/gems/shindo-0.3.4/bin/../lib/shindo/../shindo.rb:38:in `initialize'
            /Users/jeff/.rvm/gems/ruby-1.8.7-p334@ckcp/gems/shindo-0.3.4/bin/../lib/shindo/../shindo.rb:14:in `new'
            /Users/jeff/.rvm/gems/ruby-1.8.7-p334@ckcp/gems/shindo-0.3.4/bin/../lib/shindo/../shindo.rb:14:in `tests'
            /Users/jeff/vms/puppet/src/fog/tests/vsphere/compute_tests.rb:1
            /Users/jeff/.rvm/gems/ruby-1.8.7-p334@ckcp/gems/shindo-0.3.4/bin/../lib/shindo/bin.rb:61:in `load'
            /Users/jeff/.rvm/gems/ruby-1.8.7-p334@ckcp/gems/shindo-0.3.4/bin/../lib/shindo/bin.rb:61:in `run_in_thread'
            /Users/jeff/.rvm/gems/ruby-1.8.7-p334@ckcp/gems/shindo-0.3.4/bin/../lib/shindo/bin.rb:58:in `each'
            /Users/jeff/.rvm/gems/ruby-1.8.7-p334@ckcp/gems/shindo-0.3.4/bin/../lib/shindo/bin.rb:58:in `run_in_thread'
            /Users/jeff/.rvm/gems/ruby-1.8.7-p334@ckcp/gems/shindo-0.3.4/bin/../lib/shindo/bin.rb:49:in `initialize'
            /Users/jeff/.rvm/gems/ruby-1.8.7-p334@ckcp/gems/shindo-0.3.4/bin/../lib/shindo/bin.rb:49:in `new'
            /Users/jeff/.rvm/gems/ruby-1.8.7-p334@ckcp/gems/shindo-0.3.4/bin/../lib/shindo/bin.rb:49:in `run_in_thread'
            /Users/jeff/.rvm/gems/ruby-1.8.7-p334@ckcp/gems/shindo-0.3.4/bin/../lib/shindo/bin.rb:72
            /Users/jeff/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require'
            /Users/jeff/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `require'
            /Users/jeff/.rvm/gems/ruby-1.8.7-p334@ckcp/gems/shindo-0.3.4/bin/shindont:4
            /Users/jeff/.rvm/gems/ruby-1.8.7-p334@ckcp/bin/shindont:19:in `load'
            /Users/jeff/.rvm/gems/ruby-1.8.7-p334@ckcp/bin/shindont:19
++++++  
  Fog::Compute[:vsphere] | server model (vsphere) ++++++++++++++++++++++++++++++++++++++++  
  Fog::Compute[:vsphere] | servers collection (vsphere) +++++  
  Fog::Compute[:vsphere] | current_time request (vsphere) +++  
  Fog::Compute[:vsphere] | find_vm_by_ref request (vsphere) ++++++++  
  Fog::Compute[:vsphere] | list_virtual_machines request (vsphere) ++++++++  
  Fog::Compute[:servers] | vm_clone request +++++#  
  Fog::Compute[:vsphere] | vm_destroy request (vsphere) +++  
  Fog::Compute[:vsphere] | vm_power_off request (vsphere) ++++++  
  Fog::Compute[:vsphere] | vm_power_on request (vsphere) +++  
  Fog::Compute[:vsphere] | vm_reboot request (vsphere) ++++++  
  1 failed, 1 pending, 93 succeeded in 0.16869 seconds

@kelseyhightower
Copy link
Author

I may need to mock fake_vm to bring it a little closer to actual vm_mob_ref, we are mainly not responding to the collect! method, so it seems that vm_mob_ref provides an Array like interface.

Update `Fog::Compute::Vsphere` tests to reflect the way the
`Fog::Compute::Vsphere#convert_vm_mob_ref_to_attr_hash` method currently
converts a `RbVmomi::VIM::ManagedObject` object to a hash.

Without this patch, tests related to converting an instance of
`RbVmomi::VIM::ManagedObject` to a hash will raise an exception:
NoMethodError: undefined method `collect!' for Hash; causing the test to
fail.

This patch solves the problem by mocking `RbVmomi::VIM::ManagedObject`
with a new `MockManagedObject` class, which provides a `collect!`
method, and the `_ref` and `parent` attributes.

This patch renames fake_vm to fake_vm_mob_ref in order to provide a
more descriptive name for what's actually being tested.

The `Fog::Compute::Vshpere::Mock` class has been updated to require the
rbvmomi library, which prevents an `NameError` exception from being raised
due to the `Fog::Compute::Vsphere::Shared::RbVmomi` constant not being
initialized.

The `Fog::Compute::Vshpere::Mock` class has been updated with a
`get_folder_path` method, which prevents a `NoMethodError` exception
from being raised due to the `get_folder_path` method being undefined.
@kelseyhightower
Copy link
Author

All vSphere tests are passing now \o/

$ FOG_MOCK=true shindont tests/vsphere/*

  Fog::Compute[:vsphere] (vsphere) +++++++++++  
  Fog::Compute[:vsphere] | server model (vsphere) ++++++++++++++++++++++++++++++++++++++++  
  Fog::Compute[:vsphere] | servers collection (vsphere) +++++  
  Fog::Compute[:vsphere] | current_time request (vsphere) +++  
  Fog::Compute[:vsphere] | find_vm_by_ref request (vsphere) ++++++++  
  Fog::Compute[:vsphere] | list_virtual_machines request (vsphere) ++++++++  
  Fog::Compute[:servers] | vm_clone request +++++#  
  Fog::Compute[:vsphere] | vm_destroy request (vsphere) +++  
  Fog::Compute[:vsphere] | vm_power_off request (vsphere) ++++++  
  Fog::Compute[:vsphere] | vm_power_on request (vsphere) +++  
  Fog::Compute[:vsphere] | vm_reboot request (vsphere) ++++++  
 1 pending, 98 succeeded in 0.541899 seconds

@jeffmccune
Copy link

Great, this looks good Kelsey.

@geemus there's a change in behavior here that requires the rbvmomi gem to run the spec tests now. Previously, when using FOG_MOCK=true all of the mocked requests returned data structures that didn't require the rbvmomi gem to run.

Are you OK with this change in behavior?

-Jeff

@geemus
Copy link
Member

geemus commented Nov 8, 2011

@jeffmccune - Yeah, I think it is ok to have more requirements for dev than release. I think there may be a couple other places where this already appears. It sounds like that is the best way to provide this kind of stuff, so go for it.

@kelseyhightower
Copy link
Author

Sweet!

@jeffmccune
Copy link

Cool, merging this request then as I don't have any other outstanding comments. This also brings Fog in line with Puppet Enterprise. @geemus, if you do a release this week we'll likely include that release in PE rather than v1.0.0.

-Jeff

jeffmccune pushed a commit that referenced this pull request Nov 8, 2011
…nil_for_missing_attributes

vSphere usability improvements
@jeffmccune jeffmccune merged commit 59475b3 into fog:master Nov 8, 2011
@geemus
Copy link
Member

geemus commented Nov 8, 2011

Cool, I was hoping to get a release done this week anyway. So
hopefully we can make all the stars align for you.

On Tue, Nov 8, 2011 at 15:57, Jeff McCune
reply@reply.github.com
wrote:

Cool, merging this request then as I don't have any other outstanding comments.  This also brings Fog in line with Puppet Enterprise.  @geemus, if you do a release this week we'll likely include that release in PE rather than v1.0.0.

-Jeff


Reply to this email directly or view it on GitHub:
#592 (comment)

@geemus
Copy link
Member

geemus commented Nov 9, 2011

Hey guys, I'm getting YAML parse errors when I try to run the mocked tests under 1.9.2. Here is a stack trace:

Fog::Compute[:vsphere] | server model (vsphere) /Users/geemus/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/psych.rb:148:in `parse': couldn't parse YAML at line 2 column 30 (Psych::SyntaxError)
from /Users/geemus/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/psych.rb:148:in `parse_stream'
from /Users/geemus/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/psych.rb:119:in `parse'
from /Users/geemus/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/psych.rb:106:in `load'
from /Users/geemus/geemus/fog/lib/fog/vsphere/requests/compute/list_virtual_machines.rb:96:in `list_virtual_machines'
from /Users/geemus/geemus/fog/lib/fog/vsphere/models/compute/servers.rb:13:in `all'
from /Users/geemus/geemus/fog/lib/fog/core/collection.rb:131:in `lazy_load'
from /Users/geemus/geemus/fog/lib/fog/core/collection.rb:18:in `last'
from tests/vsphere/models/compute/server_tests.rb:4:in `block in <top (required)>'
from /Users/geemus/.rvm/gems/ruby-1.9.2-p290/gems/shindo-0.3.4/lib/shindo.rb:79:in `instance_eval'
from /Users/geemus/.rvm/gems/ruby-1.9.2-p290/gems/shindo-0.3.4/lib/shindo.rb:79:in `tests'
from /Users/geemus/.rvm/gems/ruby-1.9.2-p290/gems/shindo-0.3.4/lib/shindo.rb:38:in `initialize'
from /Users/geemus/.rvm/gems/ruby-1.9.2-p290/gems/shindo-0.3.4/lib/shindo.rb:14:in `new'
from /Users/geemus/.rvm/gems/ruby-1.9.2-p290/gems/shindo-0.3.4/lib/shindo.rb:14:in `tests'
from tests/vsphere/models/compute/server_tests.rb:1:in `<top (required)>'
from /Users/geemus/.rvm/gems/ruby-1.9.2-p290/gems/shindo-0.3.4/lib/shindo/bin.rb:61:in `load'
from /Users/geemus/.rvm/gems/ruby-1.9.2-p290/gems/shindo-0.3.4/lib/shindo/bin.rb:61:in `block (2 levels) in run_in_thread'
from /Users/geemus/.rvm/gems/ruby-1.9.2-p290/gems/shindo-0.3.4/lib/shindo/bin.rb:58:in `each'
from /Users/geemus/.rvm/gems/ruby-1.9.2-p290/gems/shindo-0.3.4/lib/shindo/bin.rb:58:in `block in run_in_thread'

I looked and it wasn't obvious to me what was wrong (and I didn't want to invalidate the tests by just changing something if it would then be less reflective of reality). It might be simpler to just remove the yaml and have the resulting ruby hash there directly (but this might also make it harder to keep up to date. I leave how to fix it in your hands, but if you could get it going for 1.9.2 that would be awesome, thanks!

@kelseyhightower
Copy link
Author

Taking a look at this now.

@kelseyhightower
Copy link
Author

So I have ran the vSphere tests in isolation on ruby 1.9.2p290

kelseyhightower$ which ruby
/Users/kelseyhightower/.rvm/rubies/ruby-1.9.2-p290/bin/ruby

kelseyhightower$ ruby --version
ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin11.2.0]

kelseyhightower$ FOG_MOCK=true shindont tests/vsphere/*

Fog::Compute[:vsphere] (vsphere) +++++++++++  
Fog::Compute[:vsphere] | server model (vsphere) ++++++++++++++++++++++++++++++++++++++++  
Fog::Compute[:vsphere] | servers collection (vsphere) +++++  
Fog::Compute[:vsphere] | current_time request (vsphere) +++  
Fog::Compute[:vsphere] | find_vm_by_ref request (vsphere) ++++++++  
Fog::Compute[:vsphere] | list_virtual_machines request (vsphere) ++++++++  
Fog::Compute[:servers] | vm_clone request +++++#  
Fog::Compute[:vsphere] | vm_destroy request (vsphere) +++  
Fog::Compute[:vsphere] | vm_power_off request (vsphere) ++++++  
Fog::Compute[:vsphere] | vm_power_on request (vsphere) +++  
Fog::Compute[:vsphere] | vm_reboot request (vsphere) ++++++  
1 pending, 98 succeeded in 0.700222 seconds

Can you provide the command you are running so I can attempt to reproduce this?

@kelseyhightower
Copy link
Author

I have also ran the tests following the instructions at fog.io:

kelseyhightower$ bundle exec rake

export FOG_MOCK=true && bundle exec spec spec

Pending:

Ecloud should == "192.168.0.1" (TODO)
/Users/kelseyhightower/Workspace/fog/spec/ecloud/bin_spec.rb:5:in `block in <top (required)>'

Ecloud when indexing it like an array with a service that exists should return something when indexed with a configured service (TODO)
/Users/kelseyhightower/Workspace/fog/spec/ecloud/bin_spec.rb:14:in `block (3 levels) in <top (required)>'

Ecloud when indexing it like an array with a service that does not exist should raise an ArgumentError (TODO)
/Users/kelseyhightower/Workspace/fog/spec/ecloud/bin_spec.rb:21:in `block (3 levels) in <top (required)>'

Finished in 9.093394 seconds

795 examples, 0 failures, 3 pending

rake aborted!
undefined method `downcase' for [:aws, "AWS"]:Array

Tasks: TOP => mock_tests
(See full trace by running task with --trace)

It seems I am getting another set of errors.

@geemus
Copy link
Member

geemus commented Nov 9, 2011

Hmm. Now when I run them they succeed :( I must have either not been totally up to date or accidentally introduced something locally or something. Sorry about the confusion, but thanks for the quick response. I'll keep plugging away at the rest of the tests and release process.

@kelseyhightower
Copy link
Author

Cool, let us know.

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

4 participants