Rename `detect` to `auto` special values in network segments
Fixes #1205
This commit is contained in:
parent
33b44e8a3f
commit
79f6853f4b
|
@ -68,7 +68,7 @@ Divider highlight group used: ``background:divider``.
|
|||
try:
|
||||
import netifaces
|
||||
except ImportError:
|
||||
def internal_ip(pl, interface='detect', ipv=4):
|
||||
def internal_ip(pl, interface='auto', ipv=4):
|
||||
return None
|
||||
else:
|
||||
_interface_starts = {
|
||||
|
@ -100,8 +100,8 @@ else:
|
|||
else:
|
||||
return 0
|
||||
|
||||
def internal_ip(pl, interface='detect', ipv=4):
|
||||
if interface == 'detect':
|
||||
def internal_ip(pl, interface='auto', ipv=4):
|
||||
if interface == 'auto':
|
||||
try:
|
||||
interface = next(iter(sorted(netifaces.interfaces(), key=_interface_key, reverse=True)))
|
||||
except StopIteration:
|
||||
|
@ -120,7 +120,7 @@ internal_ip = with_docstring(internal_ip,
|
|||
Requires ``netifaces`` module to work properly.
|
||||
|
||||
:param str interface:
|
||||
Interface on which IP will be checked. Use ``detect`` to automatically
|
||||
Interface on which IP will be checked. Use ``auto`` to automatically
|
||||
detect interface. In this case interfaces with lower numbers will be
|
||||
preferred over interfaces with similar names. Order of preference based on
|
||||
names:
|
||||
|
@ -174,11 +174,11 @@ class NetworkLoadSegment(KwThreadedSegment):
|
|||
replace_num_pat = re.compile(r'[a-zA-Z]+')
|
||||
|
||||
@staticmethod
|
||||
def key(interface='detect', **kwargs):
|
||||
def key(interface='auto', **kwargs):
|
||||
return interface
|
||||
|
||||
def compute_state(self, interface):
|
||||
if interface == 'detect':
|
||||
if interface == 'auto':
|
||||
proc_exists = getattr(self, 'proc_exists', None)
|
||||
if proc_exists is None:
|
||||
proc_exists = self.proc_exists = os.path.exists('/proc/net/route')
|
||||
|
@ -192,7 +192,7 @@ class NetworkLoadSegment(KwThreadedSegment):
|
|||
if not destination.replace(b'0', b''):
|
||||
interface = iface.decode('utf-8')
|
||||
break
|
||||
if interface == 'detect':
|
||||
if interface == 'auto':
|
||||
# Choose interface with most total activity, excluding some
|
||||
# well known interface names
|
||||
interface, total = 'eth0', -1
|
||||
|
@ -268,7 +268,7 @@ falls back to reading
|
|||
:file:`/sys/class/net/{interface}/statistics/{rx,tx}_bytes`.
|
||||
|
||||
:param str interface:
|
||||
network interface to measure (use the special value "detect" to have powerline try to auto-detect the network interface)
|
||||
network interface to measure (use the special value "auto" to have powerline try to auto-detect the network interface)
|
||||
:param str suffix:
|
||||
string appended to each load string
|
||||
:param bool si_prefix:
|
||||
|
|
|
@ -352,15 +352,15 @@ class TestNet(TestCommon):
|
|||
AF_INET6=netifaces.AF_INET6,
|
||||
):
|
||||
self.assertEqual(common.internal_ip(pl=pl), '192.168.100.200')
|
||||
self.assertEqual(common.internal_ip(pl=pl, interface='detect'), '192.168.100.200')
|
||||
self.assertEqual(common.internal_ip(pl=pl, interface='auto'), '192.168.100.200')
|
||||
self.assertEqual(common.internal_ip(pl=pl, interface='lo'), '127.0.0.1')
|
||||
self.assertEqual(common.internal_ip(pl=pl, interface='teredo'), None)
|
||||
self.assertEqual(common.internal_ip(pl=pl, ipv=4), '192.168.100.200')
|
||||
self.assertEqual(common.internal_ip(pl=pl, interface='detect', ipv=4), '192.168.100.200')
|
||||
self.assertEqual(common.internal_ip(pl=pl, interface='auto', ipv=4), '192.168.100.200')
|
||||
self.assertEqual(common.internal_ip(pl=pl, interface='lo', ipv=4), '127.0.0.1')
|
||||
self.assertEqual(common.internal_ip(pl=pl, interface='teredo', ipv=4), None)
|
||||
self.assertEqual(common.internal_ip(pl=pl, ipv=6), 'feff::5446:5eff:fe5a:7777%enp2s0')
|
||||
self.assertEqual(common.internal_ip(pl=pl, interface='detect', ipv=6), 'feff::5446:5eff:fe5a:7777%enp2s0')
|
||||
self.assertEqual(common.internal_ip(pl=pl, interface='auto', ipv=6), 'feff::5446:5eff:fe5a:7777%enp2s0')
|
||||
self.assertEqual(common.internal_ip(pl=pl, interface='lo', ipv=6), '::1')
|
||||
self.assertEqual(common.internal_ip(pl=pl, interface='teredo', ipv=6), 'feff::5446:5eff:fe5a:7777')
|
||||
interfaces[1:2] = ()
|
||||
|
|
Loading…
Reference in New Issue