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

(FACT-3119) RFC2863 operational state for network interfaces #2488

Merged
merged 1 commit into from
Sep 12, 2023
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
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,6 +31,7 @@ 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)
physical(interface_name)

@log.debug("Found interface #{interface_name} with #{@fact_list[:interfaces][interface_name]}")
Expand All @@ -48,6 +49,11 @@ def interfaces_mtu_and_index
mtu_and_indexes
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 physical(ifname)
@fact_list[:interfaces][ifname][:physical] = if File.exist?("/sys/class/net/#{ifname}/device")
true
Expand Down
10 changes: 10 additions & 0 deletions spec/facter/resolvers/linux/networking_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
.with('/proc/net/if_inet6', nil).and_return(load_fixture('proc_net_if_inet6').read)
allow(File).to receive(:exist?).with('/sys/class/net/lo/device').and_return(false)
allow(File).to receive(:exist?).with('/sys/class/net/ens160/device').and_return(true)
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 @@ -70,6 +74,7 @@
netmask6: 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff',
network: '127.0.0.0',
network6: '::1',
operational_state: 'unknown',
physical: false,
scope6: 'host'
},
Expand All @@ -91,6 +96,7 @@
netmask6: 'ffff:ffff:ffff:ffff::',
network: '10.16.112.0',
network6: 'fe80::',
operational_state: 'up',
physical: true,
scope6: 'link'
}
Expand Down Expand Up @@ -162,6 +168,7 @@
netmask6: 'ffff:ffff:ffff:ffff::',
network: '10.16.112.0',
network6: 'fe80::',
operational_state: 'up',
physical: true,
scope6: 'link'
}
Expand Down Expand Up @@ -213,6 +220,7 @@
mtu: 1500,
netmask: '255.255.240.0',
network: '10.16.112.0',
operational_state: 'up',
physical: true
}

Expand Down Expand Up @@ -276,6 +284,7 @@
mtu: 65_536,
netmask6: 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff',
network6: '::1',
operational_state: 'unknown',
physical: false,
scope6: 'host'
},
Expand All @@ -289,6 +298,7 @@
mtu: 1500,
netmask6: 'ffff:ffff:ffff:ffff::',
network6: 'fe80::',
operational_state: 'up',
physical: true,
scope6: 'link'
}
Expand Down
Loading