Break up Turbo-Hipster configuration
Seeing as the power of Turbo-Hipster is in its pluggable design,
this change allows the configuration to be spit up allowing
each plug in to maintain it's own part of the configuration
including overwriting any default configuration.
There is a new configuration parameter 'conf_d', which is
mapped to a directory:
"conf_d": "/etc/turbo-hipster/conf.d"
worker_server.py grabs all files inside this directory and
attempts to load them. If it fails, the error is logged.
The motivating factor for this change for me, is that it allows
the deployment of turbo-hipster via puppet much simpler.
The base TH puppet class will create the config.json, whereas
there puppet TH plug in classes can pop extra configuration into
the conf_d directory.
Change-Id: Ied20b46d4caa642d130097f3fe019df9c0ec5851
diff --git a/tests/test_worker_server.py b/tests/test_worker_server.py
new file mode 100644
index 0000000..200a7b3
--- /dev/null
+++ b/tests/test_worker_server.py
@@ -0,0 +1,52 @@
+#!/usr/bin/python2
+#
+# Copyright 2014 Rackspace Australia
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+
+import os
+import testtools
+import yaml
+
+from turbo_hipster import worker_server
+
+CONFIG_DIR = os.path.join(os.path.dirname(__file__), 'etc')
+with open(os.path.join(CONFIG_DIR, 'config.yaml'), 'r') as config_stream:
+ CONFIG = yaml.safe_load(config_stream)
+
+CONF_D_DIR = os.path.join(CONFIG_DIR, "conf.d")
+
+
+class TestServerManager(testtools.TestCase):
+ def setUp(self):
+ super(TestServerManager, self).setUp()
+ self.config = CONFIG
+
+ def tearDown(self):
+ super(TestServerManager, self).tearDown()
+
+ def test_confd_configuration(self):
+ """ Check that the server can load in other configuration from a
+ conf.d directory """
+
+ def pass_function(*args, **kargs):
+ pass
+
+ self.config["conf_d"] = CONF_D_DIR
+
+ worker_server.Server.setup_logging = pass_function
+ serv = worker_server.Server(self.config)
+ serv_config = serv.config
+ self.assertIn("extra_configuration", serv_config)
+ self.assertEquals("testing123", serv_config["extra_configuration"])