Remove count_members variable from octavia tests
So far we used the class variable count_members in all Octavia modules. Deciding how many members exist, saving it as a variable and testing by it might create conflicts in the future and will be harder to maintain. The LB should know how many members exist by using the Octavia API, not by tests module variable. This patch adds the list_members function and uses it in all Octavia modules. Change-Id: Id7c5f13db2098643ccbe4fe9a4d0ff08784d2307
This commit is contained in:
parent
716d2b2b10
commit
b1de529e88
@ -26,6 +26,7 @@ octavia_client = _client.octavia_client
|
||||
OctaviaClientFixture = _client.OctaviaClientFixture
|
||||
get_loadbalancer = _client.get_loadbalancer
|
||||
get_member = _client.get_member
|
||||
list_members = _client.list_members
|
||||
list_amphorae = _client.list_amphorae
|
||||
get_amphora_vm = _client.get_amphora_vm
|
||||
list_amphoras_compute_nodes = _client.list_amphoras_compute_nodes
|
||||
|
@ -82,6 +82,10 @@ def get_member(pool_id, member_id, client=None):
|
||||
member_id=member_id)
|
||||
|
||||
|
||||
def list_members(pool_id: str, client=None):
|
||||
return octavia_client(client).member_list(pool_id=pool_id)['members']
|
||||
|
||||
|
||||
def list_amphorae(loadbalancer_id: str, client=None):
|
||||
return octavia_client(client).amphora_list(
|
||||
loadbalancer_id=loadbalancer_id)['amphorae']
|
||||
|
@ -20,6 +20,7 @@ import typing
|
||||
from oslo_log import log
|
||||
|
||||
import tobiko
|
||||
from tobiko.openstack import octavia
|
||||
from tobiko.shell import curl
|
||||
from tobiko.shell import ssh
|
||||
|
||||
@ -27,10 +28,11 @@ from tobiko.shell import ssh
|
||||
LOG = log.getLogger(__name__)
|
||||
|
||||
|
||||
def check_members_balanced(members_count: int,
|
||||
ip_address: str,
|
||||
def check_members_balanced(ip_address: str,
|
||||
protocol: str,
|
||||
port: int,
|
||||
pool_id: str = None,
|
||||
members_count: int = None,
|
||||
lb_algorithm: str = None,
|
||||
requests_count: int = 10,
|
||||
connect_timeout: tobiko.Seconds = 2.,
|
||||
@ -42,6 +44,15 @@ def check_members_balanced(members_count: int,
|
||||
|
||||
test_case = tobiko.get_test_case()
|
||||
|
||||
# Getting the members count
|
||||
if members_count is None:
|
||||
if pool_id is None:
|
||||
raise ValueError('Either members_count or pool_id has to be passed'
|
||||
' to the function.')
|
||||
|
||||
else: # members_count is None and pool_id is not None
|
||||
members_count = len(octavia.list_members(pool_id=pool_id))
|
||||
|
||||
replies: typing.Dict[str, int] = collections.defaultdict(lambda: 0)
|
||||
for attempt in tobiko.retry(count=members_count * requests_count,
|
||||
interval=interval):
|
||||
|
@ -54,8 +54,6 @@ class OctaviaBasicFaultTest(testtools.TestCase):
|
||||
member2_stack = tobiko.required_setup_fixture(
|
||||
stacks.OctaviaOtherMemberServerStackFixture)
|
||||
|
||||
members_count = 2
|
||||
|
||||
def setUp(self):
|
||||
# pylint: disable=no-member
|
||||
super(OctaviaBasicFaultTest, self).setUp()
|
||||
@ -75,7 +73,7 @@ class OctaviaBasicFaultTest(testtools.TestCase):
|
||||
|
||||
# Send traffic
|
||||
octavia.check_members_balanced(
|
||||
members_count=self.members_count,
|
||||
pool_id=self.pool_stack.pool_id,
|
||||
ip_address=self.loadbalancer_stack.floating_ip_address,
|
||||
lb_algorithm=self.pool_stack.lb_algorithm,
|
||||
protocol=self.listener_stack.lb_protocol,
|
||||
@ -110,7 +108,7 @@ class OctaviaBasicFaultTest(testtools.TestCase):
|
||||
|
||||
# Verify Octavia functionality
|
||||
octavia.check_members_balanced(
|
||||
members_count=self.members_count,
|
||||
pool_id=self.pool_stack.pool_id,
|
||||
ip_address=self.loadbalancer_stack.floating_ip_address,
|
||||
lb_algorithm=self.pool_stack.lb_algorithm,
|
||||
protocol=self.listener_stack.lb_protocol,
|
||||
|
@ -64,8 +64,6 @@ class OctaviaServicesFaultTest(testtools.TestCase):
|
||||
member2_stack = tobiko.required_setup_fixture(
|
||||
stacks.OctaviaOtherMemberServerStackFixture)
|
||||
|
||||
members_count = 2
|
||||
|
||||
list_octavia_active_units = ('systemctl list-units ' +
|
||||
'--state=active tripleo_octavia_*')
|
||||
|
||||
@ -91,7 +89,7 @@ class OctaviaServicesFaultTest(testtools.TestCase):
|
||||
|
||||
# Sending initial traffic before we stop octavia services
|
||||
octavia.check_members_balanced(
|
||||
members_count=self.members_count,
|
||||
pool_id=self.pool_stack.pool_id,
|
||||
ip_address=self.loadbalancer_stack.floating_ip_address,
|
||||
lb_algorithm=self.pool_stack.lb_algorithm,
|
||||
protocol=self.listener_stack.lb_protocol,
|
||||
@ -179,7 +177,7 @@ class OctaviaServicesFaultTest(testtools.TestCase):
|
||||
self.assertTrue(service not in octavia_active_units, err_msg)
|
||||
|
||||
octavia.check_members_balanced(
|
||||
members_count=self.members_count,
|
||||
pool_id=self.pool_stack.pool_id,
|
||||
ip_address=self.loadbalancer_stack.floating_ip_address,
|
||||
lb_algorithm=self.pool_stack.lb_algorithm,
|
||||
protocol=self.listener_stack.lb_protocol,
|
||||
@ -210,7 +208,7 @@ class OctaviaServicesFaultTest(testtools.TestCase):
|
||||
self._make_sure_octavia_services_are_active(controller)
|
||||
|
||||
octavia.check_members_balanced(
|
||||
members_count=self.members_count,
|
||||
pool_id=self.pool_stack.pool_id,
|
||||
ip_address=self.loadbalancer_stack.floating_ip_address,
|
||||
lb_algorithm=self.pool_stack.lb_algorithm,
|
||||
protocol=self.listener_stack.lb_protocol,
|
||||
|
@ -46,8 +46,6 @@ class OctaviaBasicTrafficScenarioTest(testtools.TestCase):
|
||||
member2_stack = tobiko.required_setup_fixture(
|
||||
stacks.OctaviaOtherMemberServerStackFixture)
|
||||
|
||||
members_count = 2
|
||||
|
||||
def setUp(self):
|
||||
# pylint: disable=no-member
|
||||
super(OctaviaBasicTrafficScenarioTest, self).setUp()
|
||||
@ -65,7 +63,7 @@ class OctaviaBasicTrafficScenarioTest(testtools.TestCase):
|
||||
@pytest.mark.flaky(reruns=3)
|
||||
def test_traffic(self):
|
||||
octavia.check_members_balanced(
|
||||
members_count=self.members_count,
|
||||
pool_id=self.pool_stack.pool_id,
|
||||
ip_address=self.loadbalancer_stack.floating_ip_address,
|
||||
lb_algorithm=self.pool_stack.lb_algorithm,
|
||||
protocol=self.listener_stack.lb_protocol,
|
||||
|
Loading…
x
Reference in New Issue
Block a user