Adding model changes to support active/standby

1. Create value tables for: lb topology, and amphora roles.
2. Add a topology column to the load_balancer table.
3. Add a role column to the amphora table.
4. Functional tests.

Change-Id: If8d0523c9e74787d6a2561fa1f9a2c94cdf12502
This commit is contained in:
Sherif Abdelwahab 2015-07-17 11:40:43 -07:00
parent f074222842
commit eecbecc1f9
6 changed files with 130 additions and 5 deletions

View File

@ -130,4 +130,13 @@ RPC_NAMESPACE_CONTROLLER_AGENT = 'controller'
TOPOLOGY_SINGLE = 'SINGLE'
TOPOLOGY_STATUS_OK = 'OK'
# Active standalone roles and topology
TOPOLOGY_ACTIVE_STANDBY = 'ACTIVE_STANDBY'
ROLE_MASTER = 'MASTER'
ROLE_BACKUP = 'BACKUP'
ROLE_STANDALONE = 'STANDALONE'
SUPPORTED_LB_TOPOLOGIES = (TOPOLOGY_ACTIVE_STANDBY, TOPOLOGY_SINGLE)
SUPPORTED_AMPHORA_ROLES = (ROLE_BACKUP, ROLE_MASTER, ROLE_STANDALONE)
AGENT_API_TEMPLATES = '/templates'

View File

@ -173,7 +173,7 @@ class LoadBalancer(BaseDataModel):
def __init__(self, id=None, tenant_id=None, name=None, description=None,
provisioning_status=None, operating_status=None, enabled=None,
vip=None, listeners=None, amphorae=None):
topology=None, vip=None, listeners=None, amphorae=None):
self.id = id
self.tenant_id = tenant_id
self.name = name
@ -182,6 +182,7 @@ class LoadBalancer(BaseDataModel):
self.operating_status = operating_status
self.enabled = enabled
self.vip = vip
self.topology = topology
self.listeners = listeners or []
self.amphorae = amphorae or []
@ -224,7 +225,7 @@ class Amphora(BaseDataModel):
def __init__(self, id=None, load_balancer_id=None, compute_id=None,
status=None, lb_network_ip=None, vrrp_ip=None,
ha_ip=None, vrrp_port_id=None, ha_port_id=None,
load_balancer=None):
load_balancer=None, role=None):
self.id = id
self.load_balancer_id = load_balancer_id
self.compute_id = compute_id
@ -234,6 +235,7 @@ class Amphora(BaseDataModel):
self.ha_ip = ha_ip
self.vrrp_port_id = vrrp_port_id
self.ha_port_id = ha_port_id
self.role = role
self.load_balancer = load_balancer

View File

@ -0,0 +1,89 @@
# Copyright 2015 Hewlett-Packard Development Company, L.P.
#
# 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.
#
"""update lb and amphora data model for active passive
Revision ID: 357d17a6d5ac
Revises: 298eac0640a7
Create Date: 2015-07-16 17:41:49.029145
"""
# revision identifiers, used by Alembic.
revision = '357d17a6d5ac'
down_revision = '298eac0640a7'
from alembic import op
import sqlalchemy as sa
from sqlalchemy import sql
def upgrade():
op.create_table(
u'lb_topology',
sa.Column(u'name', sa.String(36), primary_key=True),
sa.Column(u'description', sa.String(255), nullable=True)
)
insert_table = sql.table(
u'lb_topology',
sql.column(u'name', sa.String),
sql.column(u'description', sa.String)
)
op.bulk_insert(
insert_table,
[
{'name': 'SINGLE'},
{'name': 'ACTIVE_STANDBY'}
]
)
op.create_table(
u'amphora_roles',
sa.Column(u'name', sa.String(36), primary_key=True),
sa.Column(u'description', sa.String(255), nullable=True)
)
insert_table = sql.table(
u'amphora_roles',
sql.column(u'name', sa.String),
sql.column(u'description', sa.String)
)
op.bulk_insert(
insert_table,
[
{'name': 'MASTER'},
{'name': 'BACKUP'},
{'name': 'STANDALONE'}
]
)
op.add_column(
u'load_balancer',
sa.Column(u'topology', sa.String(36),
sa.ForeignKey(u'lb_topology.name',
name=u'fk_lb_topology_name'),
nullable=True)
)
op.add_column(
u'amphora',
sa.Column(u'role', sa.String(36),
sa.ForeignKey(u'amphora_roles.name',
name=u'fk_amphora_roles_name'),
nullable=True)
)

View File

@ -42,6 +42,16 @@ class Algorithm(base_models.BASE, base_models.LookupTableMixin):
__tablename__ = "algorithm"
class AmphoraRoles(base_models.BASE, base_models.LookupTableMixin):
__tablename__ = "amphora_roles"
class LBTopology(base_models.BASE, base_models.LookupTableMixin):
__tablename__ = "lb_topology"
class SessionPersistenceType(base_models.BASE, base_models.LookupTableMixin):
__tablename__ = "session_persistence_type"
@ -212,6 +222,10 @@ class LoadBalancer(base_models.BASE, base_models.IdMixin,
sa.ForeignKey("operating_status.name",
name="fk_load_balancer_operating_status_name"),
nullable=False)
topology = sa.Column(
sa.String(36),
sa.ForeignKey("lb_topology.name", name="fk_lb_topology_name"),
nullable=True)
enabled = sa.Column(sa.Boolean, nullable=False)
amphorae = orm.relationship("Amphora", uselist=True,
backref=orm.backref("load_balancer",
@ -326,6 +340,10 @@ class Amphora(base_models.BASE):
ha_ip = sa.Column(sa.String(64), nullable=True)
vrrp_port_id = sa.Column(sa.String(36), nullable=True)
ha_port_id = sa.Column(sa.String(36), nullable=True)
role = sa.Column(
sa.String(36),
sa.ForeignKey("amphora_roles.name", name="fk_amphora_roles_name"),
nullable=True)
status = sa.Column(
sa.String(36),
sa.ForeignKey("provisioning_status.name",
@ -339,4 +357,4 @@ class AmphoraHealth(base_models.BASE):
amphora_id = sa.Column(
sa.String(36), nullable=False, primary_key=True)
last_update = sa.Column(sa.DateTime, default=func.now(),
nullable=False)
nullable=False)

View File

@ -65,6 +65,10 @@ class OctaviaDBTestBase(test_base.DbTestCase):
self._seed_lookup_table(
session, constants.SUPPORTED_SP_TYPES,
models.SessionPersistenceType)
self._seed_lookup_table(session, constants.SUPPORTED_AMPHORA_ROLES,
models.AmphoraRoles)
self._seed_lookup_table(session, constants.SUPPORTED_LB_TOPOLOGIES,
models.LBTopology)
def _seed_lookup_table(self, session, name_list, model_cls):
for name in name_list:

View File

@ -97,7 +97,8 @@ class AllRepositoriesTest(base.OctaviaDBTestBase):
def test_create_load_balancer_and_vip(self):
lb = {'name': 'test1', 'description': 'desc1', 'enabled': True,
'provisioning_status': constants.PENDING_UPDATE,
'operating_status': constants.OFFLINE}
'operating_status': constants.OFFLINE,
'topology': constants.TOPOLOGY_ACTIVE_STANDBY}
vip = {'ip_address': '10.0.0.1',
'port_id': uuidutils.generate_uuid(),
'subnet_id': uuidutils.generate_uuid()}
@ -1069,7 +1070,8 @@ class AmphoraRepositoryTest(BaseRepositoryTest):
status=constants.ACTIVE,
lb_network_ip=self.FAKE_IP,
vrrp_ip=self.FAKE_IP,
ha_ip=self.FAKE_IP)
ha_ip=self.FAKE_IP,
role=constants.ROLE_MASTER)
return amphora
def test_get(self):
@ -1083,6 +1085,7 @@ class AmphoraRepositoryTest(BaseRepositoryTest):
self.assertEqual(self.FAKE_UUID_1, amphora.id)
self.assertEqual(self.FAKE_UUID_3, amphora.compute_id)
self.assertEqual(constants.ACTIVE, amphora.status)
self.assertEqual(constants.ROLE_MASTER, amphora.role)
def test_update(self):
status_change = constants.PENDING_UPDATE