File tree Expand file tree Collapse file tree 2 files changed +47
-2
lines changed Expand file tree Collapse file tree 2 files changed +47
-2
lines changed Original file line number Diff line number Diff line change @@ -17,8 +17,24 @@ def ipaddresses(excluded_interfaces = [])
17
17
# always exclude loopback interface
18
18
excluded_interfaces += [ 'lo' ]
19
19
20
+ if !facts [ 'networking' ] . nil? && !facts [ 'networking' ] . empty?
21
+ interfaces = facts [ 'networking' ] [ 'interfaces' ]
22
+ else
23
+ interfaces = { }
24
+ facts [ 'interfaces' ] . split ( ',' ) . each do |iface |
25
+ next if facts [ "ipaddress_#{ iface } " ] . nil? && facts [ "ipaddress6_#{ iface } " ] . nil?
26
+ interfaces [ iface ] = { }
27
+ if !facts [ "ipaddress_#{ iface } " ] . nil? && !facts [ "ipaddress_#{ iface } " ] . empty?
28
+ interfaces [ iface ] [ 'bindings' ] = [ { 'address' => facts [ "ipaddress_#{ iface } " ] } ]
29
+ end
30
+ if !facts [ "ipaddress6_#{ iface } " ] . nil? && !facts [ "ipaddress6_#{ iface } " ] . empty?
31
+ interfaces [ iface ] [ 'bindings6' ] = [ { 'address' => facts [ "ipaddress6_#{ iface } " ] } ]
32
+ end
33
+ end
34
+ end
35
+
20
36
result = [ ]
21
- facts [ 'networking' ] [ ' interfaces' ] . each do |iface , data |
37
+ interfaces . each do |iface , data |
22
38
# skip excluded interfaces
23
39
next if excluded_interfaces . include? ( iface )
24
40
Original file line number Diff line number Diff line change 5
5
is_expected . not_to be_nil
6
6
end
7
7
8
- context 'with dummy fact data' do
8
+ context 'with dummy structured fact data' do
9
9
let ( :facts ) do
10
10
JSON . parse File . read ( File . join ( File . dirname ( __FILE__ ) , '../../fixtures/mock-interface-fact.json' ) )
11
11
end
27
27
end
28
28
end
29
29
end
30
+
31
+ context 'with dummy legacy fact data' do
32
+ let ( :facts ) do
33
+ {
34
+ networking : { } ,
35
+ interfaces : 'lo,docker0,eno1' ,
36
+ ipaddress_lo : '127.0.0.1' ,
37
+ ipaddress_eno1 : '10.13.42.61' ,
38
+ ipaddress_docker0 : '172.17.0.1'
39
+ }
40
+ end
41
+
42
+ describe 'without parameters' do
43
+ it 'returns all IPs other than localhost' do
44
+ is_expected . to run . and_return ( [ '172.17.0.1' , '10.13.42.61' ] )
45
+ end
46
+ end
47
+
48
+ describe 'with excluded interface' do
49
+ it 'doesn\'t return the IPs of excluded interface' do
50
+ is_expected . to run . with_params ( [ 'docker0' ] ) . and_return ( [ '10.13.42.61' ] )
51
+ end
52
+ end
53
+ describe 'with excluded interfaces' do
54
+ it 'doesn\'t return the IPs of those interfaces' do
55
+ is_expected . to run . with_params ( %w[ docker0 eno1 ] ) . and_return ( [ ] )
56
+ end
57
+ end
58
+ end
30
59
end
You can’t perform that action at this time.
0 commit comments