Implements database upgrade as storage engine independent
Currently, calling ceilometer-dbsync will be default raises an error since it tries to upgrade a SQL database, even if mongo (the default) is used. This patch fixes that by adding an upgrade capability to the storage engine connection base class, and implementing it only in SQL. Change-Id: I9a0da235ef3a93aaefd1b122d59f244ea293e9fe Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
ad5ff3e4e5
commit
c6a093511c
bin
ceilometer/storage
tests/storage
@ -2,6 +2,7 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
#
|
||||
# Author: John Tran <jhtran@att.com>
|
||||
# Author: Julien Danjou <julien@danjou.info>
|
||||
#
|
||||
# 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
|
||||
@ -14,14 +15,14 @@
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
"""Run SQLAlchemy db migration.
|
||||
"""Run storage database migration.
|
||||
"""
|
||||
|
||||
import sys
|
||||
from ceilometer import service
|
||||
from ceilometer import storage
|
||||
from ceilometer.storage import migration
|
||||
from ceilometer.openstack.common import cfg
|
||||
|
||||
if __name__ == '__main__':
|
||||
cfg.CONF(sys.argv[1:])
|
||||
migration.db_sync()
|
||||
service.prepare_service(sys.argv)
|
||||
storage.get_connection(cfg.CONF).db_sync()
|
||||
|
@ -52,6 +52,10 @@ class Connection(object):
|
||||
def __init__(self, conf):
|
||||
"""Constructor"""
|
||||
|
||||
@abc.abstractmethod
|
||||
def upgrade(self, version=None):
|
||||
"""Migrate the database to `version` or the most recent version."""
|
||||
|
||||
@abc.abstractmethod
|
||||
def record_metering_data(self, data):
|
||||
"""Write the data to the backend storage system.
|
||||
|
@ -45,6 +45,9 @@ class Connection(base.Connection):
|
||||
def __init__(self, conf):
|
||||
return
|
||||
|
||||
def upgrade(self, version=None):
|
||||
pass
|
||||
|
||||
def record_metering_data(self, data):
|
||||
"""Write the data to the backend storage system.
|
||||
|
||||
|
@ -204,6 +204,9 @@ class Connection(base.Connection):
|
||||
], name='meter_idx')
|
||||
return
|
||||
|
||||
def upgrade(self, version=None):
|
||||
pass
|
||||
|
||||
def _get_connection(self, opts):
|
||||
"""Return a connection to the database.
|
||||
|
||||
|
@ -25,6 +25,7 @@ from ceilometer.storage.sqlalchemy.models import Meter, Project, Resource
|
||||
from ceilometer.storage.sqlalchemy.models import Source, User
|
||||
from ceilometer.storage.sqlalchemy.session import func
|
||||
import ceilometer.storage.sqlalchemy.session as sqlalchemy_session
|
||||
from ceilometer.storage.sqlalchemy import migration
|
||||
|
||||
LOG = log.getLogger(__name__)
|
||||
|
||||
@ -128,6 +129,9 @@ class Connection(base.Connection):
|
||||
self.session = self._get_connection(conf)
|
||||
return
|
||||
|
||||
def upgrade(self, version=None):
|
||||
migration.db_sync(self.session.get_bind(), version=version)
|
||||
|
||||
def _get_connection(self, conf):
|
||||
"""Return a connection to the database.
|
||||
"""
|
||||
|
@ -1,29 +0,0 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
#
|
||||
# Author: John Tran <jhtran@att.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.
|
||||
|
||||
"""Database setup and migration commands."""
|
||||
|
||||
import ceilometer.storage.sqlalchemy.migration as IMPL
|
||||
|
||||
|
||||
def db_sync(version=None):
|
||||
"""Migrate the database to `version` or the most recent version."""
|
||||
return IMPL.db_sync(version=version)
|
||||
|
||||
|
||||
def db_version():
|
||||
"""Display the current database version."""
|
||||
return IMPL.db_version()
|
@ -59,7 +59,7 @@ from migrate.versioning.repository import Repository
|
||||
_REPOSITORY = None
|
||||
|
||||
|
||||
def db_sync(version=None):
|
||||
def db_sync(engine, version=None):
|
||||
if version is not None:
|
||||
try:
|
||||
version = int(version)
|
||||
@ -69,9 +69,9 @@ def db_sync(version=None):
|
||||
current_version = db_version()
|
||||
repository = _find_migrate_repo()
|
||||
if version is None or version > current_version:
|
||||
return versioning_api.upgrade(get_engine(), repository, version)
|
||||
return versioning_api.upgrade(engine, repository, version)
|
||||
else:
|
||||
return versioning_api.downgrade(get_engine(), repository,
|
||||
return versioning_api.downgrade(engine, repository,
|
||||
version)
|
||||
|
||||
|
||||
|
@ -26,7 +26,6 @@ import unittest
|
||||
from ceilometer.collector import meter
|
||||
from ceilometer import counter
|
||||
from ceilometer import storage
|
||||
from ceilometer.storage import migration
|
||||
from ceilometer.openstack.common import cfg
|
||||
from ceilometer.storage import impl_sqlalchemy
|
||||
from ceilometer.storage.sqlalchemy.models import Meter, Project, Resource
|
||||
@ -84,8 +83,7 @@ class SQLAlchemyEngineSubBase(unittest.TestCase):
|
||||
|
||||
self.conn = Connection(self.conf)
|
||||
self.session = self.conn.session
|
||||
|
||||
migration.db_sync()
|
||||
self.conn.upgrade()
|
||||
|
||||
|
||||
class SQLAlchemyEngineTestBase(SQLAlchemyEngineSubBase):
|
||||
|
Loading…
x
Reference in New Issue
Block a user