vmware-archive / vsphere-automation-sdk-ruby

DEPRECATED Ruby samples, language bindings, and API reference documentation for vSphere using the VMware REST API
MIT License
31 stars 12 forks source link

Problem with Boolean types after update to 0.2.0 #51

Closed smoeding closed 5 years ago

smoeding commented 5 years ago

Describe the bug

After the update to 0.2.0 I get internal failures from the gems. For example the ClusterApi throws the following error:

/vcenter/vendor/bundle/ruby/2.3.0/gems/vsphere-automation-vcenter-0.2.0/lib/vsphere-automation-vcenter/models/vcenter_cluster_summary.rb:184:in `const_get': unin\
itialized constant VSphereAutomation::VCenter::Boolean (NameError)

How to reproduce

Use the following code to list the clusters:

#!/usr/bin/ruby

require 'bundler/setup'

require 'vsphere-automation-cis'
require 'vsphere-automation-vcenter'
require 'pp'

configuration = VSphereAutomation::Configuration.new.tap do |c|
  c.host            = 'vcenter.test.local'
  c.username        = 'xxx'
  c.password        = 'yyy'
  c.verify_ssl      = false
  c.verify_ssl_host = false
end

api_client = VSphereAutomation::ApiClient.new(configuration)
api_client.default_headers['Authorization'] = configuration.basic_auth_token

session_api = VSphereAutomation::CIS::SessionApi.new(api_client)
session_id = session_api.create('').value

api_client.default_headers['vmware-api-session-id'] = session_id

pp VSphereAutomation::VCenter::ClusterApi.new(api_client).list()

Expected behavior

With release 0.1.0 of the gems I get the following output:

$ bundle exec ./cl.rb
#<VSphereAutomation::VCenter::VcenterClusterListResult:0x0055716f08fa80
 @value=
  [#<VSphereAutomation::VCenter::VcenterClusterSummary:0x0055716f08f7d8
    @cluster="domain-c103",
    @drs_enabled=true,
    @ha_enabled=true,
    @name="Test">,
   #<VSphereAutomation::VCenter::VcenterClusterSummary:0x0055716f08ef90
    @cluster="domain-c227",
    @drs_enabled=true,
    @ha_enabled=true,
    @name="Virt-Test">]>

Now update the gems to 0.2.0:

$ bundle update
Fetching source index from https://rubygems.org/
Resolving dependencies...
Using ffi 1.11.1
Using text-table 1.2.4
Using bundler 1.13.6
Using ethon 0.12.0
Using typhoeus 1.3.1
Installing vsphere-automation-runtime 0.2.0
Installing vsphere-automation-cis 0.2.0 (was 0.1.0)
Installing vsphere-automation-appliance 0.2.0 (was 0.1.0)
Installing vsphere-automation-content 0.2.0 (was 0.1.0)
Installing vsphere-automation-vapi 0.2.0 (was 0.1.0)
Installing vsphere-automation-vcenter 0.2.0 (was 0.1.0)
Installing vsphere-automation-sdk 0.2.0
Bundle updated!

Run again:

$ bundle exec ./cl.rb
/vcenter/vendor/bundle/ruby/2.3.0/gems/vsphere-automation-vcenter-0.2.0/lib/vsphere-automation-vcenter/models/vcenter_cluster_summary.rb:184:in `const_get': unin\
itialized constant VSphereAutomation::VCenter::Boolean (NameError)
        from /vcenter/vendor/bundle/ruby/2.3.0/gems/vsphere-automation-vcenter-0.2.0/lib/vsphere-automation-vcenter/models/vcenter_cluster_summary.rb:184:in `_de\
serialize'
        from /vcenter/vendor/bundle/ruby/2.3.0/gems/vsphere-automation-vcenter-0.2.0/lib/vsphere-automation-vcenter/models/vcenter_cluster_summary.rb:140:in `blo\
ck in build_from_hash'
        from /vcenter/vendor/bundle/ruby/2.3.0/gems/vsphere-automation-vcenter-0.2.0/lib/vsphere-automation-vcenter/models/vcenter_cluster_summary.rb:132:in `eac\
h_pair'
        from /vcenter/vendor/bundle/ruby/2.3.0/gems/vsphere-automation-vcenter-0.2.0/lib/vsphere-automation-vcenter/models/vcenter_cluster_summary.rb:132:in `bui\
ld_from_hash'
        from /vcenter/vendor/bundle/ruby/2.3.0/gems/vsphere-automation-vcenter-0.2.0/lib/vsphere-automation-vcenter/models/vcenter_cluster_list_result.rb:141:in \
`_deserialize'
        from /vcenter/vendor/bundle/ruby/2.3.0/gems/vsphere-automation-vcenter-0.2.0/lib/vsphere-automation-vcenter/models/vcenter_cluster_list_result.rb:93:in `\
block (2 levels) in build_from_hash'
        from /vcenter/vendor/bundle/ruby/2.3.0/gems/vsphere-automation-vcenter-0.2.0/lib/vsphere-automation-vcenter/models/vcenter_cluster_list_result.rb:93:in `\
map'
        from /vcenter/vendor/bundle/ruby/2.3.0/gems/vsphere-automation-vcenter-0.2.0/lib/vsphere-automation-vcenter/models/vcenter_cluster_list_result.rb:93:in `\
block in build_from_hash'
        from /vcenter/vendor/bundle/ruby/2.3.0/gems/vsphere-automation-vcenter-0.2.0/lib/vsphere-automation-vcenter/models/vcenter_cluster_list_result.rb:88:in `\
each_pair'
        from /vcenter/vendor/bundle/ruby/2.3.0/gems/vsphere-automation-vcenter-0.2.0/lib/vsphere-automation-vcenter/models/vcenter_cluster_list_result.rb:88:in `\
build_from_hash'
        from /vcenter/vendor/bundle/ruby/2.3.0/gems/vsphere-automation-runtime-0.2.0/lib/vsphere-automation-runtime/api_client.rb:215:in `block in convert_to_typ\
e'
        from /vcenter/vendor/bundle/ruby/2.3.0/gems/vsphere-automation-runtime-0.2.0/lib/vsphere-automation-runtime/api_client.rb:214:in `tap'
        from /vcenter/vendor/bundle/ruby/2.3.0/gems/vsphere-automation-runtime-0.2.0/lib/vsphere-automation-runtime/api_client.rb:214:in `convert_to_type'
        from /vcenter/vendor/bundle/ruby/2.3.0/gems/vsphere-automation-runtime-0.2.0/lib/vsphere-automation-runtime/api_client.rb:175:in `deserialize'
        from /vcenter/vendor/bundle/ruby/2.3.0/gems/vsphere-automation-runtime-0.2.0/lib/vsphere-automation-runtime/api_client.rb:71:in `call_api'
        from /vcenter/vendor/bundle/ruby/2.3.0/gems/vsphere-automation-vcenter-0.2.0/lib/vsphere-automation-vcenter/api/cluster_api.rb:121:in `list_with_http_inf\
o'
        from /vcenter/vendor/bundle/ruby/2.3.0/gems/vsphere-automation-vcenter-0.2.0/lib/vsphere-automation-vcenter/api/cluster_api.rb:84:in `list'
        from ./cl.rb:25:in `<main>'

Versions

Dev Environment:

Additional notes

The file where the error occurs has been changed just recently: vcenter/lib/vsphere-automation-vcenter/models/vcenter_cluster_summary.rb

For the 0.2.0 release the lines 41/42 have been changed from

        :'ha_enabled' => :'BOOLEAN',
        :'drs_enabled' => :'BOOLEAN'

to

        :'ha_enabled' => :'Boolean',
        :'drs_enabled' => :'Boolean'

At the same time line 163 still reads:

      when :BOOLEAN

I guess this mismatch causes the code to fall through the WHEN condition and therefore the execution reaches lines 183ff:

      else # model
        temp_model = VSphereAutomation::VCenter.const_get(type).new
        temp_model.build_from_hash(value)

This is the place where the error to terminate the program is thrown.

jrgarcia commented 5 years ago

I just ran into that as well. I'll have a new release with the fix as soon as possible.

jrgarcia commented 5 years ago

@smoeding Released 0.2.1 which should fix this issue. I tested it with your sample and it's working fine. Let me know if this release fixes the issue for you. Thanks for reporting!

smoeding commented 5 years ago

@jrgarcia Thanks for the quick fix. Looks good to me!

jrgarcia commented 5 years ago

@smoeding By the way, you no longer have to jump through hoops with the authentication. Check out a sample I updated here. You no longer have to set the basic_auth yourself and if you create a session, you no longer have to store the session_id and set it in the headers.

smoeding commented 5 years ago

@jrgarcia I saw the sample code when I tried to find the cause for the error. Looks definitely better than the old code. For the example I just wanted to make sure the code would run on 0.1.0.

But I did update my code for the project... 👍