From 01a501ff1d0557c7296ce206cadd784310d8c310 Mon Sep 17 00:00:00 2001 From: Alessandro Pilotti Date: Thu, 23 Aug 2018 23:56:51 +0300 Subject: [PATCH] Return NetConnectionID instead of Name Change get_network_adapters in the Windows osutils to return NetConnectionID from the Win32_NetworkAdapter WMI query in place of Name. Different Windows API use different naming to identify the name and description of a network adapter. In the case of Win32_NetworkAdapter, NetConnectionID is the actual name (e.g. Ethernet1) while Name is the description (e.g. Microsoft Hyper-V Network Adapter). Partially-Implements: blueprint json-network-config Change-Id: I3e690a9e0b763e9829a3eddd91a47454d3eb1df8 --- cloudbaseinit/osutils/windows.py | 2 +- cloudbaseinit/tests/osutils/test_windows.py | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/cloudbaseinit/osutils/windows.py b/cloudbaseinit/osutils/windows.py index 649a2bbe..96e6a124 100644 --- a/cloudbaseinit/osutils/windows.py +++ b/cloudbaseinit/osutils/windows.py @@ -700,7 +700,7 @@ class WindowsUtils(base.BaseOSUtils): wql += ' AND PhysicalAdapter = True' q = conn.query(wql) - return [(r.Name, r.MACAddress) for r in q] + return [(r.NetConnectionID, r.MACAddress) for r in q] def get_dhcp_hosts_in_use(self): dhcp_hosts = [] diff --git a/cloudbaseinit/tests/osutils/test_windows.py b/cloudbaseinit/tests/osutils/test_windows.py index 47061876..ac97aa4a 100644 --- a/cloudbaseinit/tests/osutils/test_windows.py +++ b/cloudbaseinit/tests/osutils/test_windows.py @@ -576,8 +576,9 @@ class TestWindowsUtils(testutils.CloudbaseInitTestBase): response = self._winutils.get_network_adapters() conn.return_value.query.assert_called_with(wql) - self.assertEqual([(mock_response.Name, mock_response.MACAddress)], - response) + self.assertEqual( + [(mock_response.NetConnectionID, mock_response.MACAddress)], + response) def test_get_network_adapters(self): self._test_get_network_adapters(False)