ggiamarchi / vagrant-openstack-provider

Use Vagrant to manage OpenStack Cloud instances.
MIT License
247 stars 101 forks source link

Does not handle http 302 response in get_api_version_list #393

Open THUzxj opened 1 year ago

THUzxj commented 1 year ago

Hi, thanks for your great work.

My Neutron responses a 302 code when called /networking, but function get_api_version_list only handles code 200 and 300 and throws an error when getting this. I can offer to fix it.

One temporary solution is to set the endpoint in Vagrantfile like os.openstack_network_url = "http://neutron/networking/v2.0".

2022-11-12 16:31 |  INFO | Looking for available endpoints...
2022-11-12 16:31 | DEBUG | request  => method  : GET
2022-11-12 16:31 | DEBUG | request  => url     : http://neutron/networking
2022-11-12 16:31 | DEBUG | request  => headers : {"X-Auth-Token"=>"xxxxx", :accept=>:json}
2022-11-12 16:31 | DEBUG | response => code    : 302
2022-11-12 16:31 | DEBUG | response => headers : {:content_length=>"52", :content_type=>"application/json", :location=>"http://neutron/networking/", :date=>"Sat, 12 Nov 2022 16:31:18 GMT"}
2022-11-12 16:31 | DEBUG | response => body    : {"code": 302, "title": "Found", "description": null}
{"code": 302, "title": "Found", "description": null}
THUzxj commented 1 year ago

This issue is same as #171

ggiamarchi commented 1 year ago

Hi @THUzxj

I have been able to easily reproduce your issue on Devstack where the Neutron endpoint URL from the catalog redirects to a different URL with a 302 code.

In this plugin implementation, we use REST Client to perform HTTP calls. According to the documentation, REST Client is supposed to follow redirections as a default behavior.

It took me a couple of hours to understand why it is not the case here. I finally figured out that when we give a &block parameter when calling RestClient::Request.execute(), redirection is not followed.

I don't know if there is a good reason for that or if this is a bug in REST Client, I didn't deep dive into the code.

I refactored our code to not use Ruby blocks, it does the trick.

Feel free to test and review the PR https://github.com/ggiamarchi/vagrant-openstack-provider/pull/395