From 7fbc3dad25c92cdc2b6474619773f6cd05c4f926 Mon Sep 17 00:00:00 2001 From: Krysta Date: Fri, 19 Jan 2018 08:56:54 -0600 Subject: [PATCH] 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 --- .../templates/bin/_shipyard-db-sync.sh.tpl | 2 ++ setup.cfg | 1 + shipyard_airflow/conf/config.py | 5 ---- shipyard_airflow/control/start_shipyard.py | 7 ----- shipyard_airflow/shipyard_upgrade_db.py | 29 +++++++++++++++++++ 5 files changed, 32 insertions(+), 12 deletions(-) create mode 100644 shipyard_airflow/shipyard_upgrade_db.py diff --git a/charts/shipyard/templates/bin/_shipyard-db-sync.sh.tpl b/charts/shipyard/templates/bin/_shipyard-db-sync.sh.tpl index e22b5872..addc45b4 100644 --- a/charts/shipyard/templates/bin/_shipyard-db-sync.sh.tpl +++ b/charts/shipyard/templates/bin/_shipyard-db-sync.sh.tpl @@ -17,3 +17,5 @@ limitations under the License. */}} set -ex + +upgrade_db diff --git a/setup.cfg b/setup.cfg index 009f692c..8ad69feb 100644 --- a/setup.cfg +++ b/setup.cfg @@ -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 diff --git a/shipyard_airflow/conf/config.py b/shipyard_airflow/conf/config.py index 9b2cbbd1..6509fa7e 100644 --- a/shipyard_airflow/conf/config.py +++ b/shipyard_airflow/conf/config.py @@ -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' ) ] ), diff --git a/shipyard_airflow/control/start_shipyard.py b/shipyard_airflow/control/start_shipyard.py index 13587413..83dce499 100644 --- a/shipyard_airflow/control/start_shipyard.py +++ b/shipyard_airflow/control/start_shipyard.py @@ -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() diff --git a/shipyard_airflow/shipyard_upgrade_db.py b/shipyard_airflow/shipyard_upgrade_db.py new file mode 100644 index 00000000..6c8ad974 --- /dev/null +++ b/shipyard_airflow/shipyard_upgrade_db.py @@ -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