summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaifeng Wang <kaifeng.w@gmail.com>2019-01-16 14:49:35 +0800
committerKaifeng Wang <kaifeng.w@gmail.com>2019-01-16 14:51:51 +0800
commit59be4054c55c334c622e69bcfdd717192fadffeb (patch)
tree11ba6d12f61712e19d61a461462388c9cf12e470
parentfe97be2a46c8913720b1b8043db36da2efacb624 (diff)
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
Notes
Notes (review): Code-Review+2: Vladyslav Drok <vdrok@mirantis.com> Code-Review+2: Dmitry Tantsur <divius.inside@gmail.com> Workflow+1: Dmitry Tantsur <divius.inside@gmail.com> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Wed, 16 Jan 2019 15:13:26 +0000 Reviewed-on: https://review.openstack.org/631148 Project: openstack/networking-generic-switch Branch: refs/heads/master
-rw-r--r--networking_generic_switch/devices/utils.py2
-rw-r--r--networking_generic_switch/tests/unit/devices/test_utils.py6
-rw-r--r--releasenotes/notes/normalize-ngs-macaddr-1ff0b6be7a53087a.yaml5
3 files changed, 12 insertions, 1 deletions
diff --git a/networking_generic_switch/devices/utils.py b/networking_generic_switch/devices/utils.py
index ceca065..a6bfe19 100644
--- a/networking_generic_switch/devices/utils.py
+++ b/networking_generic_switch/devices/utils.py
@@ -29,7 +29,7 @@ def get_switch_device(switches, switch_info=None,
29 if ngs_mac_address: 29 if ngs_mac_address:
30 for sw_info, switch in switches.items(): 30 for sw_info, switch in switches.items():
31 mac_address = switch.ngs_config.get('ngs_mac_address') 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 return switch 33 return switch
34 if switch_info: 34 if switch_info:
35 return switches.get(switch_info) 35 return switches.get(switch_info)
diff --git a/networking_generic_switch/tests/unit/devices/test_utils.py b/networking_generic_switch/tests/unit/devices/test_utils.py
index cfc5176..73e3b35 100644
--- a/networking_generic_switch/tests/unit/devices/test_utils.py
+++ b/networking_generic_switch/tests/unit/devices/test_utils.py
@@ -42,6 +42,12 @@ class TestDevices(unittest.TestCase):
42 ngs_mac_address='aa:bb:cc:dd:ee:ff'), 42 ngs_mac_address='aa:bb:cc:dd:ee:ff'),
43 self.devices['B']) 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 def test_get_switch_device_no_match(self): 51 def test_get_switch_device_no_match(self):
46 self.assertIsNone(device_utils.get_switch_device( 52 self.assertIsNone(device_utils.get_switch_device(
47 self.devices, switch_info='C')) 53 self.devices, switch_info='C'))
diff --git a/releasenotes/notes/normalize-ngs-macaddr-1ff0b6be7a53087a.yaml b/releasenotes/notes/normalize-ngs-macaddr-1ff0b6be7a53087a.yaml
new file mode 100644
index 0000000..681618a
--- /dev/null
+++ b/releasenotes/notes/normalize-ngs-macaddr-1ff0b6be7a53087a.yaml
@@ -0,0 +1,5 @@
1---
2fixes:
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.