tobiko/tobiko/openstack/stacks/_octavia.py

214 lines
6.3 KiB
Python

# Copyright (c) 2019 Red Hat, Inc.
#
# All Rights Reserved.
#
# 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.
from __future__ import absolute_import
import tobiko
from tobiko import config
from tobiko.openstack import heat
from tobiko.openstack import octavia
from tobiko.openstack.stacks import _hot
from tobiko.openstack.stacks import _neutron
from tobiko.openstack.stacks import _ubuntu
CONF = config.CONF
class OctaviaLoadbalancerStackFixture(heat.HeatStackFixture):
template = _hot.heat_template_file('octavia/load_balancer.yaml')
vip_network = tobiko.required_setup_fixture(_neutron.NetworkStackFixture)
#: Floating IP network where the Neutron floating IP are created
@property
def floating_network(self) -> str:
return self.vip_network.floating_network
@property
def has_floating_ip(self) -> bool:
return bool(self.floating_network)
ip_version = 4
provider = 'amphora'
@property
def vip_subnet_id(self):
if self.ip_version == 4:
return self.vip_network.ipv4_subnet_id
else:
return self.vip_network.ipv6_subnet_id
def wait_for_active_loadbalancer(self,
timeout: tobiko.Seconds = None):
octavia.wait_for_status(status_key=octavia.PROVISIONING_STATUS,
status=octavia.ACTIVE,
get_client=octavia.get_loadbalancer,
object_id=self.loadbalancer_id,
timeout=timeout)
def wait_for_update_loadbalancer(self,
timeout: tobiko.Seconds = None):
octavia.wait_for_status(status_key=octavia.PROVISIONING_STATUS,
status=octavia.PENDING_UPDATE,
get_client=octavia.get_loadbalancer,
object_id=self.loadbalancer_id,
timeout=timeout)
class OctaviaListenerStackFixture(heat.HeatStackFixture):
template = _hot.heat_template_file('octavia/listener.yaml')
loadbalancer = tobiko.required_setup_fixture(
OctaviaLoadbalancerStackFixture)
lb_port = 80
lb_protocol = 'HTTP'
@property
def loadbalancer_id(self):
return self.loadbalancer.loadbalancer_id
@property
def loadbalancer_provider(self):
return self.loadbalancer.provider
class OctaviaPoolStackFixture(heat.HeatStackFixture):
template = _hot.heat_template_file('octavia/pool.yaml')
listener = tobiko.required_setup_fixture(
OctaviaListenerStackFixture)
pool_protocol = 'HTTP'
lb_algorithm = 'ROUND_ROBIN'
hm_type = 'HTTP'
# healthmonitor attributes
hm_delay = 3
hm_max_retries = 4
hm_timeout = 3
#: whenever to create the health monitor
has_monitor = True
@property
def listener_id(self):
return self.listener.listener_id
def wait_for_active_members(self):
pool_id = self.stack.output_show('pool_id')['output']['output_value']
for member in octavia.list_members(pool_id=pool_id):
self.wait_for_active_member(pool_id=pool_id,
member_id=member['id'])
def wait_for_active_member(self, pool_id, member_id, **kwargs):
"""Wait for the member to be active
Waits for the member to have an ACTIVE provisioning status.
:param member_id: the member id.
:param pool_id: the pool id.
"""
octavia.wait_for_status(status_key=octavia.PROVISIONING_STATUS,
status=octavia.ACTIVE,
get_client=octavia.get_member,
object_id=pool_id,
member_id=member_id, **kwargs)
class OctaviaMemberServerStackFixture(heat.HeatStackFixture):
template = _hot.heat_template_file('octavia/member.yaml')
pool = tobiko.required_fixture(OctaviaPoolStackFixture)
server_stack = tobiko.required_fixture(_ubuntu.UbuntuServerStackFixture)
application_port = 80
ip_version = 4
@property
def pool_id(self):
return self.pool.pool_id
@property
def subnet_id(self):
if self.ip_version == 4:
return self.server_stack.network_stack.ipv4_subnet_id
else:
return self.server_stack.network_stack.ipv6_subnet_id
@property
def member_address(self) -> str:
return str(self.server_stack.find_fixed_ip(ip_version=self.ip_version))
class OctaviaOtherServerStackFixture(_ubuntu.UbuntuServerStackFixture):
pass
class OctaviaOtherMemberServerStackFixture(
OctaviaMemberServerStackFixture):
server_stack = tobiko.required_setup_fixture(
OctaviaOtherServerStackFixture)
# OVN provider stack fixtures
class OctaviaOvnProviderLoadbalancerStackFixture(
OctaviaLoadbalancerStackFixture):
provider = 'ovn'
class OctaviaOvnProviderListenerStackFixture(OctaviaListenerStackFixture):
loadbalancer = tobiko.required_setup_fixture(
OctaviaOvnProviderLoadbalancerStackFixture)
lb_port = 22
lb_protocol = 'TCP'
class OctaviaOvnProviderPoolStackFixture(OctaviaPoolStackFixture):
listener = tobiko.required_setup_fixture(
OctaviaOvnProviderListenerStackFixture)
pool_protocol = 'TCP'
lb_algorithm = 'SOURCE_IP_PORT'
#: There is any health monitor available for OVN provider
has_monitor = False
class OctaviaOvnProviderMemberServerStackFixture(
OctaviaMemberServerStackFixture):
pool = tobiko.required_setup_fixture(OctaviaOvnProviderPoolStackFixture)
application_port = 22
class OctaviaOvnProviderOtherMemberServerStackFixture(
OctaviaOvnProviderMemberServerStackFixture):
server_stack = tobiko.required_setup_fixture(
OctaviaOtherServerStackFixture)