Update config handling for logging level, and add test

Set the default to CRITICAL only, to simplify code. Add check for the
specified logging level, and  a unit test for that.

Change-Id: I3ffa467f001dfdfb840f312bf0df8265aac58299
diff --git a/config/config.py b/config/config.py
index 3694196..02de5a8 100644
--- a/config/config.py
+++ b/config/config.py
@@ -37,6 +37,12 @@
     elif text in ('0', 'n', 'N', 'f', 'F', 'False', 'false'):
         return False
 
+def is_valid_logging_level(text):
+    valid = ('CRITICAL', 'ERROR', 'WARNING', 'INFO', 'DEBUG')
+    if text in valid:
+        return True
+    return False
+    
 class DaemonConfigClass:
     """ Simple container for stuff to make for nicer syntax """
 
@@ -99,7 +105,7 @@
 
         # Set defaults logging details
         self.logging = LoggingConfigClass()
-        self.logging.level = None
+        self.logging.level = 'CRITICAL'
         self.logging.filename = None
 
         # Set default port number and VLAN tag
@@ -166,6 +172,9 @@
                     pass
                 except:
                     raise ConfigError('Invalid logging configuration (level)')
+                self.logging.level = self.logging.level.upper()
+                if not is_valid_logging_level(self.logging.level):
+                    raise ConfigError('Invalid logging configuration (level)')                    
 
                 try:
                     self.logging.filename = config.get(section, 'filename')
diff --git a/config/test-invalid-logging-level.cfg b/config/test-invalid-logging-level.cfg
new file mode 100644
index 0000000..d2de278
--- /dev/null
+++ b/config/test-invalid-logging-level.cfg
@@ -0,0 +1,30 @@
+[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
+
+[logging]
+level = bibble
+
diff --git a/config/test.py b/config/test.py
index 3d66aaf..a1edb22 100644
--- a/config/test.py
+++ b/config/test.py
@@ -40,6 +40,12 @@
             config = VlanConfig(filenames=("test-invalid-vland.cfg",))
             del config
 
+    # Check that we raise on broken logging level
+    def test_invalid_logging_level(self):
+        with self.assertRaisesRegexp(ConfigError, 'Invalid logging.*level'):
+            config = VlanConfig(filenames=("test-invalid-logging-level.cfg",))
+            del config
+
     # Check that we raise on repeated switch names
     def test_missing_repeated_switch_names(self):
         with self.assertRaisesRegexp(ConfigError, 'same name'):
diff --git a/util.py b/util.py
index e71e907..9b30325 100644
--- a/util.py
+++ b/util.py
@@ -6,11 +6,6 @@
     """VLANd utility functions"""
 
     def set_logging_level(self, level):
-
-        # Set up logging and maybe go quiet...
-        if level is None:
-            level = "CRITICAL"
-
         loglevel = logging.CRITICAL
         if level == "ERROR":
             loglevel = logging.ERROR