Skip to content

Commit

Permalink
Fixes #21710 - correct arguments to find_free_ip are used. (theforema…
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitri-d authored and ares committed Nov 22, 2017
1 parent 49a62f5 commit 09b72a0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
3 changes: 1 addition & 2 deletions modules/dhcp_common/server.rb
Expand Up @@ -96,8 +96,7 @@ def unused_ip(subnet_address, mac_address, from_address, to_address)
return r if r
end

free_ips.find_free_ip(validated_to_address, validated_to_address, subnet.netmask,
all_hosts(subnet_address) + all_leases(subnet_address))
free_ips.find_free_ip(validated_from_address, validated_to_address, all_hosts(subnet_address) + all_leases(subnet_address))
end

def find_ip_by_mac_address_and_range(subnet, mac_address, from_address, to_address)
Expand Down
15 changes: 14 additions & 1 deletion test/dhcp/server_test.rb
Expand Up @@ -8,7 +8,8 @@ class DHCPServerTest < Test::Unit::TestCase

def setup
@service = Proxy::DHCP::SubnetService.initialized_instance
@server = Proxy::DHCP::Server.new("testcase", nil, @service)
@free_ips = Object.new
@server = Proxy::DHCP::Server.new("testcase", nil, @service, @free_ips)

@subnet = Proxy::DHCP::Subnet.new("192.168.0.0", "255.255.255.0")
@service.add_subnet(@subnet)
Expand Down Expand Up @@ -125,4 +126,16 @@ def test_del_record_by_mac
@server.expects(:del_record).with(@record).once
@server.del_record_by_mac(@subnet.network, 'aa:bb:cc:dd:ee:ff')
end

def test_unused_ip
@free_ips.expects(:find_free_ip)
.with("192.168.0.1", "192.168.0.10", @service.all_hosts("192.168.0.0"))
.returns(nil)
@server.unused_ip("192.168.0.0", nil, "192.168.0.1", "192.168.0.10")
end

def test_unused_ip_with_mac_address_specified
assert_equal "192.168.0.11",
@server.unused_ip("192.168.0.0", "aa:bb:cc:dd:ee:ff", "192.168.0.1", "192.168.0.20")
end
end

0 comments on commit 09b72a0

Please sign in to comment.