Took me a little bit to track this down, but I integrated the f5-icontrol gem with my own in-house gem that abstracts a few of our different load balancing brands. Tests ran good in that. And then I upgraded that gem in one of our Chef cookbooks that handles checking pool health. Tests there started getting strange. Pools would load fine, but when I tried to members.load off of that returned object, I got this (note the URL that's actually being called):
Failure/Error: expect(f5_obj.lb.health_percentage_for_pool('foo')).to eq(1)
WebMock::NetConnectNotAllowedError:
Real HTTP connections are disabled. Unregistered request: GET https://127.0.0.1/https://127.0.0.1/mgmt/tm/ltm/pool/~Common~foo/members with headers {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization'=>'Basic YWRtaW46Zm9v', 'Host'=>'127.0.0.1', 'User-Agent'=>'rest-client/2.1.0 (darwin16.7.0 x86_64) ruby/2.5.5p157'}
You can stub this request with the following snippet:
stub_request(:get, "https://127.0.0.1/https://127.0.0.1/mgmt/tm/ltm/pool/~Common~foo/members").
with(
headers: {
'Accept'=>'*/*',
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'Authorization'=>'Basic YWRtaW46Zm9v',
'Host'=>'127.0.0.1',
'User-Agent'=>'rest-client/2.1.0 (darwin16.7.0 x86_64) ruby/2.5.5p157'
}).
to_return(status: 200, body: "", headers: {})
registered request stubs:
stub_request(:get, "https://127.0.0.1/mgmt/tm/ltm/pool/~Common~foo/members")
stub_request(:get, "https://127.0.0.1/mgmt/tm/ltm/pool/foo")
stub_request(:get, "https://127.0.0.1/mgmt/tm/ltm/pool/")
============================================================
# /Users/matt/.chefdk/gem/ruby/2.5.0/gems/webmock-3.7.6/lib/webmock/http_lib_adapters/net_http.rb:114:in `request'
# /Users/matt/.chefdk/gem/ruby/2.5.0/gems/rest-client-2.1.0/lib/restclient/request.rb:473:in `net_http_do_request'
# /Users/matt/.chefdk/gem/ruby/2.5.0/gems/rest-client-2.1.0/lib/restclient/request.rb:733:in `block in transmit'
# /Users/matt/.chefdk/gem/ruby/2.5.0/gems/webmock-3.7.6/lib/webmock/http_lib_adapters/net_http.rb:123:in `start_without_connect'
# /Users/matt/.chefdk/gem/ruby/2.5.0/gems/webmock-3.7.6/lib/webmock/http_lib_adapters/net_http.rb:150:in `start'
# /Users/matt/.chefdk/gem/ruby/2.5.0/gems/rest-client-2.1.0/lib/restclient/request.rb:727:in `transmit'
# /Users/matt/.chefdk/gem/ruby/2.5.0/gems/rest-client-2.1.0/lib/restclient/request.rb:163:in `execute'
# /Users/matt/.chefdk/gem/ruby/2.5.0/gems/rest-client-2.1.0/lib/restclient/request.rb:63:in `execute'
# /Users/matt/.chefdk/gem/ruby/2.5.0/gems/f5-icontrol-0.3.5/lib/f5/icontrol/rapi.rb:17:in `load'
...
Everything worked great in my gem's tests suite because it was using localhost as a mock target for testing. But my cookbook's test suite was mocking with 127.0.0.1. I'm not sure the reason why a rigid regex was used to remove the scheme and host portion of the reference link instead of something that matches any host, but any sort of referencing and subsequent loading will fail if the host isn't localhost with the current code.
Took me a little bit to track this down, but I integrated the f5-icontrol gem with my own in-house gem that abstracts a few of our different load balancing brands. Tests ran good in that. And then I upgraded that gem in one of our Chef cookbooks that handles checking pool health. Tests there started getting strange. Pools would
load
fine, but when I tried tomembers.load
off of that returned object, I got this (note the URL that's actually being called):The problem is here: https://github.com/swalberg/f5-icontrol/blob/4182f7def686df1ba5165acd6446e2ab64017c4c/lib/f5/icontrol/rapi/resource.rb
Everything worked great in my gem's tests suite because it was using
localhost
as a mock target for testing. But my cookbook's test suite was mocking with127.0.0.1
. I'm not sure the reason why a rigid regex was used to remove the scheme and host portion of the reference link instead of something that matches any host, but any sort of referencing and subsequent loading will fail if the host isn'tlocalhost
with the current code.I'll have a pull coming shortly.