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

Add non-filtered interfaces to the API response (LP: #2052834) #241

Merged
merged 2 commits into from
May 30, 2024
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
18 changes: 9 additions & 9 deletions landscape/lib/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,20 +152,15 @@ def get_filtered_if_info(filters=(), extended=False):
continue

ifaddresses = netifaces.ifaddresses(interface)
if not is_active(ifaddresses):
if (
not is_active(ifaddresses)
and netifaces.AF_LINK not in ifaddresses
):
continue

ifencoded = interface.encode()
flags = get_flags(sock, ifencoded)
if not is_up(flags):
continue

ip_addresses = get_ip_addresses(ifaddresses)
if not extended and netifaces.AF_INET not in ip_addresses:
# Skip interfaces with no IPv4 addr unless extended to
# keep backwards compatibility with single-IPv4 addr
# support.
continue

ifinfo = {"interface": interface}
ifinfo["flags"] = flags
Expand All @@ -184,6 +179,11 @@ def get_filtered_if_info(filters=(), extended=False):
ifaddresses,
)
ifinfo["netmask"] = get_netmask(ifaddresses)
elif netifaces.AF_LINK in ifaddresses and not extended:
ifinfo["ip_address"] = "0.0.0.0"
ifinfo["mac_address"] = get_mac_address(ifaddresses)
ifinfo["broadcast_address"] = "0.0.0.0"
ifinfo["netmask"] = "0.0.0.0"

results.append(ifinfo)
finally:
Expand Down
30 changes: 24 additions & 6 deletions landscape/lib/tests/test_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ def test_get_active_device_info(self, mock_get_network_interface_speed):
}

for device in device_info:
if device["mac_address"] == "00:00:00:00:00:00":
if (
device["mac_address"] == "00:00:00:00:00:00"
or device["ip_address"] == "0.0.0.0"
):
continue
self.assertIn(device["interface"], result)
block = interface_blocks[device["interface"]]
Expand Down Expand Up @@ -146,8 +149,21 @@ def test_skip_ipv6_only_in_non_extended_mode(
}

device_info = get_active_device_info(extended=False)

self.assertEqual(device_info, [])
self.assertEqual(
device_info,
[
{
"interface": "test_iface",
"flags": 4163,
"speed": 100,
"duplex": True,
"ip_address": "0.0.0.0",
"mac_address": "aa:bb:cc:dd:ee:f0",
"broadcast_address": "0.0.0.0",
"netmask": "0.0.0.0",
},
],
)

@patch("landscape.lib.network.get_network_interface_speed")
@patch("landscape.lib.network.get_flags")
Expand All @@ -169,7 +185,6 @@ def test_ipv6_only_in_extended_mode(
}

device_info = get_active_device_info(extended=True)

self.assertEqual(
device_info,
[
Expand Down Expand Up @@ -266,13 +281,16 @@ def test_skip_iface_with_no_ip(self, mock_interfaces, mock_ifaddresses):
@patch("landscape.lib.network.get_flags")
@patch("landscape.lib.network.netifaces.ifaddresses")
@patch("landscape.lib.network.netifaces.interfaces")
def test_skip_iface_down(
def test_iface_down(
srunde3 marked this conversation as resolved.
Show resolved Hide resolved
self,
mock_interfaces,
mock_ifaddresses,
mock_get_flags,
mock_get_network_interface_speed,
):
"""
Make sure interfaces in the 'down' state are also reported
"""
mock_get_network_interface_speed.return_value = (100, True)
mock_get_flags.return_value = 0
mock_interfaces.return_value = ["test_iface"]
Expand All @@ -282,7 +300,7 @@ def test_skip_iface_down(
}
device_info = get_active_device_info()
interfaces = [i["interface"] for i in device_info]
self.assertNotIn("test_iface", interfaces)
self.assertEqual(["test_iface"], interfaces)

@patch("landscape.lib.network.get_network_interface_speed")
@patch("landscape.lib.network.get_flags")
Expand Down
2 changes: 1 addition & 1 deletion snap-http
Submodule snap-http updated 2 files
+0 −14 CHANGELOG.md
+1 −1 pyproject.toml
Loading