diff options
author | Steve McIntyre <steve.mcintyre@linaro.org> | 2015-10-19 18:54:23 +0100 |
---|---|---|
committer | Steve McIntyre <steve.mcintyre@linaro.org> | 2015-10-19 18:54:23 +0100 |
commit | 4e9fee57404643dc017dd345232dff02615fffea (patch) | |
tree | 4cd9e036cc1f7e68d93efa76445b32d3bc153991 | |
parent | fa1beea3536761c0b8afda951cce25b5fd001368 (diff) |
Add checking for clashes in port number in config
And add test case
Change-Id: I3abe8c71bb95614c2edbbd2d8943edf6aa060f49
-rw-r--r-- | config/config.py | 5 | ||||
-rw-r--r-- | config/test-clashing-ports.cfg | 33 | ||||
-rw-r--r-- | config/test.py | 7 |
3 files changed, 45 insertions, 0 deletions
diff --git a/config/config.py b/config/config.py index e0c870f..dc2ad67 100644 --- a/config/config.py +++ b/config/config.py @@ -255,6 +255,11 @@ class VlanConfig: else: raise ConfigError('Unrecognised config section %s' % section) + # Generic checking for config values + if self.visualisation.enabled: + if self.visualisation.port == self.vland.port: + raise ConfigError('Invalid configuration: VLANd and the visualisation service must use distinct port numbers') + def __del__(self): pass diff --git a/config/test-clashing-ports.cfg b/config/test-clashing-ports.cfg new file mode 100644 index 0000000..46b2f3e --- /dev/null +++ b/config/test-clashing-ports.cfg @@ -0,0 +1,33 @@ +[database] +server = foo +port = 123 +dbname = vland +username = vland +password = vland + +[switch foo] +name = 10.172.2.51 +driver = CiscoSX300 +username = cisco +password = cisco +#enable_password = + +[switch bar] +name = 10.172.2.52 +driver = CiscoSX300 +username = cisco +password = cisco +#enable_password = + +[switch baz] +name = baz +driver = CiscoSX300 +username = cisco +password = cisco + +[vland] +port = 245 + +[visualisation] +enabled = yes +port = 245 diff --git a/config/test.py b/config/test.py index a1edb22..0ce11f6 100644 --- a/config/test.py +++ b/config/test.py @@ -46,6 +46,13 @@ class MyTest(unittest.TestCase): config = VlanConfig(filenames=("test-invalid-logging-level.cfg",)) del config + # Check that we raise when VLANd and visn are configured for the + # same port + def test_clashing_ports(self): + with self.assertRaisesRegexp(ConfigError, 'Invalid.*distinct port'): + config = VlanConfig(filenames=("test-clashing-ports.cfg",)) + del config + # Check that we raise on repeated switch names def test_missing_repeated_switch_names(self): with self.assertRaisesRegexp(ConfigError, 'same name'): |