Improved config file format

Change-Id: I3a9a1af94c143b31e1700c180941ce9b38f5ff88
This commit is contained in:
aviau 2015-04-16 14:57:42 -04:00
parent 1a4fc25a13
commit 22bf90ad69
4 changed files with 32 additions and 9 deletions

View File

@ -12,7 +12,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import pymongo
from surveil.api import hooks
@ -22,10 +21,18 @@ server = {
'host': '0.0.0.0'
}
# In the future, surveil_api_config could be loaded from somewhere else,
# as long as is it in the same format.
surveil_api_config = {
"mongodb_uri": "mongodb://mongo:27017",
"ws_arbiter_url": "http://shinken:7760"
}
app_hooks = [
hooks.DBHook(
pymongo.MongoClient('mongo', 27017),
"http://shinken:7760"
surveil_api_config['mongodb_uri'],
surveil_api_config['ws_arbiter_url']
)
]

View File

@ -13,14 +13,20 @@
# under the License.
from pecan import hooks
import pymongo
class DBHook(hooks.PecanHook):
def __init__(self, mongo_connection, ws_arbiter_url):
self.mongo_connection = mongo_connection
def __init__(self, mongo_url, ws_arbiter_url):
self.mongo_url = mongo_url
self.ws_arbiter_url = ws_arbiter_url
def before(self, state):
state.request.mongo_connection = self.mongo_connection
self.mongoclient = pymongo.MongoClient(self.mongo_url)
state.request.mongo_connection = self.mongoclient
state.request.ws_arbiter_url = self.ws_arbiter_url
def after(self, state):
self.mongoclient.close()

View File

@ -16,6 +16,7 @@
import subprocess
import pymongo
import surveilclient.client as sc
from surveil.api import config
@ -23,7 +24,7 @@ from surveil.api import config
def main():
# Create a basic config in mongodb
mongo = config.app_hooks[0].mongo_connection
mongo = pymongo.MongoClient(config.surveil_api_config['mongodb_uri'])
# Drop the current shinken config
mongo.drop_database('shinken')

View File

@ -17,9 +17,9 @@ import os
import mongomock
from oslo_config import cfg
import pecan
from pecan import hooks
import pecan.testing
from surveil.api import hooks
from surveil.tests import base
@ -38,8 +38,17 @@ class FunctionalTest(base.BaseTestCase):
self.mongoconnection = mongomock.Connection()
self.ws_arbiter_url = "http://localhost:7760"
class TestHook(hooks.PecanHook):
def __init__(self, mongoclient, wsarbiterurl):
self.mongoclient = mongoclient
self.ws_arbiter_url = wsarbiterurl
def before(self, state):
state.request.mongo_connection = self.mongoclient
state.request.ws_arbiter_url = self.ws_arbiter_url
app_hooks = [
hooks.DBHook(
TestHook(
self.mongoconnection,
self.ws_arbiter_url
)