fog / fog-openstack

Fog for OpenStack Platform
MIT License
67 stars 130 forks source link

Cannot test with Identity V3 #159

Open imriz opened 8 years ago

imriz commented 8 years ago

Since version 0.1.6, my tests fails with the following error:

2.2.1 :005 > Fog.mock!
 => true 
2.2.1 :006 > options = {:nics=>[""], :flavor_ref=>"foo_flavor", :image_ref=>"foo_image",:name => 'test'} 
 => {:nics=>[""], :flavor_ref=>"foo_flavor", :image_ref=>"foo_image", :name=>"test"} 
2.2.1 :007 > @connection_params = {
2.2.1 :008 >       openstack_auth_url:     "http://devstack.test:5000/v3/auth/tokens",
2.2.1 :009 >       openstack_username:     "admin",
2.2.1 :010 >       openstack_api_key:      "password",
2.2.1 :011 >       openstack_project_name: "admin",
2.2.1 :012 >       openstack_domain_id:    "default"
2.2.1 :013?>   }
 => {:openstack_auth_url=>"http://devstack.test:5000/v3/auth/tokens", :openstack_username=>"admin", :openstack_api_key=>"password", :openstack_project_name=>"admin", :openstack_domain_id=>"default"} 
2.2.1 :014 > compute = Fog::Compute::OpenStack.new(@connection_params)
 => #<Fog::Compute::OpenStack::Mock:0x00000003eaa288 @auth_token="lG+Gcuat8YbhZkADll1JGVukjhohIpQFf13s+TBJPYvWiD7tFhggHf9X6Or81RWI", @auth_token_expiration="2016-07-16T07:33:30Z", @openstack_auth_url="http://devstack.test:5000/v3/auth/tokens", @openstack_username="admin", @openstack_api_key="password", @openstack_project_name="admin", @openstack_domain_id="default", @openstack_identity_public_endpoint="http://devstack.test:5000/v3/auth/tokens", @openstack_auth_uri=#<URI::HTTP http://devstack.test:5000/v3/auth/tokens>, @openstack_must_reauthenticate=false, @openstack_endpoint_type="publicURL", @openstack_cache_ttl=0, @openstack_can_reauthenticate=false, @current_user=nil, @current_user_id=nil, @current_tenant=nil, @openstack_management_url="http://devstack.test:8774/v1.1/1"> 
2.2.1 :015 > compute.servers.create options
NoMethodError: undefined method `body' for nil:NilClass
        from /home/imriz/.rvm/gems/ruby-2.2.1@foreman/gems/fog-openstack-0.1.8/lib/fog/openstack/models/collection.rb:12:in `load_response'
        from /home/imriz/.rvm/gems/ruby-2.2.1@foreman/gems/fog-openstack-0.1.8/lib/fog/openstack/models/identity_v3/users.rb:12:in `all'
        from /home/imriz/.rvm/gems/ruby-2.2.1@foreman/gems/fog-core-1.42.0/lib/fog/core/collection.rb:113:in `lazy_load'
        from /home/imriz/.rvm/gems/ruby-2.2.1@foreman/gems/fog-core-1.42.0/lib/fog/core/collection.rb:17:in `each'
        from /home/imriz/.rvm/gems/ruby-2.2.1@foreman/gems/fog-openstack-0.1.8/lib/fog/openstack/requests/compute/create_server.rb:98:in `find'
        from /home/imriz/.rvm/gems/ruby-2.2.1@foreman/gems/fog-openstack-0.1.8/lib/fog/openstack/requests/compute/create_server.rb:98:in `create_server'
        from /home/imriz/.rvm/gems/ruby-2.2.1@foreman/gems/fog-openstack-0.1.8/lib/fog/openstack/models/compute/server.rb:375:in `save'
        from /home/imriz/.rvm/gems/ruby-2.2.1@foreman/gems/fog-core-1.42.0/lib/fog/core/collection.rb:51:in `create'
        from (irb):15
        from /home/imriz/.rvm/rubies/ruby-2.2.1/bin/irb:11:in `<main>'

If I set the URL to v2.0, it works fine.

What am I doing wrong?

imriz commented 8 years ago

Seems mocking is just not implemented yet for V3?

danleyden commented 7 years ago

This had me stumped for a good while too...

It appears that the new default is to use identity v3 unless the url provided contains v2.0. There is a call when creating servers that in compute that goes through and tries to list_servers and fails with the 'undefined method body' error. It fails in this way because there is a mock implementation for that method with identity V3, but it returns nil instead of the excon response.

At the very least, the mock should return a 'not implemented' error (so users can easier understand the issue) or a valid response of some kind. Ideally it would behave similarly to the V2 mock and return based on mocked data.

Carthaca commented 7 years ago

Correct, it comes down to the fact that https://github.com/fog/fog-openstack/blob/master/lib/fog/identity/openstack/v3/requests/list_users.rb#L17 does not return the mocked users

I would be happy to review if someone provides a PR for that :)