Browse Source

Use oslo_utils for string to bool conversion

Change-Id: Ieab2228ed5ba4e301aa2cbfaf1db427e7a9a3b00
Mark Goddard 6 months ago
parent
commit
1d6290e440

+ 3
- 6
networking_generic_switch/devices/__init__.py View File

@@ -15,6 +15,7 @@
15 15
 import abc
16 16
 
17 17
 from oslo_log import log as logging
18
+from oslo_utils import strutils
18 19
 import six
19 20
 import stevedore
20 21
 
@@ -99,14 +100,10 @@ class GenericSwitchDevice(object):
99 100
             return []
100 101
         return physnets.split(',')
101 102
 
102
-    @staticmethod
103
-    def _str_to_bool(value):
104
-        truthy = ('true', 'yes', '1')
105
-        return str(value).lower() in truthy
106
-
107 103
     def _disable_inactive_ports(self):
108 104
         """Return whether inactive ports should be disabled."""
109
-        return self._str_to_bool(self.ngs_config['ngs_disable_inactive_ports'])
105
+        return strutils.bool_from_string(
106
+            self.ngs_config['ngs_disable_inactive_ports'])
110 107
 
111 108
     @abc.abstractmethod
112 109
     def add_network(self, segmentation_id, network_id):

+ 11
- 1
networking_generic_switch/tests/unit/test_devices.py View File

@@ -93,7 +93,8 @@ class TestDeviceManager(unittest.TestCase):
93 93
                       "ngs_ssh_connect_interval": "20",
94 94
                       "ngs_trunk_ports": "port1,port2",
95 95
                       "ngs_physical_networks": "physnet1,physnet2",
96
-                      "ngs_port_default_vlan": "20"}
96
+                      "ngs_port_default_vlan": "20",
97
+                      "ngs_disable_inactive_ports": "true"}
97 98
         device = devices.device_manager(device_cfg)
98 99
         self.assertIsInstance(device, devices.GenericSwitchDevice)
99 100
         self.assertNotIn('ngs_mac_address', device.config)
@@ -110,6 +111,8 @@ class TestDeviceManager(unittest.TestCase):
110 111
         self.assertEqual('physnet1,physnet2',
111 112
                          device.ngs_config['ngs_physical_networks'])
112 113
         self.assertEqual('20', device.ngs_config['ngs_port_default_vlan'])
114
+        self.assertEqual('true',
115
+                         device.ngs_config['ngs_disable_inactive_ports'])
113 116
 
114 117
     def test_driver_ngs_config_defaults(self):
115 118
         device_cfg = {"device_type": 'netmiko_ovs_linux'}
@@ -121,3 +124,10 @@ class TestDeviceManager(unittest.TestCase):
121 124
         self.assertNotIn('ngs_trunk_ports', device.ngs_config)
122 125
         self.assertNotIn('ngs_physical_networks', device.ngs_config)
123 126
         self.assertNotIn('ngs_port_default_vlan', device.config)
127
+        self.assertNotIn('ngs_disable_inactive_ports', device.config)
128
+
129
+    def test__disable_inactive_ports(self):
130
+        device_cfg = {"device_type": 'netmiko_ovs_linux',
131
+                      "ngs_disable_inactive_ports": "true"}
132
+        device = devices.device_manager(device_cfg)
133
+        self.assertEqual(True, device._disable_inactive_ports())

+ 1
- 0
requirements.txt View File

@@ -8,6 +8,7 @@ neutron-lib>=1.18.0 # Apache-2.0
8 8
 oslo.config>=5.2.0 # Apache-2.0
9 9
 oslo.i18n>=3.15.3 # Apache-2.0
10 10
 oslo.log>=3.36.0 # Apache-2.0
11
+oslo.utils>=3.33.0 # Apache-2.0
11 12
 six>=1.10.0 # MIT
12 13
 tenacity>=4.4.0 # Apache-2.0
13 14
 tooz>=1.58.0 # Apache-2.0

Loading…
Cancel
Save