smart_proxy_dhcp_infoblox 0.0.5 → 0.0.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/README.md +57 -2
- data/config/dhcp_infoblox.yml.example +34 -13
- data/lib/smart_proxy_dhcp_infoblox/common_crud.rb +46 -9
- data/lib/smart_proxy_dhcp_infoblox/dhcp_infoblox_main.rb +48 -14
- data/lib/smart_proxy_dhcp_infoblox/dhcp_infoblox_plugin.rb +13 -4
- data/lib/smart_proxy_dhcp_infoblox/dhcp_infoblox_version.rb +1 -1
- data/lib/smart_proxy_dhcp_infoblox/fixed_address_crud.rb +59 -18
- data/lib/smart_proxy_dhcp_infoblox/grid_restart.rb +15 -4
- data/lib/smart_proxy_dhcp_infoblox/host_ipv4_address_crud.rb +57 -15
- data/lib/smart_proxy_dhcp_infoblox/ip_address_arithmetic.rb +6 -6
- data/lib/smart_proxy_dhcp_infoblox/network_address_range_regex_generator.rb +19 -12
- data/lib/smart_proxy_dhcp_infoblox/plugin_configuration.rb +32 -21
- data/lib/smart_proxy_dhcp_infoblox.rb +0 -1
- data/test/host_and_fixedaddress_crud_test.rb +166 -34
- data/test/infoblox_provider_test.rb +65 -11
- data/test/integration_test.rb +96 -0
- data/test/plugin_configuration_test.rb +25 -13
- data/test/test_helper.rb +1 -1
- data/test/unused_ip_test.rb +39 -29
- metadata +22 -11
- data/lib/smart_proxy_dhcp_infoblox/record_type_validator.rb +0 -8
- data/lib/smart_proxy_dhcp_infoblox/unused_ips.rb +0 -47
- data/test/record_type_validator_test.rb +0 -20
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
module ::Proxy::DHCP::Infoblox
|
|
2
2
|
module IpAddressArithmetic
|
|
3
3
|
def cidr_to_ip_mask(prefix_length)
|
|
4
|
-
bitmask = 0xFFFFFFFF ^ (2
|
|
5
|
-
(0..3).map {|i| (bitmask >> i*8) & 0xFF}.reverse.join('.')
|
|
4
|
+
bitmask = 0xFFFFFFFF ^ ((2**(32 - prefix_length)) - 1)
|
|
5
|
+
(0..3).map { |i| (bitmask >> (i * 8)) & 0xFF }.reverse.join('.')
|
|
6
6
|
end
|
|
7
7
|
|
|
8
8
|
def ipv4_to_i(an_address)
|
|
9
|
-
an_address.split('.').inject(0) {|a, c| (a << 8) + c.to_i}
|
|
9
|
+
an_address.split('.').inject(0) { |a, c| (a << 8) + c.to_i }
|
|
10
10
|
end
|
|
11
11
|
|
|
12
|
-
def i_to_ipv4(i)
|
|
13
|
-
(0..3).inject([]) {|a, c| a.push((i >> (c * 8)) & 0xFF)}.reverse.join('.')
|
|
12
|
+
def i_to_ipv4(i) # rubocop:todo Naming/MethodParameterName
|
|
13
|
+
(0..3).inject([]) { |a, c| a.push((i >> (c * 8)) & 0xFF) }.reverse.join('.')
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
def cidr_to_bitmask(prefix_length)
|
|
17
|
-
0xFFFFFFFF ^ (2
|
|
17
|
+
0xFFFFFFFF ^ ((2**(32 - prefix_length)) - 1)
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
def cidr_to_i(an_address_with_cidr)
|
|
@@ -12,7 +12,8 @@ module ::Proxy::DHCP::Infoblox
|
|
|
12
12
|
|
|
13
13
|
def add_children(values)
|
|
14
14
|
return if values.empty?
|
|
15
|
-
|
|
15
|
+
|
|
16
|
+
node = (found = children.find { |n| n.value == values.first }).nil? ? add_child(Node.new(values.first)) : found
|
|
16
17
|
node.add_children(values[1..-1])
|
|
17
18
|
end
|
|
18
19
|
|
|
@@ -21,6 +22,7 @@ module ::Proxy::DHCP::Infoblox
|
|
|
21
22
|
return 1 if other.value.to_s == '0?'
|
|
22
23
|
return 0 if value == other.value
|
|
23
24
|
return -1 if value < other.value
|
|
25
|
+
|
|
24
26
|
1
|
|
25
27
|
end
|
|
26
28
|
|
|
@@ -31,23 +33,27 @@ module ::Proxy::DHCP::Infoblox
|
|
|
31
33
|
end
|
|
32
34
|
|
|
33
35
|
def group_children
|
|
34
|
-
children.each {|n| n.group_children}
|
|
36
|
+
children.each { |n| n.group_children }
|
|
35
37
|
return if children.size < 2
|
|
36
|
-
|
|
38
|
+
|
|
39
|
+
@children = children[1..-1].each_with_object([MergedNode.new(children.first)]) do |to_group, grouped|
|
|
37
40
|
current = MergedNode.new(to_group)
|
|
38
|
-
found = grouped.find
|
|
41
|
+
found = grouped.find do |g|
|
|
42
|
+
((g.value != ['0?'] && current.value != ['0?']) || (current.value == ['0?'] && g.value == ['0?'])) && \
|
|
43
|
+
(g.children == current.children)
|
|
44
|
+
end
|
|
39
45
|
found.nil? ? grouped.push(current) : found.merge(current)
|
|
40
|
-
grouped
|
|
41
46
|
end
|
|
42
47
|
end
|
|
43
48
|
|
|
44
49
|
def as_regex
|
|
45
|
-
children.empty? ? [value.to_s] : children.map {|c| c.as_regex.map {|r| value.to_s + r}}.flatten
|
|
50
|
+
children.empty? ? [value.to_s] : children.map { |c| c.as_regex.map { |r| value.to_s + r } }.flatten
|
|
46
51
|
end
|
|
47
52
|
end
|
|
48
53
|
|
|
49
54
|
class MergedNode
|
|
50
55
|
attr_accessor :value, :children
|
|
56
|
+
|
|
51
57
|
def initialize(a_node)
|
|
52
58
|
@value = [a_node.value].flatten
|
|
53
59
|
@children = a_node.children
|
|
@@ -59,15 +65,16 @@ module ::Proxy::DHCP::Infoblox
|
|
|
59
65
|
end
|
|
60
66
|
|
|
61
67
|
def as_regex
|
|
62
|
-
children.empty? ? [value_as_regex] : children.map {|c| c.as_regex.map {|r| value_as_regex + r}}.flatten
|
|
68
|
+
children.empty? ? [value_as_regex] : children.map { |c| c.as_regex.map { |r| value_as_regex + r } }.flatten
|
|
63
69
|
end
|
|
64
70
|
|
|
65
71
|
def value_as_regex
|
|
66
|
-
value.size < 2 ? value.first.to_s : "[#{value.join
|
|
72
|
+
(value.size < 2) ? value.first.to_s : "[#{value.join}]"
|
|
67
73
|
end
|
|
68
74
|
|
|
69
75
|
def ==(other)
|
|
70
76
|
return false if self.class != other.class
|
|
77
|
+
|
|
71
78
|
value == other.value
|
|
72
79
|
end
|
|
73
80
|
end
|
|
@@ -79,14 +86,14 @@ module ::Proxy::DHCP::Infoblox
|
|
|
79
86
|
|
|
80
87
|
def as_regex
|
|
81
88
|
group_children
|
|
82
|
-
"(%s)" % children.map {|c| c.as_regex}.join('|')
|
|
89
|
+
"(%s)" % children.map { |c| c.as_regex }.join('|')
|
|
83
90
|
end
|
|
84
91
|
|
|
85
92
|
def digits(a_number)
|
|
86
93
|
to_return = []
|
|
87
94
|
begin
|
|
88
95
|
to_return.push(a_number % 10)
|
|
89
|
-
a_number
|
|
96
|
+
a_number /= 10
|
|
90
97
|
end while a_number != 0
|
|
91
98
|
to_return.reverse
|
|
92
99
|
end
|
|
@@ -94,7 +101,7 @@ module ::Proxy::DHCP::Infoblox
|
|
|
94
101
|
|
|
95
102
|
def range_regex(range_start, range_end)
|
|
96
103
|
root = Root.new(nil)
|
|
97
|
-
(range_start..range_end).to_a.each {|i| root.add_number(i)}
|
|
104
|
+
(range_start..range_end).to_a.each { |i| root.add_number(i) }
|
|
98
105
|
root.as_regex
|
|
99
106
|
end
|
|
100
107
|
end
|
|
@@ -111,7 +118,7 @@ module ::Proxy::DHCP::Infoblox
|
|
|
111
118
|
range_start_octets = range.first.split('.').map(&:to_i)
|
|
112
119
|
range_end_octets = range.last.split('.').map(&:to_i)
|
|
113
120
|
|
|
114
|
-
(0..3).map {|i| [range_start_octets[i], range_end_octets[i]]}
|
|
121
|
+
(0..3).map { |i| [range_start_octets[i], range_end_octets[i]] }
|
|
115
122
|
end
|
|
116
123
|
|
|
117
124
|
def range_to_regex(range)
|
|
@@ -3,35 +3,46 @@ module Proxy::DHCP::Infoblox
|
|
|
3
3
|
def load_classes
|
|
4
4
|
require 'infoblox'
|
|
5
5
|
require 'dhcp_common/dhcp_common'
|
|
6
|
+
require 'dhcp_common/free_ips'
|
|
6
7
|
require 'smart_proxy_dhcp_infoblox/host_ipv4_address_crud'
|
|
7
8
|
require 'smart_proxy_dhcp_infoblox/fixed_address_crud'
|
|
8
9
|
require 'smart_proxy_dhcp_infoblox/grid_restart'
|
|
9
|
-
require 'smart_proxy_dhcp_infoblox/unused_ips'
|
|
10
10
|
require 'smart_proxy_dhcp_infoblox/dhcp_infoblox_main'
|
|
11
11
|
end
|
|
12
12
|
|
|
13
|
-
def load_dependency_injection_wirings(c, settings)
|
|
13
|
+
def load_dependency_injection_wirings(c, settings) # rubocop:todo Naming/MethodParameterName
|
|
14
|
+
c.dependency :connection, (lambda {
|
|
15
|
+
::Infoblox.wapi_version = '2.0'
|
|
16
|
+
::Infoblox::Connection.new(:username => settings[:username], :password => settings[:password],
|
|
17
|
+
:host => settings[:server],
|
|
18
|
+
:ssl_opts => { :verify => !ENV['FOREMAN_INFOBLOX_NOSSLVERIFY'] },
|
|
19
|
+
:logger => ::Proxy::LogBuffer::Decorator.instance)
|
|
20
|
+
})
|
|
14
21
|
|
|
22
|
+
c.singleton_dependency :unused_ips, lambda { ::Proxy::DHCP::FreeIps.new(settings[:blacklist_duration_minutes]) }
|
|
15
23
|
|
|
16
|
-
c.dependency :
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
24
|
+
c.dependency :host_ipv4_crud, (lambda {
|
|
25
|
+
::Proxy::DHCP::Infoblox::HostIpv4AddressCRUD.new(
|
|
26
|
+
c.get_dependency(:connection),
|
|
27
|
+
settings[:dns_view],
|
|
28
|
+
settings[:used_ips_search_type])
|
|
29
|
+
})
|
|
30
|
+
c.dependency :fixed_address_crud, (lambda {
|
|
31
|
+
::Proxy::DHCP::Infoblox::FixedAddressCRUD.new(
|
|
32
|
+
c.get_dependency(:connection),
|
|
33
|
+
settings[:network_view],
|
|
34
|
+
settings[:used_ips_search_type])
|
|
35
|
+
})
|
|
36
|
+
c.dependency :grid_restart, lambda { ::Proxy::DHCP::Infoblox::GridRestart.new(c.get_dependency(:connection)) }
|
|
37
|
+
c.dependency :dhcp_provider, (lambda {
|
|
38
|
+
::Proxy::DHCP::Infoblox::Provider.new(
|
|
39
|
+
c.get_dependency(:connection),
|
|
40
|
+
c.get_dependency(settings[:record_type] == 'host' ? :host_ipv4_crud : :fixed_address_crud),
|
|
41
|
+
c.get_dependency(:grid_restart),
|
|
42
|
+
c.get_dependency(:unused_ips),
|
|
43
|
+
settings[:subnets],
|
|
44
|
+
settings[:network_view])
|
|
45
|
+
})
|
|
35
46
|
end
|
|
36
47
|
end
|
|
37
48
|
end
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
require 'test_helper'
|
|
2
|
+
require 'ostruct'
|
|
2
3
|
require 'infoblox'
|
|
3
4
|
require 'dhcp_common/dhcp_common'
|
|
4
5
|
require 'dhcp_common/record/reservation'
|
|
@@ -7,22 +8,37 @@ require 'smart_proxy_dhcp_infoblox/host_ipv4_address_crud'
|
|
|
7
8
|
|
|
8
9
|
module CommoncrudTests
|
|
9
10
|
def test_find_record_using_ip
|
|
10
|
-
@entity.expects(:find).with(@connection, 'ipv4addr' => '192.168.42.1', '_max_results' => 1).returns([@host])
|
|
11
|
+
@entity.expects(:find).with(@connection, search_condition('ipv4addr' => '192.168.42.1', '_max_results' => 1)).returns([@host])
|
|
11
12
|
assert_equal @reservation, @crud.find_record_by_ip('192.168.42.0/24', '192.168.42.1')
|
|
12
13
|
end
|
|
13
14
|
|
|
14
15
|
def test_find_record_using_ip_returns_nil_if_record_not_found
|
|
15
|
-
@entity.expects(:find).with(@connection, 'ipv4addr' => '192.168.42.1', '_max_results' => 1).returns([])
|
|
16
|
+
@entity.expects(:find).with(@connection, search_condition('ipv4addr' => '192.168.42.1', '_max_results' => 1)).returns([])
|
|
16
17
|
assert_nil @crud.find_record_by_ip('192.168.42.0/24', '192.168.42.1')
|
|
17
18
|
end
|
|
18
19
|
|
|
20
|
+
def test_find_records_using_ip_returns_empty_arrays_if_records_not_found
|
|
21
|
+
@entity.expects(:find).with(@connection, search_condition('ipv4addr' => '192.168.42.1', '_max_results' => 2147483646)).returns([])
|
|
22
|
+
assert @crud.find_records_by_ip('192.168.42.0/24', '192.168.42.1').empty?
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def test_find_records_by_ip_returns_empty_array_when_host_has_no_dhcp_record
|
|
26
|
+
found_record = OpenStruct.new(:name => 'testing',
|
|
27
|
+
:ipv4addrs => [OpenStruct.new(:ipv4addr => '192.168.42.1',
|
|
28
|
+
:mac => '00:01:02:03:04:05',
|
|
29
|
+
:configure_for_dhcp => false)])
|
|
30
|
+
@entity.expects(:find).
|
|
31
|
+
with(@connection, search_condition('ipv4addr' => '192.168.42.1', '_max_results' => 2147483646)).returns([found_record])
|
|
32
|
+
assert @crud.find_records_by_ip('192.168.42.0/24', '192.168.42.1').empty?
|
|
33
|
+
end
|
|
34
|
+
|
|
19
35
|
def test_find_record_using_mac
|
|
20
|
-
@entity.expects(:find).with(@connection, 'mac' => '00:01:02:03:05:06', '_max_results' => 1).returns([@host])
|
|
36
|
+
@entity.expects(:find).with(@connection, search_condition('mac' => '00:01:02:03:05:06', '_max_results' => 1)).returns([@host])
|
|
21
37
|
assert_equal @reservation, @crud.find_record_by_mac('192.168.42.0/24', '00:01:02:03:05:06')
|
|
22
38
|
end
|
|
23
39
|
|
|
24
40
|
def test_find_record_using_mac_returns_nil_if_record_not_found
|
|
25
|
-
@entity.expects(:find).with(@connection, 'mac' => '00:01:02:03:05:06', '_max_results' => 1).returns([])
|
|
41
|
+
@entity.expects(:find).with(@connection, search_condition('mac' => '00:01:02:03:05:06', '_max_results' => 1)).returns([])
|
|
26
42
|
assert_nil @crud.find_record_by_mac('192.168.42.0/24', '00:01:02:03:05:06')
|
|
27
43
|
end
|
|
28
44
|
|
|
@@ -46,16 +62,29 @@ module CommoncrudTests
|
|
|
46
62
|
def test_add_record_with_already_existing_host
|
|
47
63
|
@crud.expects(:build_host).with(:ip => @ip, :mac => @mac, :hostname => @hostname).returns(@host)
|
|
48
64
|
@host.expects(:post).raises(Infoblox::Error.new("IB.Data.Conflict"))
|
|
49
|
-
@crud.expects(:
|
|
65
|
+
@crud.expects(:find_hosts).with('ipv4addr' => @ip).returns([@host])
|
|
50
66
|
|
|
51
67
|
assert_raises(Proxy::DHCP::AlreadyExists) { @crud.add_record(:ip => @ip, :mac => @mac, :hostname => @hostname) }
|
|
52
68
|
end
|
|
53
69
|
|
|
54
70
|
def test_del_record
|
|
55
|
-
@crud.expects(:
|
|
71
|
+
@crud.expects(:find_hosts).with('ipv4addr' => @ip).returns([@host])
|
|
56
72
|
@host.expects(:delete)
|
|
57
73
|
@crud.del_record('unused', @reservation)
|
|
58
74
|
end
|
|
75
|
+
|
|
76
|
+
def test_del_records_by_ip
|
|
77
|
+
@crud.expects(:find_hosts).with({ 'ipv4addr' => @ip }, 2147483646).returns([@host, @host1])
|
|
78
|
+
@host.expects(:delete)
|
|
79
|
+
@host1.expects(:delete)
|
|
80
|
+
@crud.del_records_by_ip(@ip)
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def test_del_record_by_mac
|
|
84
|
+
@crud.expects(:find_hosts).with('mac' => @mac).returns([@host])
|
|
85
|
+
@host.expects(:delete)
|
|
86
|
+
@crud.del_record_by_mac(@mac)
|
|
87
|
+
end
|
|
59
88
|
end
|
|
60
89
|
|
|
61
90
|
class HostCrudTest < Test::Unit::TestCase
|
|
@@ -63,7 +92,8 @@ class HostCrudTest < Test::Unit::TestCase
|
|
|
63
92
|
|
|
64
93
|
def setup
|
|
65
94
|
@connection = Object.new
|
|
66
|
-
@
|
|
95
|
+
@view = "something"
|
|
96
|
+
@crud = ::Proxy::DHCP::Infoblox::HostIpv4AddressCRUD.new(@connection, @view, 'record_type')
|
|
67
97
|
|
|
68
98
|
@entity = ::Infoblox::Host
|
|
69
99
|
|
|
@@ -72,23 +102,63 @@ class HostCrudTest < Test::Unit::TestCase
|
|
|
72
102
|
@nextserver = '192.168.42.1'
|
|
73
103
|
@filename = '/tftpboot.img'
|
|
74
104
|
@ip = '192.168.42.1'
|
|
105
|
+
@subnet_ip = '192.168.42.0'
|
|
75
106
|
|
|
76
107
|
@host = ::Infoblox::Host.new(
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
@
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
108
|
+
:name => @hostname,
|
|
109
|
+
:view => @view,
|
|
110
|
+
:ipv4addrs => [{ :ipv4addr => @ip, :mac => @mac, :nextserver => @nextserver, :use_nextserver => true,
|
|
111
|
+
:bootfile => @filename, :use_bootfile => true, :configure_for_dhcp => true }])
|
|
112
|
+
@host1 = ::Infoblox::Host.new(
|
|
113
|
+
:name => 'another.test.com',
|
|
114
|
+
:view => @view,
|
|
115
|
+
:ipv4addrs => [{ :ipv4addr => @ip, :mac => '00:01:02:03:05:07', :nextserver => @nextserver, :use_nextserver => true,
|
|
116
|
+
:bootfile => @filename, :use_bootfile => true, :configure_for_dhcp => true }])
|
|
117
|
+
|
|
118
|
+
@ipv4address = ::Infoblox::Ipv4address.new(
|
|
119
|
+
:names => [@hostname],
|
|
120
|
+
:ip_address => @ip,
|
|
121
|
+
:mac_address => @mac
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
@ipv4address_dnsonly = ::Infoblox::Ipv4address.new(
|
|
125
|
+
:names => ['dnsonly.test.com'],
|
|
126
|
+
:ip_address => '192.168.42.2',
|
|
127
|
+
:mac_address => ''
|
|
128
|
+
)
|
|
129
|
+
|
|
130
|
+
@reservation = ::Proxy::DHCP::Reservation.new(@hostname, @ip, @mac, ::Proxy::DHCP::Subnet.new(@subnet_ip, '255.255.255.0'),
|
|
131
|
+
:hostname => @hostname, :nextServer => @nextserver, :filename => @filename,
|
|
132
|
+
:deleteable => true)
|
|
133
|
+
|
|
134
|
+
@reservation_without_opts = ::Proxy::DHCP::Reservation.new(@hostname, @ip, @mac, ::Proxy::DHCP::Subnet.new(@subnet_ip, '255.255.255.0'),
|
|
135
|
+
:hostname => @hostname, :deleteable => true)
|
|
136
|
+
|
|
137
|
+
@reservation_dnsonly = ::Proxy::DHCP::Reservation.new('dnsonly.test.com', '192.168.42.2', '00:00:00:00:00:00',
|
|
138
|
+
::Proxy::DHCP::Subnet.new(@subnet_ip, '255.255.255.0'),
|
|
139
|
+
:hostname => 'dnsonly.test.com', :deleteable => true)
|
|
85
140
|
end
|
|
86
141
|
|
|
87
|
-
def
|
|
88
|
-
::Infoblox::Host.expects(:find).with(@connection, 'ipv4addr~' => '192\.168\.42\..+', '
|
|
142
|
+
def test_all_hosts_with_find_by_record_type
|
|
143
|
+
::Infoblox::Host.expects(:find).with(@connection, 'ipv4addr~' => '192\.168\.42\..+', 'view' => @view,
|
|
144
|
+
'_max_results' => 2147483646).returns([@host])
|
|
89
145
|
assert_equal @reservation, @crud.all_hosts('192.168.42.0/24').first
|
|
90
146
|
end
|
|
91
147
|
|
|
148
|
+
def test_all_hosts_with_find_by_used
|
|
149
|
+
@crud_used = ::Proxy::DHCP::Infoblox::HostIpv4AddressCRUD.new(@connection, @view, 'used')
|
|
150
|
+
::Infoblox::Ipv4address.expects(:find).with(@connection, 'network' => '192.168.42.0/24', 'status' => 'USED',
|
|
151
|
+
'_max_results' => 2147483646).returns([@ipv4address])
|
|
152
|
+
assert_equal @reservation_without_opts, @crud_used.all_hosts('192.168.42.0/24').first
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
def test_all_hosts_with_find_by_used_dns_record_creates_reservation
|
|
156
|
+
@crud_dnsonly = ::Proxy::DHCP::Infoblox::HostIpv4AddressCRUD.new(@connection, @view, 'used')
|
|
157
|
+
::Infoblox::Ipv4address.expects(:find).with(@connection, 'network' => '192.168.42.0/24', 'status' => 'USED',
|
|
158
|
+
'_max_results' => 2147483646).returns([@ipv4address_dnsonly])
|
|
159
|
+
assert_equal @reservation_dnsonly, @crud_dnsonly.all_hosts('192.168.42.0/24').first
|
|
160
|
+
end
|
|
161
|
+
|
|
92
162
|
def test_build_host
|
|
93
163
|
built = @crud.build_host(:hostname => @hostname, :mac => @mac, :ip => @ip, :nextServer => @nextserver,
|
|
94
164
|
:filename => @filename, :deleteable => true)
|
|
@@ -106,22 +176,30 @@ class HostCrudTest < Test::Unit::TestCase
|
|
|
106
176
|
assert_equal expected_addr.bootfile, actual_addr.bootfile
|
|
107
177
|
assert actual_addr.use_bootfile
|
|
108
178
|
assert actual_addr.configure_for_dhcp
|
|
179
|
+
assert_equal @view, built.view
|
|
109
180
|
end
|
|
110
181
|
|
|
111
182
|
def test_add_record_with_collision
|
|
112
183
|
@crud.expects(:build_host).with(:ip => @ip, :mac => @mac, :hostname => @hostname).returns(@host)
|
|
113
184
|
@host.expects(:post).raises(Infoblox::Error.new("IB.Data.Conflict"))
|
|
114
|
-
@crud.expects(:
|
|
115
|
-
|
|
185
|
+
@crud.expects(:find_hosts).with('ipv4addr' => @ip).returns(
|
|
186
|
+
[::Infoblox::Host.new(:name => @hostname, :ipv4addrs => [{ :ipv4addr => @ip, :mac => '11:22:33:44:55:66"', :configure_for_dhcp => true }])])
|
|
116
187
|
|
|
117
188
|
assert_raises(Proxy::DHCP::Collision) { @crud.add_record(:ip => @ip, :mac => @mac, :hostname => @hostname) }
|
|
118
189
|
end
|
|
190
|
+
|
|
191
|
+
def search_condition(a_hash)
|
|
192
|
+
{ 'view' => @view }.merge(a_hash)
|
|
193
|
+
end
|
|
119
194
|
end
|
|
120
195
|
|
|
121
196
|
class FixedaddressCrudTest < Test::Unit::TestCase
|
|
197
|
+
include CommoncrudTests
|
|
198
|
+
|
|
122
199
|
def setup
|
|
123
200
|
@connection = Object.new
|
|
124
|
-
@
|
|
201
|
+
@network_view = "something"
|
|
202
|
+
@crud = ::Proxy::DHCP::Infoblox::FixedAddressCRUD.new(@connection, @network_view, 'record_type')
|
|
125
203
|
|
|
126
204
|
@entity = ::Infoblox::Fixedaddress
|
|
127
205
|
|
|
@@ -130,21 +208,58 @@ class FixedaddressCrudTest < Test::Unit::TestCase
|
|
|
130
208
|
@nextserver = '192.168.42.1'
|
|
131
209
|
@filename = '/tftpboot.img'
|
|
132
210
|
@ip = '192.168.42.1'
|
|
211
|
+
@subnet_ip = '192.168.42.0'
|
|
133
212
|
|
|
134
213
|
@host = ::Infoblox::Fixedaddress.new(
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
214
|
+
:name => @hostname,
|
|
215
|
+
:ipv4addr => @ip, :mac => @mac, :network_view => @network_view)
|
|
216
|
+
@host1 = ::Infoblox::Fixedaddress.new(
|
|
217
|
+
:name => 'another.test.com',
|
|
218
|
+
:ipv4addr => @ip, :mac => '00:01:02:03:05:07', :network_view => @network_view)
|
|
219
|
+
|
|
220
|
+
@ipv4address = ::Infoblox::Ipv4address.new(
|
|
221
|
+
:names => [@hostname],
|
|
222
|
+
:ip_address => @ip,
|
|
223
|
+
:mac_address => @mac
|
|
224
|
+
)
|
|
225
|
+
|
|
226
|
+
@ipv4address_dnsonly = ::Infoblox::Ipv4address.new(
|
|
227
|
+
:names => ['dnsonly.test.com'],
|
|
228
|
+
:ip_address => '192.168.42.2',
|
|
229
|
+
:mac_address => ''
|
|
230
|
+
)
|
|
231
|
+
|
|
232
|
+
@reservation = ::Proxy::DHCP::Reservation.new(@hostname, @ip, @mac, ::Proxy::DHCP::Subnet.new(@subnet_ip, '255.255.255.0'),
|
|
233
|
+
:deleteable => true, :hostname => @hostname)
|
|
234
|
+
|
|
235
|
+
@reservation_without_opts = ::Proxy::DHCP::Reservation.new(@hostname, @ip, @mac, ::Proxy::DHCP::Subnet.new(@subnet_ip, '255.255.255.0'),
|
|
236
|
+
:hostname => @hostname, :deleteable => true)
|
|
237
|
+
|
|
238
|
+
@reservation_dnsonly = ::Proxy::DHCP::Reservation.new('dnsonly.test.com', '192.168.42.2', '00:00:00:00:00:00',
|
|
239
|
+
::Proxy::DHCP::Subnet.new(@subnet_ip, '255.255.255.0'),
|
|
240
|
+
:hostname => 'dnsonly.test.com', :deleteable => true)
|
|
141
241
|
end
|
|
142
242
|
|
|
143
|
-
def
|
|
144
|
-
::Infoblox::Fixedaddress.expects(:find).with(@connection, 'network' => '192.168.42.0/24', '
|
|
243
|
+
def test_all_hosts_with_find_by_record_type
|
|
244
|
+
::Infoblox::Fixedaddress.expects(:find).with(@connection, 'network' => '192.168.42.0/24', 'network_view' => @network_view,
|
|
245
|
+
'_max_results' => 2147483646).returns([@host])
|
|
145
246
|
assert_equal @reservation, @crud.all_hosts('192.168.42.0/24').first
|
|
146
247
|
end
|
|
147
248
|
|
|
249
|
+
def test_all_hosts_with_find_by_used
|
|
250
|
+
@crud_used = ::Proxy::DHCP::Infoblox::FixedAddressCRUD.new(@connection, @network_view, 'used')
|
|
251
|
+
::Infoblox::Ipv4address.expects(:find).with(@connection, 'network' => '192.168.42.0/24', 'status' => 'USED',
|
|
252
|
+
'_max_results' => 2147483646).returns([@ipv4address])
|
|
253
|
+
assert_equal @reservation_without_opts, @crud_used.all_hosts('192.168.42.0/24').first
|
|
254
|
+
end
|
|
255
|
+
|
|
256
|
+
def test_all_hosts_with_find_by_used_dns_record_creates_reservation
|
|
257
|
+
@crud_dnsonly = ::Proxy::DHCP::Infoblox::FixedAddressCRUD.new(@connection, @network_view, 'used')
|
|
258
|
+
::Infoblox::Ipv4address.expects(:find).with(@connection, 'network' => '192.168.42.0/24', 'status' => 'USED',
|
|
259
|
+
'_max_results' => 2147483646).returns([@ipv4address_dnsonly])
|
|
260
|
+
assert_equal @reservation_dnsonly, @crud_dnsonly.all_hosts('192.168.42.0/24').first
|
|
261
|
+
end
|
|
262
|
+
|
|
148
263
|
def test_build_host
|
|
149
264
|
built = @crud.build_host(:hostname => @hostname, :mac => @mac, :ip => @ip, :nextServer => @nextserver,
|
|
150
265
|
:filename => @filename, :deleteable => true)
|
|
@@ -152,18 +267,35 @@ class FixedaddressCrudTest < Test::Unit::TestCase
|
|
|
152
267
|
assert_equal @host.name, built.name
|
|
153
268
|
assert_equal @host.ipv4addr, built.ipv4addr
|
|
154
269
|
assert_equal @host.mac, built.mac
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
270
|
+
assert_equal @nextserver, built.nextserver
|
|
271
|
+
assert built.use_nextserver
|
|
272
|
+
assert_equal @filename, built.bootfile
|
|
273
|
+
assert built.use_bootfile
|
|
274
|
+
assert_equal @network_view, built.network_view
|
|
275
|
+
end
|
|
276
|
+
|
|
277
|
+
def test_build_host_with_options
|
|
278
|
+
begin
|
|
279
|
+
Proxy::DHCP::Infoblox::Plugin.settings.options = [{"name" => "xyz"}]
|
|
280
|
+
|
|
281
|
+
host = @crud.build_host(:ip => @ip, :mac => @mac, :hostname => @hostname)
|
|
282
|
+
assert_equal [{"name" => "xyz"}], host.instance_variable_get("@options")
|
|
283
|
+
ensure
|
|
284
|
+
Proxy::DHCP::Infoblox::Plugin.settings.options = []
|
|
285
|
+
end
|
|
159
286
|
end
|
|
160
287
|
|
|
161
288
|
def test_add_record_with_collision
|
|
162
289
|
@crud.expects(:build_host).with(:ip => @ip, :mac => @mac, :hostname => @hostname).returns(@host)
|
|
163
290
|
@host.expects(:post).raises(Infoblox::Error.new("IB.Data.Conflict"))
|
|
164
|
-
@crud.expects(:
|
|
165
|
-
|
|
291
|
+
@crud.expects(:find_hosts).with('ipv4addr' => @ip).returns(
|
|
292
|
+
[::Infoblox::Fixedaddress.new(:name => @hostname, :ipv4addr => @ip, :mac => '11:22:33:44:55:66',
|
|
293
|
+
:network_view => @network_view)])
|
|
166
294
|
|
|
167
295
|
assert_raises(Proxy::DHCP::Collision) { @crud.add_record(:ip => @ip, :mac => @mac, :hostname => @hostname) }
|
|
168
296
|
end
|
|
297
|
+
|
|
298
|
+
def search_condition(a_hash)
|
|
299
|
+
{ 'network_view' => @network_view }.merge(a_hash)
|
|
300
|
+
end
|
|
169
301
|
end
|
|
@@ -11,13 +11,55 @@ class InfobloxProviderTest < Test::Unit::TestCase
|
|
|
11
11
|
@restart_grid = Object.new
|
|
12
12
|
@unused_ips = Object.new
|
|
13
13
|
@managed_subnets = nil
|
|
14
|
+
@network_view = "another"
|
|
15
|
+
@used_ips_search_type = 'record_type'
|
|
14
16
|
|
|
15
17
|
@network = Infoblox::Network.new(:network => '192.168.42.0/24')
|
|
16
18
|
@subnet = ::Proxy::DHCP::Subnet.new('192.168.42.0', '255.255.255.0')
|
|
17
19
|
|
|
20
|
+
@network_2 = Infoblox::Network.new(:network => '192.168.32.0/19')
|
|
21
|
+
@subnet_2 = ::Proxy::DHCP::Subnet.new('192.168.32.0', '255.255.224.0')
|
|
18
22
|
|
|
19
|
-
@
|
|
20
|
-
|
|
23
|
+
@network_3 = Infoblox::Network.new(:network => '192.168.43.0/24')
|
|
24
|
+
|
|
25
|
+
@provider = Proxy::DHCP::Infoblox::Provider.new(@connection, @crud, @restart_grid,
|
|
26
|
+
@unused_ips, @managed_subnets, @network_view)
|
|
27
|
+
|
|
28
|
+
@lease = Infoblox::Lease.new(:address => '192.168.43.127',
|
|
29
|
+
:binding_state => 'active',
|
|
30
|
+
:client_hostname => 'example',
|
|
31
|
+
:hardware => 'ba:be:fa:ce:ca:fe',
|
|
32
|
+
:network => @subnet.network,
|
|
33
|
+
:starts => nil,
|
|
34
|
+
:ends => nil)
|
|
35
|
+
|
|
36
|
+
@lease_2 = Infoblox::Lease.new(:address => '192.168.60.121',
|
|
37
|
+
:binding_state => 'active',
|
|
38
|
+
:client_hostname => 'example',
|
|
39
|
+
:hardware => 'c0:fe:fe:f0:01:bb',
|
|
40
|
+
:network => @subnet_2.network,
|
|
41
|
+
:starts => nil,
|
|
42
|
+
:ends => nil)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def test_leases
|
|
46
|
+
@crud = ::Proxy::DHCP::Infoblox::CommonCRUD.new(@connection, @used_ips_search_type)
|
|
47
|
+
@provider = Proxy::DHCP::Infoblox::Provider.new(@connection, @crud, @restart_grid,
|
|
48
|
+
@unused_ips, @managed_subnets, @network_view)
|
|
49
|
+
|
|
50
|
+
@provider.expects(:full_network_address).with(@subnet.network).returns(@network.network)
|
|
51
|
+
Infoblox::Lease.expects(:find).with(@connection, 'address~' => "192\\.168\\.42\\..+").returns([@lease])
|
|
52
|
+
assert_equal @lease.hardware, @provider.all_leases(@subnet.network).first.mac
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def test_nonclass_leases
|
|
56
|
+
@crud = ::Proxy::DHCP::Infoblox::CommonCRUD.new(@connection,@used_ips_search_type)
|
|
57
|
+
@provider = Proxy::DHCP::Infoblox::Provider.new(@connection, @crud, @restart_grid,
|
|
58
|
+
@unused_ips, @managed_subnets, @network_view)
|
|
59
|
+
|
|
60
|
+
@provider.expects(:full_network_address).with(@subnet_2.network).returns(@network_2.network)
|
|
61
|
+
Infoblox::Lease.expects(:find).with(@connection, 'address~' => "192\\.168\\.(0?3[3456789]|0?[45][0123456789]|0?6[012])\\..+").returns([@lease_2])
|
|
62
|
+
assert_equal @lease_2.hardware, @provider.all_leases(@subnet_2.network).first.mac
|
|
21
63
|
end
|
|
22
64
|
|
|
23
65
|
def test_subnets
|
|
@@ -26,18 +68,21 @@ class InfobloxProviderTest < Test::Unit::TestCase
|
|
|
26
68
|
end
|
|
27
69
|
|
|
28
70
|
def test_subnets_returns_managed_subnets_only
|
|
29
|
-
provider = Proxy::DHCP::Infoblox::Provider.new(@connection, @crud, @restart_grid,
|
|
30
|
-
|
|
71
|
+
provider = Proxy::DHCP::Infoblox::Provider.new(@connection, @crud, @restart_grid,
|
|
72
|
+
@unused_ips, ['192.168.42.0/255.255.255.0'], @network_view)
|
|
73
|
+
Infoblox::Network.expects(:all).with(@connection).returns([@network, @network_3])
|
|
31
74
|
assert_equal [@subnet], provider.subnets
|
|
32
75
|
end
|
|
33
76
|
|
|
34
77
|
def test_find_subnet
|
|
35
|
-
::Infoblox::Network.expects(:find).with(@connection, 'network
|
|
78
|
+
::Infoblox::Network.expects(:find).with(@connection, 'network' => '192.168.42.0',
|
|
79
|
+
'_max_results' => 1, 'network_view' => @network_view).returns([@network])
|
|
36
80
|
assert_equal @network, @provider.find_network('192.168.42.0')
|
|
37
81
|
end
|
|
38
82
|
|
|
39
83
|
def test_find_subnet_raises_exception_when_network_not_found
|
|
40
|
-
::Infoblox::Network.expects(:find).with(@connection, 'network
|
|
84
|
+
::Infoblox::Network.expects(:find).with(@connection, 'network' => '192.168.42.0',
|
|
85
|
+
'network_view' => @network_view, '_max_results' => 1).returns([])
|
|
41
86
|
assert_raises(RuntimeError) { @provider.find_network('192.168.42.0') }
|
|
42
87
|
end
|
|
43
88
|
|
|
@@ -52,10 +97,19 @@ class InfobloxProviderTest < Test::Unit::TestCase
|
|
|
52
97
|
@crud.stubs(:del_record)
|
|
53
98
|
@provider.stubs(:full_network_address)
|
|
54
99
|
@restart_grid.expects(:try_restart)
|
|
55
|
-
@provider.del_record(
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
100
|
+
@provider.del_record(::Proxy::DHCP::Record.new('192.168.42.1', '00:01:02:03:04:05',
|
|
101
|
+
::Proxy::DHCP::Subnet.new('192.168.42.0', '255.255.255.0')))
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def test_del_record_by_mac_restarts_grid
|
|
105
|
+
@crud.stubs(:del_record_by_mac)
|
|
106
|
+
@restart_grid.expects(:try_restart)
|
|
107
|
+
@provider.del_record_by_mac(@subnet.network, '00:01:02:03:04:05')
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def test_del_record_by_ip_restarts_grid
|
|
111
|
+
@crud.stubs(:del_records_by_ip)
|
|
112
|
+
@restart_grid.expects(:try_restart)
|
|
113
|
+
@provider.del_records_by_ip(@subnet.network, '192.168.42.1')
|
|
60
114
|
end
|
|
61
115
|
end
|