Add test storage driver
Create a "test" storage driver to be used by the API test code. blueprint api-server-pecan-wsme Change-Id: I99c7c82afa17ec5a9f36fd20d47b16011e64ffa9 Signed-off-by: Doug Hellmann <doug.hellmann@dreamhost.com>
This commit is contained in:
parent
b67d2c2dfb
commit
1767d89687
85
ceilometer/storage/impl_test.py
Normal file
85
ceilometer/storage/impl_test.py
Normal file
@ -0,0 +1,85 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
#
|
||||
# Copyright © 2012 New Dream Network, LLC (DreamHost)
|
||||
#
|
||||
# Author: Doug Hellmann <doug.hellmann@dreamhost.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.
|
||||
"""In-memory storage driver for use with tests.
|
||||
|
||||
This driver is based on MIM, an in-memory version of MongoDB.
|
||||
"""
|
||||
|
||||
import logging
|
||||
|
||||
from ming import mim
|
||||
|
||||
from ceilometer.storage import base
|
||||
from ceilometer.storage import impl_mongodb
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class TestDBStorage(base.StorageEngine):
|
||||
"""Put the data into an in-memory database for testing
|
||||
|
||||
This driver is based on MIM, an in-memory version of MongoDB.
|
||||
|
||||
Collections:
|
||||
|
||||
- user
|
||||
- { _id: user id
|
||||
source: [ array of source ids reporting for the user ]
|
||||
}
|
||||
- project
|
||||
- { _id: project id
|
||||
source: [ array of source ids reporting for the project ]
|
||||
}
|
||||
- meter
|
||||
- the raw incoming data
|
||||
- resource
|
||||
- the metadata for resources
|
||||
- { _id: uuid of resource,
|
||||
metadata: metadata dictionaries
|
||||
timestamp: datetime of last update
|
||||
user_id: uuid
|
||||
project_id: uuid
|
||||
meter: [ array of {counter_name: string, counter_type: string} ]
|
||||
}
|
||||
"""
|
||||
|
||||
OPTIONS = []
|
||||
|
||||
def register_opts(self, conf):
|
||||
"""Register any configuration options used by this engine.
|
||||
"""
|
||||
conf.register_opts(self.OPTIONS)
|
||||
|
||||
def get_connection(self, conf):
|
||||
"""Return a Connection instance based on the configuration settings.
|
||||
"""
|
||||
return TestConnection(conf)
|
||||
|
||||
|
||||
class TestConnection(impl_mongodb.Connection):
|
||||
|
||||
_mim_instance = None
|
||||
|
||||
def _get_connection(self, conf):
|
||||
# MIM will die if we have too many connections, so use a
|
||||
# Singleton
|
||||
if TestConnection._mim_instance is None:
|
||||
LOG.debug('Creating a new MIM Connection object')
|
||||
TestConnection._mim_instance = mim.Connection()
|
||||
return TestConnection._mim_instance
|
1
setup.py
1
setup.py
@ -127,5 +127,6 @@ setuptools.setup(
|
||||
mysql = ceilometer.storage.impl_sqlalchemy:SQLAlchemyStorage
|
||||
postgresql = ceilometer.storage.impl_sqlalchemy:SQLAlchemyStorage
|
||||
sqlite = ceilometer.storage.impl_sqlalchemy:SQLAlchemyStorage
|
||||
test = ceilometer.storage.impl_test:TestDBStorage
|
||||
"""),
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user