From 9cea1741a27bfe641eaa5895711d09485a073a1e Mon Sep 17 00:00:00 2001 From: Flavio Percoco Date: Tue, 11 Mar 2014 14:42:07 +0100 Subject: [PATCH] Add an options module to sqlalchemy Let sqla follow the pattern used in other storage drivers. This patch adds a new options module with a function used by the oslo.config.opts namespace in the entry_point section. Change-Id: I0e8b24d7de220104cf59c09883415ae8c5bed8f6 --- marconi/queues/storage/sqlalchemy/driver.py | 22 ++++++--------- marconi/queues/storage/sqlalchemy/options.py | 28 ++++++++++++++++++++ 2 files changed, 36 insertions(+), 14 deletions(-) create mode 100644 marconi/queues/storage/sqlalchemy/options.py diff --git a/marconi/queues/storage/sqlalchemy/driver.py b/marconi/queues/storage/sqlalchemy/driver.py index afd4ac5f3..63a914524 100644 --- a/marconi/queues/storage/sqlalchemy/driver.py +++ b/marconi/queues/storage/sqlalchemy/driver.py @@ -16,31 +16,25 @@ import contextlib -from oslo.config import cfg import sqlalchemy as sa from marconi.common import decorators from marconi.queues import storage from marconi.queues.storage.sqlalchemy import controllers +from marconi.queues.storage.sqlalchemy import options from marconi.queues.storage.sqlalchemy import tables from marconi.queues.storage.sqlalchemy import utils -_SQLALCHEMY_OPTIONS = [ - cfg.StrOpt('uri', default='sqlite:///:memory:', - help='An sqlalchemy URL') -] - -_SQLALCHEMY_GROUP = 'drivers:storage:sqlalchemy' - class DataDriver(storage.DataDriverBase): def __init__(self, conf, cache): super(DataDriver, self).__init__(conf, cache) - self.conf.register_opts(_SQLALCHEMY_OPTIONS, - group=_SQLALCHEMY_GROUP) - self.sqlalchemy_conf = self.conf[_SQLALCHEMY_GROUP] + opts = options.SQLALCHEMY_OPTIONS + self.conf.register_opts(opts, + group=options.SQLALCHEMY_GROUP) + self.sqlalchemy_conf = self.conf[options.SQLALCHEMY_GROUP] def _sqlite_on_connect(self, conn, record): # NOTE(flaper87): This is necesary in order @@ -127,9 +121,9 @@ class ControlDriver(storage.ControlDriverBase): def __init__(self, conf, cache): super(ControlDriver, self).__init__(conf, cache) - self.conf.register_opts(_SQLALCHEMY_OPTIONS, - group=_SQLALCHEMY_GROUP) - self.sqlalchemy_conf = self.conf[_SQLALCHEMY_GROUP] + self.conf.register_opts(options.SQLALCHEMY_OPTIONS, + group=options.SQLALCHEMY_GROUP) + self.sqlalchemy_conf = self.conf[options.SQLALCHEMY_GROUP] @decorators.lazy_property(write=False) def engine(self, *args, **kwargs): diff --git a/marconi/queues/storage/sqlalchemy/options.py b/marconi/queues/storage/sqlalchemy/options.py new file mode 100644 index 000000000..960f63690 --- /dev/null +++ b/marconi/queues/storage/sqlalchemy/options.py @@ -0,0 +1,28 @@ +# Copyright (c) 2014 Red Hat, Inc. +# +# 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. + +from oslo.config import cfg + +SQLALCHEMY_OPTIONS = ( + cfg.StrOpt('uri', default='sqlite:///:memory:', + help='An sqlalchemy URL'), +) + +SQLALCHEMY_GROUP = 'drivers:storage:sqlalchemy' + + +def _config_options(): + return [(SQLALCHEMY_GROUP, SQLALCHEMY_OPTIONS)]