diff options
author | Jenkins <jenkins@review.openstack.org> | 2017-01-27 16:57:26 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2017-01-27 16:57:26 +0000 |
commit | 60f043152dedf04c335a049feedb502b194fbc02 (patch) | |
tree | 45c068953c837832f6d891096a287c4b7064ea57 /os_net_config | |
parent | b4ecaa5c344cc33691d91398bfa187e876e6e40d (diff) | |
parent | 8c841946d441d6c90ba61ee0a64698b59c711c3a (diff) |
Merge "Add check that ovs_extra is passed as list"
Diffstat (limited to 'os_net_config')
-rw-r--r-- | os_net_config/objects.py | 25 | ||||
-rw-r--r-- | os_net_config/tests/test_objects.py | 28 |
2 files changed, 51 insertions, 2 deletions
diff --git a/os_net_config/objects.py b/os_net_config/objects.py index 741f304..e3d8978 100644 --- a/os_net_config/objects.py +++ b/os_net_config/objects.py @@ -439,7 +439,10 @@ class OvsBridge(_BaseOpts): dhclient_args, dns_servers) = _BaseOpts.base_opts_from_json( json, include_primary=False) ovs_options = json.get('ovs_options') - ovs_extra = json.get('ovs_extra') + ovs_extra = json.get('ovs_extra', []) + if not isinstance(ovs_extra, list): + msg = 'ovs_extra must be a list.' + raise InvalidConfigException(msg) fail_mode = json.get('ovs_fail_mode', DEFAULT_OVS_BRIDGE_FAIL_MODE) members = [] @@ -504,7 +507,10 @@ class OvsUserBridge(_BaseOpts): dhclient_args, dns_servers) = _BaseOpts.base_opts_from_json( json, include_primary=False) ovs_options = json.get('ovs_options') - ovs_extra = json.get('ovs_extra') + ovs_extra = json.get('ovs_extra', []) + if not isinstance(ovs_extra, list): + msg = 'ovs_extra must be a list.' + raise InvalidConfigException(msg) fail_mode = json.get('ovs_fail_mode', DEFAULT_OVS_BRIDGE_FAIL_MODE) members = [] @@ -860,6 +866,9 @@ class OvsBond(_BaseOpts): json, include_primary=False) ovs_options = json.get('ovs_options') ovs_extra = json.get('ovs_extra', []) + if ovs_extra and not isinstance(ovs_extra, list): + msg = 'ovs_extra must be a list.' + raise InvalidConfigException(msg) members = [] # members @@ -906,6 +915,9 @@ class OvsTunnel(_BaseOpts): ovs_options = json.get('ovs_options', []) ovs_options = ['options:%s' % opt for opt in ovs_options] ovs_extra = json.get('ovs_extra', []) + if not isinstance(ovs_extra, list): + msg = 'ovs_extra must be a list.' + raise InvalidConfigException(msg) opts = _BaseOpts.base_opts_from_json(json) return OvsTunnel(name, *opts, tunnel_type=tunnel_type, ovs_options=ovs_options, ovs_extra=ovs_extra) @@ -940,6 +952,9 @@ class OvsPatchPort(_BaseOpts): ovs_options = json.get('ovs_options', []) ovs_options = ['options:%s' % opt for opt in ovs_options] ovs_extra = json.get('ovs_extra', []) + if not isinstance(ovs_extra, list): + msg = 'ovs_extra must be a list.' + raise InvalidConfigException(msg) opts = _BaseOpts.base_opts_from_json(json) return OvsPatchPort(name, *opts, bridge_name=bridge_name, peer=peer, ovs_options=ovs_options, ovs_extra=ovs_extra) @@ -1023,6 +1038,9 @@ class OvsDpdkPort(_BaseOpts): ovs_options = json.get('ovs_options', []) ovs_options = ['options:%s' % opt for opt in ovs_options] ovs_extra = json.get('ovs_extra', []) + if not isinstance(ovs_extra, list): + msg = 'ovs_extra must be a list.' + raise InvalidConfigException(msg) opts = _BaseOpts.base_opts_from_json(json) return OvsDpdkPort(name, *opts, members=members, driver=driver, ovs_options=ovs_options, ovs_extra=ovs_extra) @@ -1067,6 +1085,9 @@ class OvsDpdkBond(_BaseOpts): json, include_primary=False) ovs_options = json.get('ovs_options') ovs_extra = json.get('ovs_extra', []) + if not isinstance(ovs_extra, list): + msg = 'ovs_extra must be a list.' + raise InvalidConfigException(msg) members = [] # members diff --git a/os_net_config/tests/test_objects.py b/os_net_config/tests/test_objects.py index 54d153c..0ff653c 100644 --- a/os_net_config/tests/test_objects.py +++ b/os_net_config/tests/test_objects.py @@ -295,6 +295,34 @@ class TestBridge(base.TestCase): self.assertTrue(interface2.ovs_port) self.assertEqual("br-foo", interface2.bridge_name) + def test_from_json_ovs_extra(self): + data = """{ +"type": "ovs_bridge", +"name": "br-foo", +"ovs_extra": ["bar"], +"ovs_fail_mode": "standalone" +} +""" + bridge = objects.object_from_json(json.loads(data)) + self.assertTrue(2 == len(bridge.ovs_extra)) + self.assertEqual("bar", bridge.ovs_extra[0]) + self.assertEqual("set bridge br-foo fail_mode=standalone", + bridge.ovs_extra[1]) + + def test_from_json_ovs_extra_invalid(self): + data = """{ +"type": "ovs_bridge", +"name": "br-foo", +"ovs_extra": "bar", +"ovs_fail_mode": "standalone" +} +""" + json_data = json.loads(data) + err = self.assertRaises(objects.InvalidConfigException, + objects.object_from_json, json_data) + expected = 'ovs_extra must be a list.' + self.assertIn(expected, six.text_type(err)) + class TestLinuxBridge(base.TestCase): |