Rename tenant_id to project_id

Since openstack is going through renaming tenants to projects
it is best that we do this now while its easier before it becomes
bigger and harder to do.

This also adds project_id to the health_monitor table and models
since this seemed like an oversight.

Change-Id: Icc8034dcb517a3f8d218d83c94e4a2dcc977cc29
This commit is contained in:
Brandon Logan 2015-12-03 16:18:13 -06:00
parent c85ccfc82e
commit 969f811bd4
12 changed files with 160 additions and 110 deletions

View File

@ -61,7 +61,7 @@ Load Balancers
+---------------------+------------+------------------------------------+
| vip | VIP Object | JSON VIP object below |
+---------------------+------------+------------------------------------+
| tenant_id | UUID | ``UUID`` for tenant |
| project_id | UUID | ``UUID`` for project |
+---------------------+------------+------------------------------------+
| name | String | String for load balancer name |
+---------------------+------------+------------------------------------+
@ -191,7 +191,7 @@ Create a load balancer.
+=============+==========+
| vip | yes |
+-------------+----------+
| tenant_id | no |
| project_id | no |
+-------------+----------+
| name | no |
+-------------+----------+
@ -317,7 +317,7 @@ Listeners
| default_tls\ | String | Barbican ``UUID`` for TLS container |
| _container_id | | |
+---------------------+------------+-------------------------------------+
| tenant_id | String | ``UUID`` for tenant |
| project_id | String | ``UUID`` for project |
+---------------------+------------+-------------------------------------+
| name | String | String detailing the name of the \ |
| | | listener |
@ -451,7 +451,7 @@ Create a listener.
| default_tls\ | no |
| _container_id | |
+------------------+----------+
| tenant_id | no |
| project_id | no |
+------------------+----------+
| name | no |
+------------------+----------+

View File

@ -51,13 +51,17 @@ class LoadBalancersController(base.BaseController):
return self._convert_db_to_type(load_balancer,
lb_types.LoadBalancerResponse)
@wsme_pecan.wsexpose([lb_types.LoadBalancerResponse], wtypes.text)
def get_all(self, tenant_id=None):
@wsme_pecan.wsexpose([lb_types.LoadBalancerResponse], wtypes.text,
wtypes.text)
def get_all(self, tenant_id=None, project_id=None):
"""Lists all listeners on a load balancer."""
# tenant_id is an optional query parameter
# NOTE(blogan): tenant_id and project_id are optional query parameters
# tenant_id and project_id are the same thing. tenant_id will be kept
# around for a short amount of time.
project_id = project_id or tenant_id
session = db_api.get_session()
load_balancers = self.repositories.load_balancer.get_all(
session, tenant_id=tenant_id)
session, project_id=project_id)
return self._convert_db_to_type(load_balancers,
[lb_types.LoadBalancerResponse])

View File

@ -22,10 +22,10 @@ class ContextHook(hooks.PecanHook):
def on_route(state):
user_id = state.request.headers.get('X-User-Id')
user_id = state.request.headers.get('X-User', user_id)
tenant = state.request.headers.get('X-Tenant-Id')
tenant = state.request.headers.get('X-Tenant', tenant)
project = state.request.headers.get('X-Tenant-Id')
project = state.request.headers.get('X-Tenant', project)
auth_token = state.request.headers.get('X-Auth-Token')
state.request.context = context.Context(user_id=user_id,
tenant_id=tenant,
project_id=project,
auth_token=auth_token)

View File

@ -18,8 +18,8 @@ from octavia.db import api as db_api
class Context(common_context.RequestContext):
def __init__(self, user_id, tenant_id, is_admin=False, auth_token=None):
super(Context, self).__init__(tenant=tenant_id, auth_token=auth_token,
def __init__(self, user_id, project_id, is_admin=False, auth_token=None):
super(Context, self).__init__(tenant=project_id, auth_token=auth_token,
is_admin=is_admin, user=user_id)
self._session = None

View File

@ -73,12 +73,12 @@ class ListenerStatistics(BaseDataModel):
class HealthMonitor(BaseDataModel):
def __init__(self, id=None, tenant_id=None, pool_id=None, type=None,
def __init__(self, id=None, project_id=None, pool_id=None, type=None,
delay=None, timeout=None, fall_threshold=None,
rise_threshold=None, http_method=None, url_path=None,
expected_codes=None, enabled=None, pool=None):
self.id = id
self.tenant_id = tenant_id
self.project_id = project_id
self.pool_id = pool_id
self.type = type
self.delay = delay
@ -97,12 +97,12 @@ class HealthMonitor(BaseDataModel):
class Pool(BaseDataModel):
def __init__(self, id=None, tenant_id=None, name=None, description=None,
def __init__(self, id=None, project_id=None, name=None, description=None,
protocol=None, lb_algorithm=None, enabled=None,
operating_status=None, members=None, health_monitor=None,
session_persistence=None, listener=None):
self.id = id
self.tenant_id = tenant_id
self.project_id = project_id
self.name = name
self.description = description
self.protocol = protocol
@ -121,11 +121,11 @@ class Pool(BaseDataModel):
class Member(BaseDataModel):
def __init__(self, id=None, tenant_id=None, pool_id=None, ip_address=None,
def __init__(self, id=None, project_id=None, pool_id=None, ip_address=None,
protocol_port=None, weight=None, enabled=None,
subnet_id=None, operating_status=None, pool=None):
self.id = id
self.tenant_id = tenant_id
self.project_id = project_id
self.pool_id = pool_id
self.ip_address = ip_address
self.protocol_port = protocol_port
@ -144,14 +144,14 @@ class Member(BaseDataModel):
class Listener(BaseDataModel):
def __init__(self, id=None, tenant_id=None, name=None, description=None,
def __init__(self, id=None, project_id=None, name=None, description=None,
default_pool_id=None, load_balancer_id=None, protocol=None,
protocol_port=None, connection_limit=None,
enabled=None, provisioning_status=None, operating_status=None,
tls_certificate_id=None, stats=None, default_pool=None,
load_balancer=None, sni_containers=None, peer_port=None):
self.id = id
self.tenant_id = tenant_id
self.project_id = project_id
self.name = name
self.description = description
self.default_pool_id = default_pool_id
@ -172,12 +172,12 @@ class Listener(BaseDataModel):
class LoadBalancer(BaseDataModel):
def __init__(self, id=None, tenant_id=None, name=None, description=None,
def __init__(self, id=None, project_id=None, name=None, description=None,
provisioning_status=None, operating_status=None, enabled=None,
topology=None, vip=None, listeners=None, amphorae=None,
vrrp_group=None):
self.id = id
self.tenant_id = tenant_id
self.project_id = project_id
self.name = name
self.description = description
self.provisioning_status = provisioning_status

View File

@ -62,14 +62,14 @@ class LookupTableMixin(object):
class IdMixin(object):
"""Id mixin, add to subclasses that have a tenant."""
"""Id mixin, add to subclasses that have an id."""
id = sa.Column(sa.String(36), primary_key=True,
default=uuidutils.generate_uuid)
class TenantMixin(object):
"""Tenant mixin, add to subclasses that have a tenant."""
tenant_id = sa.Column(sa.String(36))
class ProjectMixin(object):
"""Tenant mixin, add to subclasses that have a project."""
project_id = sa.Column(sa.String(36))
BASE = declarative.declarative_base(cls=OctaviaBase)

View File

@ -0,0 +1,40 @@
# Copyright 2015 Rackspace
#
# 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.
"""Tenant id to project id
Revision ID: 6abb04f24c5
Revises: 5a3ee5472c31
Create Date: 2015-12-03 15:22:25.390595
"""
# revision identifiers, used by Alembic.
revision = '6abb04f24c5'
down_revision = '1e4c1d83044c'
from alembic import op
import sqlalchemy as sa
def upgrade():
op.alter_column('load_balancer', 'tenant_id', new_column_name='project_id',
existing_type=sa.String(36))
op.alter_column('listener', 'tenant_id', new_column_name='project_id',
existing_type=sa.String(36))
op.alter_column('pool', 'tenant_id', new_column_name='project_id',
existing_type=sa.String(36))
op.alter_column('member', 'tenant_id', new_column_name='project_id',
existing_type=sa.String(36))
op.add_column('health_monitor', sa.Column('project_id', sa.String(36)))

View File

@ -126,7 +126,7 @@ class ListenerStatistics(base_models.BASE):
return value
class Member(base_models.BASE, base_models.IdMixin, base_models.TenantMixin):
class Member(base_models.BASE, base_models.IdMixin, base_models.ProjectMixin):
__data_model__ = data_models.Member
@ -155,7 +155,7 @@ class Member(base_models.BASE, base_models.IdMixin, base_models.TenantMixin):
cascade="delete"))
class HealthMonitor(base_models.BASE):
class HealthMonitor(base_models.BASE, base_models.ProjectMixin):
__data_model__ = data_models.HealthMonitor
@ -184,7 +184,7 @@ class HealthMonitor(base_models.BASE):
cascade="delete"))
class Pool(base_models.BASE, base_models.IdMixin, base_models.TenantMixin):
class Pool(base_models.BASE, base_models.IdMixin, base_models.ProjectMixin):
__data_model__ = data_models.Pool
@ -209,7 +209,7 @@ class Pool(base_models.BASE, base_models.IdMixin, base_models.TenantMixin):
class LoadBalancer(base_models.BASE, base_models.IdMixin,
base_models.TenantMixin):
base_models.ProjectMixin):
__data_model__ = data_models.LoadBalancer
@ -280,7 +280,8 @@ class Vip(base_models.BASE):
cascade="delete"))
class Listener(base_models.BASE, base_models.IdMixin, base_models.TenantMixin):
class Listener(base_models.BASE, base_models.IdMixin,
base_models.ProjectMixin):
__data_model__ = data_models.Listener

View File

@ -30,7 +30,7 @@ def generate_load_balancer(vip=None, amphorae=None):
global LB_SEED
LB_SEED += 1
lb = data_models.LoadBalancer(id='lb{0}-id'.format(LB_SEED),
tenant_id='2',
project_id='2',
name='lb{0}'.format(LB_SEED),
description='lb{0}'.format(LB_SEED),
vip=vip,

View File

@ -38,7 +38,7 @@ class ModelTestMixin(object):
load_balancer.amphorae.append(amphora)
def create_listener(self, session, **overrides):
kwargs = {'tenant_id': self.FAKE_UUID_1,
kwargs = {'project_id': self.FAKE_UUID_1,
'id': self.FAKE_UUID_1,
'protocol': constants.PROTOCOL_HTTP,
'protocol_port': 80,
@ -58,7 +58,7 @@ class ModelTestMixin(object):
return self._insert(session, models.ListenerStatistics, kwargs)
def create_pool(self, session, **overrides):
kwargs = {'tenant_id': self.FAKE_UUID_1,
kwargs = {'project_id': self.FAKE_UUID_1,
'id': self.FAKE_UUID_1,
'protocol': constants.PROTOCOL_HTTP,
'lb_algorithm': constants.LB_ALGORITHM_ROUND_ROBIN,
@ -80,12 +80,13 @@ class ModelTestMixin(object):
'timeout': 1,
'fall_threshold': 1,
'rise_threshold': 1,
'enabled': True}
'enabled': True,
'project_id': self.FAKE_UUID_1}
kwargs.update(overrides)
return self._insert(session, models.HealthMonitor, kwargs)
def create_member(self, session, pool_id, **overrides):
kwargs = {'tenant_id': self.FAKE_UUID_1,
kwargs = {'project_id': self.FAKE_UUID_1,
'id': self.FAKE_UUID_1,
'pool_id': pool_id,
'ip_address': '10.0.0.1',
@ -96,7 +97,7 @@ class ModelTestMixin(object):
return self._insert(session, models.Member, kwargs)
def create_load_balancer(self, session, **overrides):
kwargs = {'tenant_id': self.FAKE_UUID_1,
kwargs = {'project_id': self.FAKE_UUID_1,
'id': self.FAKE_UUID_1,
'provisioning_status': constants.ACTIVE,
'operating_status': constants.ONLINE,
@ -740,7 +741,7 @@ class DataModelConversionTest(base.OctaviaDBTestBase, ModelTestMixin):
self.check_health_monitor(pool.health_monitor, check_pool=False)
def check_load_balancer_data_model(self, lb):
self.assertEqual(self.FAKE_UUID_1, lb.tenant_id)
self.assertEqual(self.FAKE_UUID_1, lb.project_id)
self.assertEqual(self.FAKE_UUID_1, lb.id)
self.assertEqual(constants.ACTIVE, lb.provisioning_status)
self.assertTrue(lb.enabled)
@ -749,7 +750,7 @@ class DataModelConversionTest(base.OctaviaDBTestBase, ModelTestMixin):
self.assertEqual(self.FAKE_UUID_1, vip.load_balancer_id)
def check_listener_data_model(self, listener):
self.assertEqual(self.FAKE_UUID_1, listener.tenant_id)
self.assertEqual(self.FAKE_UUID_1, listener.project_id)
self.assertEqual(self.FAKE_UUID_1, listener.id)
self.assertEqual(constants.PROTOCOL_HTTP, listener.protocol)
self.assertEqual(80, listener.protocol_port)
@ -769,7 +770,7 @@ class DataModelConversionTest(base.OctaviaDBTestBase, ModelTestMixin):
self.assertEqual(0, stats.total_connections)
def check_pool_data_model(self, pool):
self.assertEqual(self.FAKE_UUID_1, pool.tenant_id)
self.assertEqual(self.FAKE_UUID_1, pool.project_id)
self.assertEqual(self.FAKE_UUID_1, pool.id)
self.assertEqual(constants.PROTOCOL_HTTP, pool.protocol)
self.assertEqual(constants.LB_ALGORITHM_ROUND_ROBIN, pool.lb_algorithm)
@ -789,7 +790,7 @@ class DataModelConversionTest(base.OctaviaDBTestBase, ModelTestMixin):
self.assertTrue(hm.enabled)
def check_member_data_model(self, member):
self.assertEqual(self.FAKE_UUID_1, member.tenant_id)
self.assertEqual(self.FAKE_UUID_1, member.project_id)
self.assertEqual(self.FAKE_UUID_1, member.id)
self.assertEqual(self.pool.id, member.pool_id)
self.assertEqual('10.0.0.1', member.ip_address)

View File

@ -54,16 +54,16 @@ class BaseRepositoryTest(base.OctaviaDBTestBase):
def test_get_all_return_value(self):
pool_list = self.pool_repo.get_all(self.session,
tenant_id=self.FAKE_UUID_2)
project_id=self.FAKE_UUID_2)
self.assertIsInstance(pool_list, list)
lb_list = self.lb_repo.get_all(self.session,
tenant_id=self.FAKE_UUID_2)
project_id=self.FAKE_UUID_2)
self.assertIsInstance(lb_list, list)
listener_list = self.listener_repo.get_all(self.session,
tenant_id=self.FAKE_UUID_2)
project_id=self.FAKE_UUID_2)
self.assertIsInstance(listener_list, list)
member_list = self.member_repo.get_all(self.session,
tenant_id=self.FAKE_UUID_2)
project_id=self.FAKE_UUID_2)
self.assertIsInstance(member_list, list)
@ -108,7 +108,8 @@ class AllRepositoriesTest(base.OctaviaDBTestBase):
'provisioning_status': constants.PENDING_UPDATE,
'operating_status': constants.OFFLINE,
'topology': constants.TOPOLOGY_ACTIVE_STANDBY,
'vrrp_group': None}
'vrrp_group': None,
'project_id': uuidutils.generate_uuid()}
vip = {'ip_address': '10.0.0.1',
'port_id': uuidutils.generate_uuid(),
'subnet_id': uuidutils.generate_uuid()}
@ -117,7 +118,6 @@ class AllRepositoriesTest(base.OctaviaDBTestBase):
del lb_dm_dict['vip']
del lb_dm_dict['listeners']
del lb_dm_dict['amphorae']
del lb_dm_dict['tenant_id']
self.assertEqual(lb, lb_dm_dict)
vip_dm_dict = lb_dm.vip.to_dict()
vip_dm_dict['load_balancer_id'] = lb_dm.id
@ -128,7 +128,8 @@ class AllRepositoriesTest(base.OctaviaDBTestBase):
pool = {'protocol': constants.PROTOCOL_HTTP, 'name': 'pool1',
'description': 'desc1',
'lb_algorithm': constants.LB_ALGORITHM_ROUND_ROBIN,
'enabled': True, 'operating_status': constants.ONLINE}
'enabled': True, 'operating_status': constants.ONLINE,
'project_id': uuidutils.generate_uuid()}
pool_dm = self.repos.create_pool_on_listener(self.session,
self.listener.id,
pool)
@ -137,7 +138,6 @@ class AllRepositoriesTest(base.OctaviaDBTestBase):
del pool_dm_dict['health_monitor']
del pool_dm_dict['session_persistence']
del pool_dm_dict['listener']
del pool_dm_dict['tenant_id']
self.assertEqual(pool, pool_dm_dict)
new_listener = self.repos.listener.get(self.session,
id=self.listener.id)
@ -147,7 +147,8 @@ class AllRepositoriesTest(base.OctaviaDBTestBase):
pool = {'protocol': constants.PROTOCOL_HTTP, 'name': 'pool1',
'description': 'desc1',
'lb_algorithm': constants.LB_ALGORITHM_ROUND_ROBIN,
'enabled': True, 'operating_status': constants.ONLINE}
'enabled': True, 'operating_status': constants.ONLINE,
'project_id': uuidutils.generate_uuid()}
sp = {'type': constants.SESSION_PERSISTENCE_HTTP_COOKIE,
'cookie_name': 'cookie_monster'}
pool_dm = self.repos.create_pool_on_listener(self.session,
@ -158,7 +159,6 @@ class AllRepositoriesTest(base.OctaviaDBTestBase):
del pool_dm_dict['health_monitor']
del pool_dm_dict['session_persistence']
del pool_dm_dict['listener']
del pool_dm_dict['tenant_id']
self.assertEqual(pool, pool_dm_dict)
sp_dm_dict = pool_dm.session_persistence.to_dict()
del sp_dm_dict['pool']
@ -175,7 +175,8 @@ class AllRepositoriesTest(base.OctaviaDBTestBase):
pool = {'protocol': constants.PROTOCOL_HTTP, 'name': 'pool1',
'description': 'desc1',
'lb_algorithm': constants.LB_ALGORITHM_ROUND_ROBIN,
'enabled': True, 'operating_status': constants.ONLINE}
'enabled': True, 'operating_status': constants.ONLINE,
'project_id': uuidutils.generate_uuid()}
pool_dm = self.repos.create_pool_on_listener(self.session,
self.listener.id, pool)
update_pool = {'protocol': constants.PROTOCOL_TCP, 'name': 'up_pool'}
@ -186,7 +187,6 @@ class AllRepositoriesTest(base.OctaviaDBTestBase):
del pool_dm_dict['health_monitor']
del pool_dm_dict['session_persistence']
del pool_dm_dict['listener']
del pool_dm_dict['tenant_id']
pool.update(update_pool)
self.assertEqual(pool, pool_dm_dict)
self.assertIsNone(new_pool_dm.session_persistence)
@ -195,7 +195,8 @@ class AllRepositoriesTest(base.OctaviaDBTestBase):
pool = {'protocol': constants.PROTOCOL_HTTP, 'name': 'pool1',
'description': 'desc1',
'lb_algorithm': constants.LB_ALGORITHM_ROUND_ROBIN,
'enabled': True, 'operating_status': constants.ONLINE}
'enabled': True, 'operating_status': constants.ONLINE,
'project_id': uuidutils.generate_uuid()}
sp = {'type': constants.SESSION_PERSISTENCE_HTTP_COOKIE,
'cookie_name': 'cookie_monster'}
pool_dm = self.repos.create_pool_on_listener(self.session,
@ -210,7 +211,6 @@ class AllRepositoriesTest(base.OctaviaDBTestBase):
del pool_dm_dict['health_monitor']
del pool_dm_dict['session_persistence']
del pool_dm_dict['listener']
del pool_dm_dict['tenant_id']
pool.update(update_pool)
self.assertEqual(pool, pool_dm_dict)
sp_dm_dict = new_pool_dm.session_persistence.to_dict()
@ -223,7 +223,8 @@ class AllRepositoriesTest(base.OctaviaDBTestBase):
pool = {'protocol': constants.PROTOCOL_HTTP, 'name': 'pool1',
'description': 'desc1',
'lb_algorithm': constants.LB_ALGORITHM_ROUND_ROBIN,
'enabled': True, 'operating_status': constants.ONLINE}
'enabled': True, 'operating_status': constants.ONLINE,
'project_id': uuidutils.generate_uuid()}
pool_dm = self.repos.create_pool_on_listener(self.session,
self.listener.id,
pool)
@ -242,7 +243,8 @@ class AllRepositoriesTest(base.OctaviaDBTestBase):
pool = {'protocol': constants.PROTOCOL_HTTP, 'name': 'pool1',
'description': 'desc1',
'lb_algorithm': constants.LB_ALGORITHM_ROUND_ROBIN,
'enabled': True, 'operating_status': constants.ONLINE}
'enabled': True, 'operating_status': constants.ONLINE,
'project_id': uuidutils.generate_uuid()}
pool_dm = self.repos.create_pool_on_listener(self.session,
self.listener.id,
pool)
@ -255,7 +257,8 @@ class AllRepositoriesTest(base.OctaviaDBTestBase):
pool = {'protocol': constants.PROTOCOL_HTTP, 'name': 'pool1',
'description': 'desc1',
'lb_algorithm': constants.LB_ALGORITHM_ROUND_ROBIN,
'enabled': True, 'operating_status': constants.ONLINE}
'enabled': True, 'operating_status': constants.ONLINE,
'project_id': uuidutils.generate_uuid()}
sp = {'type': constants.SESSION_PERSISTENCE_HTTP_COOKIE,
'cookie_name': 'cookie_monster'}
pool_dm = self.repos.create_pool_on_listener(self.session,
@ -269,9 +272,9 @@ class AllRepositoriesTest(base.OctaviaDBTestBase):
class PoolRepositoryTest(BaseRepositoryTest):
def create_pool(self, pool_id, tenant_id):
def create_pool(self, pool_id, project_id):
pool = self.pool_repo.create(
self.session, id=pool_id, tenant_id=tenant_id, name="pool_test",
self.session, id=pool_id, project_id=project_id, name="pool_test",
description="pool_description", protocol=constants.PROTOCOL_HTTP,
lb_algorithm=constants.LB_ALGORITHM_ROUND_ROBIN,
operating_status=constants.ONLINE, enabled=True)
@ -279,18 +282,18 @@ class PoolRepositoryTest(BaseRepositoryTest):
def test_get(self):
pool = self.create_pool(pool_id=self.FAKE_UUID_1,
tenant_id=self.FAKE_UUID_2)
project_id=self.FAKE_UUID_2)
new_pool = self.pool_repo.get(self.session, id=pool.id)
self.assertIsInstance(new_pool, models.Pool)
self.assertEqual(pool, new_pool)
def test_get_all(self):
pool_one = self.create_pool(pool_id=self.FAKE_UUID_1,
tenant_id=self.FAKE_UUID_2)
project_id=self.FAKE_UUID_2)
pool_two = self.create_pool(pool_id=self.FAKE_UUID_3,
tenant_id=self.FAKE_UUID_2)
project_id=self.FAKE_UUID_2)
pool_list = self.pool_repo.get_all(self.session,
tenant_id=self.FAKE_UUID_2)
project_id=self.FAKE_UUID_2)
self.assertIsInstance(pool_list, list)
self.assertEqual(2, len(pool_list))
self.assertEqual(pool_one, pool_list[0])
@ -298,9 +301,9 @@ class PoolRepositoryTest(BaseRepositoryTest):
def test_create(self):
pool = self.create_pool(pool_id=self.FAKE_UUID_1,
tenant_id=self.FAKE_UUID_2)
project_id=self.FAKE_UUID_2)
self.assertIsInstance(pool, models.Pool)
self.assertEqual(self.FAKE_UUID_2, pool.tenant_id)
self.assertEqual(self.FAKE_UUID_2, pool.project_id)
self.assertEqual("pool_test", pool.name)
self.assertEqual("pool_description", pool.description)
self.assertEqual(constants.PROTOCOL_HTTP, pool.protocol)
@ -309,7 +312,7 @@ class PoolRepositoryTest(BaseRepositoryTest):
def test_update(self):
pool = self.create_pool(pool_id=self.FAKE_UUID_1,
tenant_id=self.FAKE_UUID_2)
project_id=self.FAKE_UUID_2)
self.pool_repo.update(self.session, pool.id,
description="other_pool_description")
new_pool = self.pool_repo.get(self.session, id=self.FAKE_UUID_1)
@ -317,15 +320,15 @@ class PoolRepositoryTest(BaseRepositoryTest):
def test_delete(self):
pool = self.create_pool(pool_id=self.FAKE_UUID_1,
tenant_id=self.FAKE_UUID_2)
project_id=self.FAKE_UUID_2)
self.pool_repo.delete(self.session, id=pool.id)
self.assertIsNone(self.pool_repo.get(self.session, id=pool.id))
def test_delete_with_member(self):
pool = self.create_pool(pool_id=self.FAKE_UUID_1,
tenant_id=self.FAKE_UUID_2)
project_id=self.FAKE_UUID_2)
member = self.member_repo.create(self.session, id=self.FAKE_UUID_3,
tenant_id=self.FAKE_UUID_2,
project_id=self.FAKE_UUID_2,
pool_id=pool.id,
ip_address="10.0.0.1",
protocol_port=80, enabled=True,
@ -339,7 +342,7 @@ class PoolRepositoryTest(BaseRepositoryTest):
def test_delete_with_health_monitor(self):
pool = self.create_pool(pool_id=self.FAKE_UUID_1,
tenant_id=self.FAKE_UUID_2)
project_id=self.FAKE_UUID_2)
hm = self.hm_repo.create(self.session, pool_id=pool.id,
type=constants.HEALTH_MONITOR_HTTP,
delay=1, timeout=1, fall_threshold=1,
@ -353,7 +356,7 @@ class PoolRepositoryTest(BaseRepositoryTest):
def test_delete_with_session_persistence(self):
pool = self.create_pool(pool_id=self.FAKE_UUID_1,
tenant_id=self.FAKE_UUID_2)
project_id=self.FAKE_UUID_2)
sp = self.sp_repo.create(
self.session, pool_id=pool.id,
type=constants.SESSION_PERSISTENCE_HTTP_COOKIE,
@ -367,13 +370,13 @@ class PoolRepositoryTest(BaseRepositoryTest):
def test_delete_with_all_children(self):
pool = self.create_pool(pool_id=self.FAKE_UUID_1,
tenant_id=self.FAKE_UUID_2)
project_id=self.FAKE_UUID_2)
hm = self.hm_repo.create(self.session, pool_id=pool.id,
type=constants.HEALTH_MONITOR_HTTP,
delay=1, timeout=1, fall_threshold=1,
rise_threshold=1, enabled=True)
member = self.member_repo.create(self.session, id=self.FAKE_UUID_3,
tenant_id=self.FAKE_UUID_2,
project_id=self.FAKE_UUID_2,
pool_id=pool.id,
ip_address="10.0.0.1",
protocol_port=80,
@ -402,15 +405,16 @@ class MemberRepositoryTest(BaseRepositoryTest):
def setUp(self):
super(MemberRepositoryTest, self).setUp()
self.pool = self.pool_repo.create(
self.session, id=self.FAKE_UUID_1, tenant_id=self.FAKE_UUID_2,
self.session, id=self.FAKE_UUID_1, project_id=self.FAKE_UUID_2,
name="pool_test", description="pool_description",
protocol=constants.PROTOCOL_HTTP,
lb_algorithm=constants.LB_ALGORITHM_ROUND_ROBIN,
operating_status=constants.ONLINE, enabled=True)
def create_member(self, member_id, tenant_id, pool_id, ip_address):
def create_member(self, member_id, project_id, pool_id, ip_address):
member = self.member_repo.create(self.session, id=member_id,
tenant_id=tenant_id, pool_id=pool_id,
project_id=project_id,
pool_id=pool_id,
ip_address=ip_address,
protocol_port=80,
operating_status=constants.ONLINE,
@ -430,7 +434,7 @@ class MemberRepositoryTest(BaseRepositoryTest):
member_two = self.create_member(self.FAKE_UUID_3, self.FAKE_UUID_2,
self.pool.id, "10.0.0.2")
member_list = self.member_repo.get_all(self.session,
tenant_id=self.FAKE_UUID_2)
project_id=self.FAKE_UUID_2)
self.assertIsInstance(member_list, list)
self.assertEqual(2, len(member_list))
self.assertEqual(member_one, member_list[0])
@ -441,7 +445,7 @@ class MemberRepositoryTest(BaseRepositoryTest):
self.pool.id, ip_address="10.0.0.1")
new_member = self.member_repo.get(self.session, id=member.id)
self.assertEqual(self.FAKE_UUID_1, new_member.id)
self.assertEqual(self.FAKE_UUID_2, new_member.tenant_id)
self.assertEqual(self.FAKE_UUID_2, new_member.project_id)
self.assertEqual(self.pool.id, new_member.pool_id)
self.assertEqual("10.0.0.1", new_member.ip_address)
self.assertEqual(80, new_member.protocol_port)
@ -472,7 +476,7 @@ class SessionPersistenceRepositoryTest(BaseRepositoryTest):
def setUp(self):
super(SessionPersistenceRepositoryTest, self).setUp()
self.pool = self.pool_repo.create(
self.session, id=self.FAKE_UUID_1, tenant_id=self.FAKE_UUID_2,
self.session, id=self.FAKE_UUID_1, project_id=self.FAKE_UUID_2,
name="pool_test", description="pool_description",
protocol=constants.PROTOCOL_HTTP,
lb_algorithm=constants.LB_ALGORITHM_ROUND_ROBIN,
@ -522,14 +526,14 @@ class ListenerRepositoryTest(BaseRepositoryTest):
def setUp(self):
super(ListenerRepositoryTest, self).setUp()
self.load_balancer = self.lb_repo.create(
self.session, id=self.FAKE_UUID_1, tenant_id=self.FAKE_UUID_2,
self.session, id=self.FAKE_UUID_1, project_id=self.FAKE_UUID_2,
name="lb_name", description="lb_description",
provisioning_status=constants.ACTIVE,
operating_status=constants.ONLINE, enabled=True)
def create_listener(self, listener_id, port, default_pool_id=None):
listener = self.listener_repo.create(
self.session, id=listener_id, tenant_id=self.FAKE_UUID_2,
self.session, id=listener_id, project_id=self.FAKE_UUID_2,
name="listener_name", description="listener_description",
protocol=constants.PROTOCOL_HTTP, protocol_port=port,
connection_limit=1, load_balancer_id=self.load_balancer.id,
@ -547,7 +551,7 @@ class ListenerRepositoryTest(BaseRepositoryTest):
listener_one = self.create_listener(self.FAKE_UUID_1, 80)
listener_two = self.create_listener(self.FAKE_UUID_3, 88)
listener_list = self.listener_repo.get_all(self.session,
tenant_id=self.FAKE_UUID_2)
project_id=self.FAKE_UUID_2)
self.assertIsInstance(listener_list, list)
self.assertEqual(2, len(listener_list))
self.assertEqual(listener_one, listener_list[0])
@ -557,7 +561,7 @@ class ListenerRepositoryTest(BaseRepositoryTest):
listener = self.create_listener(self.FAKE_UUID_1, 80)
new_listener = self.listener_repo.get(self.session, id=listener.id)
self.assertEqual(self.FAKE_UUID_1, new_listener.id)
self.assertEqual(self.FAKE_UUID_2, new_listener.tenant_id)
self.assertEqual(self.FAKE_UUID_2, new_listener.project_id)
self.assertEqual("listener_name", new_listener.name)
self.assertEqual("listener_description", new_listener.description)
self.assertEqual(constants.PROTOCOL_HTTP, new_listener.protocol)
@ -608,7 +612,7 @@ class ListenerRepositoryTest(BaseRepositoryTest):
def test_delete_with_pool(self):
pool = self.pool_repo.create(
self.session, id=self.FAKE_UUID_3, tenant_id=self.FAKE_UUID_2,
self.session, id=self.FAKE_UUID_3, project_id=self.FAKE_UUID_2,
name="pool_test", description="pool_description",
protocol=constants.PROTOCOL_HTTP,
lb_algorithm=constants.LB_ALGORITHM_ROUND_ROBIN,
@ -624,7 +628,7 @@ class ListenerRepositoryTest(BaseRepositoryTest):
def test_delete_with_all_children(self):
pool = self.pool_repo.create(
self.session, id=self.FAKE_UUID_3, tenant_id=self.FAKE_UUID_2,
self.session, id=self.FAKE_UUID_3, project_id=self.FAKE_UUID_2,
name="pool_test", description="pool_description",
protocol=constants.PROTOCOL_HTTP,
lb_algorithm=constants.LB_ALGORITHM_ROUND_ROBIN,
@ -655,7 +659,7 @@ class ListenerStatisticsRepositoryTest(BaseRepositoryTest):
def setUp(self):
super(ListenerStatisticsRepositoryTest, self).setUp()
self.listener = self.listener_repo.create(
self.session, id=self.FAKE_UUID_1, tenant_id=self.FAKE_UUID_2,
self.session, id=self.FAKE_UUID_1, project_id=self.FAKE_UUID_2,
name="listener_name", description="listener_description",
protocol=constants.PROTOCOL_HTTP, protocol_port=80,
connection_limit=1, provisioning_status=constants.ACTIVE,
@ -752,7 +756,7 @@ class HealthMonitorRepositoryTest(BaseRepositoryTest):
def setUp(self):
super(HealthMonitorRepositoryTest, self).setUp()
self.pool = self.pool_repo.create(
self.session, id=self.FAKE_UUID_1, tenant_id=self.FAKE_UUID_2,
self.session, id=self.FAKE_UUID_1, project_id=self.FAKE_UUID_2,
name="pool_test", description="pool_description",
protocol=constants.PROTOCOL_HTTP,
lb_algorithm=constants.LB_ALGORITHM_ROUND_ROBIN,
@ -806,7 +810,7 @@ class LoadBalancerRepositoryTest(BaseRepositoryTest):
def create_loadbalancer(self, lb_id):
lb = self.lb_repo.create(self.session, id=lb_id,
tenant_id=self.FAKE_UUID_2, name="lb_name",
project_id=self.FAKE_UUID_2, name="lb_name",
description="lb_description",
provisioning_status=constants.ACTIVE,
operating_status=constants.ONLINE,
@ -823,7 +827,7 @@ class LoadBalancerRepositoryTest(BaseRepositoryTest):
lb_one = self.create_loadbalancer(self.FAKE_UUID_1)
lb_two = self.create_loadbalancer(self.FAKE_UUID_3)
lb_list = self.lb_repo.get_all(self.session,
tenant_id=self.FAKE_UUID_2)
project_id=self.FAKE_UUID_2)
self.assertEqual(2, len(lb_list))
self.assertEqual(lb_one, lb_list[0])
self.assertEqual(lb_two, lb_list[1])
@ -831,7 +835,7 @@ class LoadBalancerRepositoryTest(BaseRepositoryTest):
def test_create(self):
lb = self.create_loadbalancer(self.FAKE_UUID_1)
self.assertEqual(self.FAKE_UUID_1, lb.id)
self.assertEqual(self.FAKE_UUID_2, lb.tenant_id)
self.assertEqual(self.FAKE_UUID_2, lb.project_id)
self.assertEqual("lb_name", lb.name)
self.assertEqual("lb_description", lb.description)
self.assertEqual(constants.ACTIVE, lb.provisioning_status)
@ -910,7 +914,7 @@ class LoadBalancerRepositoryTest(BaseRepositoryTest):
def test_delete_with_listener(self):
lb = self.create_loadbalancer(self.FAKE_UUID_1)
listener = self.listener_repo.create(
self.session, id=self.FAKE_UUID_1, tenant_id=self.FAKE_UUID_2,
self.session, id=self.FAKE_UUID_1, project_id=self.FAKE_UUID_2,
name="listener_name", description="listener_description",
load_balancer_id=lb.id, protocol=constants.PROTOCOL_HTTP,
protocol_port=80, connection_limit=1,
@ -927,14 +931,14 @@ class LoadBalancerRepositoryTest(BaseRepositoryTest):
def test_delete_with_many_listeners(self):
lb = self.create_loadbalancer(self.FAKE_UUID_1)
listener_1 = self.listener_repo.create(
self.session, id=self.FAKE_UUID_1, tenant_id=self.FAKE_UUID_2,
self.session, id=self.FAKE_UUID_1, project_id=self.FAKE_UUID_2,
name="listener_name", description="listener_description",
load_balancer_id=lb.id, protocol=constants.PROTOCOL_HTTP,
protocol_port=80, connection_limit=1,
provisioning_status=constants.ACTIVE,
operating_status=constants.ONLINE, enabled=True)
listener_2 = self.listener_repo.create(
self.session, id=self.FAKE_UUID_3, tenant_id=self.FAKE_UUID_2,
self.session, id=self.FAKE_UUID_3, project_id=self.FAKE_UUID_2,
name="listener_name", description="listener_description",
load_balancer_id=lb.id, protocol=constants.PROTOCOL_HTTPS,
protocol_port=443, connection_limit=1,
@ -962,7 +966,7 @@ class LoadBalancerRepositoryTest(BaseRepositoryTest):
vip = self.vip_repo.create(self.session, load_balancer_id=lb.id,
ip_address="10.0.0.1")
listener = self.listener_repo.create(
self.session, id=self.FAKE_UUID_1, tenant_id=self.FAKE_UUID_2,
self.session, id=self.FAKE_UUID_1, project_id=self.FAKE_UUID_2,
name="listener_name", description="listener_description",
load_balancer_id=lb.id, protocol=constants.PROTOCOL_HTTP,
protocol_port=80, connection_limit=1,
@ -1013,7 +1017,7 @@ class VipRepositoryTest(BaseRepositoryTest):
def setUp(self):
super(VipRepositoryTest, self).setUp()
self.lb = self.lb_repo.create(
self.session, id=self.FAKE_UUID_1, tenant_id=self.FAKE_UUID_2,
self.session, id=self.FAKE_UUID_1, project_id=self.FAKE_UUID_2,
name="lb_name", description="lb_description",
provisioning_status=constants.ACTIVE,
operating_status=constants.ONLINE, enabled=True)
@ -1060,7 +1064,7 @@ class SNIRepositoryTest(BaseRepositoryTest):
def setUp(self):
super(SNIRepositoryTest, self).setUp()
self.listener = self.listener_repo.create(
self.session, id=self.FAKE_UUID_1, tenant_id=self.FAKE_UUID_2,
self.session, id=self.FAKE_UUID_1, project_id=self.FAKE_UUID_2,
name="listener_name", description="listener_description",
protocol=constants.PROTOCOL_HTTP, protocol_port=80,
connection_limit=1, provisioning_status=constants.ACTIVE,
@ -1110,7 +1114,7 @@ class AmphoraRepositoryTest(BaseRepositoryTest):
def setUp(self):
super(AmphoraRepositoryTest, self).setUp()
self.lb = self.lb_repo.create(
self.session, id=self.FAKE_UUID_1, tenant_id=self.FAKE_UUID_2,
self.session, id=self.FAKE_UUID_1, project_id=self.FAKE_UUID_2,
name="lb_name", description="lb_description",
provisioning_status=constants.ACTIVE,
operating_status=constants.ONLINE, enabled=True)
@ -1354,7 +1358,7 @@ class VRRPGroupRepositoryTest(BaseRepositoryTest):
def setUp(self):
super(VRRPGroupRepositoryTest, self).setUp()
self.lb = self.lb_repo.create(
self.session, id=self.FAKE_UUID_1, tenant_id=self.FAKE_UUID_2,
self.session, id=self.FAKE_UUID_1, project_id=self.FAKE_UUID_2,
name="lb_name", description="lb_description",
provisioning_status=constants.ACTIVE,
operating_status=constants.ONLINE, enabled=True)

View File

@ -124,19 +124,19 @@ class TestIdMixin(BaseTestUuid):
self._type, body)
class TestTenantIdMixin(BaseTestUuid):
tenant_id_attr = 'tenant_id'
class TestProjectIdMixin(BaseTestUuid):
project_id_attr = 'project_id'
def test_tenant_id(self):
self.assert_uuid_attr(self.tenant_id_attr)
self.assert_uuid_attr_fail_with_integer(self.tenant_id_attr)
self.assert_uuid_attr_fail_with_short_str(self.tenant_id_attr)
self.assert_uuid_attr_fail_with_shorter_than_uuid(self.tenant_id_attr)
self.assert_uuid_attr_fail_with_longer_than_uuid(self.tenant_id_attr)
def test_project_id(self):
self.assert_uuid_attr(self.project_id_attr)
self.assert_uuid_attr_fail_with_integer(self.project_id_attr)
self.assert_uuid_attr_fail_with_short_str(self.project_id_attr)
self.assert_uuid_attr_fail_with_shorter_than_uuid(self.project_id_attr)
self.assert_uuid_attr_fail_with_longer_than_uuid(self.project_id_attr)
def test_tenant_id_readonly(self):
def test_project_id_readonly(self):
body = build_body(self._mandatory_fields,
{self.tenant_id_attr: uuidutils.generate_uuid()})
{self.project_id_attr: uuidutils.generate_uuid()})
self.assertRaises(exc.InvalidInput, wsme_json.fromjson,
self._type, body)