add support for database migration
This commit is contained in:
@@ -82,6 +82,7 @@ from nova import quota
|
||||
from nova import utils
|
||||
from nova.auth import manager
|
||||
from nova.cloudpipe import pipelib
|
||||
from nova.db import migration
|
||||
|
||||
|
||||
logging.basicConfig()
|
||||
@@ -515,6 +516,22 @@ class LogCommands(object):
|
||||
print re.sub('#012', "\n", "\n".join(lines))
|
||||
|
||||
|
||||
class DbCommands(object):
|
||||
"""Class for managing the database."""
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def sync(self, version=None):
|
||||
"""adds role to user
|
||||
if project is specified, adds project specific role
|
||||
arguments: user, role [project]"""
|
||||
return migration.db_sync(version)
|
||||
|
||||
def version(self):
|
||||
print migration.db_version()
|
||||
|
||||
|
||||
CATEGORIES = [
|
||||
('user', UserCommands),
|
||||
('project', ProjectCommands),
|
||||
@@ -524,7 +541,8 @@ CATEGORIES = [
|
||||
('floating', FloatingIpCommands),
|
||||
('network', NetworkCommands),
|
||||
('service', ServiceCommands),
|
||||
('log', LogCommands)]
|
||||
('log', LogCommands),
|
||||
('db', DbCommands)]
|
||||
|
||||
|
||||
def lazy_match(name, key_value_tuples):
|
||||
|
||||
@@ -209,19 +209,6 @@ class Service(object):
|
||||
self.model_disconnected = True
|
||||
logging.exception(_("model server went away"))
|
||||
|
||||
try:
|
||||
# NOTE(vish): This is late-loaded to make sure that the
|
||||
# database is not created before flags have
|
||||
# been loaded.
|
||||
from nova.db.sqlalchemy import models
|
||||
models.register_models()
|
||||
except OperationalError:
|
||||
logging.exception(_("Data store %s is unreachable."
|
||||
" Trying again in %d seconds.") %
|
||||
(FLAGS.sql_connection,
|
||||
FLAGS.sql_retry_interval))
|
||||
time.sleep(FLAGS.sql_retry_interval)
|
||||
|
||||
|
||||
def serve(*services):
|
||||
FLAGS(sys.argv)
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
|
||||
import gettext
|
||||
import os
|
||||
import unittest
|
||||
import sys
|
||||
@@ -26,6 +26,10 @@ from nose import config
|
||||
from nose import result
|
||||
from nose import core
|
||||
|
||||
gettext.install('nova', unicode=1)
|
||||
|
||||
from nova.db import migration
|
||||
|
||||
|
||||
class NovaTestResult(result.TextTestResult):
|
||||
def __init__(self, *args, **kw):
|
||||
@@ -62,6 +66,9 @@ if __name__ == '__main__':
|
||||
env=os.environ,
|
||||
verbosity=3)
|
||||
|
||||
migration.db_sync()
|
||||
|
||||
|
||||
runner = NovaTestRunner(stream=c.stream,
|
||||
verbosity=c.verbosity,
|
||||
config=c)
|
||||
|
||||
Reference in New Issue
Block a user