Move to billingstack.storage

Change-Id: I64979139fc99bc1e6c7c27e64e4ecdddf169eb26
This commit is contained in:
Endre Karlson 2013-06-24 15:36:51 +02:00
parent bbbb1d0b0d
commit a6d2cacd6d
7 changed files with 46 additions and 48 deletions

View File

@ -16,7 +16,7 @@
from oslo.config import cfg
from billingstack.openstack.common import log as logging
from billingstack.openstack.common.rpc import service as rpc_service
from billingstack.biller import storage
from billingstack.storage.utils import get_connection
cfg.CONF.import_opt('biller_topic', 'billingstack.biller.rpcapi')
@ -39,5 +39,5 @@ class Service(rpc_service.Service):
super(Service, self).__init__(*args, **kwargs)
def start(self):
self.storage_conn = storage.get_connection()
self.storage_conn = get_connection('biller')
super(Service, self).start()

View File

@ -14,7 +14,6 @@
# License for the specific language governing permissions and limitations
# under the License.
from oslo.config import cfg
from billingstack.storage import base
@ -25,9 +24,3 @@ class StorageEngine(base.StorageEngine):
class Connection(base.Connection):
"""Define the base API for biller storage"""
def get_connection():
name = cfg.CONF['service:biller'].storage_driver
plugin = StorageEngine.get_plugin(name, invoke_on_load=True)
return plugin.get_connection()

View File

@ -20,7 +20,7 @@ from oslo.config import cfg
from billingstack.openstack.common import log as logging
from billingstack.openstack.common.rpc import service as rpc_service
from billingstack.openstack.common import service as os_service
from billingstack.central import storage
from billingstack.storage.utils import get_connection
from billingstack import service as bs_service
@ -41,7 +41,7 @@ class Service(rpc_service.Service):
super(Service, self).__init__(*args, **kwargs)
def start(self):
self.storage_conn = storage.get_connection()
self.storage_conn = get_connection('central')
super(Service, self).start()
def __getattr__(self, name):

View File

@ -15,7 +15,6 @@
# under the License.
#
# Copied: Moniker
from oslo.config import cfg
from billingstack.openstack.common import log as logging
from billingstack.storage import base
@ -30,29 +29,3 @@ class StorageEngine(base.StorageEngine):
class Connection(base.Connection):
pass
def get_engine(engine_name):
"""
Return the engine class from the provided engine name
"""
return StorageEngine.get_plugin(engine_name, invoke_on_load=True)
def get_connection():
engine = get_engine(cfg.CONF['service:central'].storage_driver)
return engine.get_connection()
def setup_schema():
""" Create the DB - Used for testing purposes """
LOG.debug("Setting up Schema")
connection = get_connection()
connection.setup_schema()
def teardown_schema():
""" Reset the DB to default - Used for testing purposes """
LOG.debug("Tearing down Schema")
connection = get_connection()
connection.teardown_schema()

View File

@ -19,7 +19,7 @@ from oslo.config import cfg
from billingstack.openstack.common import log as logging
from billingstack.openstack.common import service as os_service
from billingstack.openstack.common.rpc import service as rpc_service
from billingstack.rater import storage
from billingstack.storage.utils import get_connection
from billingstack import service as bs_service
@ -47,7 +47,7 @@ class Service(rpc_service.Service):
super(Service, self).__init__(*args, **kwargs)
def start(self):
self.storage_conn = storage.get_connection()
self.storage_conn = get_connection('rater')
super(Service, self).start()
def create_usage(self, ctxt, values):

View File

@ -0,0 +1,38 @@
# -*- encoding: utf-8 -*-
#
# Author: Endre Karlson <endre.karlson@gmail.com>
#
# 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
from billingstack.openstack.common import importutils
def get_engine(service_name, driver_name):
"""
Return the engine class from the provided engine name
"""
path = 'billingstack.%s.storage.StorageEngine' % service_name
base = importutils.import_object(path)
return base.get_plugin(driver_name, invoke_on_load=True)
def get_connection(service_name, driver_name=None):
"""
Return a instance of a storage connection
"""
driver_name = driver_name or \
cfg.CONF['service:%s' % service_name].storage_driver
engine = get_engine(service_name, driver_name)
return engine.get_connection()

View File

@ -14,6 +14,7 @@ from oslo.config import cfg
from billingstack import exceptions
from billingstack import paths
from billingstack import samples
from billingstack.storage import utils as storage_utils
from billingstack.openstack.common.context import RequestContext, \
get_admin_context
from billingstack.openstack.common import importutils
@ -142,10 +143,6 @@ class StorageFixture(fixtures.Fixture):
group=self.svc_group)
set_config(storage_driver=self.driver, group=self.svc_group)
# FIXME: Move this to a generic get_storage() method instead?
self.module = importutils.import_module(
'billingstack.%s.storage' % self.svc)
# FIXME: Workout a way to support the different storage types
self.helper = SQLAlchemyHelper(self)
@ -175,11 +172,8 @@ class StorageFixture(fixtures.Fixture):
"""
Import the storage module for the service that we are going to act on,
then return a connection object for that storage module.
:param service: The service.
"""
engine = self.module.get_engine(self.driver)
return engine.get_connection()
return storage_utils.get_connection(self.svc, self.driver)
class ServiceFixture(fixtures.Fixture):