Skip to content

Commit

Permalink
(FACT-3119) RFC2863 operational state for network interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
jcpunk committed Aug 15, 2023
1 parent 0b0b988 commit ed0a1ca
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 6 additions & 0 deletions lib/facter/resolvers/linux/networking.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,17 @@ def add_info_from_socket_reader
@fact_list[:interfaces].keys.each do |interface_name|
mtu(interface_name, mtu_and_indexes)
dhcp(interface_name, mtu_and_indexes)
operstate(interface_name)

@log.debug("Found interface #{interface_name} with #{@fact_list[:interfaces][interface_name]}")
end
end

def operstate(interface_name)
state = Facter::Util::FileHelper.safe_read("/sys/class/net/#{interface_name}/operstate", nil)
@fact_list[:interfaces][interface_name][:operational_state] = state.strip if state
end

def interfaces_mtu_and_index
mtu_and_indexes = {}
output = Facter::Core::Execution.execute('ip link show', logger: log)
Expand Down
10 changes: 9 additions & 1 deletion spec/facter/resolvers/linux/networking_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
allow(File).to receive(:exist?).with('/proc/net/if_inet6').and_return(true)
allow(Facter::Util::FileHelper).to receive(:safe_read)
.with('/proc/net/if_inet6', nil).and_return(load_fixture('proc_net_if_inet6').read)
allow(Facter::Util::FileHelper).to receive(:safe_read).with('/sys/class/net/lo/operstate', nil).and_return('unknown')
allow(Facter::Util::FileHelper).to receive(:safe_read).with('/sys/class/net/ens160/operstate', nil).and_return('up')
end

after do
Expand Down Expand Up @@ -68,6 +70,7 @@
netmask6: 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff',
network: '127.0.0.0',
network6: '::1',
operational_state: 'unknown',
scope6: 'host'
},
'ens160' => {
Expand All @@ -88,6 +91,7 @@
netmask6: 'ffff:ffff:ffff:ffff::',
network: '10.16.112.0',
network6: 'fe80::',
operational_state: 'up',
scope6: 'link'
}
}
Expand Down Expand Up @@ -158,6 +162,7 @@
netmask6: 'ffff:ffff:ffff:ffff::',
network: '10.16.112.0',
network6: 'fe80::',
operational_state: 'up',
scope6: 'link'
}
end
Expand Down Expand Up @@ -207,7 +212,8 @@
mac: '00:50:56:9a:61:46',
mtu: 1500,
netmask: '255.255.240.0',
network: '10.16.112.0'
network: '10.16.112.0',
operational_state: 'up'
}

expect(networking_linux.resolve(:interfaces)['ens160']).to eq(expected)
Expand Down Expand Up @@ -270,6 +276,7 @@
mtu: 65_536,
netmask6: 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff',
network6: '::1',
operational_state: 'unknown',
scope6: 'host'
},
'ens160' => {
Expand All @@ -282,6 +289,7 @@
mtu: 1500,
netmask6: 'ffff:ffff:ffff:ffff::',
network6: 'fe80::',
operational_state: 'up',
scope6: 'link'
}
}
Expand Down

0 comments on commit ed0a1ca

Please sign in to comment.