Merge "DB migration to add ID column to HM"

This commit is contained in:
Jenkins 2017-03-17 21:36:50 +00:00 committed by Gerrit Code Review
commit 1714db29ac
7 changed files with 85 additions and 10 deletions

View File

@ -0,0 +1,56 @@
# Copyright 2017 Intel Corporation
#
# 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.
#
"""Add ID column to Healthmonitor table
Revision ID: fac584114642
Revises: fc5582da7d8a
Create Date: 2017-02-07 20:47:52.405865
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'fac584114642'
down_revision = 'fc5582da7d8a'
def upgrade():
op.add_column('health_monitor',
sa.Column('id',
sa.String(length=36),
nullable=True,
))
op.drop_constraint('fk_health_monitor_pool_id',
'health_monitor',
type_='foreignkey',)
op.execute("UPDATE health_monitor SET id = pool_id")
op.execute("ALTER TABLE health_monitor MODIFY id varchar(36) NOT NULL")
op.execute("ALTER TABLE health_monitor DROP PRIMARY KEY,"
"ADD PRIMARY KEY(id);")
op.create_foreign_key('fk_health_monitor_pool_id', 'health_monitor',
'pool', ['pool_id'], ['id'])
op.create_index('uq_health_monitor_pool',
'health_monitor', ['pool_id'],
unique=True)

View File

@ -193,7 +193,8 @@ class Member(base_models.BASE, base_models.IdMixin, base_models.ProjectMixin,
nullable=True)
class HealthMonitor(base_models.BASE, base_models.ProjectMixin,
class HealthMonitor(base_models.BASE, base_models.IdMixin,
base_models.ProjectMixin,
base_models.NameMixin):
__data_model__ = data_models.HealthMonitor
@ -208,7 +209,7 @@ class HealthMonitor(base_models.BASE, base_models.ProjectMixin,
pool_id = sa.Column(
sa.String(36),
sa.ForeignKey("pool.id", name="fk_health_monitor_pool_id"),
nullable=False, primary_key=True)
nullable=False)
delay = sa.Column(sa.Integer, nullable=False)
timeout = sa.Column(sa.Integer, nullable=False)
fall_threshold = sa.Column(sa.Integer, nullable=False)

View File

@ -142,5 +142,6 @@ def create_member(member_dict, pool_id):
def create_health_monitor(hm_dict, pool_id):
hm_dict['id'] = pool_id
hm_dict['pool_id'] = pool_id
return hm_dict

View File

@ -534,6 +534,7 @@ class Repositories(object):
data_models.HealthMonitor,
lb_dict['project_id']):
raise exceptions.QuotaException
hm_dict['id'] = pool_dm.id
hm_dict['pool_id'] = pool_dm.id
self.health_monitor.create(lock_session, **hm_dict)
for r_member_dict in member_dicts:
@ -582,6 +583,7 @@ class Repositories(object):
data_models.HealthMonitor,
lb_dict['project_id']):
raise exceptions.QuotaException
r_hm_dict['id'] = r_pool_dm.id
r_hm_dict['pool_id'] = r_pool_dm.id
self.health_monitor.create(lock_session,
**r_hm_dict)
@ -679,6 +681,13 @@ class VipRepository(BaseRepository):
class HealthMonitorRepository(BaseRepository):
model_class = models.HealthMonitor
def create(self, session, **model_kwargs):
with session.begin(subtransactions=True):
model_kwargs['id'] = model_kwargs['pool_id']
model = self.model_class(**model_kwargs)
session.add(model)
return model.to_data_model()
def update(self, session, pool_id, **model_kwargs):
"""Updates a health monitor entity in the database by pool_id."""
with session.begin(subtransactions=True):

View File

@ -80,7 +80,8 @@ class ModelTestMixin(object):
return self._insert(session, models.SessionPersistence, kwargs)
def create_health_monitor(self, session, pool_id, **overrides):
kwargs = {'pool_id': pool_id,
kwargs = {'id': pool_id,
'pool_id': pool_id,
'type': constants.HEALTH_MONITOR_HTTP,
'delay': 1,
'timeout': 1,

View File

@ -1296,8 +1296,8 @@ class AllRepositoriesTest(base.OctaviaDBTestBase):
operating_status=constants.ONLINE,
enabled=True, load_balancer_id=lb.id)
self.repos.health_monitor.create(
self.session, project_id=project_id, name="health_mon1",
type=constants.HEALTH_MONITOR_HTTP,
self.session, project_id=project_id,
name="health_mon1", type=constants.HEALTH_MONITOR_HTTP,
delay=1, timeout=1, fall_threshold=1, rise_threshold=1,
provisioning_status=constants.ACTIVE,
enabled=True, pool_id=pool.id)
@ -1325,8 +1325,8 @@ class AllRepositoriesTest(base.OctaviaDBTestBase):
operating_status=constants.ONLINE,
enabled=True, load_balancer_id=lb.id)
self.repos.health_monitor.create(
self.session, project_id=project_id, name="health_mon1",
type=constants.HEALTH_MONITOR_HTTP,
self.session, project_id=project_id,
name="health_mon1", type=constants.HEALTH_MONITOR_HTTP,
delay=1, timeout=1, fall_threshold=1, rise_threshold=1,
provisioning_status=constants.DELETED,
enabled=True, pool_id=pool.id)
@ -2433,9 +2433,10 @@ class HealthMonitorRepositoryTest(BaseRepositoryTest):
def create_health_monitor(self, pool_id):
health_monitor = self.hm_repo.create(
self.session, type=constants.HEALTH_MONITOR_HTTP, pool_id=pool_id,
delay=1, timeout=1, fall_threshold=1, rise_threshold=1,
http_method="POST", url_path="http://localhost:80/index.php",
self.session, type=constants.HEALTH_MONITOR_HTTP,
pool_id=pool_id, delay=1, timeout=1, fall_threshold=1,
rise_threshold=1, http_method="POST",
url_path="http://localhost:80/index.php",
expected_codes="200", enabled=True)
return health_monitor

View File

@ -0,0 +1,6 @@
---
upgrade:
- Adding `ID` column to the health_monitor table in Octavia,
whose value is same as the `pool_id` column.
The database needs to be upgraded first, followed by upgrade
and restart of the API servers.