From 4c3d0b74ecd140d51bd2478841b7d2dbddd4804a Mon Sep 17 00:00:00 2001 From: Zhang Hua Date: Thu, 2 Nov 2023 22:33:52 +0800 Subject: [PATCH] cherry-pick the fix for lp bug 2021550 to xena branch (#858) * Allow users to disable wsgi socket rotation (#801) The lp bug 1863232 introduced a new configuration option called WSGISocketRotation which allows users to disable socket rotation on the apache side. This patch will also allow setting this option on the charm side. Other gerrit review links: horizon: https://review.opendev.org/c/openstack/charm-openstack-dashboard/+/886373 cinder: https://review.opendev.org/c/openstack/charm-cinder/+/886356 keystone: https://review.opendev.org/c/openstack/charm-keystone/+/886377 ncc: https://review.opendev.org/c/openstack/charm-nova-cloud-controller/+/885836 Partial-Bug: 2021550 (cherry picked from commit 996f2410632b44a7dc207cc4bbfc1a38c83140a8) Signed-off-by: zhhuabj * Rename wsgi-rotation to wsgi-socket-rotation Commit 996f241 added support for new config option 'wsgi-rotation' but that name should have been 'wsgi-socket-rotation' in order to have a 1:1 relation with the apache config it changes. The following patches that implement this config are currently blocked until this lands so that they can be synced before merge: * https://review.opendev.org/c/openstack/charm-ceilometer/+/887793 * https://review.opendev.org/c/openstack/charm-cinder/+/886356 * https://review.opendev.org/c/openstack/charm-glance/+/886376 * https://review.opendev.org/c/openstack/charm-keystone/+/886377 * https://review.opendev.org/c/openstack/charm-nova-cloud-controller/+/885836 * https://review.opendev.org/c/openstack/charm-openstack-dashboard/+/886373 Related-Bug: #2021550 (cherry picked from commit 1a90eb03052102a2e8d906262f97e7f3ff87fcdc) Signed-off-by: zhhuabj * Fix pep8 error in assert type comparison charmhelpers/fetch/snap.py:55:12: E721 do not compare types, for exact checks use `is` / `is not`, for instance checks use `isinstance()` (cherry picked from commit 5b0a3e6aa3e3141d70120aad7dd2c321595d7225) (cherry picked from commit 452988fad4a5833d6946fd92906c57bee0b37fe7) (cherry picked from commit d0a54fcadc8da54cd3ee7f9100fc2ac867698ad0) Signed-off-by: zhhuabj --------- Signed-off-by: zhhuabj Co-authored-by: Edward Hope-Morley Co-authored-by: Rodrigo Barbieri --- charmhelpers/contrib/openstack/context.py | 4 ++++ .../openstack/templates/wsgi-openstack-api.conf | 6 ++++++ charmhelpers/fetch/snap.py | 2 +- tests/contrib/openstack/test_os_contexts.py | 10 ++++++++-- 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/charmhelpers/contrib/openstack/context.py b/charmhelpers/contrib/openstack/context.py index 2c21ed357..1d37217cf 100644 --- a/charmhelpers/contrib/openstack/context.py +++ b/charmhelpers/contrib/openstack/context.py @@ -1674,6 +1674,9 @@ def __init__(self, name=None, script=None, admin_script=None, def __call__(self): total_processes = _calculate_workers() + enable_wsgi_socket_rotation = config('wsgi-socket-rotation') + if enable_wsgi_socket_rotation is None: + enable_wsgi_socket_rotation = True ctxt = { "service_name": self.service_name, "user": self.user, @@ -1687,6 +1690,7 @@ def __call__(self): "public_processes": int(math.ceil(self.public_process_weight * total_processes)), "threads": 1, + "wsgi_socket_rotation": enable_wsgi_socket_rotation, } return ctxt diff --git a/charmhelpers/contrib/openstack/templates/wsgi-openstack-api.conf b/charmhelpers/contrib/openstack/templates/wsgi-openstack-api.conf index 6c4e37e40..de5f603fc 100644 --- a/charmhelpers/contrib/openstack/templates/wsgi-openstack-api.conf +++ b/charmhelpers/contrib/openstack/templates/wsgi-openstack-api.conf @@ -12,6 +12,12 @@ Listen {{ admin_port }} Listen {{ public_port }} {% endif -%} +{% if wsgi_socket_rotation -%} +WSGISocketRotation On +{% else -%} +WSGISocketRotation Off +{% endif -%} + {% if port -%} WSGIDaemonProcess {{ service_name }} processes={{ processes }} threads={{ threads }} user={{ user }} group={{ group }} \ diff --git a/charmhelpers/fetch/snap.py b/charmhelpers/fetch/snap.py index 36d6bce9a..231e4fded 100644 --- a/charmhelpers/fetch/snap.py +++ b/charmhelpers/fetch/snap.py @@ -52,7 +52,7 @@ def _snap_exec(commands): :param commands: List commands :return: Integer exit code """ - assert type(commands) == list + assert type(commands) is list retry_count = 0 return_code = None diff --git a/tests/contrib/openstack/test_os_contexts.py b/tests/contrib/openstack/test_os_contexts.py index fde43dc0e..ca21d15c7 100644 --- a/tests/contrib/openstack/test_os_contexts.py +++ b/tests/contrib/openstack/test_os_contexts.py @@ -3295,7 +3295,9 @@ def test_loglevel_context_unset(self): @patch.object(context, '_calculate_workers') def test_wsgi_worker_config_context(self, _calculate_workers): - self.config.return_value = 2 # worker-multiplier=2 + self.config.side_effect = fake_config({ + 'worker-multiplier': 2, 'non-defined-wsgi-socket-rotation': True + }) _calculate_workers.return_value = 8 service_name = 'service-name' script = '/usr/bin/script' @@ -3312,13 +3314,16 @@ def test_wsgi_worker_config_context(self, "admin_processes": 2, "public_processes": 6, "threads": 1, + "wsgi_socket_rotation": True, } self.assertEqual(expect, ctxt()) @patch.object(context, '_calculate_workers') def test_wsgi_worker_config_context_user_and_group(self, _calculate_workers): - self.config.return_value = 1 + self.config.side_effect = fake_config({ + 'worker-multiplier': 1, 'wsgi-socket-rotation': False + }) _calculate_workers.return_value = 1 service_name = 'service-name' script = '/usr/bin/script' @@ -3339,6 +3344,7 @@ def test_wsgi_worker_config_context_user_and_group(self, "admin_processes": 1, "public_processes": 1, "threads": 1, + "wsgi_socket_rotation": False, } self.assertEqual(expect, ctxt())