fog-openstack icon indicating copy to clipboard operation
fog-openstack copied to clipboard

Unable to perform Fog::Mock.reset

Open zhitongLBN opened this issue 9 years ago • 12 comments
trafficstars

When I try to do Fog::Mock.reset, I got a:

NameError: uninitialized constant Fog::OpenStack::Compute
from XXXX/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/fog-core-1.35.0/lib/fog/core/mock.rb:98:in `const_get'

please fix this , or at least tell me where was wrong so that I can help to fix this!!! Thank you!

zhitongLBN avatar Mar 15 '16 14:03 zhitongLBN

Hi @zhitongLBN

Can you please show the code you ran to encounter this? Particularly the require line where you include Fog in your code.

seanhandley avatar Mar 15 '16 18:03 seanhandley

Hi @seanhandley, to prove that, i've try to do a test in spec/fog/ and run bundle exec shindo spec/fog/my_spec.rb

require_relative '../spec_helper'

Fog.mock!
p 'i have Fog Openstack'
p Fog::OpenStack.constants
p 'this is gonna to fail'
Fog::Mock.reset

what I got in return is:

"i have Fog"
Fog
Fog::Compute
Fog::OpenStack
[:Core, :Common, :Errors, :Compute, :IdentityV2, :IdentityV3, :Image, :ImageV2, :Metering, :Network, :Orchestration, :Volume, :Baremetal]
"this is gonna to fail"
bundler: failed to load command: shindo (/home/lzt/.rbenv/versions/2.1.2/bin/shindo)
NameError: uninitialized constant Fog::OpenStack::Compute
  /home/lzt/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/fog-core-1.35.0/lib/fog/core/mock.rb:96:in `const_get'
  /home/lzt/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/fog-core-1.35.0/lib/fog/core/mock.rb:96:in `block (2 levels) in reset'
  /home/lzt/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/fog-core-1.35.0/lib/fog/core/mock.rb:95:in `map'
  /home/lzt/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/fog-core-1.35.0/lib/fog/core/mock.rb:95:in `block in reset'
  /home/lzt/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/fog-core-1.35.0/lib/fog/core/mock.rb:93:in `map'
  /home/lzt/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/fog-core-1.35.0/lib/fog/core/mock.rb:93:in `reset'
  /home/lzt/lbn/fog-openstack/spec/fog/my_spec.rb:9:in `<top (required)>'
  /home/lzt/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/shindo-0.3.8/lib/shindo/bin.rb:61:in `load'
  /home/lzt/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/shindo-0.3.8/lib/shindo/bin.rb:61:in `block (2 levels) in run_in_thread'
  /home/lzt/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/shindo-0.3.8/lib/shindo/bin.rb:58:in `each'
  /home/lzt/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/shindo-0.3.8/lib/shindo/bin.rb:58:in `block in run_in_thread'

same with bundle exec ruby spec/fog/my_spec.rb

zhitongLBN avatar Mar 16 '16 09:03 zhitongLBN

What are the contents of my_spec.rb ?

The constant Fog::OpenStack::Compute isn't defined anywhere in Fog; the constant I think you're looking for is Fog::Compute::OpenStack.

seanhandley avatar Mar 16 '16 11:03 seanhandley

We found that by removing require fog/openstack/XXX (https://github.com/fog/fog-openstack/blob/master/lib/fog/openstack.rb#L9-L23 https://github.com/fog/fog-openstack/blob/master/lib/fog/openstack.rb#L30-L34) in 'lib/fog/openstack.rb' before and in module and using only autoload, we have no more pb with Fog::Mock.reset. Thought we still not found why it cause problem like this. Please tell me if you have idea

zhitongLBN avatar Mar 16 '16 13:03 zhitongLBN

my_spec.rb

require_relative '../spec_helper'

Fog.mock!
p 'i have Fog Openstack'
p Fog::OpenStack.constants
p 'this is gonna to fail'
Fog::Mock.reset

zhitongLBN avatar Mar 16 '16 13:03 zhitongLBN

I'm afraid I can't see anything obvious. I've grepped through all the source files in the fog-openstack repository and I can't find any references to Fog::OpenStack::Compute.

All I can think of is that somewhere in your code there's a reference to Fog::OpenStack::Compute that's being loaded by the test environment.

seanhandley avatar Mar 16 '16 15:03 seanhandley

AFAIK there should be OpenStack[:compute]

But the class is Fog::Compute::OpenStack

Could you maybe send a PR with a test you are trying to write, so we can see the code and the failing tests in CI?

Ladas avatar Mar 16 '16 15:03 Ladas

Hello guys ! Thank you for your time in this case. I work with Zhitong and I would like to try to explain our problem.

Like Zhitong said, we have a problem when we call Fog::Mock.reset, and that is raising in the body of this method. You can find this method here : https://github.com/fog/fog-core/blob/master/lib/fog/core/mock.rb#L91 .

In our case in this method we have : x = OpenStack => x_const = Fog::OpenStack y = Compute then this method try to have y_const = Fog::OpenStack::Compute but can't, then we have our error "NameError: uninitialized constant Fog::OpenStack::Compute"

Our test is one an external solution, we can't easly show that, but Zhitong try this test with the same result in the gem fog-openstack :

my_spec.rb

 require_relative '../spec_helper'

 Fog.mock!
 p 'i have Fog Openstack'
 p Fog::OpenStack.constants
 p 'this is gonna to fail'
 Fog::Mock.reset

KevinLoiseau avatar Mar 17 '16 14:03 KevinLoiseau

I'm not sure I understand your use case.

Why do you need a constant called Fog::OpenStack::Compute when the constant defined in the gem is actually Fog::Compute::OpenStack ?

seanhandley avatar Mar 17 '16 15:03 seanhandley

Personally I don't need this constant, but Fog::Mock.reset tried to get it.

I push one test with this problem in a fork repo of fog-openstack, you can find him here : https://github.com/KevinLoiseau/fog-openstack/tree/bug/mock_reset_doesnt_works

The branch "bug/mock_reset_doesnt_works" contain the test "tests/openstack/bug_mock_reset_tests.rb" tested with the command : bundle exec shindont "tests/openstack/bug_mock_reset_tests.rb"

KevinLoiseau avatar Mar 17 '16 16:03 KevinLoiseau

I can reproduce this but the code raising the error is part of the Fog::Core library, so I've referenced this issue from the issue tracker on that project.

https://github.com/fog/fog-core/issues/178

I'm really not sure what's behind this...

seanhandley avatar Mar 18 '16 12:03 seanhandley

When do you think a new version of this gem will be cut/released with this fix?

bsedat avatar Mar 31 '16 19:03 bsedat