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

Fixes #20947 - return the network that was searched for. #31

Merged
merged 1 commit into from
Sep 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/smart_proxy_dhcp_infoblox/dhcp_infoblox_main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def unused_ip(subnet, _, from_ip_address, to_ip_address)
end

def find_network(network_address)
network = ::Infoblox::Network.find(connection, 'network~' => network_address, '_max_results' => 1).first
network = ::Infoblox::Network.find(connection, 'network' => network_address, '_max_results' => 1).first
raise "Subnet #{network_address} not found" if network.nil?
network
end
Expand Down
4 changes: 2 additions & 2 deletions lib/smart_proxy_dhcp_infoblox/unused_ips.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def excluded_ips(subnet_address, from, to)
end

def find_range(network_address, from, to)
ranges = ::Infoblox::Range.find(@connection, 'network~' => network_address)
ranges = ::Infoblox::Range.find(@connection, 'network' => network_address)
range = (from.nil? || to.nil?) ? ranges.first : ranges.find {|r| r.start_addr == from && r.end_addr == to}
raise "No Ranges found for #{network_address} network" if range.nil?
range
Expand All @@ -40,7 +40,7 @@ def find_range(network_address, from, to)
def find_network(network_address)
return @memoized_network if !@memoized_network.nil? && @memoized_address == network_address
@memoized_address = network_address
@memoized_network = ::Infoblox::Network.find(@connection, 'network~' => network_address, '_max_results' => 1).first
@memoized_network = ::Infoblox::Network.find(@connection, 'network' => network_address, '_max_results' => 1).first
raise "Subnet #{network_address} not found" if @memoized_network.nil?
@memoized_network
end
Expand Down
4 changes: 2 additions & 2 deletions test/infoblox_provider_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ def test_subnets_returns_managed_subnets_only
end

def test_find_subnet
::Infoblox::Network.expects(:find).with(@connection, 'network~' => '192.168.42.0', '_max_results' => 1).returns([@network])
::Infoblox::Network.expects(:find).with(@connection, 'network' => '192.168.42.0', '_max_results' => 1).returns([@network])
assert_equal @network, @provider.find_network('192.168.42.0')
end

def test_find_subnet_raises_exception_when_network_not_found
::Infoblox::Network.expects(:find).with(@connection, 'network~' => '192.168.42.0', '_max_results' => 1).returns([])
::Infoblox::Network.expects(:find).with(@connection, 'network' => '192.168.42.0', '_max_results' => 1).returns([])
assert_raises(RuntimeError) { @provider.find_network('192.168.42.0') }
end

Expand Down
4 changes: 2 additions & 2 deletions test/unused_ip_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ def test_excluded_ips_is_empty_when_range_end_is_nil
end

def test_unused_network_ip
::Infoblox::Network.expects(:find).with(@connection, 'network~' => '1.1.1.0', '_max_results' => 1).returns([@network])
::Infoblox::Network.expects(:find).with(@connection, 'network' => '1.1.1.0', '_max_results' => 1).returns([@network])
@network.expects(:next_available_ip).with(1, ['1.1.1.254', '1.1.1.255']).returns(['1.1.1.1'])
assert_equal '1.1.1.1', @unused_ips.unused_network_ip('1.1.1.0', '1.1.1.0', '1.1.1.253')
end

def test_unused_range_ip
::Infoblox::Range.expects(:find).with(@connection, 'network~' => '1.1.1.0').returns([@range])
::Infoblox::Range.expects(:find).with(@connection, 'network' => '1.1.1.0').returns([@range])
@range.expects(:next_available_ip).with(1).returns(['1.1.1.1'])
assert_equal '1.1.1.1', @unused_ips.unused_range_ip('1.1.1.0', '1.1.1.0', '1.1.1.253')
end
Expand Down