Skip to content

Commit edb2855

Browse files
committed
fix: fix regex to get vfs details properly
Fixes #29 Signed-off-by: Łukasz Kleina <[email protected]>
1 parent 9c13b17 commit edb2855

File tree

2 files changed

+49
-2
lines changed
  • mfd_network_adapter/network_interface/feature/virtualization
  • tests/unit/test_mfd_network_adapter/test_network_interface/test_feature/test_virtualization

2 files changed

+49
-2
lines changed

mfd_network_adapter/network_interface/feature/virtualization/linux.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def _get_vfs_details(self) -> List[VFDetail]:
5353

5454
command = f"ip link show dev {self._interface().name}"
5555
pattern = (
56-
r"vf\s*(?P<vf_id>\d+)\s*link/ether\s*(?P<mac_address>[0-9a-fA-F]{2}(?::[0-9a-fA-F]{2}){5})\s*.*?,"
56+
r"vf\s*(?P<vf_id>\d+)\s*(link/ether|MAC)\s*(?P<mac_address>[0-9a-fA-F]{2}(?::[0-9a-fA-F]{2}){5})\s*.*?,"
5757
r"\s*spoof checking\s*(?P<spoofchk>\w+),\s*link-state\s*(?P<link_state>\w+),\s*trust\s*("
5858
r"?P<trust>\w+)"
5959
)

tests/unit/test_mfd_network_adapter/test_network_interface/test_feature/test_virtualization/test_virtualization_linux.py

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ def test_set_mac_for_vf_error(self, interface, mocker):
220220
with pytest.raises(VirtualizationFeatureException):
221221
interface.virtualization.set_mac_for_vf(vf_id=vf_id, mac=mac)
222222

223-
def test__get_vfs_details_pass(self, interface, mocker):
223+
def test__get_vfs_details_link_ether_pass(self, interface, mocker):
224224
interface._interface_info.name = "eth1"
225225
interface.virtualization._raise_error_if_not_supported_type = mocker.Mock()
226226
expected_command = f"ip link show dev {interface._interface_info.name}"
@@ -267,6 +267,53 @@ def test__get_vfs_details_pass(self, interface, mocker):
267267
command=expected_command, custom_exception=VirtualizationFeatureException
268268
)
269269

270+
def test__get_vfs_details_mac_pass(self, interface, mocker):
271+
interface._interface_info.name = "eth1"
272+
interface.virtualization._raise_error_if_not_supported_type = mocker.Mock()
273+
expected_command = f"ip link show dev {interface._interface_info.name}"
274+
output = dedent(
275+
"""
276+
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP mode DEFAULT group default qlen 1000
277+
link/ether 00:00:00:00:00:00 brd 00:00:00:00:00:00
278+
vf 0 MAC 00:00:00:00:00:00, spoof checking on, link-state auto, trust off, query_rss off
279+
vf 1 MAC 00:00:00:00:00:00, spoof checking on, link-state enable, trust off, query_rss off
280+
vf 9 MAC 00:00:00:00:00:00, spoof checking on, link-state auto, trust off, query_rss off`
281+
"""
282+
)
283+
284+
interface._connection.execute_command.return_value = ConnectionCompletedProcess(
285+
args="", stdout=output, return_code=0
286+
)
287+
288+
expected_details = [
289+
VFDetail(
290+
id=0,
291+
mac_address=MACAddress("00:00:00:00:00:00"),
292+
spoofchk=State.ENABLED,
293+
link_state=LinkState.AUTO,
294+
trust=State.DISABLED,
295+
),
296+
VFDetail(
297+
id=1,
298+
mac_address=MACAddress("00:00:00:00:00:00"),
299+
spoofchk=State.ENABLED,
300+
link_state=LinkState.ENABLE,
301+
trust=State.DISABLED,
302+
),
303+
VFDetail(
304+
id=9,
305+
mac_address=MACAddress("00:00:00:00:00:00"),
306+
spoofchk=State.ENABLED,
307+
link_state=LinkState.AUTO,
308+
trust=State.DISABLED,
309+
),
310+
]
311+
312+
assert interface.virtualization._get_vfs_details() == expected_details
313+
interface._connection.execute_command.assert_called_with(
314+
command=expected_command, custom_exception=VirtualizationFeatureException
315+
)
316+
270317
def test__get_vfs_details_error(self, interface, mocker):
271318
interface.virtualization._raise_error_if_not_supported_type = mocker.Mock()
272319
interface._connection.execute_command.side_effect = VirtualizationFeatureException(1, "", "", "")

0 commit comments

Comments
 (0)