summaryrefslogtreecommitdiffstats
path: root/os_net_config/tests/test_objects.py
diff options
context:
space:
mode:
authorFrank A. Zdarsky <fzdarsky@redhat.com>2017-01-05 12:55:55 +0100
committerFrank A. Zdarsky <fzdarsky@redhat.com>2017-01-05 12:55:55 +0100
commit8c841946d441d6c90ba61ee0a64698b59c711c3a (patch)
tree2c604939738d97f88e04f779aa372b9d4c4a0ceb /os_net_config/tests/test_objects.py
parentd929214c7a904da57a406dd56ac06f001fdc7d7b (diff)
Add check that ovs_extra is passed as list
This patch adds a check that ensures the ovs_extra option, if present, is passed in as list and raises an InvalidConfigException if not. It addresses the issue that a user may mistakingly pass the value as string, which would cause an error later when appending the failure mode or when formatting the ovs_extra parameter. Note: Also fixes a sample file in which ovs_extra was passed as string. Change-Id: I9e8e47390b63d284de10d27b1db2c2cc54c86924 Closes-Bug: #1654196
Diffstat (limited to 'os_net_config/tests/test_objects.py')
-rw-r--r--os_net_config/tests/test_objects.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/os_net_config/tests/test_objects.py b/os_net_config/tests/test_objects.py
index 23a3bbe..200d7b7 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):