From 1c9e662d78b328c6d4587171ccba08572e8dcf25 Mon Sep 17 00:00:00 2001 From: Gabriel Cocenza Date: Wed, 26 Oct 2022 16:39:00 -0300 Subject: [PATCH] Add support for HAProxy L7 checks This change adds the haproxy options if defined by the charm class to enable HTTP checks to the HAProxy configuration, instead of the default TCP connection checks. options.ssl check if the environment is using http or https mode. We disable certificate verification because we are only interested in the health of the service. Fix for tox4 compability Closes-Bug: #1880610 Change-Id: Ie091fdfe560b6a060f0c29c6b92a99f5e564eddf --- pip.sh | 18 ----------------- templates/haproxy.cfg | 9 +++++++++ tox.ini | 45 +++++++++++-------------------------------- 3 files changed, 20 insertions(+), 52 deletions(-) delete mode 100755 pip.sh diff --git a/pip.sh b/pip.sh deleted file mode 100755 index 9a7e6b0..0000000 --- a/pip.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/env bash -# -# This file is managed centrally by release-tools and should not be modified -# within individual charm repos. See the 'global' dir contents for available -# choices of tox.ini for OpenStack Charms: -# https://github.com/openstack-charmers/release-tools -# -# setuptools 58.0 dropped the support for use_2to3=true which is needed to -# install blessings (an indirect dependency of charm-tools). -# -# More details on the beahvior of tox and virtualenv creation can be found at -# https://github.com/tox-dev/tox/issues/448 -# -# This script is wrapper to force the use of the pinned versions early in the -# process when the virtualenv was created and upgraded before installing the -# depedencies declared in the target. -pip install 'pip<20.3' 'setuptools<50.0.0' -pip "$@" diff --git a/templates/haproxy.cfg b/templates/haproxy.cfg index bde32f9..bdce096 100644 --- a/templates/haproxy.cfg +++ b/templates/haproxy.cfg @@ -72,8 +72,17 @@ frontend tcp-in_{{ service }} {% for frontend in cluster.cluster_hosts -%} backend {{ service }}_{{ frontend }} balance leastconn + {% if options.haproxy_healthcheck -%} + {% for key, val in options.haproxy_healthcheck.items() -%} + {{ key }} {{ val }} + {% endfor -%} + {% endif -%} {% for unit, address in cluster.cluster_hosts[frontend]['backends'].items() -%} + {% if options.ssl -%} + server {{ unit }} {{ address }}:{{ ports[1] }} check check-ssl verify none + {% else -%} server {{ unit }} {{ address }}:{{ ports[1] }} check + {% endif -%} {% endfor %} {% endfor -%} {% endfor -%} diff --git a/tox.ini b/tox.ini index 575fab0..344b66d 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,4 @@ [tox] -skipsdist = True envlist = pep8 toxworkdir = /tmp/tox # NOTE(beisner): Avoid build/test env pollution by not enabling sitepackages. @@ -7,31 +6,19 @@ sitepackages = False # NOTE(beisner): Avoid false positives by not skipping missing interpreters. skip_missing_interpreters = False -# NOTES: -# * We avoid the new dependency resolver by pinning pip < 20.3, see -# https://github.com/pypa/pip/issues/9187 -# * Pinning dependencies requires tox >= 3.2.0, see -# https://tox.readthedocs.io/en/latest/config.html#conf-requires -# * It is also necessary to pin virtualenv as a newer virtualenv would still -# lead to fetching the latest pip in the func* tox targets, see -# https://stackoverflow.com/a/38133283 -requires = - pip < 20.3 - virtualenv < 20.0 - setuptools<50.0.0 - -# NOTE: https://wiki.canonical.com/engineering/OpenStack/InstallLatestToxOnOsci -minversion = 3.18.0 - [testenv] +# We use tox mainly for virtual environment management for test requirements +# and do not install the charm code as a Python package into that environment. +# Ref: https://tox.wiki/en/latest/config.html#skip_install +skip_install = True basepython = python3 setenv = VIRTUAL_ENV={envdir} PYTHONHASHSEED=0 TERM=linux JUJU_REPOSITORY={envdir}/tmp/build -passenv = http_proxy https_proxy -install_command = - {toxinidir}/pip.sh install {opts} {packages} +passenv = + http_proxy + https_proxy deps = -r{toxinidir}/requirements.txt whitelist_externals = /bin/true /bin/echo /bin/mkdir /bin/ln @@ -48,24 +35,14 @@ commands = charm-build --log-level DEBUG -o {envdir}/tmp/build/builds . /bin/ln -s {envdir}/tmp/build/builds/ {envdir}/tmp/build/trusty /bin/ln -s {envdir}/tmp/build {toxinidir}/build +allowlist_externals = + /bin/* [testenv:venv] commands = {posargs} -[testenv:py34] -basepython = python3.4 -deps = -r{toxinidir}/test-requirements.txt -# TODO: Need to write unit tests then remove the following command. -commands = /bin/true - -[testenv:py35] -basepython = python3.5 -deps = -r{toxinidir}/test-requirements.txt -# TODO: Need to write unit tests then remove the following command. -commands = /bin/true - -[testenv:py36] -basepython = python3.6 +[testenv:py3] +basepython = python3 deps = -r{toxinidir}/test-requirements.txt # TODO: Need to write unit tests then remove the following command. commands = /bin/true