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

Fog::Mock.reset is not resetting image (glance) mock data. #292

Open
zeroDivisible opened this issue May 18, 2017 · 0 comments
Open

Fog::Mock.reset is not resetting image (glance) mock data. #292

zeroDivisible opened this issue May 18, 2017 · 0 comments

Comments

@zeroDivisible
Copy link
Contributor

zeroDivisible commented May 18, 2017

So, I'm not entirely sure if this a bug in fog-openstack - or an incorrect assumption made in fog-core (I'd say a bit of both).

The problem is that if I understand correctly, if one wishes to reset the mocks when testing, this can be achieved by calling

Fog::Mock.reset

The reset method is implemented in fog-core:

def self.reset
  mocked_services = []
  Fog.constants.map do |x|
    next if Fog.autoload?(x)
    x_const = Fog.const_get(x)
    x_const.respond_to?(:constants) && x_const.constants.map do |y|
      next if x_const.autoload?(y)
      y_const = x_const.const_get(y)
      y_const.respond_to?(:constants) && y_const.constants.map do |z|
        next if y_const.autoload?(z)
        mocked_services << y_const.const_get(z) if z.to_sym == :Mock
      end
    end
  end

  mocked_services.each do |mocked_service|
    next unless mocked_service.respond_to?(:reset)
    mocked_service.reset
  end
end

So: get constants under Fog (i.e. :Image), get constants under Fog::Image (i.e. :OpenStack) and then get from Fog::Image::OpenStack - if one of them is called :Mock, make it a candidate for resetting.

The problem is that there are different classes for different versions of Glance API: i.e. Fog::Image::OpenStack::V1::Mock - so the Mock class in the hierarchy is under V1, not under OpenStack, where fog-core is searching for it.

Until this issue is fixed, a workaround is to i.e. call:

Fog::Mock.reset
Fog::Image::OpenStack::V1::Mock.reset

to manually reset those mocks - however, I think that a proper solution would need to be added. I think that the same issue will apply to other implementations of versioned APIs (i.e. Keystone), though I didn't check this.

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

1 participant