Merge "Add common api handlers for v1 and v2"

changes/43/423543/23
Jenkins 6 years ago committed by Gerrit Code Review
commit 8d7f95ffda

@ -24,7 +24,7 @@ import time
from oslo_log import log as logging
from octavia.api.v1.handlers import abstract_handler
from octavia.api.handlers import abstract_handler
from octavia.common import constants
from octavia.common import data_models
from octavia.db import api as db_api

@ -30,7 +30,7 @@ from oslo_config import cfg
import oslo_messaging as messaging
import six
from octavia.api.v1.handlers import abstract_handler
from octavia.api.handlers import abstract_handler
from octavia.common import constants
from octavia.common import data_models

@ -1,67 +0,0 @@
# Copyright 2014 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.
import abc
import six
@six.add_metaclass(abc.ABCMeta)
class BaseObjectHandler(object):
"""Base class for any object handler."""
@abc.abstractmethod
def create(self, model_id):
"""Begins process of actually creating data_model."""
pass
@abc.abstractmethod
def update(self, model_id, updated_dict):
"""Begins process of actually updating data_model."""
pass
@abc.abstractmethod
def delete(self, model_id):
"""Begins process of actually deleting data_model."""
pass
class NotImplementedObjectHandler(BaseObjectHandler):
"""Default Object Handler to force implementation of subclasses.
Helper class to make any subclass of AbstractHandler explode if it
is missing any of the required object managers.
"""
@staticmethod
def update(model_id, updated_dict):
raise NotImplementedError()
@staticmethod
def delete(model_id):
raise NotImplementedError()
@staticmethod
def create(model_id):
raise NotImplementedError()
@six.add_metaclass(abc.ABCMeta)
class BaseHandler(object):
"""Base class for all handlers."""
load_balancer = NotImplementedObjectHandler()
listener = NotImplementedObjectHandler()
pool = NotImplementedObjectHandler()
health_monitor = NotImplementedObjectHandler()
member = NotImplementedObjectHandler()
l7policy = NotImplementedObjectHandler()
l7rule = NotImplementedObjectHandler()

@ -1,449 +0,0 @@
# Copyright 2014 Rackspace
# Copyright 2016 Blue Box, an IBM Company
#
# 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.
"""
This is just a handler that will simulate successful operations a controller
should perform. There is nothing useful about this other than database
entity status management.
"""
import threading
import time
from oslo_log import log as logging
from octavia.api.v2.handlers import abstract_handler
from octavia.common import constants
from octavia.common import data_models
from octavia.db import api as db_api
import octavia.db.repositories as repos
from octavia.i18n import _LI
LOG = logging.getLogger(__name__)
ASYNC_TIME = 1
def validate_input(expected, actual):
if not isinstance(actual, expected):
raise InvalidHandlerInputObject(obj_type=actual.__class__)
def simulate_controller(data_model, delete=False, update=False, create=False):
"""Simulates a successful controller operator for a data model.
:param data_model: data model to simulate controller operation
:param delete: deletes from the database
"""
repo = repos.Repositories()
def member_controller(member, delete=False, update=False, create=False):
time.sleep(ASYNC_TIME)
LOG.info(_LI("Simulating controller operation for member..."))
db_mem = None
if delete:
db_mem = repo.member.get(db_api.get_session(), member.id)
repo.member.delete(db_api.get_session(), id=member.id)
elif update:
db_mem = repo.member.get(db_api.get_session(), member.id)
member_dict = member.to_dict()
member_dict['operating_status'] = db_mem.operating_status
repo.member.update(db_api.get_session(), member.id, **member_dict)
elif create:
repo.member.update(db_api.get_session(), member.id,
operating_status=constants.ONLINE)
listeners = []
if db_mem:
for listener in db_mem.pool.listeners:
if listener not in listeners:
listeners.append(listener)
if member.pool.listeners:
for listener in member.pool.listeners:
if listener not in listeners:
listeners.append(listener)
if listeners:
for listener in listeners:
repo.listener.update(db_api.get_session(), listener.id,
operating_status=constants.ONLINE,
provisioning_status=constants.ACTIVE)
repo.load_balancer.update(db_api.get_session(),
member.pool.load_balancer.id,
operating_status=constants.ONLINE,
provisioning_status=constants.ACTIVE)
LOG.info(_LI("Simulated Controller Handler Thread Complete"))
def l7policy_controller(l7policy, delete=False, update=False,
create=False):
time.sleep(ASYNC_TIME)
LOG.info(_LI("Simulating controller operation for l7policy..."))
db_l7policy = None
if delete:
db_l7policy = repo.l7policy.get(db_api.get_session(), l7policy.id)
repo.l7policy.delete(db_api.get_session(), id=l7policy.id)
elif update:
db_l7policy = repo.l7policy.get(db_api.get_session(), l7policy.id)
l7policy_dict = l7policy.to_dict()
repo.l7policy.update(db_api.get_session(), l7policy.id,
**l7policy_dict)
elif create:
db_l7policy = repo.l7policy.create(db_api.get_session(),
**l7policy_dict)
if db_l7policy.listener:
repo.listener.update(db_api.get_session(), db_l7policy.listener.id,
operating_status=constants.ONLINE,
provisioning_status=constants.ACTIVE)
repo.load_balancer.update(db_api.get_session(),
db_l7policy.listener.load_balancer.id,
operating_status=constants.ONLINE,
provisioning_status=constants.ACTIVE)
LOG.info(_LI("Simulated Controller Handler Thread Complete"))
def l7rule_controller(l7rule, delete=False, update=False, create=False):
time.sleep(ASYNC_TIME)
LOG.info(_LI("Simulating controller operation for l7rule..."))
db_l7rule = None
if delete:
db_l7rule = repo.l7rule.get(db_api.get_session(), l7rule.id)
repo.l7rule.delete(db_api.get_session(), id=l7rule.id)
elif update:
db_l7rule = repo.l7rule.get(db_api.get_session(), l7rule.id)
l7rule_dict = l7rule.to_dict()
repo.l7rule.update(db_api.get_session(), l7rule.id, **l7rule_dict)
elif create:
db_l7rule = repo.l7rule.create(db_api.get_session(), **l7rule_dict)
if db_l7rule.l7policy.listener:
listener = db_l7rule.l7policy.listener
repo.listener.update(db_api.get_session(), listener.id,
operating_status=constants.ONLINE,
provisioning_status=constants.ACTIVE)
repo.load_balancer.update(db_api.get_session(),
listener.load_balancer.id,
operating_status=constants.ONLINE,
provisioning_status=constants.ACTIVE)
LOG.info(_LI("Simulated Controller Handler Thread Complete"))
def health_monitor_controller(health_monitor, delete=False, update=False,
create=False):
time.sleep(ASYNC_TIME)
LOG.info(_LI("Simulating controller operation for health monitor..."))
db_hm = None
if delete:
db_hm = repo.health_monitor.get(db_api.get_session(),
pool_id=health_monitor.pool.id)
repo.health_monitor.delete(db_api.get_session(),
pool_id=health_monitor.pool.id)
elif update:
db_hm = repo.health_monitor.get(db_api.get_session(),
health_monitor.pool_id)
hm_dict = health_monitor.to_dict()
hm_dict['operating_status'] = db_hm.operating_status()
repo.health_monitor.update(db_api.get_session(), **hm_dict)
elif create:
repo.pool.update(db_api.get_session(), health_monitor.pool_id,
operating_status=constants.ONLINE)
listeners = []
if db_hm:
for listener in db_hm.pool.listeners:
if listener not in listeners:
listeners.append(listener)
if health_monitor.pool.listeners:
for listener in health_monitor.pool.listeners:
if listener not in listeners:
listeners.append(listener)
if listeners:
for listener in listeners:
repo.test_and_set_lb_and_listener_prov_status(
db_api.get_session(),
health_monitor.pool.load_balancer.id,
listener.id, constants.ACTIVE,
constants.ACTIVE)
repo.listener.update(db_api.get_session(),
listener.id,
operating_status=constants.ONLINE,
provisioning_status=constants.ACTIVE)
repo.load_balancer.update(
db_api.get_session(),
health_monitor.pool.load_balancer.id,
operating_status=constants.ONLINE,
provisioning_status=constants.ACTIVE)
LOG.info(_LI("Simulated Controller Handler Thread Complete"))
def pool_controller(pool, delete=False, update=False, create=False):
time.sleep(ASYNC_TIME)
LOG.info(_LI("Simulating controller operation for pool..."))
db_pool = None
if delete:
db_pool = repo.pool.get(db_api.get_session(), id=pool.id)
repo.pool.delete(db_api.get_session(), id=pool.id)
elif update:
db_pool = repo.pool.get(db_api.get_session(), id=pool.id)
pool_dict = pool.to_dict()
pool_dict['operating_status'] = db_pool.operating_status
repo.update_pool_and_sp(db_api.get_session(), pool.id, pool_dict)
elif create:
repo.pool.update(db_api.get_session(), pool.id,
operating_status=constants.ONLINE)
listeners = []
if db_pool:
for listener in db_pool.listeners:
if listener not in listeners:
listeners.append(listener)
if pool.listeners:
for listener in pool.listeners:
if listener not in listeners:
listeners.append(listener)
if listeners:
for listener in listeners:
repo.listener.update(db_api.get_session(), listener.id,
operating_status=constants.ONLINE,
provisioning_status=constants.ACTIVE)
repo.load_balancer.update(db_api.get_session(),
pool.load_balancer.id,
operating_status=constants.ONLINE,
provisioning_status=constants.ACTIVE)
LOG.info(_LI("Simulated Controller Handler Thread Complete"))
def listener_controller(listener, delete=False, update=False,
create=False):
time.sleep(ASYNC_TIME)
LOG.info(_LI("Simulating controller operation for listener..."))
if delete:
repo.listener.update(db_api.get_session(), listener.id,
operating_status=constants.OFFLINE,
provisioning_status=constants.DELETED)
elif update:
db_listener = repo.listener.get(db_api.get_session(),
id=listener.id)
listener_dict = listener.to_dict()
listener_dict['operating_status'] = db_listener.operating_status
repo.listener.update(db_api.get_session(), listener.id,
**listener_dict)
elif create:
repo.listener.update(db_api.get_session(), listener.id,
operating_status=constants.ONLINE,
provisioning_status=constants.ACTIVE)
repo.load_balancer.update(db_api.get_session(),
listener.load_balancer.id,
operating_status=constants.ONLINE,
provisioning_status=constants.ACTIVE)
LOG.info(_LI("Simulated Controller Handler Thread Complete"))
def loadbalancer_controller(loadbalancer, delete=False, update=False,
create=False):
time.sleep(ASYNC_TIME)
LOG.info(_LI("Simulating controller operation for loadbalancer..."))
if delete:
repo.load_balancer.update(
db_api.get_session(), id=loadbalancer.id,
operating_status=constants.OFFLINE,
provisioning_status=constants.DELETED)
elif update:
db_lb = repo.listener.get(db_api.get_session(), id=loadbalancer.id)
lb_dict = loadbalancer.to_dict()
lb_dict['operating_status'] = db_lb.operating_status
repo.load_balancer.update(db_api.get_session(), loadbalancer.id,
**lb_dict)
elif create:
repo.load_balancer.update(db_api.get_session(), id=loadbalancer.id,
operating_status=constants.ONLINE,
provisioning_status=constants.ACTIVE)
LOG.info(_LI("Simulated Controller Handler Thread Complete"))
controller = loadbalancer_controller
if isinstance(data_model, data_models.Member):
controller = member_controller
elif isinstance(data_model, data_models.HealthMonitor):
controller = health_monitor_controller
elif isinstance(data_model, data_models.Pool):
controller = pool_controller
elif isinstance(data_model, data_models.Listener):
controller = listener_controller
thread = threading.Thread(target=controller, args=(data_model, delete,
update, create))
thread.start()
class InvalidHandlerInputObject(Exception):
message = "Invalid Input Object %(obj_type)"
def __init__(self, **kwargs):
message = self.message % kwargs
super(InvalidHandlerInputObject, self).__init__(message=message)
class LoadBalancerHandler(abstract_handler.BaseObjectHandler):
def create(self, load_balancer_id):
LOG.info(_LI("%(entity)s handling the creation of "
"load balancer %(id)s"),
{"entity": self.__class__.__name__, "id": load_balancer_id})
simulate_controller(load_balancer_id, create=True)
def update(self, old_lb, load_balancer):
validate_input(data_models.LoadBalancer, load_balancer)
LOG.info(_LI("%(entity)s handling the update of "
"load balancer %(id)s"),
{"entity": self.__class__.__name__, "id": old_lb.id})
load_balancer.id = old_lb.id
simulate_controller(load_balancer, update=True)
def delete(self, load_balancer_id):
LOG.info(_LI("%(entity)s handling the deletion of "
"load balancer %(id)s"),
{"entity": self.__class__.__name__, "id": load_balancer_id})
simulate_controller(load_balancer_id, delete=True)
class ListenerHandler(abstract_handler.BaseObjectHandler):
def create(self, listener_id):
LOG.info(_LI("%(entity)s handling the creation of listener %(id)s"),
{"entity": self.__class__.__name__, "id": listener_id})
simulate_controller(listener_id, create=True)
def update(self, old_listener, listener):
validate_input(data_models.Listener, listener)
LOG.info(_LI("%(entity)s handling the update of listener %(id)s"),
{"entity": self.__class__.__name__, "id": old_listener.id})
listener.id = old_listener.id
simulate_controller(listener, update=True)
def delete(self, listener_id):
LOG.info(_LI("%(entity)s handling the deletion of listener %(id)s"),
{"entity": self.__class__.__name__, "id": listener_id})
simulate_controller(listener_id, delete=True)
class PoolHandler(abstract_handler.BaseObjectHandler):
def create(self, pool_id):
LOG.info(_LI("%(entity)s handling the creation of pool %(id)s"),
{"entity": self.__class__.__name__, "id": pool_id})
simulate_controller(pool_id, create=True)
def update(self, old_pool, pool):
validate_input(data_models.Pool, pool)
LOG.info(_LI("%(entity)s handling the update of pool %(id)s"),
{"entity": self.__class__.__name__, "id": old_pool.id})
pool.id = old_pool.id
simulate_controller(pool, update=True)
def delete(self, pool_id):
LOG.info(_LI("%(entity)s handling the deletion of pool %(id)s"),
{"entity": self.__class__.__name__, "id": pool_id})
simulate_controller(pool_id, delete=True)
class HealthMonitorHandler(abstract_handler.BaseObjectHandler):
def create(self, pool_id):
LOG.info(_LI("%(entity)s handling the creation of health monitor "
"on pool %(id)s"),
{"entity": self.__class__.__name__, "id": pool_id})
simulate_controller(pool_id, create=True)
def update(self, old_health_monitor, health_monitor):
validate_input(data_models.HealthMonitor, health_monitor)
LOG.info(_LI("%(entity)s handling the update of health monitor "
"on pool %(id)s"),
{"entity": self.__class__.__name__,
"id": old_health_monitor.pool_id})
health_monitor.pool_id = old_health_monitor.pool_id
simulate_controller(health_monitor, update=True)
def delete(self, pool_id):
LOG.info(_LI("%(entity)s handling the deletion of health monitor "
"on pool %(id)s"),
{"entity": self.__class__.__name__, "id": pool_id})
simulate_controller(pool_id, delete=True)
class MemberHandler(abstract_handler.BaseObjectHandler):
def create(self, member_id):
LOG.info(_LI("%(entity)s handling the creation of member %(id)s"),
{"entity": self.__class__.__name__, "id": member_id})
simulate_controller(member_id, create=True)
def update(self, old_member, member):
validate_input(data_models.Member, member)
LOG.info(_LI("%(entity)s handling the update of member %(id)s"),
{"entity": self.__class__.__name__, "id": old_member.id})
member.id = old_member.id
simulate_controller(member, update=True)
def delete(self, member_id):
LOG.info(_LI("%(entity)s handling the deletion of member %(id)s"),
{"entity": self.__class__.__name__, "id": member_id})
simulate_controller(member_id, delete=True)
class L7PolicyHandler(abstract_handler.BaseObjectHandler):
def create(self, l7policy_id):
LOG.info(_LI("%(entity)s handling the creation of l7policy %(id)s"),
{"entity": self.__class__.__name__, "id": l7policy_id})
simulate_controller(l7policy_id, create=True)
def update(self, old_l7policy, l7policy):
validate_input(data_models.L7Policy, l7policy)
LOG.info(_LI("%(entity)s handling the update of l7policy %(id)s"),
{"entity": self.__class__.__name__, "id": old_l7policy.id})
l7policy.id = old_l7policy.id
simulate_controller(l7policy, update=True)
def delete(self, l7policy_id):
LOG.info(_LI("%(entity)s handling the deletion of l7policy %(id)s"),
{"entity": self.__class__.__name__, "id": l7policy_id})
simulate_controller(l7policy_id, delete=True)
class L7RuleHandler(abstract_handler.BaseObjectHandler):
def create(self, l7rule):
LOG.info(_LI("%(entity)s handling the creation of l7rule %(id)s"),
{"entity": self.__class__.__name__, "id": l7rule.id})
simulate_controller(l7rule, create=True)
def update(self, old_l7rule, l7rule):
validate_input(data_models.L7Rule, l7rule)
LOG.info(_LI("%(entity)s handling the update of l7rule %(id)s"),
{"entity": self.__class__.__name__, "id": old_l7rule.id})
l7rule.id = old_l7rule.id
simulate_controller(l7rule, update=True)
def delete(self, l7rule):
LOG.info(_LI("%(entity)s handling the deletion of l7rule %(id)s"),
{"entity": self.__class__.__name__, "id": l7rule.id})
simulate_controller(l7rule, delete=True)
class SimulatedControllerHandler(abstract_handler.BaseHandler):
"""Handler that simulates database calls of a successful controller."""
load_balancer = LoadBalancerHandler()
listener = ListenerHandler()
pool = PoolHandler()
health_monitor = HealthMonitorHandler()
member = MemberHandler()
l7policy = L7PolicyHandler()
l7rule = L7RuleHandler()

@ -1,204 +0,0 @@
# Copyright 2014 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.# Copyright 2014 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.
import abc
from oslo_config import cfg
import oslo_messaging as messaging
import six
from octavia.api.v2.handlers import abstract_handler
from octavia.common import constants
from octavia.common import data_models
cfg.CONF.import_group('oslo_messaging', 'octavia.common.config')
@six.add_metaclass(abc.ABCMeta)
class BaseProducer(abstract_handler.BaseObjectHandler):
"""Base queue producer class."""
@abc.abstractproperty
def payload_class(self):
"""returns a string representing the container class."""
pass
def __init__(self):
topic = cfg.CONF.oslo_messaging.topic
self.transport = messaging.get_transport(cfg.CONF)
self.target = messaging.Target(
namespace=constants.RPC_NAMESPACE_CONTROLLER_AGENT,
topic=topic, version="1.0", fanout=False)
self.client = messaging.RPCClient(self.transport, target=self.target)
def create(self, model):
"""Sends a create message to the controller via oslo.messaging
:param model:
"""
model_id = getattr(model, 'id', None)
p_class = self.payload_class
if isinstance(model, data_models.HealthMonitor):
model_id = model.pool_id
p_class = PoolProducer.PAYLOAD_CLASS
kw = {"{0}_id".format(p_class): model_id}
method_name = "create_{0}".format(self.payload_class)
self.client.cast({}, method_name, **kw)
def update(self, data_model, updated_model):
"""sends an update message to the controller via oslo.messaging
:param updated_model:
:param data_model:
"""
model_id = getattr(data_model, 'id', None)
p_class = self.payload_class
if isinstance(data_model, data_models.HealthMonitor):
model_id = data_model.pool_id
p_class = PoolProducer.PAYLOAD_CLASS
kw = {"{0}_updates".format(self.payload_class):
updated_model.to_dict(render_unsets=False),
"{0}_id".format(p_class): model_id}
method_name = "update_{0}".format(self.payload_class)
self.client.cast({}, method_name, **kw)
def delete(self, data_model):
"""sends a delete message to the controller via oslo.messaging
:param data_model:
"""
model_id = getattr(data_model, 'id', None)
p_class = self.payload_class
if isinstance(data_model, data_models.HealthMonitor):
model_id = data_model.pool_id
p_class = PoolProducer.PAYLOAD_CLASS
kw = {"{0}_id".format(p_class): model_id}
method_name = "delete_{0}".format(self.payload_class)
self.client.cast({}, method_name, **kw)
class LoadBalancerProducer(BaseProducer):
"""Sends updates,deletes and creates to the RPC end of the queue consumer
"""
PAYLOAD_CLASS = "load_balancer"
@property
def payload_class(self):
return self.PAYLOAD_CLASS
def delete(self, data_model, cascade):
"""sends a delete message to the controller via oslo.messaging
:param data_model:
:param: cascade: delete listeners, etc. as well
"""
model_id = getattr(data_model, 'id', None)
p_class = self.payload_class
kw = {"{0}_id".format(p_class): model_id, "cascade": cascade}
method_name = "delete_{0}".format(self.payload_class)
self.client.cast({}, method_name, **kw)
class ListenerProducer(BaseProducer):
"""Sends updates,deletes and creates to the RPC end of the queue consumer
"""
PAYLOAD_CLASS = "listener"
@property
def payload_class(self):
return self.PAYLOAD_CLASS
class PoolProducer(BaseProducer):
"""Sends updates,deletes and creates to the RPC end of the queue consumer
"""
PAYLOAD_CLASS = "pool"
@property
def payload_class(self):
return self.PAYLOAD_CLASS
class HealthMonitorProducer(BaseProducer):
"""Sends updates,deletes and creates to the RPC end of the queue consumer
"""
PAYLOAD_CLASS = "health_monitor"
@property
def payload_class(self):
return self.PAYLOAD_CLASS
class MemberProducer(BaseProducer):
"""Sends updates,deletes and creates to the RPC end of the queue consumer
"""
PAYLOAD_CLASS = "member"
@property
def payload_class(self):
return self.PAYLOAD_CLASS
class L7PolicyProducer(BaseProducer):
"""Sends updates,deletes and creates to the RPC end of the queue consumer
"""
PAYLOAD_CLASS = "l7policy"
@property
def payload_class(self):
return self.PAYLOAD_CLASS
class L7RuleProducer(BaseProducer):
"""Sends updates,deletes and creates to the RPC end of the queue consumer
"""
PAYLOAD_CLASS = "l7rule"
@property
def payload_class(self):
return self.PAYLOAD_CLASS
class ProducerHandler(abstract_handler.BaseHandler):
"""Base class for all QueueProducers.
used to send messages via the Class variables load_balancer, listener,
health_monitor, and member.
"""
load_balancer = LoadBalancerProducer()
listener = ListenerProducer()
pool = PoolProducer()
health_monitor = HealthMonitorProducer()
member = MemberProducer()
l7policy = L7PolicyProducer()
l7rule = L7RuleProducer()

@ -66,7 +66,7 @@ class BaseAPITest(base_db_test.OctaviaDBTestBase):
self.pool_repo = repositories.PoolRepository()
self.member_repo = repositories.MemberRepository()
self.amphora_repo = repositories.AmphoraRepository()
patcher = mock.patch('octavia.api.v1.handlers.controller_simulator.'
patcher = mock.patch('octavia.api.handlers.controller_simulator.'
'handler.SimulatedControllerHandler')
self.handler_mock = patcher.start()
self.check_quota_met_true_mock = mock.patch(

@ -71,7 +71,7 @@ class BaseAPITest(base_db_test.OctaviaDBTestBase):
self.pool_repo = repositories.PoolRepository()
self.member_repo = repositories.MemberRepository()
self.amphora_repo = repositories.AmphoraRepository()
patcher = mock.patch('octavia.api.v1.handlers.controller_simulator.'
patcher = mock.patch('octavia.api.handlers.controller_simulator.'
'handler.SimulatedControllerHandler')
self.handler_mock = patcher.start()
self.app = self._make_app()

@ -29,7 +29,7 @@ from oslo_config import cfg
from oslo_config import fixture as oslo_fixture
import oslo_messaging as messaging
from octavia.api.v1.handlers.queue import producer
from octavia.api.handlers.queue import producer
from octavia.api.v1.types import health_monitor
from octavia.api.v1.types import l7policy
from octavia.api.v1.types import l7rule
@ -49,12 +49,12 @@ class TestProducer(base.TestCase):
conf = self.useFixture(oslo_fixture.Config(cfg.CONF))
conf.config(group="oslo_messaging", topic='OCTAVIA_PROV')
mck_target = mock.patch(
'octavia.api.v1.handlers.queue.producer.messaging.Target')
'octavia.api.handlers.queue.producer.messaging.Target')
mck_transport = mock.patch(
'octavia.api.v1.handlers.queue.producer.messaging.get_transport')
'octavia.api.handlers.queue.producer.messaging.get_transport')
self.mck_client = mock.create_autospec(messaging.RPCClient)
mck_client = mock.patch(
'octavia.api.v1.handlers.queue.producer.messaging.RPCClient',
'octavia.api.handlers.queue.producer.messaging.RPCClient',
return_value=self.mck_client)
mck_target.start()
mck_transport.start()

@ -1,236 +0,0 @@
# Copyright 2014 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.# Copyright 2014 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.
import mock
from oslo_config import cfg
from oslo_config import fixture as oslo_fixture
import oslo_messaging as messaging
from octavia.api.v1.types import health_monitor
from octavia.api.v1.types import l7policy
from octavia.api.v1.types import l7rule
from octavia.api.v1.types import listener
from octavia.api.v1.types import load_balancer
from octavia.api.v1.types import member
from octavia.api.v1.types import pool
from octavia.api.v2.handlers.queue import producer
from octavia.common import data_models
from octavia.tests.unit import base
class TestProducer(base.TestCase):
def setUp(self):
super(TestProducer, self).setUp()
self.mck_model = mock.Mock()
self.mck_model.id = '10'
conf = self.useFixture(oslo_fixture.Config(cfg.CONF))
conf.config(group="oslo_messaging", topic='OCTAVIA_PROV')
mck_target = mock.patch(
'octavia.api.v1.handlers.queue.producer.messaging.Target')
mck_transport = mock.patch(
'octavia.api.v1.handlers.queue.producer.messaging.get_transport')
self.mck_client = mock.create_autospec(messaging.RPCClient)
mck_client = mock.patch(
'octavia.api.v1.handlers.queue.producer.messaging.RPCClient',
return_value=self.mck_client)
mck_target.start()
mck_transport.start()
mck_client.start()
self.addCleanup(mck_target.stop)
self.addCleanup(mck_transport.stop)
self.addCleanup(mck_client.stop)
def test_create_loadbalancer(self):
p = producer.LoadBalancerProducer()
p.create(self.mck_model)
kw = {'load_balancer_id': self.mck_model.id}
self.mck_client.cast.assert_called_once_with(
{}, 'create_load_balancer', **kw)
def test_delete_loadbalancer(self):
p = producer.LoadBalancerProducer()
p.delete(self.mck_model, False)
kw = {'load_balancer_id': self.mck_model.id,
'cascade': False}
self.mck_client.cast.assert_called_once_with(
{}, 'delete_load_balancer', **kw)
def test_update_loadbalancer(self):
p = producer.LoadBalancerProducer()
lb = data_models.LoadBalancer(id=10)
lb_updates = load_balancer.LoadBalancerPUT(enabled=False)
p.update(lb, lb_updates)
kw = {'load_balancer_id': lb.id,
'load_balancer_updates': lb_updates.to_dict(render_unsets=False)}
self.mck_client.cast.assert_called_once_with(
{}, 'update_load_balancer', **kw)
def test_create_listener(self):
p = producer.ListenerProducer()
p.create(self.mck_model)
kw = {'listener_id': self.mck_model.id}
self.mck_client.cast.assert_called_once_with(
{}, 'create_listener', **kw)
def test_delete_listener(self):
p = producer.ListenerProducer()
p.delete(self.mck_model)
kw = {'listener_id': self.mck_model.id}
self.mck_client.cast.assert_called_once_with(
{}, 'delete_listener', **kw)
def test_update_listener(self):
p = producer.ListenerProducer()
listener_model = data_models.LoadBalancer(id=10)
listener_updates = listener.ListenerPUT(enabled=False)
p.update(listener_model, listener_updates)
kw = {'listener_id': listener_model.id,
'listener_updates': listener_updates.to_dict(
render_unsets=False)}
self.mck_client.cast.assert_called_once_with(
{}, 'update_listener', **kw)
def test_create_pool(self):
p = producer.PoolProducer()
p.create(self.mck_model)
kw = {'pool_id': self.mck_model.id}
self.mck_client.cast.assert_called_once_with(
{}, 'create_pool', **kw)
def test_delete_pool(self):
p = producer.PoolProducer()
p.delete(self.mck_model)
kw = {'pool_id': self.mck_model.id}
self.mck_client.cast.assert_called_once_with(
{}, 'delete_pool', **kw)
def test_update_pool(self):
p = producer.PoolProducer()
pool_model = data_models.Pool(id=10)
pool_updates = pool.PoolPUT(enabled=False)
p.update(pool_model, pool_updates)
kw = {'pool_id': pool_model.id,
'pool_updates': pool_updates.to_dict(render_unsets=False)}
self.mck_client.cast.assert_called_once_with(
{}, 'update_pool', **kw)
def test_create_healthmonitor(self):
p = producer.HealthMonitorProducer()
p.create(self.mck_model)
kw = {'health_monitor_id': self.mck_model.id}
self.mck_client.cast.assert_called_once_with(
{}, 'create_health_monitor', **kw)
def test_delete_healthmonitor(self):
p = producer.HealthMonitorProducer()
p.delete(self.mck_model)
kw = {'health_monitor_id': self.mck_model.id}
self.mck_client.cast.assert_called_once_with(
{}, 'delete_health_monitor', **kw)
def test_update_healthmonitor(self):
p = producer.HealthMonitorProducer()
hm = data_models.HealthMonitor(pool_id=10)
hm_updates = health_monitor.HealthMonitorPUT(enabled=False)
p.update(hm, hm_updates)
kw = {'pool_id': hm.pool_id,
'health_monitor_updates': hm_updates.to_dict(
render_unsets=False)}
self.mck_client.cast.assert_called_once_with(
{}, 'update_health_monitor', **kw)
def test_create_member(self):
p = producer.MemberProducer()
p.create(self.mck_model)
kw = {'member_id': self.mck_model.id}
self.mck_client.cast.assert_called_once_with(
{}, 'create_member', **kw)
def test_delete_member(self):
p = producer.MemberProducer()
p.delete(self.mck_model)
kw = {'member_id': self.mck_model.id}
self.mck_client.cast.assert_called_once_with(
{}, 'delete_member', **kw)
def test_update_member(self):
p = producer.MemberProducer()
member_model = data_models.Member(id=10)
member_updates = member.MemberPUT(enabled=False)
p.update(member_model, member_updates)
kw = {'member_id': member_model.id,
'member_updates': member_updates.to_dict(render_unsets=False)}
self.mck_client.cast.assert_called_once_with(
{}, 'update_member', **kw)
def test_create_l7policy(self):
p = producer.L7PolicyProducer()
p.create(self.mck_model)
kw = {'l7policy_id': self.mck_model.id}
self.mck_client.cast.assert_called_once_with(
{}, 'create_l7policy', **kw)
def test_delete_l7policy(self):
p = producer.L7PolicyProducer()
p.delete(self.mck_model)
kw = {'l7policy_id': self.mck_model.id}
self.mck_client.cast.assert_called_once_with(
{}, 'delete_l7policy', **kw)
def test_update_l7policy(self):
p = producer.L7PolicyProducer()
l7policy_model = data_models.L7Policy(id=10)
l7policy_updates = l7policy.L7PolicyPUT(enabled=False)
p.update(l7policy_model, l7policy_updates)
kw = {'l7policy_id': l7policy_model.id,
'l7policy_updates': l7policy_updates.to_dict(
render_unsets=False)}
self.mck_client.cast.assert_called_once_with(
{}, 'update_l7policy', **kw)
def test_create_l7rule(self):
p = producer.L7RuleProducer()
p.create(self.mck_model)
kw = {'l7rule_id': self.mck_model.id}
self.mck_client.cast.assert_called_once_with(
{}, 'create_l7rule', **kw)
def test_delete_l7rule(self):
p = producer.L7RuleProducer()
p.delete(self.mck_model)
kw = {'l7rule_id': self.mck_model.id}
self.mck_client.cast.assert_called_once_with(
{}, 'delete_l7rule', **kw)
def test_update_l7rule(self):
p = producer.L7RuleProducer()
l7rule_model = data_models.L7Rule(id=10)
l7rule_updates = l7rule.L7RulePUT(enabled=False)
p.update(l7rule_model, l7rule_updates)
kw = {'l7rule_id': l7rule_model.id,
'l7rule_updates': l7rule_updates.to_dict(render_unsets=False)}
self.mck_client.cast.assert_called_once_with(
{}, 'update_l7rule', **kw)

@ -58,8 +58,8 @@ console_scripts =
amphora-agent = octavia.cmd.agent:main
haproxy-vrrp-check = octavia.cmd.haproxy_vrrp_check:main
octavia.api.handlers =
simulated_handler = octavia.api.v1.handlers.controller_simulator.handler:SimulatedControllerHandler
queue_producer = octavia.api.v1.handlers.queue.producer:ProducerHandler
simulated_handler = octavia.api.handlers.controller_simulator.handler:SimulatedControllerHandler
queue_producer = octavia.api.handlers.queue.producer:ProducerHandler
octavia.amphora.drivers =
amphora_noop_driver = octavia.amphorae.drivers.noop_driver.driver:NoopAmphoraLoadBalancerDriver
amphora_haproxy_rest_driver = octavia.amphorae.drivers.haproxy.rest_api_driver:HaproxyAmphoraLoadBalancerDriver

Loading…
Cancel
Save