DB migration to add ID column to HM
For the effort of aligning Octavia API to nlbaasv2, the health monitor resource needs an `ID` field. This migration script adds that required column in the Octavia database. Change-Id: I3cfe26fd6312019471ff48df4ad9cd970f7173b6
This commit is contained in:
parent
fc675669d6
commit
0b08075ad6
@ -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)
|
@ -175,7 +175,8 @@ class Member(base_models.BASE, base_models.IdMixin, base_models.ProjectMixin,
|
|||||||
nullable=True)
|
nullable=True)
|
||||||
|
|
||||||
|
|
||||||
class HealthMonitor(base_models.BASE, base_models.ProjectMixin,
|
class HealthMonitor(base_models.BASE, base_models.IdMixin,
|
||||||
|
base_models.ProjectMixin,
|
||||||
base_models.NameMixin):
|
base_models.NameMixin):
|
||||||
|
|
||||||
__data_model__ = data_models.HealthMonitor
|
__data_model__ = data_models.HealthMonitor
|
||||||
@ -190,7 +191,7 @@ class HealthMonitor(base_models.BASE, base_models.ProjectMixin,
|
|||||||
pool_id = sa.Column(
|
pool_id = sa.Column(
|
||||||
sa.String(36),
|
sa.String(36),
|
||||||
sa.ForeignKey("pool.id", name="fk_health_monitor_pool_id"),
|
sa.ForeignKey("pool.id", name="fk_health_monitor_pool_id"),
|
||||||
nullable=False, primary_key=True)
|
nullable=False)
|
||||||
delay = sa.Column(sa.Integer, nullable=False)
|
delay = sa.Column(sa.Integer, nullable=False)
|
||||||
timeout = sa.Column(sa.Integer, nullable=False)
|
timeout = sa.Column(sa.Integer, nullable=False)
|
||||||
fall_threshold = sa.Column(sa.Integer, nullable=False)
|
fall_threshold = sa.Column(sa.Integer, nullable=False)
|
||||||
|
@ -142,5 +142,6 @@ def create_member(member_dict, pool_id):
|
|||||||
|
|
||||||
|
|
||||||
def create_health_monitor(hm_dict, pool_id):
|
def create_health_monitor(hm_dict, pool_id):
|
||||||
|
hm_dict['id'] = pool_id
|
||||||
hm_dict['pool_id'] = pool_id
|
hm_dict['pool_id'] = pool_id
|
||||||
return hm_dict
|
return hm_dict
|
||||||
|
@ -532,6 +532,7 @@ class Repositories(object):
|
|||||||
data_models.HealthMonitor,
|
data_models.HealthMonitor,
|
||||||
lb_dict['project_id']):
|
lb_dict['project_id']):
|
||||||
raise exceptions.QuotaException
|
raise exceptions.QuotaException
|
||||||
|
hm_dict['id'] = pool_dm.id
|
||||||
hm_dict['pool_id'] = pool_dm.id
|
hm_dict['pool_id'] = pool_dm.id
|
||||||
self.health_monitor.create(lock_session, **hm_dict)
|
self.health_monitor.create(lock_session, **hm_dict)
|
||||||
for r_member_dict in member_dicts:
|
for r_member_dict in member_dicts:
|
||||||
@ -580,6 +581,7 @@ class Repositories(object):
|
|||||||
data_models.HealthMonitor,
|
data_models.HealthMonitor,
|
||||||
lb_dict['project_id']):
|
lb_dict['project_id']):
|
||||||
raise exceptions.QuotaException
|
raise exceptions.QuotaException
|
||||||
|
r_hm_dict['id'] = r_pool_dm.id
|
||||||
r_hm_dict['pool_id'] = r_pool_dm.id
|
r_hm_dict['pool_id'] = r_pool_dm.id
|
||||||
self.health_monitor.create(lock_session,
|
self.health_monitor.create(lock_session,
|
||||||
**r_hm_dict)
|
**r_hm_dict)
|
||||||
@ -677,6 +679,13 @@ class VipRepository(BaseRepository):
|
|||||||
class HealthMonitorRepository(BaseRepository):
|
class HealthMonitorRepository(BaseRepository):
|
||||||
model_class = models.HealthMonitor
|
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):
|
def update(self, session, pool_id, **model_kwargs):
|
||||||
"""Updates a health monitor entity in the database by pool_id."""
|
"""Updates a health monitor entity in the database by pool_id."""
|
||||||
with session.begin(subtransactions=True):
|
with session.begin(subtransactions=True):
|
||||||
|
@ -80,7 +80,8 @@ class ModelTestMixin(object):
|
|||||||
return self._insert(session, models.SessionPersistence, kwargs)
|
return self._insert(session, models.SessionPersistence, kwargs)
|
||||||
|
|
||||||
def create_health_monitor(self, session, pool_id, **overrides):
|
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,
|
'type': constants.HEALTH_MONITOR_HTTP,
|
||||||
'delay': 1,
|
'delay': 1,
|
||||||
'timeout': 1,
|
'timeout': 1,
|
||||||
|
@ -1296,8 +1296,8 @@ class AllRepositoriesTest(base.OctaviaDBTestBase):
|
|||||||
operating_status=constants.ONLINE,
|
operating_status=constants.ONLINE,
|
||||||
enabled=True, load_balancer_id=lb.id)
|
enabled=True, load_balancer_id=lb.id)
|
||||||
self.repos.health_monitor.create(
|
self.repos.health_monitor.create(
|
||||||
self.session, project_id=project_id, name="health_mon1",
|
self.session, project_id=project_id,
|
||||||
type=constants.HEALTH_MONITOR_HTTP,
|
name="health_mon1", type=constants.HEALTH_MONITOR_HTTP,
|
||||||
delay=1, timeout=1, fall_threshold=1, rise_threshold=1,
|
delay=1, timeout=1, fall_threshold=1, rise_threshold=1,
|
||||||
provisioning_status=constants.ACTIVE,
|
provisioning_status=constants.ACTIVE,
|
||||||
enabled=True, pool_id=pool.id)
|
enabled=True, pool_id=pool.id)
|
||||||
@ -1325,8 +1325,8 @@ class AllRepositoriesTest(base.OctaviaDBTestBase):
|
|||||||
operating_status=constants.ONLINE,
|
operating_status=constants.ONLINE,
|
||||||
enabled=True, load_balancer_id=lb.id)
|
enabled=True, load_balancer_id=lb.id)
|
||||||
self.repos.health_monitor.create(
|
self.repos.health_monitor.create(
|
||||||
self.session, project_id=project_id, name="health_mon1",
|
self.session, project_id=project_id,
|
||||||
type=constants.HEALTH_MONITOR_HTTP,
|
name="health_mon1", type=constants.HEALTH_MONITOR_HTTP,
|
||||||
delay=1, timeout=1, fall_threshold=1, rise_threshold=1,
|
delay=1, timeout=1, fall_threshold=1, rise_threshold=1,
|
||||||
provisioning_status=constants.DELETED,
|
provisioning_status=constants.DELETED,
|
||||||
enabled=True, pool_id=pool.id)
|
enabled=True, pool_id=pool.id)
|
||||||
@ -2433,9 +2433,10 @@ class HealthMonitorRepositoryTest(BaseRepositoryTest):
|
|||||||
|
|
||||||
def create_health_monitor(self, pool_id):
|
def create_health_monitor(self, pool_id):
|
||||||
health_monitor = self.hm_repo.create(
|
health_monitor = self.hm_repo.create(
|
||||||
self.session, type=constants.HEALTH_MONITOR_HTTP, pool_id=pool_id,
|
self.session, type=constants.HEALTH_MONITOR_HTTP,
|
||||||
delay=1, timeout=1, fall_threshold=1, rise_threshold=1,
|
pool_id=pool_id, delay=1, timeout=1, fall_threshold=1,
|
||||||
http_method="POST", url_path="http://localhost:80/index.php",
|
rise_threshold=1, http_method="POST",
|
||||||
|
url_path="http://localhost:80/index.php",
|
||||||
expected_codes="200", enabled=True)
|
expected_codes="200", enabled=True)
|
||||||
return health_monitor
|
return health_monitor
|
||||||
|
|
||||||
|
@ -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.
|
Loading…
x
Reference in New Issue
Block a user