Merge "Pass timeout_dict to _get_haproxy_versions" into stable/victoria

This commit is contained in:
Zuul 2022-04-22 15:31:17 +00:00 committed by Gerrit Code Review
commit 34f3042339
5 changed files with 109 additions and 16 deletions

View File

@ -77,15 +77,17 @@ class HaproxyAmphoraLoadBalancerDriver(
connection_logging=CONF.haproxy_amphora.connection_logging)
self.udp_jinja = jinja_udp_cfg.LvsJinjaTemplater()
def _get_haproxy_versions(self, amphora):
def _get_haproxy_versions(self, amphora, timeout_dict=None):
"""Get major and minor version number from haproxy
Example: ['1', '6']
:returns version_list: A list with the major and minor numbers
"""
self._populate_amphora_api_version(amphora)
amp_info = self.clients[amphora.api_version].get_info(amphora)
self._populate_amphora_api_version(
amphora, timeout_dict=timeout_dict)
amp_info = self.clients[amphora.api_version].get_info(
amphora, timeout_dict=timeout_dict)
haproxy_version_string = amp_info['haproxy_version']
return haproxy_version_string.split('.')[:2]
@ -135,7 +137,8 @@ class HaproxyAmphoraLoadBalancerDriver(
return
# Check which HAProxy version is on the amp
haproxy_versions = self._get_haproxy_versions(amphora)
haproxy_versions = self._get_haproxy_versions(
amphora, timeout_dict=timeout_dict)
# Check which config style to use
api_version = self._populate_amphora_api_version(amphora)
if api_version[0] == 0 and api_version[1] <= 5: # 0.5 or earlier
@ -258,15 +261,18 @@ class HaproxyAmphoraLoadBalancerDriver(
self._populate_amphora_api_version(amp)
self.clients[amp.api_version].update_cert_for_rotation(amp, pem)
def _apply(self, func_name, loadbalancer, amphora=None, *args):
def _apply(self, func_name, loadbalancer, amphora=None, *args, **kwargs):
if amphora is None:
amphorae = loadbalancer.amphorae
else:
amphorae = [amphora]
timeout_dict = args[0]
for amp in amphorae:
if amp.status != consts.DELETED:
api_version = self._populate_amphora_api_version(amp)
api_version = self._populate_amphora_api_version(
amp, timeout_dict=timeout_dict)
# Check which config style to use
if api_version[0] == 0 and api_version[1] <= 5:
# 0.5 or earlier
@ -368,11 +374,14 @@ class HaproxyAmphoraLoadBalancerDriver(
self.clients[amphora.api_version].delete_listener(
amphora, listener.load_balancer.id)
def get_info(self, amphora, raise_retry_exception=False):
def get_info(self, amphora, raise_retry_exception=False,
timeout_dict=None):
self._populate_amphora_api_version(
amphora, raise_retry_exception=raise_retry_exception)
amphora, raise_retry_exception=raise_retry_exception,
timeout_dict=timeout_dict)
return self.clients[amphora.api_version].get_info(
amphora, raise_retry_exception=raise_retry_exception)
amphora, raise_retry_exception=raise_retry_exception,
timeout_dict=timeout_dict)
def get_diagnostics(self, amphora):
pass
@ -808,8 +817,10 @@ class AmphoraAPIClient0_5(AmphoraAPIClientBase):
amp, 'listeners/{listener_id}'.format(listener_id=listener_id))
return exc.check_exception(r, (404,))
def get_info(self, amp, raise_retry_exception=False):
r = self.get(amp, "info", raise_retry_exception=raise_retry_exception)
def get_info(self, amp, raise_retry_exception=False,
timeout_dict=None):
r = self.get(amp, "info", raise_retry_exception=raise_retry_exception,
timeout_dict=timeout_dict)
if exc.check_exception(r):
return r.json()
return None
@ -937,8 +948,10 @@ class AmphoraAPIClient1_0(AmphoraAPIClientBase):
amp, 'listeners/{object_id}'.format(object_id=object_id))
return exc.check_exception(r, (404,))
def get_info(self, amp, raise_retry_exception=False):
r = self.get(amp, "info", raise_retry_exception=raise_retry_exception)
def get_info(self, amp, raise_retry_exception=False,
timeout_dict=None):
r = self.get(amp, "info", raise_retry_exception=raise_retry_exception,
timeout_dict=timeout_dict)
if exc.check_exception(r):
return r.json()
return None

View File

@ -50,7 +50,8 @@ class KeepalivedAmphoraDriverMixin(driver_base.VRRPDriverMixin):
LOG.debug("Update amphora %s VRRP configuration.", amphora.id)
self._populate_amphora_api_version(amphora)
self._populate_amphora_api_version(amphora,
timeout_dict=timeout_dict)
# Get the VIP subnet prefix for the amphora
# For amphorav2 amphorae_network_config will be list of dicts
try:

View File

@ -487,6 +487,16 @@ class TestHaproxyAmphoraLoadBalancerDriverTest(base.TestCase):
API_VERSION].reload_listener.assert_called_once_with(
amp1, listener.id, None)
self.driver.clients[
API_VERSION].reload_listener.reset_mock()
timeout_dict = {
'elem1': 1000
}
self.driver.reload(loadbalancer, timeout_dict=timeout_dict)
self.driver.clients[
API_VERSION].reload_listener.assert_called_once_with(
amp1, listener.id, timeout_dict)
def test_start_with_amphora(self):
# Execute driver method
amp = mock.MagicMock()
@ -656,7 +666,19 @@ class TestHaproxyAmphoraLoadBalancerDriverTest(base.TestCase):
ref_haproxy_versions = ['1', '6']
result = self.driver._get_haproxy_versions(self.amp)
self.driver.clients[API_VERSION].get_info.assert_called_once_with(
self.amp)
self.amp, timeout_dict=None)
self.assertEqual(ref_haproxy_versions, result)
def test_get_haproxy_versions_with_timeout_dict(self):
ref_haproxy_versions = ['1', '6']
timeout_dict = {
constants.CONN_MAX_RETRIES: 100,
constants.CONN_RETRY_INTERVAL: 1
}
result = self.driver._get_haproxy_versions(self.amp,
timeout_dict=timeout_dict)
self.driver.clients[API_VERSION].get_info.assert_called_once_with(
self.amp, timeout_dict=timeout_dict)
self.assertEqual(ref_haproxy_versions, result)
def test_populate_amphora_api_version(self):
@ -750,6 +772,19 @@ class TestAmphoraAPIClientTest(base.TestCase):
information = self.driver.get_info(self.amp)
self.assertEqual(info, information)
@requests_mock.mock()
def test_get_info_with_timeout_dict(self, m):
info = {"hostname": "some_hostname", "version": "some_version",
"api_version": "0.5", "uuid": FAKE_UUID_1}
m.get("{base}/info".format(base=self.base_url_ver),
json=info)
timeout_dict = {
constants.CONN_MAX_RETRIES: 100,
constants.CONN_RETRY_INTERVAL: 1
}
information = self.driver.get_info(self.amp, timeout_dict=timeout_dict)
self.assertEqual(info, information)
@requests_mock.mock()
def test_get_info_unauthorized(self, m):
m.get("{base}/info".format(base=self.base_url_ver),

View File

@ -489,6 +489,16 @@ class TestHaproxyAmphoraLoadBalancerDriverTest(base.TestCase):
API_VERSION].reload_listener.assert_called_once_with(
amp1, loadbalancer.id, None)
self.driver.clients[
API_VERSION].reload_listener.reset_mock()
timeout_dict = {
'elem1': 1000
}
self.driver.reload(loadbalancer, timeout_dict=timeout_dict)
self.driver.clients[
API_VERSION].reload_listener.assert_called_once_with(
amp1, loadbalancer.id, timeout_dict)
def test_start_with_amphora(self):
# Execute driver method
amp = mock.MagicMock()
@ -751,7 +761,19 @@ class TestHaproxyAmphoraLoadBalancerDriverTest(base.TestCase):
ref_haproxy_versions = ['1', '6']
result = self.driver._get_haproxy_versions(self.amp)
self.driver.clients[API_VERSION].get_info.assert_called_once_with(
self.amp)
self.amp, timeout_dict=None)
self.assertEqual(ref_haproxy_versions, result)
def test_get_haproxy_versions_with_timeout_dict(self):
ref_haproxy_versions = ['1', '6']
timeout_dict = {
constants.CONN_MAX_RETRIES: 100,
constants.CONN_RETRY_INTERVAL: 1
}
result = self.driver._get_haproxy_versions(self.amp,
timeout_dict=timeout_dict)
self.driver.clients[API_VERSION].get_info.assert_called_once_with(
self.amp, timeout_dict=timeout_dict)
self.assertEqual(ref_haproxy_versions, result)
def test_populate_amphora_api_version(self):
@ -839,6 +861,19 @@ class TestAmphoraAPIClientTest(base.TestCase):
information = self.driver.get_info(self.amp)
self.assertEqual(info, information)
@requests_mock.mock()
def test_get_info_with_timeout_dict(self, m):
info = {"hostname": "some_hostname", "version": "some_version",
"api_version": "0.5", "uuid": FAKE_UUID_1}
m.get("{base}/info".format(base=self.base_url_ver),
json=info)
timeout_dict = {
constants.CONN_MAX_RETRIES: 100,
constants.CONN_RETRY_INTERVAL: 1
}
information = self.driver.get_info(self.amp, timeout_dict=timeout_dict)
self.assertEqual(info, information)
@requests_mock.mock()
def test_get_info_unauthorized(self, m):
m.get("{base}/info".format(base=self.base_url_ver),

View File

@ -0,0 +1,9 @@
---
fixes:
- |
Fix an issue when Octavia performs a failover of an ACTIVE-STANDBY load
balancer that has both amphorae missing.
Some tasks in the controller took too much time to timeout because the
timeout value defined in
``[haproxy_amphora].active_connection_max_retries`` and
``[haproxy_amphora].active_connection_rety_interval`` was not used.