summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Goddard <mark@stackhpc.com>2018-10-01 14:07:42 +0100
committerMark Goddard <mark@stackhpc.com>2018-10-01 14:07:42 +0100
commit1d6290e4407085addce8110f019c74dbf64491fa (patch)
treefeeb1de5f1b9884f510b974d7575dcd26c7b41b8
parent55a9efeffd2265bd355c23d7be2e1e77a919e03c (diff)
Use oslo_utils for string to bool conversion
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: Mon, 01 Oct 2018 17:45:13 +0000 Reviewed-on: https://review.openstack.org/606945 Project: openstack/networking-generic-switch Branch: refs/heads/master
-rw-r--r--networking_generic_switch/devices/__init__.py9
-rw-r--r--networking_generic_switch/tests/unit/test_devices.py12
-rw-r--r--requirements.txt1
3 files changed, 15 insertions, 7 deletions
diff --git a/networking_generic_switch/devices/__init__.py b/networking_generic_switch/devices/__init__.py
index 12c6831..c231951 100644
--- a/networking_generic_switch/devices/__init__.py
+++ b/networking_generic_switch/devices/__init__.py
@@ -15,6 +15,7 @@
15import abc 15import abc
16 16
17from oslo_log import log as logging 17from oslo_log import log as logging
18from oslo_utils import strutils
18import six 19import six
19import stevedore 20import stevedore
20 21
@@ -99,14 +100,10 @@ class GenericSwitchDevice(object):
99 return [] 100 return []
100 return physnets.split(',') 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 def _disable_inactive_ports(self): 103 def _disable_inactive_ports(self):
108 """Return whether inactive ports should be disabled.""" 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 @abc.abstractmethod 108 @abc.abstractmethod
112 def add_network(self, segmentation_id, network_id): 109 def add_network(self, segmentation_id, network_id):
diff --git a/networking_generic_switch/tests/unit/test_devices.py b/networking_generic_switch/tests/unit/test_devices.py
index 89f0ade..93c0154 100644
--- a/networking_generic_switch/tests/unit/test_devices.py
+++ b/networking_generic_switch/tests/unit/test_devices.py
@@ -93,7 +93,8 @@ class TestDeviceManager(unittest.TestCase):
93 "ngs_ssh_connect_interval": "20", 93 "ngs_ssh_connect_interval": "20",
94 "ngs_trunk_ports": "port1,port2", 94 "ngs_trunk_ports": "port1,port2",
95 "ngs_physical_networks": "physnet1,physnet2", 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 device = devices.device_manager(device_cfg) 98 device = devices.device_manager(device_cfg)
98 self.assertIsInstance(device, devices.GenericSwitchDevice) 99 self.assertIsInstance(device, devices.GenericSwitchDevice)
99 self.assertNotIn('ngs_mac_address', device.config) 100 self.assertNotIn('ngs_mac_address', device.config)
@@ -110,6 +111,8 @@ class TestDeviceManager(unittest.TestCase):
110 self.assertEqual('physnet1,physnet2', 111 self.assertEqual('physnet1,physnet2',
111 device.ngs_config['ngs_physical_networks']) 112 device.ngs_config['ngs_physical_networks'])
112 self.assertEqual('20', device.ngs_config['ngs_port_default_vlan']) 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 def test_driver_ngs_config_defaults(self): 117 def test_driver_ngs_config_defaults(self):
115 device_cfg = {"device_type": 'netmiko_ovs_linux'} 118 device_cfg = {"device_type": 'netmiko_ovs_linux'}
@@ -121,3 +124,10 @@ class TestDeviceManager(unittest.TestCase):
121 self.assertNotIn('ngs_trunk_ports', device.ngs_config) 124 self.assertNotIn('ngs_trunk_ports', device.ngs_config)
122 self.assertNotIn('ngs_physical_networks', device.ngs_config) 125 self.assertNotIn('ngs_physical_networks', device.ngs_config)
123 self.assertNotIn('ngs_port_default_vlan', device.config) 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())
diff --git a/requirements.txt b/requirements.txt
index 678ca14..9f68dcc 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -8,6 +8,7 @@ neutron-lib>=1.18.0 # Apache-2.0
8oslo.config>=5.2.0 # Apache-2.0 8oslo.config>=5.2.0 # Apache-2.0
9oslo.i18n>=3.15.3 # Apache-2.0 9oslo.i18n>=3.15.3 # Apache-2.0
10oslo.log>=3.36.0 # Apache-2.0 10oslo.log>=3.36.0 # Apache-2.0
11oslo.utils>=3.33.0 # Apache-2.0
11six>=1.10.0 # MIT 12six>=1.10.0 # MIT
12tenacity>=4.4.0 # Apache-2.0 13tenacity>=4.4.0 # Apache-2.0
13tooz>=1.58.0 # Apache-2.0 14tooz>=1.58.0 # Apache-2.0