Browse Source

Normalize mac address to be case insensitive

Fixes the issue that n-g-s is not working when ngs_mac_address and
switch_id represent the same address but not case sensitive identical.

MAC address will be lower cased before comparison.

Change-Id: I428af67ddc486521d3b883c4adaf98d6bfd64489
Story: 2004609
Task: 28507
Kaifeng Wang 3 months ago
parent
commit
59be4054c5

+ 1
- 1
networking_generic_switch/devices/utils.py View File

@@ -29,7 +29,7 @@ def get_switch_device(switches, switch_info=None,
29 29
     if ngs_mac_address:
30 30
         for sw_info, switch in switches.items():
31 31
             mac_address = switch.ngs_config.get('ngs_mac_address')
32
-            if mac_address and mac_address == ngs_mac_address:
32
+            if mac_address and mac_address.lower() == ngs_mac_address.lower():
33 33
                 return switch
34 34
     if switch_info:
35 35
         return switches.get(switch_info)

+ 6
- 0
networking_generic_switch/tests/unit/devices/test_utils.py View File

@@ -42,6 +42,12 @@ class TestDevices(unittest.TestCase):
42 42
             ngs_mac_address='aa:bb:cc:dd:ee:ff'),
43 43
             self.devices['B'])
44 44
 
45
+    def test_get_switch_device_match_mac_ignore_case(self):
46
+        self.assertEqual(device_utils.get_switch_device(
47
+            self.devices, switch_info='A',
48
+            ngs_mac_address='AA:BB:CC:DD:EE:FF'),
49
+            self.devices['B'])
50
+
45 51
     def test_get_switch_device_no_match(self):
46 52
         self.assertIsNone(device_utils.get_switch_device(
47 53
             self.devices, switch_info='C'))

+ 5
- 0
releasenotes/notes/normalize-ngs-macaddr-1ff0b6be7a53087a.yaml View File

@@ -0,0 +1,5 @@
1
+---
2
+fixes:
3
+  - |
4
+    Fixes an issue that n-g-s is not working when ``ngs_mac_address`` and
5
+    ``switch_id`` represent the same address but not case sensitive identical.

Loading…
Cancel
Save