Add database upgrade entrypoint

Removes the database upgrade from start shipyard and
instead adds it as an entrypoint, so the database upgrade
is only done once.

Change-Id: I8c087af58aa46051d0d1c47ba5f35e5e86c1acdc
This commit is contained in:
Krysta 2018-01-19 08:56:54 -06:00 committed by Krysta Knight
parent 08f228ed91
commit 7fbc3dad25
5 changed files with 32 additions and 12 deletions

View File

@ -17,3 +17,5 @@ limitations under the License.
*/}}
set -ex
upgrade_db

View File

@ -26,6 +26,7 @@ oslo.policy.policies =
shipyard_airflow = shipyard_airflow.policy:list_policies
console_scripts =
shipyard = shipyard_client.cli.commands:shipyard
upgrade_db = shipyard_airflow.shipyard_upgrade_db:upgrade_db
[build_sphinx]
source-dir = docs/source

View File

@ -52,11 +52,6 @@ SECTIONS = [
'alembic_ini_path',
default='/home/shipyard/shipyard',
help='The direcotry containing the alembic.ini file'
),
cfg.BoolOpt(
'upgrade_db',
default=True,
help='Upgrade the database on startup'
)
]
),

View File

@ -21,7 +21,6 @@ from oslo_config import cfg
from shipyard_airflow.conf import config
import shipyard_airflow.control.api as api
from shipyard_airflow.control import ucp_logging
from shipyard_airflow.db import db
from shipyard_airflow import policy
CONF = cfg.CONF
@ -37,11 +36,5 @@ def start_shipyard(default_config_files=None):
policy.policy_engine = policy.ShipyardPolicy()
policy.policy_engine.register_policy()
# Upgrade database
if CONF.base.upgrade_db:
# this is a reasonable place to put any online alembic upgrades
# desired. Currently only shipyard db is under shipyard control.
db.SHIPYARD_DB.update_db()
# Start the API
return api.start_api()

View File

@ -0,0 +1,29 @@
# Copyright 2017 AT&T Intellectual Property. All other rights reserved.
#
# 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 shipyard_airflow.conf import config
from shipyard_airflow.db import db
def shipyard_upgrade_db(default_config_files=None):
"""
Starts database upgrade
"""
# Trigger configuration resolution.
config.parse_args(args=[], default_config_files=default_config_files)
db.SHIPYARD_DB.update_db()
upgrade_db = shipyard_upgrade_db